ompl::tools::SelfConfig::SelfConfig(const base::SpaceInformationPtr &si, const std::string &context) :
    context_(context.empty() ? "" : context + ": ")
{
    typedef std::map<base::SpaceInformation*, boost::shared_ptr<SelfConfigImpl> > ConfigMap;

    static ConfigMap    SMAP;
    static boost::mutex LOCK;

    boost::mutex::scoped_lock smLock(LOCK);

    // clean expired entries from the map
    ConfigMap::iterator dit = SMAP.begin();
    while (dit != SMAP.end())
    {
        if (dit->second->expired())
            SMAP.erase(dit++);
        else
          ++dit;
    }

    ConfigMap::const_iterator it = SMAP.find(si.get());

    if (it != SMAP.end())
        impl_ = it->second.get();
    else
    {
        impl_ = new SelfConfigImpl(si);
        SMAP[si.get()].reset(impl_);
    }
}
Beispiel #2
0
 static void dumpConfigMapToYaml(YAML::Emitter &emitter,
                                 const ConfigMap &configMap) {
   emitter << YAML::BeginMap;
   ConfigMap::const_iterator it;
   for(it = configMap.begin(); it != configMap.end(); ++it) {
     emitter << YAML::Key << it->first;
     if(!(emitter.good())) {
       fprintf(stderr, "problem with ConfigMap for: %s\n", it->first.c_str());
     }
     emitter << YAML::Value;
     dumpConfigVectorToYaml(emitter, it->second);
   }
   emitter << YAML::EndMap;
 }
Beispiel #3
0
/* mainFunction method {{{ */
int mainFunction(ConfigMap &config) {
    if(config.find("general::equation")==config.end()) {
        cerr << "[E] No problem defined!" << endl;
        return -1;
    }
    cerr << "[I] Initializing problem...\n";
    Expression *eqn=parseString(config["general::equation"]);
    Expression *pot=parseString(config["general::potential"]);
    cerr << "[I] Equation: " << eqn << endl;
    cerr << "[I] Potential: " << pot << endl;
    VarDef params;
    cerr << "[I] Getting parameters:\n";
    for(ConfigMap::iterator it=config.begin();it!=config.end();it++) {
        if((it->first).find("parameters::")!=string::npos) {
            string name=(it->first).substr(12);
            params[name]=parseString(it->second);
            cerr << "[I]\t" << name << "=" << it->second << "\n";
        }
    }
    cerr.flush();
    eqn=eqn->simplify(params);
    pot=pot->simplify(params);
    GPE *gpe=0;
    if(pot->find("X")) {
        if(pot->find("Y")) {
            if(pot->find("Z")) {
                if(eqn->find("LZ"))
                    gpe=new GPE3DROT(config,eqn,pot);
                else
                    gpe=new GPE3D(config,eqn,pot);
            } else {
                if(eqn->find("LZ"))
                    gpe=new GPE2DROT(config,eqn,pot);
                else
                    gpe=new GPE2D(config,eqn,pot);
            }
        } else
            gpe=new GPE1D(config,eqn,pot);
    } else if(eqn->find("R"))
        gpe=new Polar1D(config,eqn,pot);
    if(gpe==0) {
        cerr << "[E] Unknown problem type!" << std::endl;
        return -1;
    }
    gpe->initialize(pot);
    if(config["in"].size()>0) {
        gpe->load(config["in"]);
    }
    string out="psi1.dat";
    if(config["out"].size()>0) {
        out=config["out"];
    }
    string log="";
    if(config.find("log")!=config.end()) {
        log="log.txt";
        if(config["log"].size()>0) {
            log=config["log"];
        }
    }
    if(config.find("imprint")!=config.end()) {
        int l=getConfig(config,string("imprint"),1);
        std::cerr << "[I] Imprinting a l=" << l << " circulation" << endl;
        gpe->imprint(l);
    }
    if(config.find("groundstate")!=config.end()) {
        double dt=getConfig(config,string("general::dt"),1e-3);
        double tol=getConfig(config,string("general::tol"),1e-12);
        double dttol=getConfig(config,string("general::dttol"),0.999);
        gpe->findGroundState(dt,tol,dttol,log);
        gpe->save(out);
    }
    if(config.find("spectrum")!=config.end()) {
        range<int> def={0,0,1};
        range<int> m=getConfig(config,string("spectrum"),def);
        for(int i=m.min;i<=m.max;i+=m.incr)
            gpe->spectrum(log,i);
    }
    if(config.find("evolve")!=config.end()) {
        range<double> def={0.,1.,1e-3};
        range<double> t=getConfig(config,string("evolve"),def);
        gpe->evolve(t.min,t.incr,t.max,out);
    }
    if(config.find("plot")!=config.end()) {
        int n=5; //getConfig(config,string("plot"),0);
        gpe->plot(n,config["plot"]);
    }
    if(config.find("measure")!=config.end()) {
        std::cout << gpe->measure() << std::endl;
    }
    return 0;
};
Beispiel #4
0
void GlobalCFG::got_input(std::vector<std::string> params, std::vector<int> intparams, std::string command)
{
	if (params[0] == "help")
	{
		ng_slogout("gcfg","gcfg_list - show all global config values set");
		ng_slogout("gcfg","gcfg <name> <value> - set a global cfg value");
	}

	if (params[0] == "gcfg_list")
	{
		ng_slogout("gcfg","listing:");
		ConfigMap *cmdata = GetData();
		ConfigMap::iterator it;
		for (it=cmdata->begin(); it != cmdata->end(); it++) {
			ConfigData *entry = (*it).second;
			if (!entry) continue;

			switch (entry->GetType())
			{
				case 0:
						ng_slogout("gcfg","int %s: %d",(*it).first.c_str(),entry->GetInt());
						break;
				case 1:
						ng_slogout("gcfg","str %s: %s",(*it).first.c_str(),entry->GetStr().c_str());
						break;
				default:
						ng_slogout("gcfg","%s: <unkown type>",(*it).first.c_str());
			}
		}
	}

	if (params[0] == "gcfg")
	{
			
		if (params.size() >= 3)
		{
			if (intparams[2]!=MININT)
			{
				SetInt(params[1],intparams[2]);
			} else {
				std::string mydata;
				for( unsigned int i=2; i < params.size(); i++ )
				{
					if (i>2)
						mydata.append(" ");
					mydata.append(params[i]);
				}
				SetStr(params[1],mydata);
			}

			ConfigData *entry = GetItem(params[1]);
			if (!entry) {
				ng_slogerror("gcfg","could not set %s",params[1].c_str());
				return;
			}

			switch (entry->GetType())
			{
				case 0:
						ng_slogout("gcfg","set int %s: %d",params[1].c_str(),entry->GetInt());
						break;
				case 1:
						ng_slogout("gcfg","set str %s: %s",params[1].c_str(),entry->GetStr().c_str());
						break;
			}
		} else ng_slogout_ret("gcfg",RET_WRONG_SYNTAX,"usage: gcfg <name> <value> - set a global cfg value");
	}
}