/
GeneticAlgorithm.h
69 lines (56 loc) · 1.59 KB
/
GeneticAlgorithm.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef _GENETIC_ALGORITHM_H
#define _GENETIC_ALGORITHM_H
//****************************************************************************
//**
//** GeneticAlgorithm.h
//**
//** Copyright (c) 2010 Matthew Robbins
//**
//** Author: Matthew Robbins
//** Created: 04/2010
//**
//****************************************************************************
#include <vector>
// Forward Declarations
namespace CarDemo
{
class Genome;
class NeuralNet;
};
namespace CarDemo
{
class GeneticAlgorithm
{
private:
int currentGenome;
unsigned int totalPopulation;
int genomeID;
int generation;
int totalGenomeWeights;
std::vector<Genome*> population;
std::vector<int> crossoverSplits;
void GetBestCases(int totalGenomes, std::vector<Genome*> &out);
void CrossBreed(Genome* g1, Genome* g2, Genome* &baby1, Genome* &baby2);
void Mutate(Genome* genome);
Genome* CreateNewGenome(unsigned int totalWeights);
protected:
public:
GeneticAlgorithm();
~GeneticAlgorithm();
Genome* GetNextGenome();
Genome* GetBestGenome();
Genome* GetWorstGenome();
Genome* GetGenome(int index);
int GetCurrentGenomeIndex() const;
int GetCurrentGenomeID() const;
int GetCurrentGeneration() const;
int GetTotalPopulation() const;
// Creates a new population
void GenerateNewPopulation(unsigned int totalPop, unsigned int totalWeights);
void BreedPopulation();
void ClearPopulation();
void GenerateCrossoverSplits(int neuronsPerHidden, int inputs, int outputs);
void SetGenomeFitness(float fitness, int index);
};
}; // End namespace CarDemo.
#endif // #ifndef _GENETIC_ALGORITHM_H