OPAL (Object Oriented Parallel Accelerator Library) 2024.2
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 <map>
61#include <set>
62#include <string>
63#include <vector>
64
65extern Inform *gmsg;
66
67namespace {
68 enum {
69 INPUT,
70 OUTPUT,
71 OUTDIR,
72 OBJECTIVES,
73 DVARS,
74 CONSTRAINTS,
75 INITIALPOPULATION,
76 STARTPOPULATION,
77 NUMMASTERS,
78 NUMCOWORKERS,
79 DUMPDAT,
80 DUMPFREQ,
81 DUMPOFFSPRING,
82 NUMINDGEN,
83 MAXGENERATIONS,
84 EPSILON,
85 EXPECTEDHYPERVOL,
86 HYPERVOLREFERENCE,
87 CONVHVOLPROG,
88 ONEPILOTCONVERGE,
89 SOLSYNCH,
90 GENEMUTATIONPROBABILITY,
91 MUTATIONPROBABILITY,
92 RECOMBINATIONPROBABILITY,
93 SIMBINCROSSOVERNU,
94 INITIALOPTIMIZATION,
95 BIRTHCONTROL,
96 SIMTMPDIR,
97 TEMPLATEDIR,
98 FIELDMAPDIR,
99 DISTDIR,
100 CROSSOVER,
101 MUTATION,
102 RESTART_FILE,
103 RESTART_STEP,
104 SIZE
105 };
106}
107
109 Action(SIZE, "OPTIMIZE",
110 "The \"OPTIMIZE\" command initiates optimization.") {
112 ("INPUT", "Path to input file");
114 ("OUTPUT", "Name used in output file generation");
116 ("OUTDIR", "Name of directory used to store generation output files");
118 ("OBJECTIVES", "List of objectives to be used");
120 ("DVARS", "List of optimization variables to be used");
122 ("CONSTRAINTS", "List of constraints to be used");
123 itsAttr[INITIALPOPULATION] = Attributes::makeReal
124 ("INITIALPOPULATION", "Size of the initial population");
125 itsAttr[STARTPOPULATION] = Attributes::makeString
126 ("STARTPOPULATION", "Generation file (JSON format) to be started from (optional)", "");
127 itsAttr[NUMMASTERS] = Attributes::makeReal
128 ("NUM_MASTERS", "Number of master nodes");
129 itsAttr[NUMCOWORKERS] = Attributes::makeReal
130 ("NUM_COWORKERS", "Number processors per worker");
132 ("DUMP_DAT", "Dump old generation data format with frequency (PISA only)");
133 itsAttr[DUMPFREQ] = Attributes::makeReal
134 ("DUMP_FREQ", "Dump generation data with frequency (PISA only)");
135 itsAttr[DUMPOFFSPRING] = Attributes::makeBool
136 ("DUMP_OFFSPRING", "Dump offspring (instead of parent population), default: true");
137 itsAttr[NUMINDGEN] = Attributes::makeReal
138 ("NUM_IND_GEN", "Number of individuals in a generation (PISA only)");
139 itsAttr[MAXGENERATIONS] = Attributes::makeReal
140 ("MAXGENERATIONS", "Number of generations to run");
142 ("EPSILON", "Tolerance of hypervolume criteria, default 0.001");
143 itsAttr[EXPECTEDHYPERVOL] = Attributes::makeReal
144 ("EXPECTED_HYPERVOL", "The reference hypervolume, default 0");
145 itsAttr[HYPERVOLREFERENCE] = Attributes::makeRealArray
146 ("HYPERVOLREFERENCE", "The reference point (real array) for the hypervolume, default empty (origin)");
147 itsAttr[CONVHVOLPROG] = Attributes::makeReal
148 ("CONV_HVOL_PROG", "Converge if change in hypervolume is smaller, default 0");
149 itsAttr[ONEPILOTCONVERGE] = Attributes::makeBool
150 ("ONE_PILOT_CONVERGE", "default false");
151 itsAttr[SOLSYNCH] = Attributes::makeReal
152 ("SOL_SYNCH", "Solution exchange frequency, default 0");
153 itsAttr[GENEMUTATIONPROBABILITY] = Attributes::makeReal
154 ("GENE_MUTATION_PROBABILITY", "Mutation probability of individual gene, default: 0.5");
155 itsAttr[MUTATIONPROBABILITY] = Attributes::makeReal
156 ("MUTATION_PROBABILITY", "Mutation probability of genome, default: 0.5");
157 itsAttr[RECOMBINATIONPROBABILITY] = Attributes::makeReal
158 ("RECOMBINATION_PROBABILITY", "Probability for genes to recombine, default: 0.5");
159 itsAttr[SIMBINCROSSOVERNU] = Attributes::makeReal
160 ("SIMBIN_CROSSOVER_NU", "Simulated binary crossover, default: 2.0");
161 itsAttr[INITIALOPTIMIZATION] = Attributes::makeBool
162 ("INITIAL_OPTIMIZATION", "Optimize speed of initial generation, default: false");
163 itsAttr[BIRTHCONTROL] = Attributes::makeBool
164 ("BIRTH_CONTROL", "Enforce strict population sizes (or flexible to keep workers busy), default: false");
166 ("SIMTMPDIR", "Directory where simulations are run");
167 itsAttr[TEMPLATEDIR] = Attributes::makeString
168 ("TEMPLATEDIR", "Directory where templates are stored");
169 itsAttr[FIELDMAPDIR] = Attributes::makeString
170 ("FIELDMAPDIR", "Directory where field maps are stored");
172 ("DISTDIR", "Directory where distributions are stored", "");
174 ("CROSSOVER", "Type of cross over.", {"BLEND", "NAIVEONEPOINT", "NAIVEUNIFORM", "SIMULATEDBINARY"}, "BLEND");
176 ("MUTATION", "Type of bit mutation.", {"ONEBIT", "INDEPENDENTBIT"}, "INDEPENDENTBIT");
177 itsAttr[RESTART_FILE] = Attributes::makeString
178 ("RESTART_FILE", "H5 file to restart the OPAL simulations from (optional)", "");
179 itsAttr[RESTART_STEP] = Attributes::makeReal
180 ("RESTART_STEP", "Restart from given H5 step (optional)",
181 std::numeric_limits<int>::min());
183}
184
185OptimizeCmd::OptimizeCmd(const std::string& name, OptimizeCmd* parent):
186 Action(name, parent)
187{ }
188
191
192OptimizeCmd *OptimizeCmd::clone(const std::string& name) {
193 return new OptimizeCmd(name, this);
194}
195
197 namespace fs = std::filesystem;
198
199 auto opal = OpalData::getInstance();
200 opal->setOptimizerFlag();
201
202 fs::path inputfile(Attributes::getString(itsAttr[INPUT]));
203
204 std::vector<std::string> dvarsstr = Attributes::getStringArray(itsAttr[DVARS]);
205 std::vector<std::string> objectivesstr = Attributes::getStringArray(itsAttr[OBJECTIVES]);
206 std::vector<std::string> constraintsstr = Attributes::getStringArray(itsAttr[CONSTRAINTS]);
207 DVarContainer_t dvars;
208 Expressions::Named_t objectives;
209 Expressions::Named_t constraints;
210
211 // Setup/Configuration
213
214 // prepare function dictionary and add all available functions in
215 // expressions
218 ff = FromFile();
219 funcs.insert(std::pair<std::string, client::function::type>
220 ("fromFile", ff));
221
222 ff = SumErrSq();
223 funcs.insert(std::pair<std::string, client::function::type>
224 ("sumErrSq", ff));
225
226 ff = SDDSVariable();
227 funcs.insert(std::pair<std::string, client::function::type>
228 ("sddsVariableAt", ff));
229
230 ff = RadialPeak();
231 funcs.insert(std::pair<std::string, client::function::type>
232 ("radialPeak", ff));
233
234 ff = MaxNormRadialPeak();
235 funcs.insert(std::pair<std::string, client::function::type>
236 ("maxNormRadialPeak", ff));
237
238 ff = NumberOfPeaks();
239 funcs.insert(std::pair<std::string, client::function::type>
240 ("numberOfPeaks", ff));
241
242 ff = SumErrSqRadialPeak();
243 funcs.insert(std::pair<std::string, client::function::type>
244 ("sumErrSqRadialPeak", ff));
245
246 ff = ProbeVariable();
247 funcs.insert(std::pair<std::string, client::function::type>
248 ("probVariableWithID", ff));
249
250 std::string fname = inputfile.stem().native();
251 ff = sameSDDSVariable(fname);
252 funcs.insert(std::pair<std::string, client::function::type>
253 ("statVariableAt", ff));
254
255 ff = SeptumExpr();
256 funcs.insert(std::pair<std::string, client::function::type>
257 ("septum", ff));
258
260
261 std::vector<std::string> arguments(opal->getArguments());
262 std::vector<char*> argv;
263 std::map<unsigned int, std::string> argumentMapper({
264 {INPUT, "inputfile"},
265 {OUTPUT, "outfile"},
266 {OUTDIR, "outdir"},
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"}
289 });
290
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") {
296 if (!Attributes::getString(itsAttr[i]).empty()) {
297 std::string argument = "--" + (*it).second + "=" + Attributes::getString(itsAttr[i]);
298 arguments.push_back(argument);
299 }
300 } else if (type == "real") {
301 if (itsAttr[i]) {
302 std::string val = std::to_string (Attributes::getReal(itsAttr[i]));
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);
308 }
309 } else if (type == "logical") {
310 if (itsAttr[i]) {
311 std::string argument = "--" + (*it).second + "=" + std::to_string(Attributes::getBool(itsAttr[i]));
312 arguments.push_back(argument);
313 }
314 }
315 }
316 }
317 // sanity checks
318 if (Attributes::getString(itsAttr[INPUT]).empty()) {
319 throw OpalException("OptimizeCmd::execute",
320 "The argument INPUT has to be provided");
321 }
322 if (Attributes::getReal(itsAttr[INITIALPOPULATION]) <= 0) {
323 throw OpalException("OptimizeCmd::execute",
324 "The argument INITIALPOPULATION has to be provided");
325 }
326 if (Attributes::getReal(itsAttr[MAXGENERATIONS]) <= 0) {
327 throw OpalException("OptimizeCmd::execute",
328 "The argument MAXGENERATIONS has to be provided");
329 }
330 if (Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE]).empty() == false &&
331 Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE]).size() != objectivesstr.size()) {
332 throw OpalException("OptimizeCmd::execute",
333 "The hypervolume reference point should have the same dimension as the objectives");
334 }
335 if (!Attributes::getString(itsAttr[STARTPOPULATION]).empty() &&
336 Attributes::getBool( itsAttr[INITIALOPTIMIZATION]) == true) {
337 throw OpalException("OptimizeCmd::execute",
338 "No INITIAL_OPTIMIZATION possible when reading initial population from file (STARTPOPULATION)");
339 }
340 if (Attributes::getBool(itsAttr[BIRTHCONTROL]) == true &&
341 Attributes::getBool(itsAttr[INITIALOPTIMIZATION]) == true) {
342 throw OpalException("OptimizeCmd::execute",
343 "No INITIAL_OPTIMIZATION possible with BIRTH_CONTROL");
344 }
345
346 if (!Attributes::getString(itsAttr[SIMTMPDIR]).empty()) {
347 fs::path dir(Attributes::getString(itsAttr[SIMTMPDIR]));
348 if (dir.is_relative()) {
349 fs::path path = fs::path(std::string(getenv("PWD")));
350 path /= dir;
351 dir = path;
352 }
353
354 if (!fs::exists(dir)) {
355 fs::create_directory(dir);
356 }
357 std::string argument = "--simtmpdir=" + dir.native();
358 arguments.push_back(argument);
359 }
360
361 if (!Attributes::getString(itsAttr[TEMPLATEDIR]).empty()) {
362 fs::path dir(Attributes::getString(itsAttr[TEMPLATEDIR]));
363 if (dir.is_relative()) {
364 fs::path path = fs::path(std::string(getenv("PWD")));
365 path /= dir;
366 dir = path;
367 }
368
369 std::string argument = "--templates=" + dir.native();
370 arguments.push_back(argument);
371 }
372
373 if (!Attributes::getString(itsAttr[FIELDMAPDIR]).empty()) {
374 fs::path dir(Attributes::getString(itsAttr[FIELDMAPDIR]));
375 if (dir.is_relative()) {
376 fs::path path = fs::path(std::string(getenv("PWD")));
377 path /= dir;
378 dir = path;
379 }
380
381 setenv("FIELDMAPS", dir.c_str(), 1);
382 }
383
384 if (!Attributes::getString(itsAttr[DISTDIR]).empty()) {
385 fs::path dir(Attributes::getString(itsAttr[DISTDIR]));
386 if (dir.is_relative()) {
387 fs::path path = fs::path(std::string(getenv("PWD")));
388 path /= dir;
389 dir = path;
390 }
391
392 setenv("DISTRIBUTIONS", dir.c_str(), 1);
393 }
394
395 *gmsg << endl;
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] << " ";
399 }
400 *gmsg << endl;
401
402 std::set<std::string> vars; // check if all unique vars
403 for (const std::string &name: dvarsstr) {
404 Object *obj = opal->find(name);
405 DVar* dvar = dynamic_cast<DVar*>(obj);
406 if (dvar == nullptr) {
407 throw OpalException("OptimizeCmd::execute",
408 "The design variable " + name + " is not known");
409 }
410 std::string var = dvar->getVariable();
411 double lowerbound = dvar->getLowerBound();
412 double upperbound = dvar->getUpperBound();
413
414 DVar_t tmp = std::make_tuple(var, lowerbound, upperbound);
415 dvars.insert(namedDVar_t(name, tmp));
416 auto ret = vars.insert(var);
417 if (ret.second == false) {
418 throw OpalException("OptimizeCmd::execute",
419 "There is already a design variable with the variable " + var + " defined");
420 }
421 }
422 std::set<std::string> objExpressions; // check if all unique objective expressions
423 for (const std::string &name: objectivesstr) {
424 Object *obj = opal->find(name);
425 Objective* objective = dynamic_cast<Objective*>(obj);
426 if (objective == nullptr) {
427 throw OpalException("OptimizeCmd::execute",
428 "The objective " + name + " is not known");
429 }
430 std::string expr = objective->getExpression();
431 objectives.insert(Expressions::SingleNamed_t(
432 name, new Expressions::Expr_t(expr, funcs)));
433 auto ret = objExpressions.insert(expr);
434 if (ret.second == false) {
435 throw OpalException("OptimizeCmd::execute",
436 "There is already a objective with the expression " + expr + " defined");
437 }
438 }
439 std::set<std::string> constraintExpressions; // check if all unique constraint expressions
440 for (const std::string &name: constraintsstr) {
441 Object *obj = opal->find(name);
442 Constraint* constraint = dynamic_cast<Constraint*>(obj);
443 if (constraint == nullptr) {
444 throw OpalException("OptimizeCmd::execute",
445 "The constraint " + name + " is not known");
446 }
447 std::string expr = constraint->getExpression();
448 constraints.insert(Expressions::SingleNamed_t(
449 name, new Expressions::Expr_t(expr, funcs)));
450 auto ret = constraintExpressions.insert(expr);
451 if (ret.second == false) {
452 throw OpalException("OptimizeCmd::execute",
453 "There is already a constraint with the expression " + expr + " defined");
454 }
455 }
456
457 {
458 std::string tmplFile = Attributes::getString(itsAttr[INPUT]);
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);
464 tmplFile = Attributes::getString(itsAttr[TEMPLATEDIR]) + "/" + tmplFile + ".tmpl";
465
466 std::ifstream infile(tmplFile.c_str());
467
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));
471 }
472
473 while(infile.good()) {
474 std::string line;
475 std::getline(infile, line, '\n');
476
477 //XXX doing the inverse would be better
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;
483 }
484 }
485 }
486 infile.close();
487
488 for (auto itr = dvarCheck.begin(); itr != dvarCheck.end(); ++ itr) {
489 if (itr->second == 0) {
490 throw OpalException("OptimizeCmd::execute()",
491 "Couldn't find the design variable '" + itr->first + "' in '" + tmplFile + "'!");
492 }
493 }
494 }
495
496 Inform *origGmsg = gmsg;
497 gmsg = 0;
498 try {
499 CmdArguments_t args(new CmdArguments(argv.size(), &argv[0]));
500
501 this->run(args, funcs, dvars, objectives, constraints);
502
503 } catch (OptPilotException &e) {
504 std::cout << "Exception caught: " << e.what() << std::endl;
505 MPI_Abort(MPI_COMM_WORLD, -100);
506 }
507 gmsg = origGmsg;
508}
509
516
523
525 static const std::map<std::string, CrossOver> map = {
526 {"BLEND", CrossOver::Blend},
527 {"NAIVEONEPOINT", CrossOver::NaiveOnePoint},
528 {"NAIVEUNIFORM", CrossOver::NaiveUniform},
529 {"SIMULATEDBINARY", CrossOver::SimulatedBinary}
530 };
531
532 auto it = map.find(crossover);
533 if (it == map.end()) {
534 throw OpalException("OptimizeCmd::crossoverSelection",
535 "No cross over '" + crossover + "' supported.");
536 }
537
538 return it->second;
539}
540
542 static const std::map<std::string, Mutation> map = {
543 {"INDEPENDENTBIT", Mutation::IndependentBit},
544 {"ONEBIT", Mutation::OneBit}
545 };
546
547 auto it = map.find(mutation);
548 if (it == map.end()) {
549 throw OpalException("OptimizeCmd::mutationSelection",
550 "No mutation '" + mutation + "' supported.");
551 }
552
553 return it->second;
554}
555
557 const functionDictionary_t& funcs,
558 const DVarContainer_t& dvars,
559 const Expressions::Named_t& objectives,
560 const Expressions::Named_t& constraints)
561{
562 typedef OpalSimulation Sim_t;
563
565 typedef SocialNetworkGraph< NoCommTopology > SolPropagationGraph_t;
566
567 std::shared_ptr<Comm_t> comm(new Comm_t(args, MPI_COMM_WORLD));
568 if (comm->isWorker())
570
571 CrossOver crossover = this->crossoverSelection(Attributes::getString(itsAttr[CROSSOVER]));
572 Mutation mutation = this->mutationSelection(Attributes::getString(itsAttr[MUTATION]));
573
574 std::map<std::string, std::string> userVariables = OpalData::getInstance()->getVariableData();
575
576 switch (crossover) {
577 case CrossOver::Blend:
578 switch (mutation) {
580 {
583
584 const std::unique_ptr<pilot_t> pi(new pilot_t(
585 args, comm, funcs, dvars, objectives, constraints,
586 Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE]),
587 true, userVariables));
588 break;
589 }
590 case Mutation::OneBit:
591 {
594
595 const std::unique_ptr<pilot_t> pi(new pilot_t(
596 args, comm, funcs, dvars, objectives, constraints,
597 Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE]),
598 true, userVariables));
599 break;
600 }
601 default:
602 break;
603 }
604 break;
605
607 switch (mutation) {
609 {
612
613 const std::unique_ptr<pilot_t> pi(new pilot_t(
614 args, comm, funcs, dvars, objectives, constraints,
615 Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE]),
616 true, userVariables));
617 break;
618 }
619 case Mutation::OneBit:
620 {
623
624 const std::unique_ptr<pilot_t> pi(new pilot_t(
625 args, comm, funcs, dvars, objectives, constraints,
626 Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE]),
627 true, userVariables));
628 break;
629 }
630 default:
631 break;
632 }
633 break;
634
636 switch (mutation) {
638 {
641
642 const std::unique_ptr<pilot_t> pi(new pilot_t(
643 args, comm, funcs, dvars, objectives, constraints,
644 Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE]),
645 true, userVariables));
646 break;
647 }
648 case Mutation::OneBit:
649 {
652
653 const std::unique_ptr<pilot_t> pi(new pilot_t(
654 args, comm, funcs, dvars, objectives, constraints,
655 Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE]),
656 true, userVariables));
657 break;
658 }
659 default:
660 break;
661 }
662 break;
663
665 switch (mutation) {
667 {
670
671 const std::unique_ptr<pilot_t> pi(new pilot_t(
672 args, comm, funcs, dvars, objectives, constraints,
673 Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE]),
674 true, userVariables));
675 break;
676 }
677 case Mutation::OneBit:
678 {
681
682 const std::unique_ptr<pilot_t> pi(new pilot_t(
683 args, comm, funcs, dvars, objectives, constraints,
684 Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE]),
685 true, userVariables));
686 break;
687 }
688 default:
689 break;
690 }
691 break;
692
693 default:
694 throw OpalException("OptimizeCmd::run",
695 "No such cross over and mutation combination supported.");
696 }
697
698 if (comm->isWorker())
700}
@ SIZE
Definition IndexMap.cpp:174
Inform * gmsg
Definition Main.cpp:70
Inform * gmsg
Definition Main.cpp:70
const double pi
Definition fftpack.cpp:894
Inform & endl(Inform &inf)
Definition Inform.cpp:42
std::shared_ptr< CmdArguments > CmdArguments_t
std::map< std::string, DVar_t > DVarContainer_t
Definition Types.h:90
std::tuple< std::string, double, double > DVar_t
type of design variables
Definition Types.h:81
std::pair< std::string, DVar_t > namedDVar_t
Definition Types.h:89
const std::string name
std::map< std::string, client::function::type > functionDictionary_t
Definition Expression.h:55
std::map< std::string, Expressions::Expr_t * > Named_t
type of an expressions with a name
Definition Expression.h:73
std::pair< std::string, Expressions::Expr_t * > SingleNamed_t
Definition Expression.h:76
Attribute makeBool(const std::string &name, const std::string &help)
Make logical attribute.
double getReal(const Attribute &attr)
Return real value.
Attribute makeStringArray(const std::string &name, const std::string &help)
Create a string array attribute.
Attribute makePredefinedString(const std::string &name, const std::string &help, const std::initializer_list< std::string > &predefinedStrings)
Make predefined string attribute.
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
bool getBool(const Attribute &attr)
Return logical value.
Attribute makeRealArray(const std::string &name, const std::string &help)
Create real array attribute.
std::vector< double > getRealArray(const Attribute &attr)
Get array value.
std::vector< std::string > getStringArray(const Attribute &attr)
Get string array value.
std::string getString(const Attribute &attr)
Get string value.
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
std::function< std::tuple< double, bool >(arguments_t)> type
Definition function.hpp:16
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:716
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 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.
virtual ~OptimizeCmd()
virtual OptimizeCmd * clone(const std::string &name)
Make clone.
void popEnvironment()
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.
CrossOver crossoverSelection(const std::string &crossover)
OptimizeCmd()
Exemplar constructor.
Mutation mutationSelection(const std::string &mutation)
Sampling method that reads design variable values from a text file.
Definition FromFile.h:50
static Track * pop()
Definition Track.cpp:83
static void stash()
Definition Track.cpp:76
The base class for all OPAL exceptions.
static void pop()
static void stash()
Definition IpplInfo.cpp:988
static void stash()
static void pop()
Definition Pilot.h:99