Skip to content

Commit 49baadd

Browse files
committed
Added RandomNetworkAmount-Property and Implemented it.
RandomNetworkAmount is for creating Random networks to keep a better variation in the networks
1 parent 4fac10e commit 49baadd

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

NeuralBotMasterFramework/NeuralBotMasterFramework/Interfaces/IGeneticAlgorithm.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public interface IGeneticAlgorithm
1010
{
1111
int TotalNetworks { get; }
1212
int NetworksToKeep { get; }
13+
int RandomNetworkAmount { get; }
1314
double MutationRate { get; }
1415
double MutationChance { get; }
1516

NeuralBotMasterFramework/NeuralBotMasterFramework/Logic/Algorithms/GeneticAlgorithm.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class GeneticAlgorithm : IGeneticAlgorithm
1414
{
1515
public int TotalNetworks { get; }
1616
public int NetworksToKeep { get; set; }
17+
public int RandomNetworkAmount { get; set; }
1718
public double MutationRate { get; set; }
1819
public double MutationChance { get; set; }
1920
public Dictionary<IWeightedNetwork, double> NetworksAndFitness { get; private set; } = new Dictionary<IWeightedNetwork, double>();
@@ -33,17 +34,22 @@ public GeneticAlgorithm(int totalNetworks, int inputNodes, int hiddenNodes, int
3334
HiddenLayers = hiddenLayers;
3435
OutputNodes = outputNodes;
3536

36-
InitializeNetworks();
37+
AddNewNetworks(TotalNetworks);
3738
}
3839

39-
private void InitializeNetworks()
40+
private void AddNewNetworks(int amount)
4041
{
41-
for (int i = 0; i < TotalNetworks; ++i)
42+
for (int i = 0; i < amount; ++i)
4243
{
43-
NetworksAndFitness.Add(new WeightedNetwork(InputNodes, HiddenLayers, HiddenLayers, OutputNodes), 0);
44+
AddNewNetwork();
4445
}
4546
}
4647

48+
private void AddNewNetwork()
49+
{
50+
NetworksAndFitness.Add(new WeightedNetwork(InputNodes, HiddenLayers, HiddenLayers, OutputNodes), 0);
51+
}
52+
4753
public void SetupTest(double[][] input, double[][] expected = null)
4854
{
4955
CurrentInput = (double[][])input.Clone();
@@ -118,6 +124,7 @@ private void RemoveUnneccessaryNetworks()
118124

119125
private void BreedNewNetworks()
120126
{
127+
AddNewNetworks(RandomNetworkAmount);
121128
List<IWeightedNetwork> networkAndLikelinesToBreed = GetBreedingPool();
122129
BreedNetworks(networkAndLikelinesToBreed);
123130
}

0 commit comments

Comments
 (0)