34#include <boost/property_tree/json_parser.hpp>
35#include <boost/property_tree/ptree.hpp>
37#include <boost/filesystem.hpp>
49 "We shouldn't get here!");
54 std::shared_ptr<SamplingMethod>
61 , sampleMethods_m(sampleMethods)
64 , objectives_m(objectives)
70 std::string resultFile = args->getArg<std::string>(
"outfile",
"output",
false);
71 std::string resultDir = args->getArg<std::string>(
"outdir",
"samples",
false);
74 std::ostringstream filename;
75 filename << resultDir <<
"/" << resultFile
79 if ( !boost::filesystem::exists(resultDir) ) {
80 boost::filesystem::create_directory(resultDir);
86 std::pair<double, double>
87 (boost::get<LOWER_BOUND>(itr->second),
88 boost::get<UPPER_BOUND>(itr->second)));
102 int nMasters =
args_->getArg<
int>(
"num-masters",
true);
106 "More masters than samples.");
110 int rest =
nSamples_m - nMasters * nLocSamples;
136 unsigned int jid =
static_cast<unsigned int>(length);
137 typename std::map<size_t, boost::shared_ptr<Individual_t> >
::iterator it;
141 std::cout <<
"NON-EXISTING JOB with ID = " << jid <<
std::endl;
147 boost::shared_ptr<Individual_t> ind = it->second;
152 ind->objectives.clear();
155 for(; itr != res.end(); ++itr) {
157 if(!itr->second.is_valid || (itr->second.value.size() > 1 && !itr->second.value[0])) {
158 ind->objectives.push_back(std::numeric_limits<double>::infinity());
161 if(itr->second.value.size() == 1)
162 ind->objectives.push_back(itr->second.value[0]);
175 std::cout <<
"(Sampler) Error: unexpected MPI_TAG: "
195 std::vector<std::string> dNames;
199 std::string dName = boost::get<VAR_NAME>(itr->second);
200 dNames.push_back(dName);
203 boost::shared_ptr<Individual_t> ind = boost::shared_ptr<Individual_t>(
new Individual_t(dNames));
208 std::string dName = boost::get<VAR_NAME>(itr->second);
209 int i = ind->getIndex(dName);
219 namespace pt = boost::property_tree;
223 tree.put(
"name",
"sampler");
232 std::string dvar = boost::get<VAR_NAME>(itr->second);
233 bounds <<
"[ " << it->first <<
", " << it->second <<
" ]";
234 tree.put(
"dvar-bounds." + dvar,
bounds.str());
248 namespace pt = boost::property_tree;
255 if ( tree.get_optional<std::string>(
"samples") ) {
259 samples = tree.get_child(
"samples");
260 tree.erase(
"samples");
267 std::string
id = std::to_string(ind.
id);
271 std::string
name = boost::get<VAR_NAME>(itr->second);
273 samples.put(
id +
".dvar." +
name, ind.
genes[i]);
279 for(
size_t i=0; i < ind.
objectives.size(); i++, expr_it++) {
280 std::string
name = expr_it->first;
283 if (
name ==
"dummy" )
290 tree.add_child(
"samples", samples);
291 boost::property_tree::write_json(
jsonFname_m, tree);
351 std::string dName = boost::get<VAR_NAME>(itr->second);
352 int i = ind->getIndex(dName);
354 std::pair<std::string, double>
355 (dName, ind->genes[i]));
358 size_t jid =
static_cast<size_t>(ind->id);
370 std::pair<
size_t, boost::shared_ptr<Individual_t> >(jid, ind));
#define OPAL_PROJECT_VERSION
#define OPAL_PROJECT_NAME
void bounds(const PETE_Expr< T1 > &expr, Vektor< T2, D > &minval, Vektor< T2, D > &maxval)
Inform & endl(Inform &inf)
#define MPI_OPT_CONVERGED_TAG
optimizer notifies pilot that optimization has converged (EXIT)
void MPI_Send_params(Param_t params, size_t pid, MPI_Comm comm)
void MPI_Recv_reqvars(reqVarContainer_t &reqvars, size_t pid, MPI_Comm comm)
std::map< std::string, DVar_t > DVarContainer_t
std::map< std::string, reqVarInfo_t > reqVarContainer_t
namedVariableCollection_t Param_t
boost::shared_ptr< CmdArguments > CmdArguments_t
std::map< std::string, Expressions::Expr_t * > Named_t
type of an expressions with a name
std::string::iterator iterator
std::string getGitRevision()
genes_t genes
genes of an individual
int getIndex(std::string name)
objectives_t objectives
values of objectives of an individual
SampleIndividual Individual_t
std::map< size_t, boost::shared_ptr< Individual_t > > jobmapping_m
mapping from unique job ID to individual
bool onMessage(MPI_Status status, size_t length)
void postPoll()
executed after handling (if any) new request
void dispatch_forward_solves()
std::list< Individual_t > individualsToDump_m
Expressions::Named_t objectives_m
objectives
virtual void initialize()
Initialization and start algorithm.
std::size_t jsonDumpFreq_m
Dumps id, design variables and bound.
Comm::Bundle_t comms_
communicator bundle for the optimizer
std::map< std::string, std::shared_ptr< SamplingMethod > > sampleMethods_m
DVarContainer_t dvars_m
design variables
std::queue< boost::shared_ptr< Individual_t > > individuals_m
void dumpIndividualsToJSON()
CmdArguments_t args_
command line arguments specified by the user
int act_sample_m
current generation
void addIndividualToJSON(const boost::shared_ptr< Individual_t > &ind)
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)
void createNewIndividual()
bounds_t dVarBounds_m
bounds on each specified gene
bundles all communicators for a specific role/pid