aboutsummaryrefslogtreecommitdiff
path: root/Simulation/SimFitness_UpdateSpecs.cpp
diff options
context:
space:
mode:
authorPaul Oliver <contact@pauloliver.dev>2024-02-29 19:27:35 +0100
committerPaul Oliver <contact@pauloliver.dev>2024-02-29 19:27:49 +0100
commit17909d029c6a8872b2fddf4e171d7925bbbe9c5c (patch)
treecbb08af84cd68d24acc362d593a2048b0fa79689 /Simulation/SimFitness_UpdateSpecs.cpp
Initial commitHEADmaster
Diffstat (limited to 'Simulation/SimFitness_UpdateSpecs.cpp')
-rw-r--r--Simulation/SimFitness_UpdateSpecs.cpp40
1 files changed, 40 insertions, 0 deletions
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));
+ }
+}