-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChromosome.h
95 lines (69 loc) · 1.33 KB
/
Chromosome.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//
#pragma once
//
#include "BitEvolver/Includes.h"
//
#include <memory>
#include <string>
#include <sstream>
#include <vector>
#include <mutex>
//
namespace BitEvolver
{
//
using std::string;
//
class Chromosome
{
//
public:
//
Chromosome(std::shared_ptr<class Random> _random, int _bits);
//
void Reset();
void Randomize();
//
void SetGenerationNumber(int g);
void IncrementGenerationNumber();
int GetGenerationNumber();
//
void SetBitCount(int count);
int GetBitCount();
//
void FlipBit(int index);
//
bool GetBit(int index);
void SetBit(int index, bool b);
void SetBits(string s);
//
void ResetFitness();
void SetFitness(double d);
void AdjustFitness(double d);
double GetFitness();
/**
Error is just inverted fitness
*/
void ResetError();
void SetError(double e);
void AdjustError(double e);
double GetError();
//
std::string ToString();
//
const Chromosome& operator=(const Chromosome& other);
//
private:
// Random number generator
std::shared_ptr<class Random> random;
//
int generation_number;
//
std::vector<bool> bits;
int bits_count_desired;
// Fitness
double fitness;
// Mutexes
std::recursive_mutex modification_mutex;
};
};