00001
00017 #ifndef NODE_H
00018 #define NODE_H
00019
00020 #include <vector>
00021 #include <string>
00022 #include <time.h>
00023 #include <stdio.h>
00024 #include <stdlib.h>
00025
00026 using namespace std;
00027
00028 #include "Tree.h"
00029
00030 extern bool verbose;
00031 extern bool outputAll;
00032 extern bool globalUp;
00033 extern bool rinputs;
00034 extern bool calc;
00035
00036 void ipause();
00037
00038 class NodeList;
00039
00045 class Node {
00046 public:
00047 Node();
00049 virtual ~Node(){};
00051 Node &setValue(bool v){init = v; current = v; previous = v; return *this;};
00053 bool getValue(){return previous;};
00054 void setMut ( string m );
00055 void setName(string m){name = m;};
00056 void setMutRate(int i){mutRate = i;bMutRate=i;};
00057 virtual bool evaluate(NodeList &nl, int t)=0;
00058 virtual string getType(void)=0;
00059 virtual void reset(void)=0;
00060 protected:
00061 bool init;
00062 string name;
00063 int mutRate;
00064 int bMutRate;
00065 string mutation;
00066 bool current;
00067 bool previous;
00068 int timeT;
00069 };
00070
00078 class InputNode : public Node {
00079 public:
00080 InputNode();
00081 virtual bool evaluate(NodeList &nl, int t);
00082 virtual string getType(void){return "Input";};
00083 virtual void reset(void);
00084
00086 InputNode &setStart(int s) {start.push_back(s); return *this;};
00088 InputNode &setDosage(int d) {dosage.push_back(d); return *this;};
00090 InputNode &setDuration(int d) {duration.push_back(d); return *this;};
00092 InputNode &setInjectionValue() {injectionValue = !previous; return *this;};
00093 void setLevels(int,int);
00094 void checkDosages(void);
00095 void reverseParams(void);
00096 void printParams(void);
00097 void setNoise( bool );
00098 void setManual( bool );
00099 void setInputBitString( const string &, NodeList & );
00100 void setRange(int i, int j){high=i;low=j;};
00101 int getDos(void){return dosage[0];};
00102
00103 private:
00104 int high, low;
00105 vector<int> start;
00106 vector<int> dosage;
00107 vector<int> duration;
00108 vector<bool> amount;
00109 string inputBitStr;
00110 int NC_amount;
00111 void amountInit( int );
00112 bool injectionValue;
00113 bool noisy;
00114 bool manual;
00115 int on;
00116
00117
00118 bool set;
00119 vector<int> bstart;
00120 vector<int> bdosage;
00121 vector<int> bduration;
00122 };
00123
00129 class OutputNode : public Node {
00130 public:
00131 OutputNode();
00133 OutputNode &setSource(int s) {source = s; return *this;};
00134 virtual bool evaluate(NodeList &nl, int t);
00135 virtual string getType(void){return "Output";};
00136 virtual void reset(void){timeT=0; current = init; previous = init;};
00137 private:
00138 int source;
00139 };
00140
00141 class Mutant {
00142 public:
00144 Mutant( const string & n, const string &m)
00145 {
00146 name = n;
00147 mutation = m;
00148 };
00150 string getType (void) { return mutation; };
00152 string getName (void) { return name; };
00153 private:
00154 string name;
00155 string mutation;
00156 };
00157
00158
00166 class BooleanNode : public Node {
00167 public:
00168 BooleanNode();
00169 virtual bool evaluate(NodeList &nl, int t);
00170 virtual void reset(void){timeT=0; current = init; previous = init;mutRate=bMutRate;};
00171 virtual string getType(void){return "Bool";};
00172 void mutate(int,int, string);
00173 BooleanNode &addDecision(string s);
00174 BooleanNode &addSource(int item);
00175 void simplify(void){path.simplify();};
00176 void setH(void){path.setH(sources.size()), mutTree.setH(sources.size());};
00178 BooleanNode &setTarget(bool b){target=b; return *this;};
00179 private:
00180 Tree path;
00181 Tree mutTree;
00182 vector<int> sources;
00184 int sourceSize() {return static_cast<int>(sources.size());};
00185 vector<int> table;
00187 int tableSize() {return static_cast<int>(table.size());};
00188 bool target;
00189 };
00190
00196 class DelayNode : public Node {
00197 public:
00198 DelayNode(int d=1);
00199 ~DelayNode();
00200 DelayNode(const DelayNode &r);
00201 const DelayNode &operator =(const DelayNode &);
00202 virtual bool evaluate(NodeList &nl, int t);
00203 virtual string getType(void){return "Delay";};
00204 virtual void reset(void){timeT=0; current = init; previous = init;};
00205 DelayNode &setDelay(int d);
00207 DelayNode &setSource(int s){source=s; return *this;};
00208 private:
00209 int source;
00210 int delay;
00211 int *pipeline;
00212 };
00213
00219 class SustainNode : public Node {
00220 public:
00221 SustainNode(int d=1);
00222 virtual bool evaluate(NodeList &nl, int t);
00223 virtual string getType(void){return "Sustain";};
00224 virtual void reset(void){timeT=0; current = init; previous = init;};
00226 SustainNode &setDuration(int d) {duration = d; return *this;};
00228 SustainNode &setSource(int s) {source=s; return *this;};
00229 private:
00230 int source;
00231 int duration;
00232 int start;
00233 };
00234 #endif