197 namespace fs = std::filesystem;
200 opal->setOptimizerFlag();
219 funcs.insert(std::pair<std::string, client::function::type>
223 funcs.insert(std::pair<std::string, client::function::type>
227 funcs.insert(std::pair<std::string, client::function::type>
228 (
"sddsVariableAt", ff));
231 funcs.insert(std::pair<std::string, client::function::type>
235 funcs.insert(std::pair<std::string, client::function::type>
236 (
"maxNormRadialPeak", ff));
239 funcs.insert(std::pair<std::string, client::function::type>
240 (
"numberOfPeaks", ff));
243 funcs.insert(std::pair<std::string, client::function::type>
244 (
"sumErrSqRadialPeak", ff));
247 funcs.insert(std::pair<std::string, client::function::type>
248 (
"probVariableWithID", ff));
250 std::string fname = inputfile.stem().native();
252 funcs.insert(std::pair<std::string, client::function::type>
253 (
"statVariableAt", ff));
256 funcs.insert(std::pair<std::string, client::function::type>
261 std::vector<std::string> arguments(opal->getArguments());
262 std::vector<char*> argv;
263 std::map<unsigned int, std::string> argumentMapper({
264 {INPUT,
"inputfile"},
267 {INITIALPOPULATION,
"initialPopulation"},
268 {STARTPOPULATION,
"start-population"},
269 {NUMMASTERS,
"num-masters"},
270 {NUMCOWORKERS,
"num-coworkers"},
271 {DUMPDAT,
"dump-dat"},
272 {DUMPFREQ,
"dump-freq"},
273 {DUMPOFFSPRING,
"dump-offspring"},
274 {NUMINDGEN,
"num-ind-gen"},
275 {MAXGENERATIONS,
"maxGenerations"},
276 {EPSILON,
"epsilon"},
277 {EXPECTEDHYPERVOL,
"expected-hypervol"},
278 {CONVHVOLPROG,
"conv-hvol-prog"},
279 {ONEPILOTCONVERGE,
"one-pilot-converge"},
280 {SOLSYNCH,
"sol-synch"},
281 {GENEMUTATIONPROBABILITY,
"gene-mutation-probability"},
282 {MUTATIONPROBABILITY,
"mutation-probability"},
283 {RECOMBINATIONPROBABILITY,
"recombination-probability"},
284 {SIMBINCROSSOVERNU,
"simbin-crossover-nu"},
285 {INITIALOPTIMIZATION,
"initial-optimization"},
286 {BIRTHCONTROL,
"birth-control"},
287 {RESTART_FILE,
"restartfile"},
288 {RESTART_STEP,
"restartstep"}
291 auto it = argumentMapper.end();
292 for (
unsigned int i = 0; i <
SIZE; ++ i) {
293 if ((it = argumentMapper.find(i)) != argumentMapper.end()) {
294 std::string type =
itsAttr[i].getType();
295 if (type ==
"string") {
298 arguments.push_back(argument);
300 }
else if (type ==
"real") {
303 size_t last = val.find_last_not_of(
'0');
304 if (val[last] !=
'.') ++ last;
305 val.erase (last, std::string::npos );
306 std::string argument =
"--" + (*it).second +
"=" + val;
307 arguments.push_back(argument);
309 }
else if (type ==
"logical") {
312 arguments.push_back(argument);
320 "The argument INPUT has to be provided");
324 "The argument INITIALPOPULATION has to be provided");
328 "The argument MAXGENERATIONS has to be provided");
333 "The hypervolume reference point should have the same dimension as the objectives");
338 "No INITIAL_OPTIMIZATION possible when reading initial population from file (STARTPOPULATION)");
343 "No INITIAL_OPTIMIZATION possible with BIRTH_CONTROL");
348 if (dir.is_relative()) {
349 fs::path path = fs::path(std::string(getenv(
"PWD")));
354 if (!fs::exists(dir)) {
355 fs::create_directory(dir);
357 std::string argument =
"--simtmpdir=" + dir.native();
358 arguments.push_back(argument);
363 if (dir.is_relative()) {
364 fs::path path = fs::path(std::string(getenv(
"PWD")));
369 std::string argument =
"--templates=" + dir.native();
370 arguments.push_back(argument);
375 if (dir.is_relative()) {
376 fs::path path = fs::path(std::string(getenv(
"PWD")));
381 setenv(
"FIELDMAPS", dir.c_str(), 1);
386 if (dir.is_relative()) {
387 fs::path path = fs::path(std::string(getenv(
"PWD")));
392 setenv(
"DISTRIBUTIONS", dir.c_str(), 1);
396 for (
size_t i = 0; i < arguments.size(); ++ i) {
397 argv.push_back(
const_cast<char*
>(arguments[i].c_str()));
398 *
gmsg << arguments[i] <<
" ";
402 std::set<std::string> vars;
403 for (
const std::string &
name: dvarsstr) {
405 DVar* dvar =
dynamic_cast<DVar*
>(obj);
406 if (dvar ==
nullptr) {
408 "The design variable " +
name +
" is not known");
414 DVar_t tmp = std::make_tuple(var, lowerbound, upperbound);
416 auto ret = vars.insert(var);
417 if (ret.second ==
false) {
419 "There is already a design variable with the variable " + var +
" defined");
422 std::set<std::string> objExpressions;
423 for (
const std::string &
name: objectivesstr) {
426 if (objective ==
nullptr) {
428 "The objective " +
name +
" is not known");
433 auto ret = objExpressions.insert(expr);
434 if (ret.second ==
false) {
436 "There is already a objective with the expression " + expr +
" defined");
439 std::set<std::string> constraintExpressions;
440 for (
const std::string &
name: constraintsstr) {
443 if (constraint ==
nullptr) {
445 "The constraint " +
name +
" is not known");
450 auto ret = constraintExpressions.insert(expr);
451 if (ret.second ==
false) {
453 "There is already a constraint with the expression " + expr +
" defined");
459 size_t pos = tmplFile.find_last_of(
"/");
460 if(pos != std::string::npos)
461 tmplFile = tmplFile.substr(pos+1);
462 pos = tmplFile.find(
".");
463 tmplFile = tmplFile.substr(0,pos);
466 std::ifstream infile(tmplFile.c_str());
468 std::map<std::string, short> dvarCheck;
469 for (
auto itr = dvars.begin(); itr != dvars.end(); ++ itr) {
470 dvarCheck.insert(std::make_pair(std::get<0>(itr->second), 0));
473 while(infile.good()) {
475 std::getline(infile, line,
'\n');
478 for(
auto &check: dvarCheck) {
479 pos = line.find(
"_" + check.first +
"_");
480 if (pos != std::string::npos &&
481 dvarCheck.find(check.first) != dvarCheck.end()) {
482 dvarCheck.at(check.first) = 1;
488 for (
auto itr = dvarCheck.begin(); itr != dvarCheck.end(); ++ itr) {
489 if (itr->second == 0) {
491 "Couldn't find the design variable '" + itr->first +
"' in '" + tmplFile +
"'!");
501 this->
run(args, funcs, dvars, objectives, constraints);
504 std::cout <<
"Exception caught: " << e.what() << std::endl;
505 MPI_Abort(MPI_COMM_WORLD, -100);
567 std::shared_ptr<Comm_t> comm(
new Comm_t(args, MPI_COMM_WORLD));
568 if (comm->isWorker())
584 const std::unique_ptr<pilot_t>
pi(
new pilot_t(
585 args, comm, funcs, dvars, objectives, constraints,
587 true, userVariables));
595 const std::unique_ptr<pilot_t>
pi(
new pilot_t(
596 args, comm, funcs, dvars, objectives, constraints,
598 true, userVariables));
613 const std::unique_ptr<pilot_t>
pi(
new pilot_t(
614 args, comm, funcs, dvars, objectives, constraints,
616 true, userVariables));
624 const std::unique_ptr<pilot_t>
pi(
new pilot_t(
625 args, comm, funcs, dvars, objectives, constraints,
627 true, userVariables));
642 const std::unique_ptr<pilot_t>
pi(
new pilot_t(
643 args, comm, funcs, dvars, objectives, constraints,
645 true, userVariables));
653 const std::unique_ptr<pilot_t>
pi(
new pilot_t(
654 args, comm, funcs, dvars, objectives, constraints,
656 true, userVariables));
671 const std::unique_ptr<pilot_t>
pi(
new pilot_t(
672 args, comm, funcs, dvars, objectives, constraints,
674 true, userVariables));
682 const std::unique_ptr<pilot_t>
pi(
new pilot_t(
683 args, comm, funcs, dvars, objectives, constraints,
685 true, userVariables));
695 "No such cross over and mutation combination supported.");
698 if (comm->isWorker())