-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgprogram.cc
More file actions
70 lines (59 loc) · 1.39 KB
/
Copy pathgprogram.cc
File metadata and controls
70 lines (59 loc) · 1.39 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
# include <gprogram.h>
/* The implementation of the class gprogram.
* */
GProgram::GProgram()
{
/* The default constructor.
* The default value for start_symbol is NULL.
* */
start_symbol = NULL;
}
GProgram::GProgram(GSymbol *s)
{
/* Set the value of start_symbol to s.
* */
start_symbol = s;
}
void GProgram::setStartSymbol(GSymbol *s)
{
/* Set the value of start_symbol to s.
* */
start_symbol = s;
}
GSymbol *GProgram::getStartSymbol() const
{
/* Return the value of the starting symbol.
* */
return start_symbol;
}
string GProgram::printProgram(vector<int> &genome,int &redo)
{
/* Return the program represented by the rules in genome.
* Initially the value of redo must be set to zero. After
* the method has done, the user must check the value of
* redo, in order to understand if the maximum number of
* wrapping events has been reached.
* */
/* str: The returning program.
* count: Initially is zero.
* r,pos: Auxiliary variables.
* */
string str="";
int count=0;
GRule *r;
int pos;
if(start_symbol == NULL) return "";
/* Take the first rule from the starting symbol and proceed.
* */
r=start_symbol->getRule(0);
redo = 0;
str=r->printRule(genome,count,redo);
return str;
}
double GProgram::fitness(vector<int> &genome)
{
/* This method must be redefined by the derived classes, in
* order to assign values to programs.
* */
return 0.0;
}