-
Notifications
You must be signed in to change notification settings - Fork 19
/
basicFunctions.h
97 lines (88 loc) · 1.8 KB
/
basicFunctions.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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* basicFunctions.h
* GeneticProg
*
* Created by Peter Harrington on 7/1/11.
* Copyright 2011 Clean Micro, LLC. All rights reserved.
* To Do:
Transforms to add:
[ ] Lag
[ ] input^2
[ ] sqrt
[ ] ln
*
*/
#ifndef BASIC_FTNS_H
#define BASIC_FTNS_H 1
#include <string>
using namespace std;
//Master abstract class: GOftn: Genetic Optimize Function
class GOftn
{
public:
string label;
int numChildren;
GOftn* children[];
GOftn() { } // to be used later
virtual ~GOftn() { } // to be used later
virtual double eval(double inVal) = 0; //setting the 0 makes it a PURE
virtual GOftn* clone() = 0; //make a deep copy of the current tree
virtual string getLabel() = 0;
};
//class for storing constant values
class ConstNode : public GOftn {
double constVal;
public:
ConstNode();
ConstNode(double preSetVal);
virtual double eval(double inVal);
ConstNode* clone();
virtual string getLabel();
};
//class for using inputs
class InputNode : public GOftn {
int inputIndex;
public:
InputNode(int numPossibleInputs);
virtual double eval(double inVal);
InputNode* clone();
void setValues(int inIndex);
virtual string getLabel();
};
//addition
class Add : public GOftn {
public:
Add();
GOftn* children[2];
virtual double eval(double inVal);
Add* clone();
virtual string getLabel();
};
//subtraction
class Subtract : public GOftn {
public:
Subtract();
GOftn* children[2];
virtual double eval(double inVal);
Subtract* clone();
virtual string getLabel();
};
//multiplication
class Multiply : public GOftn {
public:
Multiply();
GOftn* children[2];
virtual double eval(double inVal);
Multiply* clone();
virtual string getLabel();
};
//division
class Divide : public GOftn {
public:
Divide();
GOftn* children[2];
virtual double eval(double inVal);
Divide* clone();
virtual string getLabel();
};
#endif