-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdna.h
45 lines (35 loc) · 948 Bytes
/
dna.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
#ifndef _DNA_INC
#define _DNA_INC
#include <QByteArray>
class MutationTable {
public:
float add_chunk;
float remove_chunk;
float move_chunk;
float reverse_section;
float swap_bit;
float random_byte;
float add_crossover;
};
class DNA {
public:
DNA();
DNA(QByteArray &d, float mut);
virtual ~DNA() {}
void set_data(QByteArray *d) {data = d;}
void blend(const DNA &mum, const DNA &dad, int max_size, int min_size);
void set_from(const DNA &parent, int max_size, int min_size);
const QByteArray &getData() const {return *data;}
int size() const {return data->size();}
void set_mutation(float mut) {mutation = mut;}
float get_mutation() const {return mutation;}
protected:
QByteArray *data;
float mutation;
void mutate(int max_size, int min_size);
void add_chunk(int max_size);
void remove_chunk(int min_size);
void move_chunk();
void reverse_section();
};
#endif