-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChromosome.cpp
More file actions
57 lines (52 loc) · 1.05 KB
/
Chromosome.cpp
File metadata and controls
57 lines (52 loc) · 1.05 KB
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
#include "Chromosome.h"
Chromosome::Chromosome()
{
}
Chromosome::Chromosome(const int &size)
{
this->size = size;
chr = std::unique_ptr<double[]>(new double[size]);
}
Chromosome &Chromosome::operator=(const Chromosome &other)
{
this->size = other.size;
this->fitness = other.fitness;
for (int i = 0; i < size; i++)
this->chr[i] = other.chr[i];
return *this;
}
Chromosome::~Chromosome()
{
}
void Chromosome::setChromosomeSize(const int &chromosome_size)
{
size = chromosome_size;
}
void Chromosome::setChromosome(const int &idx, const double &value)
{
if (idx < 0 || idx >= size)
return;
chr[idx] = value;
}
void Chromosome::setChromosome(const int &idx, const int &value)
{
if (idx < 0 || idx >= size)
return;
chr[idx] = value;
}
void Chromosome::setFitness(const double &value)
{
fitness = value;
}
double Chromosome::getChromosome(const int &idx) const
{
return chr[idx];
}
double Chromosome::GetFitness() const
{
return fitness;
}
int Chromosome::GetSize() const
{
return size;
}