|
@@ -46,6 +46,7 @@ namespace mdd {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
OptimizerEvolutionary::OptimizerEvolutionary()
|
|
|
:OptimizerBase(R"JSON(
|
|
|
{
|
|
@@ -84,31 +85,61 @@ namespace mdd {
|
|
|
auto jit = config.find("converges");
|
|
|
if (jit != config.end())
|
|
|
{
|
|
|
- _converges = jit.value()["value"].get<int>();
|
|
|
+ json jval = jit.value()["value"];
|
|
|
+ if (jval.is_string())
|
|
|
+ {
|
|
|
+ jval = json::parse(jval.get<std::string>());
|
|
|
+ }
|
|
|
+ _converges = jval.get<int>();
|
|
|
+ _base_config["configure"]["converges"]["value"] = _converges;
|
|
|
found = true;
|
|
|
}
|
|
|
jit = config.find("grow generation");
|
|
|
if (jit != config.end())
|
|
|
{
|
|
|
- _grow_generation = jit.value()["value"].get<int>();
|
|
|
+ json jval = jit.value()["value"];
|
|
|
+ if (jval.is_string())
|
|
|
+ {
|
|
|
+ jval = json::parse(jval.get<std::string>());
|
|
|
+ }
|
|
|
+ _grow_generation = jval.get<int>();
|
|
|
+ _base_config["configure"]["grow generation"]["value"] = _grow_generation;
|
|
|
found = true;
|
|
|
}
|
|
|
jit = config.find("max fitness");
|
|
|
if (jit != config.end())
|
|
|
{
|
|
|
- _max_fitness = jit.value()["value"].get<int>();
|
|
|
+ json jval = jit.value()["value"];
|
|
|
+ if (jval.is_string())
|
|
|
+ {
|
|
|
+ jval = json::parse(jval.get<std::string>());
|
|
|
+ }
|
|
|
+ _max_fitness = jval.get<int>();
|
|
|
+ _base_config["configure"]["max fitness"]["value"] = _max_fitness;
|
|
|
found = true;
|
|
|
}
|
|
|
jit = config.find("min generations");
|
|
|
if (jit != config.end())
|
|
|
{
|
|
|
- _min_generations = jit.value()["value"].get<int>();
|
|
|
+ json jval = jit.value()["value"];
|
|
|
+ if (jval.is_string())
|
|
|
+ {
|
|
|
+ jval = json::parse(jval.get<std::string>());
|
|
|
+ }
|
|
|
+ _min_generations = jval.get<int>();
|
|
|
+ _base_config["configure"]["min generations"]["value"] = _min_generations;
|
|
|
found = true;
|
|
|
}
|
|
|
jit = config.find("precision");
|
|
|
if (jit != config.end())
|
|
|
{
|
|
|
- _precision = jit.value()["value"].get<double>();
|
|
|
+ json jval = jit.value()["value"];
|
|
|
+ if (jval.is_string())
|
|
|
+ {
|
|
|
+ jval = json::parse(jval.get<std::string>());
|
|
|
+ }
|
|
|
+ _precision = jval.get<double>();
|
|
|
+ _base_config["configure"]["precision"]["value"] = _precision;
|
|
|
found = true;
|
|
|
}
|
|
|
return found;
|
|
@@ -177,6 +208,7 @@ namespace mdd {
|
|
|
|
|
|
return _bests[0].fitness;
|
|
|
}
|
|
|
+
|
|
|
std::vector<double> OptimizerEvolutionary::mutateGene(std::shared_ptr<IInput> input, std::vector<double> seed)
|
|
|
{
|
|
|
|
|
@@ -308,6 +340,7 @@ namespace mdd {
|
|
|
}
|
|
|
evaluate(init_len);
|
|
|
}
|
|
|
+
|
|
|
OptimizerEvolutionary::Individual OptimizerEvolutionary::combine(Individual par1, Individual par2)
|
|
|
{
|
|
|
size_t len = par1.dna.size();
|
|
@@ -329,6 +362,7 @@ namespace mdd {
|
|
|
}
|
|
|
return child;
|
|
|
}
|
|
|
+
|
|
|
OptimizerEvolutionary::Individual OptimizerEvolutionary::generateIndividual()
|
|
|
{
|
|
|
Individual ret;
|
|
@@ -338,9 +372,11 @@ namespace mdd {
|
|
|
}
|
|
|
return ret;
|
|
|
}
|
|
|
+
|
|
|
std::vector<OptimizerEvolutionary::Individual> OptimizerEvolutionary::getBests() {
|
|
|
return _bests;
|
|
|
}
|
|
|
+
|
|
|
double OptimizerEvolutionary::evaluateFitness(const Individual& ind) {
|
|
|
for (size_t j = 0; j < _inputs.size(); j++)
|
|
|
{
|