11 FitnessP
evaluate(IndividualP individual);
13 std::vector<long int> domain;
14 std::vector<long int> codomain;
23 ifstream input(
"list.txt");
33 codomain.push_back(y);
62 for(uint i = 0; i < nSamples; i++) {
73 value += abs(codomain[i] - key);
85 fitness->setValue(value);
105 long int first, second;
106 long int& division = *(
long int*)result;
111 division = abs(second) > 0.000000001 ? first / second : 1;
129 long int& arg = *(
long int*)result;
133 arg = (
long int) sqrt(1. * arg);
155 long int first, second;
156 long int& modulo = *(
long int*)result;
162 modulo = first % second;
169uint showTree(
Tree::Tree* tree, uint iNode = 0, uint prefix = 0)
171 Tree::PrimitiveP prim = tree->at(iNode)->primitive_;
172 int arity = prim->getNumberOfArguments();
177 else if(prim->getName() ==
"pow") {
180 iNode = showTree(tree, iNode, prefix);
183 iNode = showTree(tree, iNode, prefix);
186 else if(arity == 2) {
189 iNode = showTree(tree, iNode, prefix);
190 cout << prim->getName();
192 iNode = showTree(tree, iNode, prefix);
196 cout << prim->getName();
198 for(
int child = 0; child < arity; child++) {
200 iNode = showTree(tree, iNode, prefix);
209int isPrime6k1_sp(
unsigned long long int number)
215 else if (number == 1)
223 else if (number % 2 == 0)
231 else if (number%3==0)
237 unsigned long long int up_range;
238 up_range = (
unsigned long long int) sqrt(1. * number);
240 unsigned long long int tmp = 5;
242 while (tmp<=up_range)
248 if (number%(tmp+2)==0)
264int main(
int argc,
char **argv)
266 StateP state (
new State);
277 Tree::PrimitiveP div (
new DivInt);
283 Tree::PrimitiveP sqrt (
new Sqrt);
285 Tree::PrimitiveP mod (
new Mod);
289 state->addGenotype(tree);
291 state->initialize(argc, argv);
303 for(i=32582658; i < 260000000; i++)
305 if( isPrime6k1_sp(i) == 1 )
307 if( !(isPrime6k1_sp(2*i+1) == 1 && i % 4 == 3) )
void execute(void *result, Tree::Tree &tree)
Execute the primitive.
Fitness for minimization problems.
std::string getName()
Return genotype's name (each genotype is uniquely identified with its name).
void execute(void *result, Tree::Tree &tree)
Execute the primitive.
FitnessP evaluate(IndividualP individual)
Evaluate a single individual. Method must create and return a Fitness object.
bool initialize(StateP)
Initialize the evaluator. Called before first evaluation occurs.
void execute(void *result, Tree::Tree &tree)
Execute the primitive.
State class - backbone of the framework.
Add function primitive (Tree genotype)
Div function primitive (Tree genotype)
Mul function primitive (Tree genotype)
Base primitive class (Tree genotype).
void getNextArgument(void *result, Tree &tree)
Execute next child node's primitive (execute next subtree).
Sub function primitive (Tree genotype)
Tree class - implements genotype as a tree.
bool addFunction(PrimitiveP)
Add user defined function primitive. Must be called prior to initialization (no impact otherwise).
void setTerminalValue(std::string, void *)
Set a terminal's value.
void execute(void *)
Execute current tree.