-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram.hpp
More file actions
84 lines (67 loc) · 1.93 KB
/
Copy pathprogram.hpp
File metadata and controls
84 lines (67 loc) · 1.93 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
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
#ifndef __PROGRAM_H_INCLUDED__
#define __PROGRAM_H_INCLUDED__
#include <fstream>
#include <vector>
#include <list>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include "random.hpp"
#include "primitives.hpp"
#define MAX_DRAWS 2
#define MAX_PRIMITIVES 4
#define MAX_MUTATION_DEPTH 1
#define MUTATION_CHANGE_LEAF 0
#define MUTATION_LEAF 1
#define MUTATION_TREE 2
#define MUTATION_MIXED 3
#define MUTATION_MIXED_N_TREE 4
#define CHANGE_LEAF_P1 0
#define CHANGE_LEAF_P2 1
#define CHANGE_LEAF_H 2
#define CHANGE_LEAF_V 3
#define CHANGE_LEAF_HV 4
#define CHANGE_LEAF_R 5
#define CHANGE_LEAF_COLOR 6
#define CHANGE_LEAF_THICK 7
class Program {
private:
R rand;
public:
int width, height;
double fitness = std::numeric_limits<float>::max();
std::vector<Draw*> nodes;
explicit Program(const Program &p);
Program(int const& width, int const& height);
virtual ~Program();
virtual Program* clone() const;
void draw(cv::Mat const& img);
void show();
void saveImage(std::string &filename);
void saveProgram(std::string &filename);
double calculateFitness(cv::Mat const& originalImg);
void fillRandomNodes(int maxDepth);
int changePoint();
Program* crossover(Program *pB, int const& cpA, int const& cpB);
void mutation(int const& type);
void mutationChangeLeaf();
void mutationLeaf();
void mutationTree();
static Program* generateRandomNodes(int maxDepth, const int& w, const int& h);
static Program** crossover(Program* parentA, Program* parentB);
friend std::ostream& operator<<(std::ostream &strm, const Program &p) {
return strm << p.nodes.front();
}
friend std::ostream& operator<<(std::ostream &strm, const Program *p) {
return strm << p->nodes.front();
}
friend bool operator<(const Program &a, const Program &b) {
return a.fitness < b.fitness;
}
static bool compare(Program *a, Program *b){
return a->fitness < b->fitness;
}
};
#endif