Code indexing in gitaly is broken and leads to code not being visible to the user. We work on the issue with highest priority.

Skip to content
Snippets Groups Projects
Commit 5d045b26 authored by frey_m's avatar frey_m
Browse files

Closes #259

parent ffa5f743
No related branches found
No related tags found
No related merge requests found
......@@ -16,6 +16,12 @@
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/map.hpp>
#include "OPALconfig.h"
#include "Utilities/Util.h"
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include "Util/OptPilotException.h"
#include "Util/MPIHelper.h"
......@@ -729,88 +735,78 @@ template< template <class> class CO, template <class> class MO >
void FixedPisaNsga2<CO, MO>::dumpPopulationToJSON() {
typedef typename FixedPisaNsga2::Individual_t individual;
boost::shared_ptr<individual> temp;
std::ofstream file;
std::ostringstream filename;
filename << resultDir_m << "/" << act_gen << "_" << resultFile_m
<< "_" << comms_.island_id << ".json";
file.open(filename.str().c_str(), std::ios::out);
file << "{" << std::endl;
file << "\t" << "\"name\": " << "\"opt-pilot\"," << std::endl;
file << "\t" << "\"dvar-bounds\": {" << std::endl;
typedef boost::property_tree::ptree ptree_t;
ptree_t tree;
tree.put("name", "opt-pilot");
tree.put(OPAL_PROJECT_NAME " version", OPAL_PROJECT_VERSION);
tree.put("git revision", Util::getGitRevision());
std::stringstream bounds;
DVarContainer_t::iterator itr = dvars_m.begin();
for ( bounds_t::iterator it = dVarBounds_m.begin();
it != dVarBounds_m.end(); ++it, ++itr )
for (bounds_t::iterator it = dVarBounds_m.begin();
it != dVarBounds_m.end(); ++it, ++itr)
{
file << "\t\t\"" << boost::get<VAR_NAME>(itr->second) << "\": "
<< "[ " << it->first << ", " << it->second << " ]";
if ( it != dVarBounds_m.end() - 1 )
file << ",";
file << "\n";
std::string dvar = boost::get<VAR_NAME>(itr->second);
bounds << "[ " << it->first << ", " << it->second << " ]";
tree.put("dvar-bounds." + dvar, bounds.str());
bounds.str("");
}
file << "\t}\n\t," << std::endl;
file << "\t" << "\"constraints\": [" << std::endl;
ptree_t constraints;
for ( Expressions::Named_t::iterator it = constraints_m.begin();
it != constraints_m.end(); ++it )
{
std::string s = it->second->toString();
/// cleanup string to make json reader happy
s.erase(std::remove(s.begin(), s.end(), '"'), s.end());
file << "\t\t\"" << s << "\"";
if ( it != std::prev(constraints_m.end(), 1) )
file << ",";
file << "\n";
// 22. November 2018
// https://stackoverflow.com/questions/2114466/creating-json-arrays-in-boost-using-property-trees
ptree_t constraint;
constraint.put("", s);
constraints.push_back(std::make_pair("", constraint));
}
file << "\t]\n\t," << std::endl;
file << "\t" << "\"solutions\": " << "[" << std::endl;
tree.add_child("constraints", constraints);
boost::shared_ptr<individual> ind;
typename std::map<unsigned int, boost::shared_ptr<individual> >::iterator it;
for(it = variator_m->population()->begin();
it != variator_m->population()->end(); it++) {
if(it != variator_m->population()->begin())
file << "\t" << "," << std::endl;
file << "\t" << "{" << std::endl;
file << "\t" << "\t" << "\"ID\": " << it->first << "," << std::endl;
std::string id = std::to_string(it->first);
Expressions::Named_t::iterator expr_it;
expr_it = objectives_m.begin();
temp = it->second;
file << "\t\t\"obj\":\n" << "\t\t{\n";
for(size_t i=0; i < temp->objectives_m.size(); i++, expr_it++) {
file << "\t" << "\t" << "\t" << "\"" << expr_it->first << "\": "
<< temp->objectives_m[i];
if( i + 1 != temp->objectives_m.size())
file << ",";
file << std::endl;
ind = it->second;
for(size_t i=0; i < ind->objectives_m.size(); i++, expr_it++) {
std::string name = expr_it->first;
tree.put("population." + id + ".obj." + name, ind->objectives_m[i]);
}
file << "\t\t}\n" << "\t\t,\n" << "\t\t\"dvar\":\n" << "\t\t{\n";
size_t i = 0;
for(itr = dvars_m.begin(); itr != dvars_m.end(); ++i, ++itr) {
file << "\t\t\t\"" << boost::get<VAR_NAME>(itr->second) << "\": "
<< temp->genes_m[i];
if ( i + 1 != temp->genes_m.size())
file << ",";
file << "\n";
std::string name = boost::get<VAR_NAME>(itr->second);
tree.put("population." + id + ".dvar." + name, ind->genes_m[i]);
}
file << "\t\t}\n";
file << "\t" << "}" << std::endl;
}
std::ostringstream filename;
filename << resultDir_m << "/" << act_gen << "_" << resultFile_m
<< "_" << comms_.island_id << ".json";
file << "\t" << "]" << std::endl;
file << "}" << std::endl;
file.close();
boost::property_tree::write_json(filename.str(), tree);
}
......
  • Developer

    @adelmann and @frey_m does opt-pilot have other users than OPAL? If so then adding the OPAL revision is problematic and will break their build process!

  • Author Maintainer

    The optimizer is integrated in OPAL, thus, I do not really understand your question. I do not know if there's a standalone repo for the optimizer. There it would be still the same, of course.

  • Developer

    Even though the sources of opt-pilot are integrated into OPAL's it's still usable as a stand alone optimizer in other projects. It was integrated into the OPAL repo because @adelmann didn't want to manage several repositories.

  • snuverink_j @snuverink_j ·
    Developer

    I think this is a relevant discussion that is good to settle now. Since I think the standalone repo is somewhat outdated and should no longer be used. And now a dependency to the OPAL core has been introduced. We could use a preprocessor variable for a standalone build if there is the need.

    Perhaps @ext-kranjcevic_m is using opt-pilot standalone?

  • Developer

    Adding a preprocessor variable is easy to implement. Alternatively we write a header file from the cmake configuration file in the optimizer directory and overwrite it from the main cmake configuration file.

    Edited by kraus
  • snuverink_j @snuverink_j

    mentioned in issue #263 (closed)

    ·

    mentioned in issue #263 (closed)

    Toggle commit list
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment