Commit 97149d3d authored by frey_m's avatar frey_m
Browse files

optional *.data file

parent 71abbc3e
......@@ -10,6 +10,7 @@
#include <vector>
#include <boost/algorithm/string.hpp>
#include "boost/filesystem.hpp"
#include "Util/OptPilotException.h"
......@@ -126,6 +127,12 @@ private:
*/
void fillDictionary() {
namespace fs = boost::filesystem;
fs::path pwd = fs::current_path();
if (!fs::exists(varDictionary_) || fs::is_empty(varDictionary_))
return;
std::ifstream infile;
infile.open(varDictionary_.c_str(), std::ifstream::in);
......
......@@ -752,7 +752,7 @@ std::map<std::string, std::string> OpalData::getVariableData() {
std::vector<std::string> uvars = this->getVariableNames();
for (auto& uvar : uvars) {
RealVariable &variable = *dynamic_cast<RealVariable *>(OpalData::getInstance()->find(uvar));
udata.insert({uvar, variable.value().getBase().getImage()});
udata[uvar] = std::to_string(variable.getReal());
}
return udata;
}
......
......@@ -121,18 +121,13 @@ OpalSimulation::OpalSimulation(Expressions::Named_t objectives,
std::string tmplFile = tmplDir + "/" + simulationName_ + ".tmpl";
// data file is assumed to be located in the root directory
std::string dataFile = simulationName_ + ".data";
fs::path pwd = fs::current_path();
if (!fs::exists(dataFile))
throw OptPilotException("OpalSimulation::OpalSimulation",
"The data file '" + dataFile + "' \n" +
" doesn't exist in directory '" + pwd.native() + "'");
if (!fs::exists(tmplFile))
throw OptPilotException("OpalSimulation::OpalSimulation",
"The template file '" + tmplFile + "' doesn't exit");
for (const auto& uvar : userVariables_) {
uvars.insert({uvar.first, uvar.second});
uvars.insert(std::pair<std::string, std::string>(uvar.first, uvar.second));
}
gs_.reset(new GenerateOpalSimulation(tmplFile, dataFile, uvars));
......
......@@ -577,6 +577,9 @@ void OptimizeCmd::run(const CmdArguments_t& args,
CrossOver crossover = this->crossoverSelection(Attributes::getString(itsAttr[CROSSOVER]));
Mutation mutation = this->mutationSelection(Attributes::getString(itsAttr[MUTATION]));
std::map<std::string, std::string> userVariables = OpalData::getInstance()->getVariableData();
switch ( crossover + mutation ) {
case CrossOver::Blend + Mutation::IndependentBit:
{
......@@ -586,7 +589,8 @@ void OptimizeCmd::run(const CmdArguments_t& args,
boost::scoped_ptr<pilot_t> pi(new pilot_t(args, comm,
funcs, dvars,
objectives, constraints,
Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE])));
Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE]),
true, userVariables));
break;
}
case CrossOver::Blend + Mutation::OneBit:
......@@ -597,7 +601,8 @@ void OptimizeCmd::run(const CmdArguments_t& args,
boost::scoped_ptr<pilot_t> pi(new pilot_t(args, comm,
funcs, dvars,
objectives, constraints,
Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE])));
Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE]),
true, userVariables));
break;
}
case CrossOver::NaiveOnePoint + Mutation::IndependentBit:
......@@ -608,7 +613,8 @@ void OptimizeCmd::run(const CmdArguments_t& args,
boost::scoped_ptr<pilot_t> pi(new pilot_t(args, comm,
funcs, dvars,
objectives, constraints,
Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE])));
Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE]),
true, userVariables));
break;
}
case CrossOver::NaiveOnePoint + Mutation::OneBit:
......@@ -619,7 +625,8 @@ void OptimizeCmd::run(const CmdArguments_t& args,
boost::scoped_ptr<pilot_t> pi(new pilot_t(args, comm,
funcs, dvars,
objectives, constraints,
Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE])));
Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE]),
true, userVariables));
break;
}
case CrossOver::NaiveUniform + Mutation::IndependentBit:
......@@ -630,7 +637,8 @@ void OptimizeCmd::run(const CmdArguments_t& args,
boost::scoped_ptr<pilot_t> pi(new pilot_t(args, comm,
funcs, dvars,
objectives, constraints,
Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE])));
Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE]),
true, userVariables));
break;
}
case CrossOver::NaiveUniform + Mutation::OneBit:
......@@ -641,7 +649,8 @@ void OptimizeCmd::run(const CmdArguments_t& args,
boost::scoped_ptr<pilot_t> pi(new pilot_t(args, comm,
funcs, dvars,
objectives, constraints,
Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE])));
Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE]),
true, userVariables));
break;
}
case CrossOver::SimulatedBinary + Mutation::IndependentBit:
......@@ -652,7 +661,8 @@ void OptimizeCmd::run(const CmdArguments_t& args,
boost::scoped_ptr<pilot_t> pi(new pilot_t(args, comm,
funcs, dvars,
objectives, constraints,
Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE])));
Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE]),
true, userVariables));
break;
}
case CrossOver::SimulatedBinary + Mutation::OneBit:
......@@ -663,7 +673,8 @@ void OptimizeCmd::run(const CmdArguments_t& args,
boost::scoped_ptr<pilot_t> pi(new pilot_t(args, comm,
funcs, dvars,
objectives, constraints,
Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE])));
Attributes::getRealArray(itsAttr[HYPERVOLREFERENCE]),
true, userVariables));
break;
}
default:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment