-
Notifications
You must be signed in to change notification settings - Fork 0
/
GeneticAlgorithm.cpp
63 lines (48 loc) · 1.3 KB
/
GeneticAlgorithm.cpp
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
#ifndef GA
#define GA
typedef struct DNA{
float* fDNA;
unsigned fLength;
BoolArray bDNA;
unsigned bLength;
}DNA;
typedef struct Organism{
void* org;
float fit;
}Organism;
class GeneticAlgorithm{
public:
GeneticAlgorithm(unsigned popSize, DNA dna, float (*fitness)(void*),
void* (*fromDNA)(DNA), bool (*termination)(float));
void* evolve();
void generation();
//variables:
//# of parents to an organism
unsigned parents;
// avg # of children
unsigned children;
// range of # of children;
float childDistribution;
// percent by which crossover favors organisms with higher fitness
float geneFit;
//probability of a randomized gene
float geneMutation;
//probability of a slightly changed gene
float geneModification;
float geneModSize;
// percent of population that reproduces
float parentPercentage;
//parents can join the next generation
bool parentsSurvive;
//organisms can have multiple sex partners!
bool multipleParentSets;
private:
void** population;
DNA maxVals;
DNA* popDNA;
int fLength, bLength;
unsigned popSize;
float (*fitness)(void*);
void* (*fromDNA)(DNA);
bool (*termination)(float);
};