13 #include <boost/property_tree/json_parser.hpp>
15 #include <boost/filesystem.hpp>
22 std::vector<double> hypervolRef,
27 "We shouldn't get here!");
32 std::shared_ptr<SamplingMethod>
39 , sampleMethods_m(sampleMethods)
42 , objectives_m(objectives)
48 std::string resultFile = args->getArg<std::string>(
"outfile",
"output",
false);
49 std::string resultDir = args->getArg<std::string>(
"outdir",
"samples",
false);
52 std::ostringstream filename;
53 filename << resultDir <<
"/" << resultFile
57 if ( !boost::filesystem::exists(resultDir) ) {
58 boost::filesystem::create_directory(resultDir);
64 std::pair<double, double>
65 (boost::get<LOWER_BOUND>(itr->second),
66 boost::get<UPPER_BOUND>(itr->second)));
80 int nMasters =
args_->getArg<
int>(
"num-masters",
true);
84 "More masters than samples.");
88 int rest =
nSamples_m - nMasters * nLocSamples;
114 unsigned int jid =
static_cast<unsigned int>(length);
115 typename std::map<size_t, boost::shared_ptr<Individual_t> >
::iterator it;
119 std::cout <<
"NON-EXISTING JOB with ID = " << jid <<
std::endl;
125 boost::shared_ptr<Individual_t> ind = it->second;
130 ind->objectives.clear();
133 for(; itr != res.end(); ++itr) {
135 if(!itr->second.is_valid || (itr->second.value.size() > 1 && !itr->second.value[0])) {
136 ind->objectives.push_back(std::numeric_limits<double>::infinity());
139 if(itr->second.value.size() == 1)
140 ind->objectives.push_back(itr->second.value[0]);
153 std::cout <<
"(Sampler) Error: unexpected MPI_TAG: "
173 std::vector<std::string> dNames;
177 std::string dName = boost::get<VAR_NAME>(itr->second);
178 dNames.push_back(dName);
181 boost::shared_ptr<Individual_t> ind = boost::shared_ptr<Individual_t>(
new Individual_t(dNames));
186 std::string dName = boost::get<VAR_NAME>(itr->second);
187 int i = ind->getIndex(dName);
197 namespace pt = boost::property_tree;
201 tree.put(
"name",
"sampler");
210 std::string dvar = boost::get<VAR_NAME>(itr->second);
211 bounds <<
"[ " << it->first <<
", " << it->second <<
" ]";
212 tree.put(
"dvar-bounds." + dvar, bounds.str());
226 namespace pt = boost::property_tree;
233 if ( tree.get_optional<std::string>(
"samples") ) {
237 samples = tree.get_child(
"samples");
238 tree.erase(
"samples");
245 std::string
id = std::to_string(ind.
id);
249 std::string
name = boost::get<VAR_NAME>(itr->second);
251 samples.put(
id +
".dvar." + name, ind.
genes[i]);
257 for(
size_t i=0; i < ind.
objectives.size(); i++, expr_it++) {
258 std::string
name = expr_it->first;
261 if ( name ==
"dummy" )
264 samples.put(
id +
".obj." + name, ind.
objectives[i]);
268 tree.add_child(
"samples", samples);
269 boost::property_tree::write_json(
jsonFname_m, tree);
329 std::string dName = boost::get<VAR_NAME>(itr->second);
330 int i = ind->getIndex(dName);
332 std::pair<std::string, double>
333 (dName, ind->genes[i]));
336 size_t jid =
static_cast<size_t>(ind->id);
348 std::pair<
size_t, boost::shared_ptr<Individual_t> >(jid, ind));
std::map< std::string, reqVarInfo_t > reqVarContainer_t
SampleIndividual Individual_t
DVarContainer_t dvars_m
design variables
virtual void initialize()
Initialization and start algorithm.
void dumpIndividualsToJSON()
void dispatch_forward_solves()
CmdArguments_t args_
command line arguments specified by the user
boost::shared_ptr< CmdArguments > CmdArguments_t
std::map< std::string, std::shared_ptr< SamplingMethod > > sampleMethods_m
std::map< size_t, boost::shared_ptr< Individual_t > > jobmapping_m
mapping from unique job ID to individual
#define MPI_OPT_CONVERGED_TAG
optimizer notifies pilot that optimization has converged (EXIT)
void postPoll()
executed after handling (if any) new request
Expressions::Named_t objectives_m
objectives
void bounds(const PETE_Expr< T1 > &expr, Vektor< T2, D > &minval, Vektor< T2, D > &maxval)
#define OPAL_PROJECT_NAME
std::list< Individual_t > individualsToDump_m
namedVariableCollection_t Param_t
bool onMessage(MPI_Status status, size_t length)
Sampler(Expressions::Named_t objectives, Expressions::Named_t constraints, DVarContainer_t dvars, size_t dim, Comm::Bundle_t comms, CmdArguments_t args, std::vector< double > hypervolRef, int nrWorkerGroups)
An abstract class defining the interface for all optimizer components.
int getIndex(std::string name)
int act_sample_m
current generation
#define OPAL_PROJECT_VERSION
genes_t genes
genes of an individual
std::map< std::string, DVar_t > DVarContainer_t
void MPI_Send_params(Param_t params, size_t pid, MPI_Comm comm)
std::map< std::string, Expressions::Expr_t * > Named_t
type of an expressions with a name
void createNewIndividual()
objectives_t objectives
values of objectives of an individual
void MPI_Recv_reqvars(reqVarContainer_t &reqvars, size_t pid, MPI_Comm comm)
std::string getGitRevision()
std::queue< boost::shared_ptr< Individual_t > > individuals_m
std::string::iterator iterator
bundles all communicators for a specific role/pid
void addIndividualToJSON(const boost::shared_ptr< Individual_t > &ind)
bounds_t dVarBounds_m
bounds on each specified gene
Comm::Bundle_t comms_
communicator bundle for the optimizer
std::size_t jsonDumpFreq_m
Dumps id, design variables and bound.
Inform & endl(Inform &inf)