示例#1
0
void SaveISISNexus::instrument() {
  NXmakegroup(handle, "instrument", "NXinstrument");
  NXopengroup(handle, "instrument", "NXinstrument");
  saveCharOpen("name", &m_isisRaw->i_inst, 8);
  putAttr("short_name", m_isisRaw->hdr.inst_abrv, 3);
  close();
  dae();
  detector_1();
  moderator();
  source();
  NXclosegroup(handle);
}
示例#2
0
VfsPath CColladaManager::GetLoadableFilename(const VfsPath& pathnameNoExtension, FileType type)
{
	std::wstring extn;
	switch (type)
	{
	case PMD: extn = L".pmd"; break;
	case PSA: extn = L".psa"; break;
		// no other alternatives
	}

	/*

	If there is a .dae file:
		* Calculate a hash to identify it.
		* Look for a cached .pmd file matching that hash.
		* If it exists, load it. Else, convert the .dae into .pmd and load it.
	Otherwise, if there is a (non-cache) .pmd file:
		* Load it.
	Else, fail.

	The hash calculation ought to be fast, since normally (during development)
	the .dae file will exist but won't have changed recently and so the cache
	would be used. Hence, just hash the file's size, mtime, and the converter
	version number (so updates of the converter can cause regeneration of .pmds)
	instead of the file's actual contents.

	TODO (maybe): The .dae -> .pmd conversion may fail (e.g. if the .dae is
	invalid or unsupported), but it may take a long time to start the conversion
	then realise it's not going to work. That will delay the loading of the game
	every time, which is annoying, so maybe it should cache the error message
	until the .dae is updated and fixed. (Alternatively, avoid having that many
	broken .daes in the game.)

	*/

	// (TODO: the comments and variable names say "pmd" but actually they can
	// be "psa" too.)

	VfsPath dae(pathnameNoExtension.ChangeExtension(L".dae"));
	if (! VfsFileExists(dae))
	{
		// No .dae - got to use the .pmd, assuming there is one
		return pathnameNoExtension.ChangeExtension(extn);
	}

	// There is a .dae - see if there's an up-to-date cached copy

	FileInfo fileInfo;
	if (g_VFS->GetFileInfo(dae, &fileInfo) < 0)
	{
		// This shouldn't occur for any sensible reasons
		LOGERROR(L"Failed to stat DAE file '%ls'", dae.string().c_str());
		return VfsPath();
	}

	// Build a struct of all the data we want to hash.
	// (Use ints and not time_t/off_t because we don't care about overflow
	// but do care about the fields not being 64-bit aligned)
	// (Remove the lowest bit of mtime because some things round it to a
	// resolution of 2 seconds)
#pragma pack(push, 1)
	struct { int version; int mtime; int size; } hashSource
		= { COLLADA_CONVERTER_VERSION, (int)fileInfo.MTime() & ~1, (int)fileInfo.Size() };
	cassert(sizeof(hashSource) == sizeof(int) * 3); // no padding, because that would be bad
#pragma pack(pop)

	// Calculate the hash, convert to hex
	u32 hash = fnv_hash(static_cast<void*>(&hashSource), sizeof(hashSource));
	wchar_t hashString[9];
	swprintf_s(hashString, ARRAY_SIZE(hashString), L"%08x", hash);
	std::wstring extension(L"_");
	extension += hashString;
	extension += extn;

	// realDaePath_ is "[..]/mods/whatever/art/meshes/whatever.dae"
	OsPath realDaePath_;
	Status ret = g_VFS->GetRealPath(dae, realDaePath_);
	ENSURE(ret == INFO::OK);
	wchar_t realDaeBuf[PATH_MAX];
	wcscpy_s(realDaeBuf, ARRAY_SIZE(realDaeBuf), realDaePath_.string().c_str());
	std::replace(realDaeBuf, realDaeBuf+ARRAY_SIZE(realDaeBuf), '\\', '/');
	const wchar_t* realDaePath = wcsstr(realDaeBuf, L"mods/");

	// cachedPmdVfsPath is "cache/mods/whatever/art/meshes/whatever_{hash}.pmd"
	VfsPath cachedPmdVfsPath = VfsPath("cache") / realDaePath;
	cachedPmdVfsPath = cachedPmdVfsPath.ChangeExtension(extension);

	// If it's not in the cache, we'll have to create it first
	if (! VfsFileExists(cachedPmdVfsPath))
	{
		if (! m->Convert(dae, cachedPmdVfsPath, type))
			return L""; // failed to convert
	}

	return cachedPmdVfsPath;
}
示例#3
0
int main ( int argc, char* argv[] )
{
    // WALLOCK TIME COUNTER
    eo::mpi::Node::init( argc, argv );
    time_t time_start = std::time(NULL);

    /**************
     * PARAMETERS *
     **************/

    // EO
    eoParser parser(argc, argv);
    make_verbose(parser);
    make_parallel(parser);
    
    eoState state;
    
    // log some EO parameters
    eo::log << eo::logging << "Parameters:" << std::endl;
    eo::log << eo::logging << FORMAT_LEFT_FILL_W_PARAM << "verbose" << eo::log.getLevelSelected() << std::endl;
    eo::log << eo::logging << FORMAT_LEFT_FILL_W_PARAM << "parallelize-loop" << eo::parallel.isEnabled() << std::endl;
    eo::log << eo::logging << FORMAT_LEFT_FILL_W_PARAM << "parallelize-dynamic" << eo::parallel.isDynamic() << std::endl;
    eo::log << eo::logging << FORMAT_LEFT_FILL_W_PARAM << "parallelize-prefix" << eo::parallel.prefix() << std::endl;
    eo::log << eo::logging << FORMAT_LEFT_FILL_W_PARAM << "parallelize-nthreads" << eo::parallel.nthreads() << std::endl;


    // GENERAL PARAMETERS
    // createParam (ValueType _defaultValue, std::string _longName, std::string _description, char _shortHand=0, std::string _section="", bool _required=false)
    std::string domain = parser.createParam( (std::string)"domain-zeno-time.pddl", "domain", "PDDL domain file", 'D', "Problem", true ).value();
    eo::log << eo::logging << FORMAT_LEFT_FILL_W_PARAM << "domain" << domain << std::endl;

    std::string instance = parser.createParam( (std::string)"zeno10.pddl", "instance", "PDDL instance file", 'I', "Problem", true ).value();
    eo::log << eo::logging << FORMAT_LEFT_FILL_W_PARAM << "instance" << instance << std::endl;

    std::string plan_file = parser.createParam( (std::string)"plan.soln", "plan-file", "Plan file backup", 'F', "Misc" ).value();
    eo::log << eo::logging << FORMAT_LEFT_FILL_W_PARAM << "plan-file" << plan_file << std::endl;

    // pop size
    unsigned int pop_size = parser.createParam( (unsigned int)100, "popSize", "Population Size", 'P', "Evolution Engine").value();
    eo::log << eo::logging << FORMAT_LEFT_FILL_W_PARAM << "pop_size" << pop_size << std::endl;

    // multi-start
    unsigned int maxruns = parser.createParam( (unsigned int)0, "runs-max", 
            "Maximum number of runs, if x==0: unlimited multi-starts, if x>1: will do <x> multi-start", 'r', "Stopping criterions" ).value();
    eo::log << eo::logging << FORMAT_LEFT_FILL_W_PARAM << "maxruns" << maxruns << std::endl;

    // b_max estimation
    bool insemination = parser.createParam(true, "insemination", "Use the insemination heuristic to estimate b_max at init", '\0', "Initialization").value();

    // seed
    eoValueParam<unsigned int> & param_seed = parser.createParam( (unsigned int)0, "seed", "Random number seed", 'S' );
    // if one want to initialize on current time
    if ( param_seed.value() == 0) {
        // change the parameter itself, that will be dumped in the status file
      //        param_seed.value( time(0) );
      param_seed.value()=time(0); // EO compatibility fixed by CC on 2010.12.24
    }
    unsigned int seed = param_seed.value();
    rng.reseed( seed );
    eo::log << eo::logging << FORMAT_LEFT_FILL_W_PARAM << "seed" << seed << std::endl;

    // Parameters makers
    daex::do_make_eval_param( parser );
    daex::do_make_init_param( parser );
    daex::do_make_variation_param( parser, pop_size);
    daex::do_make_checkpoint_param( parser );
    daex::do_make_replace_param( parser );

    // special case of stopping criteria parameters
    daex::do_make_continue_param( parser )    ;
    // Those parameters are needed during restarts (see below)
    unsigned int mingen = parser.valueOf<unsigned int>("gen-min");
    unsigned int steadygen = parser.valueOf<unsigned int>("gen-steady");
    unsigned int maxgens = parser.valueOf<unsigned int>("gen-max");

    make_help( parser );


    /***********
     * PARSING *
     ***********/

    // PDDL
#ifndef NDEBUG
    eo::log << eo::progress << "Load the instance..." << std::endl;
    eo::log.flush();
#endif
    
    daex::pddlLoad pddl( domain, instance, SOLVER_YAHSP, HEURISTIC_H1, eo::parallel.nthreads(), std::vector<std::string>());
   
#ifndef NDEBUG
    eo::log << eo::progress << "Load the instance...OK" << std::endl;
    eo::log << eo::progress << "Initialization...";
    eo::log.flush();
#endif


    /******************
     * INITIALIZATION *
     ******************/

    daex::Init<daex::Decomposition>& init = daex::do_make_init_op<daex::Decomposition>( parser, state, pddl );
    daex::Goal::atoms( & pddl.atoms() );

    // randomly generate the population with the init operator
    eoPop<daex::Decomposition> pop = eoPop<daex::Decomposition>( pop_size, init );
    // eoPop<daex::Decomposition> pop = eoPop<daex::Decomposition>( 10, init );

    // used to pass the eval count through the several eoEvalFuncCounter evaluators
    unsigned int eval_count = 0;
    
    TimeVal best_makespan = MAXTIME;

#ifndef SINGLE_EVAL_ITER_DUMP
    std::string dump_sep = ".";
    unsigned int dump_file_count = 1;
    std::string metadata = "domain " + domain + "\n" + IPC_PLAN_COMMENT + "instance " + instance;
#endif

    unsigned int b_max_fixed = parser.valueOf<unsigned int>("bmax-fixed");
    if( b_max_fixed == 0 ) {
        // b_max_fixed = 2048; // 128
        b_max_fixed = daex::estimate_bmax_insemination( parser, pddl, pop, init.l_max() );
    }

    unsigned b_max_in = b_max_fixed;
    double b_max_last_weight = parser.valueOf<double>("bmax-last-weight");
    unsigned int b_max_last = static_cast<unsigned int>( std::floor( b_max_in * b_max_last_weight ) );
#ifndef NDEBUG
    eo::log << eo::logging << std::endl << "\tb_max for intermediate goals, b_max_in: "   << b_max_in   << std::endl;
    eo::log << eo::logging              << "\tb_max for        final goal,  b_max_last: " << b_max_last << std::endl;
#endif

    /**************
     * EVALUATION *
     **************/

#ifndef NDEBUG
    eo::log << eo::progress << "Creating evaluators...";
    eo::log.flush();
#endif

    // do_make_eval returns a pair: the evaluator instance 
    // and a pointer on a func counter that may be null of we are in release mode
    std::pair< eoEvalFunc<daex::Decomposition>&, eoEvalFuncCounter<daex::Decomposition>* > eval_pair
        = daex::do_make_eval_op<daex::Decomposition>(
                parser, state, init.l_max(), eval_count, b_max_in, b_max_last, plan_file, best_makespan, dump_sep, dump_file_count, metadata
            );
    eoEvalFunc<daex::Decomposition>& eval = eval_pair.first;

#ifndef NDEBUG
    // in debug mode, we should have a func counter
    assert( eval_pair.second != NULL );
    eoEvalFuncCounter<daex::Decomposition>& eval_counter = * eval_pair.second;

    eo::log << eo::progress << "OK" << std::endl;
    
    eo::log << eo::progress << "Evaluating the first population...";
    eo::log.flush();
#endif

    // a first evaluation of generated pop
    eoPopLoopEval<daex::Decomposition> pop_eval( eval );
    pop_eval( pop, pop );

#ifndef NDEBUG
    eo::log << eo::progress << "OK" << std::endl;
#endif


    /********************
     * EVOLUTION ENGINE *
     ********************/

#ifndef NDEBUG
    eo::log << eo::progress << "Algorithm instanciation...";
    eo::log.flush();
#endif

    // STOPPING CRITERIA
    eoCombinedContinue<daex::Decomposition> continuator = daex::do_make_continue_op<daex::Decomposition>( parser, state );
    
    // Direct access to continuators are needed during restarts (see below)
    eoSteadyFitContinue<daex::Decomposition> & steadyfit 
        = *( dynamic_cast<eoSteadyFitContinue<daex::Decomposition>* >( continuator[0] ) );
    eoGenContinue<daex::Decomposition> & maxgen 
        = *( dynamic_cast< eoGenContinue<daex::Decomposition>* >( continuator[1] ) );


    // CHECKPOINTING 
    eoCheckPoint<daex::Decomposition> & checkpoint = daex::do_make_checkpoint_op( continuator, parser, state, pop
#ifndef NDEBUG
        , eval_counter
#endif
    );

    // SELECTION AND VARIATION
    // daex::MutationDelGoal<daex::Decomposition> delgoal; // FIXME Erreur de segmentation ici : delgoal devrait être un pointeur alloué.
    daex::MutationDelGoal<daex::Decomposition>* delgoal = new daex::MutationDelGoal<daex::Decomposition>;
    eoGeneralBreeder<daex::Decomposition> & breed = daex::do_make_variation_op<daex::Decomposition>( parser, state, pddl, delgoal );

    // REPLACEMENT
    eoReplacement<daex::Decomposition> & replacor = daex::do_make_replace_op<daex::Decomposition>( parser, state );
    unsigned int offsprings = parser.valueOf<unsigned int>("offsprings");

    // ALGORITHM
    eoEasyEA<daex::Decomposition> dae( checkpoint, eval, breed, replacor, offsprings );

#ifndef NDEBUG
    eo::log << eo::progress << "OK" << std::endl;
    //eo::log << eo::progress << "Note: dual fitness is printed as two numbers: a value followed by a boolean (0=unfeasible, 1=feasible)" << std::endl;
    eo::log.flush();
    eo::log << eo::debug << "Legend: \n\t- already valid, no eval\n\tx plan not found\n\t* plan found\n\ta add atom\n\tA add goal\n\td delete atom\n\tD delete goal\n\tC crossover" << std::endl;
#endif


    /********************
     * MULTI-START RUNS *
     ********************/

    // best decomposition of all the runs, in case of multi-start
    // start at the best element of the init
    daex::Decomposition best = pop.best_element();

    std::cout << "[Bench] Beginning serialization..." << std::endl;


    daex::Decomposition read;
    // Serializes in json
    int benchNb = 10;

    std::stringstream ss;
    eoserial::Object* jsonBest;
    time_t before_serialize = time(0);
    for (int i = 0; i < benchNb; ++i)
    {
        jsonBest = best.pack();

        ss.clear();
        ss.str(std::string());
        jsonBest->print( ss );

        delete jsonBest;
    }
    // std::cout<< "\n\n" << jsonBest << std::endl;
    time_t after_serialize = time(0);
    std::cout << "[Bench] Serialization took " << after_serialize - before_serialize << " seconds." << std::endl;
    
    std::cout<< "\n\nParsing..." << std::endl;

    time_t before_deserialize = time(0);
    for (int i = 0; i < benchNb; ++i)
    {
        eoserial::Object* received = eoserial::Parser::parse( ss.str() );

        // Deserializes from json
        read.unpack( received );

        delete received;
    }
    time_t after_deserialize = time(0);
    
    // std::cout<<"\n\nParsing finished, this is what I read :" << std::endl;
    // std::cout << received << std::endl;
    std::cout << "[Bench] Deserialization took " << after_deserialize - before_deserialize << " seconds." << std::endl;
    std::cout << "\n\nEnd of main, test is finished.\n" << std::endl;
}
示例#4
0
文件: testDAE.cpp 项目: einsnull/DAE
int main()
{
	//learning rate
	double alpha = 0.03;
	int maxIter = 15000;
	int miniBatchSize = 1000;
	double noiseRatio = 0.3;
	int inputSize = 28*28;
	int hiddenSize = 28;
	int imgWidth = 8; 
	char *fileBuf  = new char[4096];
	bool ret = loadFileToBuf("ParamConfig.ini",fileBuf,4096);
	if(ret)
	{
		getConfigDoubleValue(fileBuf,"noiseRatio:",noiseRatio);
		getConfigDoubleValue(fileBuf,"alpha:",alpha);
		getConfigIntValue(fileBuf,"maxIter:",maxIter);
		getConfigIntValue(fileBuf,"miniBatchSize:",miniBatchSize);
		getConfigIntValue(fileBuf,"hiddenSize:",hiddenSize);
		getConfigIntValue(fileBuf,"inputSize:",inputSize);
		getConfigIntValue(fileBuf,"imgWidth:",imgWidth);
		cout << "noiseRatio:" << noiseRatio << endl;
		cout << "alpha:" << alpha << endl;
		cout << "maxIter:" << maxIter << endl;
		cout << "miniBatchSize:" << miniBatchSize << endl;
		cout << "hiddenSize:" << hiddenSize << endl;
		cout << "inputSize:" << inputSize << endl;
		cout << "imgWidth:" << imgWidth << endl;
	}
	delete []fileBuf;

	//set eigen threads
	SYSTEM_INFO info;
	GetSystemInfo(&info);
	Eigen::setNbThreads(info.dwNumberOfProcessors);

	MatrixXd trainData(1,inputSize);
	DAE dae(inputSize,hiddenSize);
	ret = loadMnistData(trainData,"mnist\\train-images-idx3-ubyte");
	cout << "Loading training data..." << endl;
	if(ret == false)
	{
		return -1;
	}
	clock_t start = clock();
	//cout << trainData.rows() << " " << trainData.cols() << endl; 
	MatrixXd showImage = trainData.leftCols(100).transpose();
	buildImage(showImage,imgWidth,"data.jpg");
	dae.train(trainData,noiseRatio,alpha,maxIter,miniBatchSize);
	cout << "End Train" << endl;
	MatrixXd hiddenTheta = dae.getTheta();
	buildImage(hiddenTheta,imgWidth,"weights.jpg",true);
	cout << "Saving hidden neurons" << endl;
	dae.saveModel("DAE_Model.txt");
	clock_t end = clock();
	cout << "The code ran for " << (end - start)/(double)(CLOCKS_PER_SEC*60)
		<< " minutes on " << Eigen::nbThreads() << " thread(s)." << endl;
	cout << "noiseRatio: " << noiseRatio << endl;
	cout << "alpha: " << alpha << endl;
	cout << "miniBatchSize: " << miniBatchSize << endl;
	system("pause");
	return 0;
}