Commit d196f211 authored by frey_m's avatar frey_m
Browse files

Sampler: JSON structure update #259

parent c8ac40e2
...@@ -167,9 +167,8 @@ void Sampler::createNewIndividual_m() { ...@@ -167,9 +167,8 @@ void Sampler::createNewIndividual_m() {
void Sampler::dumpIndividualsToJSON_m() { void Sampler::dumpIndividualsToJSON_m() {
boost::property_tree::ptree tree; tree_m.put("name", "sampler");
tree_m.put("version", "1.1");
tree.put("name", "sampler");
std::stringstream bounds; std::stringstream bounds;
DVarContainer_t::iterator itr = dvars_m.begin(); DVarContainer_t::iterator itr = dvars_m.begin();
...@@ -178,30 +177,26 @@ void Sampler::dumpIndividualsToJSON_m() { ...@@ -178,30 +177,26 @@ void Sampler::dumpIndividualsToJSON_m() {
{ {
std::string dvar = boost::get<VAR_NAME>(itr->second); std::string dvar = boost::get<VAR_NAME>(itr->second);
bounds << "[ " << it->first << ", " << it->second << " ]"; bounds << "[ " << it->first << ", " << it->second << " ]";
tree.put("dvar-bounds." + dvar, bounds.str()); tree_m.put("dvar-bounds." + dvar, bounds.str());
bounds.str(""); bounds.str("");
} }
tree.add_child("samples", samples_m);
std::ostringstream filename; std::ostringstream filename;
filename << resultDir_m << "/" << resultFile_m filename << resultDir_m << "/" << resultFile_m
<< "_samples.json"; << "_samples.json";
boost::property_tree::write_json(filename.str(), tree); boost::property_tree::write_json(filename.str(), tree_m);
} }
void Sampler::addIndividualToJSON_m(const boost::shared_ptr<Individual_t>& ind) { void Sampler::addIndividualToJSON_m(const boost::shared_ptr<Individual_t>& ind) {
boost::property_tree::ptree sample;
std::string id = std::to_string(ind->id);
sample.put("ID", ind->id);
DVarContainer_t::iterator itr; DVarContainer_t::iterator itr;
for(itr = dvars_m.begin(); itr != dvars_m.end(); itr++) { for(itr = dvars_m.begin(); itr != dvars_m.end(); itr++) {
std::string name = boost::get<VAR_NAME>(itr->second); std::string name = boost::get<VAR_NAME>(itr->second);
int i = ind->getIndex(name); int i = ind->getIndex(name);
sample.put("dvar." + name, ind->genes[i]); tree_m.put("samples." + id + ".dvar." + name, ind->genes[i]);
} }
Expressions::Named_t::iterator expr_it; Expressions::Named_t::iterator expr_it;
...@@ -209,10 +204,8 @@ void Sampler::addIndividualToJSON_m(const boost::shared_ptr<Individual_t>& ind) ...@@ -209,10 +204,8 @@ void Sampler::addIndividualToJSON_m(const boost::shared_ptr<Individual_t>& ind)
for(size_t i=0; i < ind->objectives.size(); i++, expr_it++) { for(size_t i=0; i < ind->objectives.size(); i++, expr_it++) {
std::string name = expr_it->first; std::string name = expr_it->first;
sample.put("obj." + name, ind->objectives[i]); tree_m.put("samples." + id + ".obj." + name, ind->objectives[i]);
} }
samples_m.push_back(std::make_pair("", sample));
} }
......
...@@ -146,7 +146,7 @@ private: ...@@ -146,7 +146,7 @@ private:
std::string resultFile_m; std::string resultFile_m;
std::string resultDir_m; std::string resultDir_m;
boost::property_tree::ptree samples_m; boost::property_tree::ptree tree_m;
void dumpIndividualsToJSON_m(); void dumpIndividualsToJSON_m();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment