From 17909d029c6a8872b2fddf4e171d7925bbbe9c5c Mon Sep 17 00:00:00 2001 From: Paul Oliver Date: Thu, 29 Feb 2024 19:27:35 +0100 Subject: Initial commit --- Simulation/SimFitness_UpdateSpecs.cpp | 40 +++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Simulation/SimFitness_UpdateSpecs.cpp (limited to 'Simulation/SimFitness_UpdateSpecs.cpp') diff --git a/Simulation/SimFitness_UpdateSpecs.cpp b/Simulation/SimFitness_UpdateSpecs.cpp new file mode 100644 index 0000000..3919914 --- /dev/null +++ b/Simulation/SimFitness_UpdateSpecs.cpp @@ -0,0 +1,40 @@ +#include "SimFitness.hpp" + +void SimFitness::updateSpecs() +{ + for (auto &i : guppies) + { + i.update(); + } + + if (!guppieCount) + { + unsigned soul = 0; + for (auto &i : guppies) + { + population->setFitness(currentPopulation * prms.popSize + soul, (unsigned)i.fitness); + ++soul; + } + + ++currentPopulation; + if (currentPopulation == prms.popQtty) + { + population->roulleteWheel(); + + currentPopulation = 0; + ++currentGeneration; + } + + unsigned index = 0; + for (auto &i : guppies) + { + i.clean(); + i.create(); + i.neuralNet->setChromosome(population->getChromosome(currentPopulation * prms.popSize + index)); + ++index; + } + + text.currentPop.setString("Current population: " + nts(currentPopulation + 1) + " / " + nts(prms.popQtty)); + text.currentGen.setString("Current generation: " + nts(currentGeneration + 1)); + } +} -- cgit v1.2.1