OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
OptimizeCmd.cpp
Go to the documentation of this file.
1//
2// Class OptimizeCmd
3// The OptimizeCmd definition.
4// A OptimizeCmd definition is used to parse the parametes for the optimizer.
5//
6// Copyright (c) 2017, Christof Metzger-Kraus
7// All rights reserved
8//
9// This file is part of OPAL.
10//
11// OPAL is free software: you can redistribute it and/or modify
12// it under the terms of the GNU General Public License as published by
13// the Free Software Foundation, either version 3 of the License, or
14// (at your option) any later version.
15//
16// You should have received a copy of the GNU General Public License
17// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
18//
20#include "Optimize/Objective.h"
21#include "Optimize/Constraint.h"
23
27
28//#include "Utility/Inform.h"
29#include "Utility/IpplInfo.h"
30#include "Utility/IpplTimings.h"
31#include "Track/Track.h"
32
33#include "Pilot/Pilot.h"
35
43
44#include "Comm/CommSplitter.h"
48
50#include "Expression/FromFile.h"
51#include "Expression/SumErrSq.h"
59
60#include <boost/filesystem.hpp>
61
62#include <map>
63#include <set>
64#include <string>
65#include <vector>
66
67extern Inform *gmsg;
68
69namespace {
70 enum {
71 INPUT,
72 OUTPUT,
73 OUTDIR,
74 OBJECTIVES,
75 DVARS,
76 CONSTRAINTS,
77 INITIALPOPULATION,
78 STARTPOPULATION,
79 NUMMASTERS,
80 NUMCOWORKERS,
81 DUMPDAT,
82 DUMPFREQ,
83 DUMPOFFSPRING,
84 NUMINDGEN,
85 MAXGENERATIONS,
86 EPSILON,
87 EXPECTEDHYPERVOL,
88 HYPERVOLREFERENCE,
89 CONVHVOLPROG,
90 ONEPILOTCONVERGE,
91 SOLSYNCH,
92 GENEMUTATIONPROBABILITY,
93 MUTATIONPROBABILITY,
94 RECOMBINATIONPROBABILITY,
95 SIMBINCROSSOVERNU,
96 INITIALOPTIMIZATION,
97 BIRTHCONTROL,
98 SIMTMPDIR,
99 TEMPLATEDIR,
100 FIELDMAPDIR,
101 DISTDIR,
102 CROSSOVER,
103 MUTATION,
104 RESTART_FILE,
105 RESTART_STEP,
106 SIZE
107 };
108}
109
111 Action(SIZE, "OPTIMIZE",
112 "The \"OPTIMIZE\" command initiates optimization.") {
114 ("INPUT", "Path to input file");
116 ("OUTPUT", "Name used in output file generation");
118 ("OUTDIR", "Name of directory used to store generation output files");
120 ("OBJECTIVES", "List of objectives to be used");
122 ("DVARS", "List of optimization variables to be used");
124 ("CONSTRAINTS", "List of constraints to be used");
125 itsAttr[INITIALPOPULATION] = Attributes::makeReal
126 ("INITIALPOPULATION", "Size of the initial population");
127 itsAttr[STARTPOPULATION] = Attributes::makeString
128 ("STARTPOPULATION", "Generation file (JSON format) to be started from (optional)", "");
129 itsAttr[NUMMASTERS] = Attributes::makeReal
130 ("NUM_MASTERS", "Number of master nodes");
131 itsAttr[NUMCOWORKERS] = Attributes::makeReal
132 ("NUM_COWORKERS", "Number processors per worker");
134 ("DUMP_DAT", "Dump old generation data format with frequency (PISA only)");
135 itsAttr[DUMPFREQ] = Attributes::makeReal
136 ("DUMP_FREQ", "Dump generation data with frequency (PISA only)");
137 itsAttr[DUMPOFFSPRING] = Attributes::makeBool
138 ("DUMP_OFFSPRING", "Dump offspring (instead of parent population), default: true");
139 itsAttr[NUMINDGEN] = Attributes::makeReal
140 ("NUM_IND_GEN", "Number of individuals in a generation (PISA only)");
141 itsAttr[MAXGENERATIONS] = Attributes::makeReal
142 ("MAXGENERATIONS", "Number of generations to run");
144 ("EPSILON", "Tolerance of hypervolume criteria, default 0.001");
145 itsAttr[EXPECTEDHYPERVOL] = Attributes::makeReal
146 ("EXPECTED_HYPERVOL", "The reference hypervolume, default 0");
147 itsAttr[HYPERVOLREFERENCE] = Attributes::makeRealArray
148 ("HYPERVOLREFERENCE", "The reference point (real array) for the hypervolume, default empty (origin)");
149 itsAttr[CONVHVOLPROG] = Attributes::makeReal
150 ("CONV_HVOL_PROG", "Converge if change in hypervolume is smaller, default 0");
151 itsAttr[ONEPILOTCONVERGE] = Attributes::makeBool
152 ("ONE_PILOT_CONVERGE", "default false");
153 itsAttr[SOLSYNCH] = Attributes::makeReal
154 ("SOL_SYNCH", "Solution exchange frequency, default 0");
155 itsAttr[GENEMUTATIONPROBABILITY] = Attributes::makeReal
156 ("GENE_MUTATION_PROBABILITY", "Mutation probability of individual gene, default: 0.5");
157 itsAttr[MUTATIONPROBABILITY] = Attributes::makeReal
158 ("MUTATION_PROBABILITY", "Mutation probability of genome, default: 0.5");
159 itsAttr[RECOMBINATIONPROBABILITY] = Attributes::makeReal
160 ("RECOMBINATION_PROBABILITY", "Probability for genes to recombine, default: 0.5");
161 itsAttr[SIMBINCROSSOVERNU] = Attributes::makeReal
162 ("SIMBIN_CROSSOVER_NU", "Simulated binary crossover, default: 2.0");
163 itsAttr[INITIALOPTIMIZATION] = Attributes::makeBool
164 ("INITIAL_OPTIMIZATION", "Optimize speed of initial generation, default: false");
165 itsAttr[BIRTHCONTROL] = Attributes::makeBool
166 ("BIRTH_CONTROL", "Enforce strict population sizes (or flexible to keep workers busy), default: false");
168 ("SIMTMPDIR", "Directory where simulations are run");
169 itsAttr[TEMPLATEDIR] = Attributes::makeString
170 ("TEMPLATEDIR", "Directory where templates are stored");
171 itsAttr[FIELDMAPDIR] = Attributes::makeString
172 ("FIELDMAPDIR", "Directory where field maps are stored");
174 ("DISTDIR", "Directory where distributions are stored", "");
176 ("CROSSOVER", "Type of cross over.", {"BLEND", "NAIVEONEPOINT", "NAIVEUNIFORM", "SIMULATEDBINARY"}, "BLEND");
178 ("MUTATION", "Type of bit mutation.", {"ONEBIT", "INDEPENDENTBIT"}, "INDEPENDENTBIT");
179 itsAttr[RESTART_FILE] = Attributes::makeString
180 ("RESTART_FILE", "H5 file to restart the OPAL simulations from (optional)", "");
181 itsAttr[RESTART_STEP] = Attributes::makeReal
182 ("RESTART_STEP", "Restart from given H5 step (optional)",
185}
186
187OptimizeCmd::OptimizeCmd(const std::string &name, OptimizeCmd *parent):
188 Action(name, parent)
189{ }
190
192{ }
193
194OptimizeCmd *OptimizeCmd::clone(const std::string &name) {
195 return new OptimizeCmd(name, this);
196}
197
199 namespace fs = boost::filesystem;
200
201 auto opal = OpalData::getInstance();
202 opal->setOptimizerFlag();
203
204 fs::path inputfile(Attributes::getString(itsAttr[INPUT]));
205
206 std::vector<std::string> dvarsstr = Attributes::getStringArray(itsAttr[DVARS]);
207 std::vector<std::string> objectivesstr = Attributes::getStringArray(itsAttr[OBJECTIVES]);
208 std::vector<std::string> constraintsstr = Attributes::getStringArray(itsAttr[CONSTRAINTS]);
209 DVarContainer_t dvars;
210 Expressions::Named_t objectives;
211 Expressions::Named_t constraints;
212
213 // Setup/Configuration
215
216 // prepare function dictionary and add all available functions in
217 // expressions
220 ff = FromFile();
221 funcs.insert(std::pair<std::string, client::function::type>
222 ("fromFile", ff));
223
224 ff = SumErrSq();
225 funcs.insert(std::pair<std::string, client::function::type>
226 ("sumErrSq", ff));
227
228 ff = SDDSVariable();
229 funcs.insert(std::pair<std::string, client::function::type>
230 ("sddsVariableAt", ff));
231
232 ff = RadialPeak();
233 funcs.insert(std::pair<std::string, client::function::type>
234 ("radialPeak", ff));
235
236 ff = MaxNormRadialPeak();
237 funcs.insert(std::pair<std::string, client::function::type>
238 ("maxNormRadialPeak", ff));
239
240 ff = NumberOfPeaks();
241 funcs.insert(std::pair<std::string, client::function::type>
242 ("numberOfPeaks", ff));
243
244 ff = SumErrSqRadialPeak();
245 funcs.insert(std::pair<std::string, client::function::type>
246 ("sumErrSqRadialPeak", ff));
247
248 ff = ProbeVariable();
249 funcs.insert(std::pair<std::string, client::function::type>
250 ("probVariableWithID", ff));
251
252 std::string fname = inputfile.stem().native();
253 ff = sameSDDSVariable(fname);
254 funcs.insert(std::pair<std::string, client::function::type>
255 ("statVariableAt", ff));
256
257 ff = SeptumExpr();
258 funcs.insert(std::pair<std::string, client::function::type>
259 ("septum", ff));
260
262
263 std::vector<std::string> arguments(opal->getArguments());
264 std::vector<char*> argv;
265 std::map<unsigned int, std::string> argumentMapper({
266 {INPUT, "inputfile"},
267 {OUTPUT, "outfile"},
268 {OUTDIR, "outdir"},
269 {INITIALPOPULATION, "initialPopulation"},
270 {STARTPOPULATION, "start-population"},
271 {NUMMASTERS, "num-masters"},
272 {NUMCOWORKERS, "num-coworkers"},
273 {DUMPDAT, "dump-dat"},
274 {DUMPFREQ, "dump-freq"},
275 {DUMPOFFSPRING, "dump-offspring"},
276 {NUMINDGEN, "num-ind-gen"},
277 {MAXGENERATIONS, "maxGenerations"},
278 {EPSILON, "epsilon"},
279 {EXPECTEDHYPERVOL, "expected-hypervol"},
280 {CONVHVOLPROG, "conv-hvol-prog"},
281 {ONEPILOTCONVERGE, "one-pilot-converge"},
282 {SOLSYNCH, "sol-synch"},
283 {GENEMUTATIONPROBABILITY, "gene-mutation-probability"},
284 {MUTATIONPROBABILITY, "mutation-probability"},
285 {RECOMBINATIONPROBABILITY, "recombination-probability"},
286 {SIMBINCROSSOVERNU, "simbin-crossover-nu"},
287 {INITIALOPTIMIZATION, "initial-optimization"},
288 {BIRTHCONTROL, "birth-control"},
289 {RESTART_FILE, "restartfile"},
290 {RESTART_STEP, "restartstep"}
291 });
292
293 auto it = argumentMapper.end();
294 for (unsigned int i = 0; i < SIZE; ++ i) {
295 if ((it = argumentMapper.find(i)) != argumentMapper.end()) {
296 std::string type = itsAttr[i].getType();
297 if (type == "string") {
298 if (!Attributes::getString(itsAttr[i]).empty()) {
299 std::string argument = "--" + (*it).second + "=" + Attributes::getString(itsAttr[i]);
300 arguments.push_back(argument);
301 }
302 } else if (type == "real") {
303 if (itsAttr[i]) {
304 std::string val = std::to_string (Attributes::getReal(itsAttr[i]));
305 size_t last = val.find_last_not_of('0');
306 if (val[last] != '.') ++ last;
307 val.erase (last, std::string::npos );
308 std::string argument = "--" + (*it).second + "=" + val;
309 arguments.push_back(argument);
310 }
311 } else if (type == "logical") {
312 if (itsAttr[i]) {
313 std::string argument = "--" + (*it).second + "=" + std::to_string(Attributes::getBool(itsAttr[i]));
314 arguments.push_back(argument);
315 }
316 }
317 }
318 }
319 // sanity checks
320 if (Attributes::getString(itsAttr[INPUT]).empty()) {
321 throw OpalException("OptimizeCmd::execute",
322 "The argument INPUT has to be provided");
323 }
324 if (Attributes::getReal(itsAttr[INITIALPOPULATION]) <= 0) {
325 throw OpalException("OptimizeCmd::execute",
326 "The argument INITIALPOPULATION has to be provided");
327 }
328 if (Attributes::getReal(itsAttr[MAXGENERATIONS]) <= 0) {
329 throw OpalException("OptimizeCmd::execute",
330 "The argument MAXGENERATIONS has to be provided");
331 }
332 if (Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE]).empty() == false &&
333 Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE]).size() != objectivesstr.size()) {
334 throw OpalException("OptimizeCmd::execute",
335 "The hypervolume reference point should have the same dimension as the objectives");
336 }
337 if (!Attributes::getString(itsAttr[STARTPOPULATION]).empty() &&
338 Attributes::getBool( itsAttr[INITIALOPTIMIZATION]) == true) {
339 throw OpalException("OptimizeCmd::execute",
340 "No INITIAL_OPTIMIZATION possible when reading initial population from file (STARTPOPULATION)");
341 }
342 if (Attributes::getBool(itsAttr[BIRTHCONTROL]) == true &&
343 Attributes::getBool(itsAttr[INITIALOPTIMIZATION]) == true) {
344 throw OpalException("OptimizeCmd::execute",
345 "No INITIAL_OPTIMIZATION possible with BIRTH_CONTROL");
346 }
347
348 if (!Attributes::getString(itsAttr[SIMTMPDIR]).empty()) {
349 fs::path dir(Attributes::getString(itsAttr[SIMTMPDIR]));
350 if (dir.is_relative()) {
351 fs::path path = fs::path(std::string(getenv("PWD")));
352 path /= dir;
353 dir = path;
354 }
355
356 if (!fs::exists(dir)) {
357 fs::create_directory(dir);
358 }
359 std::string argument = "--simtmpdir=" + dir.native();
360 arguments.push_back(argument);
361 }
362
363 if (!Attributes::getString(itsAttr[TEMPLATEDIR]).empty()) {
364 fs::path dir(Attributes::getString(itsAttr[TEMPLATEDIR]));
365 if (dir.is_relative()) {
366 fs::path path = fs::path(std::string(getenv("PWD")));
367 path /= dir;
368 dir = path;
369 }
370
371 std::string argument = "--templates=" + dir.native();
372 arguments.push_back(argument);
373 }
374
375 if (!Attributes::getString(itsAttr[FIELDMAPDIR]).empty()) {
376 fs::path dir(Attributes::getString(itsAttr[FIELDMAPDIR]));
377 if (dir.is_relative()) {
378 fs::path path = fs::path(std::string(getenv("PWD")));
379 path /= dir;
380 dir = path;
381 }
382
383 setenv("FIELDMAPS", dir.c_str(), 1);
384 }
385
386 if (!Attributes::getString(itsAttr[DISTDIR]).empty()) {
387 fs::path dir(Attributes::getString(itsAttr[DISTDIR]));
388 if (dir.is_relative()) {
389 fs::path path = fs::path(std::string(getenv("PWD")));
390 path /= dir;
391 dir = path;
392 }
393
394 setenv("DISTRIBUTIONS", dir.c_str(), 1);
395 }
396
397
398 *gmsg << endl;
399 for (size_t i = 0; i < arguments.size(); ++ i) {
400 argv.push_back(const_cast<char*>(arguments[i].c_str()));
401 *gmsg << arguments[i] << " ";
402 }
403 *gmsg << endl;
404
405 std::set<std::string> vars; // check if all unique vars
406 for (const std::string &name: dvarsstr) {
407 Object *obj = opal->find(name);
408 DVar* dvar = dynamic_cast<DVar*>(obj);
409 if (dvar == nullptr) {
410 throw OpalException("OptimizeCmd::execute",
411 "The design variable " + name + " is not known");
412
413 }
414 std::string var = dvar->getVariable();
415 double lowerbound = dvar->getLowerBound();
416 double upperbound = dvar->getUpperBound();
417
418 DVar_t tmp = boost::make_tuple(var, lowerbound, upperbound);
419 dvars.insert(namedDVar_t(name, tmp));
420 auto ret = vars.insert(var);
421 if (ret.second == false) {
422 throw OpalException("OptimizeCmd::execute",
423 "There is already a design variable with the variable " + var + " defined");
424 }
425 }
426 std::set<std::string> objExpressions; // check if all unique objective expressions
427 for (const std::string &name: objectivesstr) {
428 Object *obj = opal->find(name);
429 Objective* objective = dynamic_cast<Objective*>(obj);
430 if (objective == nullptr) {
431 throw OpalException("OptimizeCmd::execute",
432 "The objective " + name + " is not known");
433
434 }
435 std::string expr = objective->getExpression();
436 objectives.insert(Expressions::SingleNamed_t(
437 name, new Expressions::Expr_t(expr, funcs)));
438 auto ret = objExpressions.insert(expr);
439 if (ret.second == false) {
440 throw OpalException("OptimizeCmd::execute",
441 "There is already a objective with the expression " + expr + " defined");
442 }
443 }
444 std::set<std::string> constraintExpressions; // check if all unique constraint expressions
445 for (const std::string &name: constraintsstr) {
446 Object *obj = opal->find(name);
447 Constraint* constraint = dynamic_cast<Constraint*>(obj);
448 if (constraint == nullptr) {
449 throw OpalException("OptimizeCmd::execute",
450 "The constraint " + name + " is not known");
451
452 }
453 std::string expr = constraint->getExpression();
454 constraints.insert(Expressions::SingleNamed_t(
455 name, new Expressions::Expr_t(expr, funcs)));
456 auto ret = constraintExpressions.insert(expr);
457 if (ret.second == false) {
458 throw OpalException("OptimizeCmd::execute",
459 "There is already a constraint with the expression " + expr + " defined");
460 }
461 }
462
463 {
464 std::string tmplFile = Attributes::getString(itsAttr[INPUT]);
465 size_t pos = tmplFile.find_last_of("/");
466 if(pos != std::string::npos)
467 tmplFile = tmplFile.substr(pos+1);
468 pos = tmplFile.find(".");
469 tmplFile = tmplFile.substr(0,pos);
470 tmplFile = Attributes::getString(itsAttr[TEMPLATEDIR]) + "/" + tmplFile + ".tmpl";
471
472 std::ifstream infile(tmplFile.c_str());
473
474 std::map<std::string, short> dvarCheck;
475 for (auto itr = dvars.begin(); itr != dvars.end(); ++ itr) {
476 dvarCheck.insert(std::make_pair(boost::get<0>(itr->second), 0));
477 }
478
479 while(infile.good()) {
480 std::string line;
481 std::getline(infile, line, '\n');
482
483 //XXX doing the inverse would be better
484 for(auto &check: dvarCheck) {
485 pos = line.find("_" + check.first + "_");
486 if (pos != std::string::npos &&
487 dvarCheck.find(check.first) != dvarCheck.end()) {
488 dvarCheck.at(check.first) = 1;
489 }
490 }
491 }
492 infile.close();
493
494 for (auto itr = dvarCheck.begin(); itr != dvarCheck.end(); ++ itr) {
495 if (itr->second == 0) {
496 throw OpalException("OptimizeCmd::execute()",
497 "Couldn't find the design variable '" + itr->first + "' in '" + tmplFile + "'!");
498 }
499 }
500 }
501
502 Inform *origGmsg = gmsg;
503 gmsg = 0;
504 try {
505 CmdArguments_t args(new CmdArguments(argv.size(), &argv[0]));
506
507 this->run(args, funcs, dvars, objectives, constraints);
508
509 } catch (OptPilotException &e) {
510 std::cout << "Exception caught: " << e.what() << std::endl;
511 MPI_Abort(MPI_COMM_WORLD, -100);
512 }
513 gmsg = origGmsg;
514}
515
517 Ippl::stash();
519 Track::stash();
521}
522
524 Ippl::pop();
527 Track::pop();
528}
529
531 std::map<std::string, CrossOver> map;
532 map["BLEND"] = CrossOver::Blend;
533 map["NAIVEONEPOINT"] = CrossOver::NaiveOnePoint;
534 map["NAIVEUNIFORM"] = CrossOver::NaiveUniform;
535 map["SIMULATEDBINARY"] = CrossOver::SimulatedBinary;
536
537 CrossOver co = CrossOver::Blend;
538
539 switch ( map[crossover] ) {
540 case CrossOver::Blend:
541 break;
542 case CrossOver::NaiveOnePoint:
543 co = CrossOver::NaiveOnePoint;
544 break;
545 case CrossOver::NaiveUniform:
546 co = CrossOver::NaiveUniform;
547 break;
548 case CrossOver::SimulatedBinary:
549 co = CrossOver::SimulatedBinary;
550 break;
551 default:
552 throw OpalException("OptimizeCmd::crossoverSelection",
553 "No cross over '" + crossover + "' supported.");
554 }
555
556 return co;
557}
558
560 std::map<std::string, Mutation> map;
561 map["INDEPENDENTBIT"] = Mutation::IndependentBit;
562 map["ONEBIT"] = Mutation::OneBit;
563
564 Mutation mut = Mutation::IndependentBit;
565
566 switch ( map[mutation] ) {
567 case Mutation::IndependentBit:
568 break;
569 case Mutation::OneBit:
570 mut = Mutation::OneBit;
571 break;
572 default:
573 throw OpalException("OptimizeCmd::mutationSelection",
574 "No mutation '" + mutation + "' supported.");
575 }
576
577 return mut;
578}
579
581 const functionDictionary_t& funcs,
582 const DVarContainer_t& dvars,
583 const Expressions::Named_t& objectives,
584 const Expressions::Named_t& constraints)
585{
586 typedef OpalSimulation Sim_t;
587
589 typedef SocialNetworkGraph< NoCommTopology > SolPropagationGraph_t;
590
591 boost::shared_ptr<Comm_t> comm(new Comm_t(args, MPI_COMM_WORLD));
592 if (comm->isWorker())
594
595 CrossOver crossover = this->crossoverSelection(Attributes::getString(itsAttr[CROSSOVER]));
596 Mutation mutation = this->mutationSelection(Attributes::getString(itsAttr[MUTATION]));
597
598
599 std::map<std::string, std::string> userVariables = OpalData::getInstance()->getVariableData();
600
601 switch ( crossover + mutation ) {
602 case CrossOver::Blend + Mutation::IndependentBit:
603 {
606
607 boost::scoped_ptr<pilot_t> pi(new pilot_t(args, comm,
608 funcs, dvars,
609 objectives, constraints,
610 Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE]),
611 true, userVariables));
612 break;
613 }
614 case CrossOver::Blend + Mutation::OneBit:
615 {
618
619 boost::scoped_ptr<pilot_t> pi(new pilot_t(args, comm,
620 funcs, dvars,
621 objectives, constraints,
622 Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE]),
623 true, userVariables));
624 break;
625 }
626 case CrossOver::NaiveOnePoint + Mutation::IndependentBit:
627 {
630
631 boost::scoped_ptr<pilot_t> pi(new pilot_t(args, comm,
632 funcs, dvars,
633 objectives, constraints,
634 Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE]),
635 true, userVariables));
636 break;
637 }
638 case CrossOver::NaiveOnePoint + Mutation::OneBit:
639 {
642
643 boost::scoped_ptr<pilot_t> pi(new pilot_t(args, comm,
644 funcs, dvars,
645 objectives, constraints,
646 Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE]),
647 true, userVariables));
648 break;
649 }
650 case CrossOver::NaiveUniform + Mutation::IndependentBit:
651 {
654
655 boost::scoped_ptr<pilot_t> pi(new pilot_t(args, comm,
656 funcs, dvars,
657 objectives, constraints,
658 Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE]),
659 true, userVariables));
660 break;
661 }
662 case CrossOver::NaiveUniform + Mutation::OneBit:
663 {
666
667 boost::scoped_ptr<pilot_t> pi(new pilot_t(args, comm,
668 funcs, dvars,
669 objectives, constraints,
670 Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE]),
671 true, userVariables));
672 break;
673 }
674 case CrossOver::SimulatedBinary + Mutation::IndependentBit:
675 {
678
679 boost::scoped_ptr<pilot_t> pi(new pilot_t(args, comm,
680 funcs, dvars,
681 objectives, constraints,
682 Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE]),
683 true, userVariables));
684 break;
685 }
686 case CrossOver::SimulatedBinary + Mutation::OneBit:
687 {
690
691 boost::scoped_ptr<pilot_t> pi(new pilot_t(args, comm,
692 funcs, dvars,
693 objectives, constraints,
694 Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE]),
695 true, userVariables));
696 break;
697 }
698 default:
699 throw OpalException("OptimizeCmd::run",
700 "No such cross over and mutation combination supported.");
701 }
702
703 if (comm->isWorker())
705}
Inform * gmsg
Definition: Main.cpp:61
@ SIZE
Definition: IndexMap.cpp:174
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:76
const double pi
Definition: fftpack.cpp:894
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
boost::tuple< std::string, double, double > DVar_t
type of design variables
Definition: Types.h:84
std::map< std::string, DVar_t > DVarContainer_t
Definition: Types.h:92
std::pair< std::string, DVar_t > namedDVar_t
Definition: Types.h:91
boost::shared_ptr< CmdArguments > CmdArguments_t
Definition: CmdArguments.h:176
const std::string name
std::map< std::string, client::function::type > functionDictionary_t
Definition: Expression.h:56
std::map< std::string, Expressions::Expr_t * > Named_t
type of an expressions with a name
Definition: Expression.h:74
std::pair< std::string, Expressions::Expr_t * > SingleNamed_t
Definition: Expression.h:77
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
Definition: Attributes.cpp:90
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:252
Attribute makeStringArray(const std::string &name, const std::string &help)
Create a string array attribute.
Definition: Attributes.cpp:473
Attribute makePredefinedString(const std::string &name, const std::string &help, const std::initializer_list< std::string > &predefinedStrings)
Make predefined string attribute.
Definition: Attributes.cpp:409
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Definition: Attributes.cpp:240
bool getBool(const Attribute &attr)
Return logical value.
Definition: Attributes.cpp:100
Attribute makeRealArray(const std::string &name, const std::string &help)
Create real array attribute.
Definition: Attributes.cpp:289
std::vector< double > getRealArray(const Attribute &attr)
Get array value.
Definition: Attributes.cpp:294
std::vector< std::string > getStringArray(const Attribute &attr)
Get string array value.
Definition: Attributes.cpp:478
std::string getString(const Attribute &attr)
Get string value.
Definition: Attributes.cpp:343
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
Definition: Attributes.cpp:332
constexpr double e
The value of.
Definition: Physics.h:39
boost::function< boost::tuple< double, bool >(arguments_t)> type
Definition: function.hpp:21
FRONT * fs
Definition: hypervolume.cpp:59
double FromFile(std::string file, const std::vector< double > &referencePoint)
The base class for all OPAL actions.
Definition: Action.h:30
The base class for all OPAL objects.
Definition: Object.h:48
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
Definition: Object.cpp:191
std::vector< Attribute > itsAttr
The object attributes.
Definition: Object.h:216
std::map< std::string, std::string > getVariableData()
Definition: OpalData.cpp:711
static void stashInstance()
Definition: OpalData.cpp:212
static OpalData * getInstance()
Definition: OpalData.cpp:196
static OpalData * popInstance()
Definition: OpalData.cpp:223
std::string getExpression() const
Definition: Constraint.cpp:31
Definition: DVar.h:6
std::string getVariable() const
Definition: DVar.cpp:37
double getUpperBound() const
Definition: DVar.cpp:45
double getLowerBound() const
Definition: DVar.cpp:41
std::string getExpression() const
Definition: Objective.cpp:31
Concrete implementation of an Opal simulation wrapper.
The OPTIMIZE command.
Definition: OptimizeCmd.h:16
virtual ~OptimizeCmd()
virtual OptimizeCmd * clone(const std::string &name)
Make clone.
CrossOver crossoverSelection(std::string crossover)
void popEnvironment()
Mutation mutationSelection(std::string mutation)
void run(const CmdArguments_t &args, const functionDictionary_t &funcs, const DVarContainer_t &dvars, const Expressions::Named_t &objectives, const Expressions::Named_t &constraints)
void stashEnvironment()
virtual void execute()
Execute the command.
OptimizeCmd()
Exemplar constructor.
static Track * pop()
Definition: Track.cpp:83
static void stash()
Definition: Track.cpp:76
The base class for all OPAL exceptions.
Definition: OpalException.h:28
Definition: Inform.h:42
static void pop()
Definition: IpplInfo.cpp:1053
static void stash()
Definition: IpplInfo.cpp:988
static void stash()
static void pop()
Definition: Pilot.h:102