aboutsummaryrefslogtreecommitdiff
path: root/Simulation/SimFitness_StartSpecs.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_StartSpecs.cpp
Initial commitHEADmaster
Diffstat (limited to 'Simulation/SimFitness_StartSpecs.cpp')
-rw-r--r--Simulation/SimFitness_StartSpecs.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/Simulation/SimFitness_StartSpecs.cpp b/Simulation/SimFitness_StartSpecs.cpp
new file mode 100644
index 0000000..8fe1a41
--- /dev/null
+++ b/Simulation/SimFitness_StartSpecs.cpp
@@ -0,0 +1,60 @@
+#include "SimFitness.hpp"
+
+bool SimFitness::startSpecs()
+{
+ if (!text.startup(this, SELECTION_BY_FITNESS))
+ {
+ return false;
+ }
+
+ std::unique_ptr<NeuralNet> dummy;
+ if (prms.netClass == SINGLE_MLP)
+ {
+ dummy = std::unique_ptr<NeuralNet>(new SingleMLP(82, prms.npHiddenLayer, 5, prms.nodeClass, true));
+ }
+ else if (prms.netClass == DUAL_MLP)
+ {
+ dummy = std::unique_ptr<NeuralNet>(new DualMLP(82, prms.npHiddenLayer, 5, prms.nodeClass, true));
+ }
+ else if (prms.netClass == SIMPLE_RN)
+ {
+ dummy = std::unique_ptr<NeuralNet>(new SimpleRN(82, prms.npHiddenLayer, 5, prms.nodeClass, true));
+ }
+ else if (prms.netClass == FULLY_RN)
+ {
+ dummy = std::unique_ptr<NeuralNet>(new FullyRN(82, prms.npHiddenLayer, 5, prms.nodeClass, true));
+ }
+ unsigned chromosomeSize = dummy->getChromosomeSize();
+ population = std::unique_ptr<Population>(new Population(prms.popQtty * prms.popSize, prms.elites, chromosomeSize));
+
+ // Set first population
+ guppies.resize(prms.popSize);
+ unsigned index = 0;
+ for (auto &i : guppies)
+ {
+ i.startup(this);
+ if (prms.netClass == SINGLE_MLP)
+ {
+ i.neuralNet = std::shared_ptr<NeuralNet>(new SingleMLP(82, prms.npHiddenLayer, 5, prms.nodeClass, true));
+ }
+ else if (prms.netClass == DUAL_MLP)
+ {
+ i.neuralNet = std::shared_ptr<NeuralNet>(new DualMLP(82, prms.npHiddenLayer, 5, prms.nodeClass, true));
+ }
+ else if (prms.netClass == SIMPLE_RN)
+ {
+ i.neuralNet = std::shared_ptr<SimpleRN>(new SimpleRN(82, prms.npHiddenLayer, 5, prms.nodeClass, true));
+ }
+ else if (prms.netClass == FULLY_RN)
+ {
+ i.neuralNet = std::shared_ptr<FullyRN>(new FullyRN(82, prms.npHiddenLayer, 5, prms.nodeClass, true));
+ }
+ i.create();
+ // Set neural net initial random weights
+ i.neuralNet->setChromosome(population->getChromosome(index));
+
+ ++index;
+ }
+
+ return true;
+}