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