[1] | 1 | /* |
---|
| 2 | * conv_f8tof1.h |
---|
| 3 | * L-systemToF1 |
---|
| 4 | * |
---|
| 5 | * Created by Maciej Wajcht on 08-03-21. |
---|
| 6 | * Copyright 2008 __MyCompanyName__. All rights reserved. |
---|
| 7 | * |
---|
| 8 | */ |
---|
| 9 | |
---|
| 10 | #ifndef _CONV_F8_TO_F1_H |
---|
| 11 | #define _CONV_F8_TO_F1_H |
---|
| 12 | |
---|
| 13 | #include <map> |
---|
| 14 | #include <vector> |
---|
| 15 | #include <string> |
---|
| 16 | #include <list> |
---|
| 17 | #include <iostream> |
---|
| 18 | #include "genoconv.h" |
---|
| 19 | #include "model.h" |
---|
| 20 | |
---|
| 21 | using std::ostream; |
---|
| 22 | using std::vector; |
---|
| 23 | using std::list; |
---|
| 24 | using std::string; |
---|
| 25 | using std::map; |
---|
| 26 | |
---|
| 27 | enum RelationType { |
---|
| 28 | r_greater, |
---|
| 29 | r_greaterEqual, |
---|
| 30 | r_less, |
---|
| 31 | r_lessEqual, |
---|
| 32 | r_equal, |
---|
| 33 | r_different |
---|
| 34 | }; |
---|
| 35 | |
---|
| 36 | class Condition { |
---|
| 37 | public: |
---|
| 38 | RelationType relation; |
---|
| 39 | SString parameter; |
---|
| 40 | double value; |
---|
| 41 | |
---|
| 42 | friend ostream& operator<<(ostream& os, const Condition& c); |
---|
| 43 | }; |
---|
| 44 | |
---|
| 45 | class ActionP; |
---|
| 46 | |
---|
| 47 | class Action { |
---|
| 48 | public: |
---|
| 49 | SString name; |
---|
| 50 | bool ignoreParams; |
---|
| 51 | virtual const SString getF1Genotype(vector<double> params) = 0; |
---|
| 52 | virtual const list<ActionP> getActionList(const vector<double> params) = 0; |
---|
| 53 | virtual const SString getF8Representation() = 0; |
---|
| 54 | virtual ~Action() {} |
---|
| 55 | }; |
---|
| 56 | |
---|
| 57 | class ActionStrP { |
---|
| 58 | public: |
---|
| 59 | Action *action; |
---|
| 60 | vector<SString> params; |
---|
| 61 | }; |
---|
| 62 | |
---|
| 63 | class ActionP { |
---|
| 64 | public: |
---|
| 65 | Action *action; |
---|
| 66 | vector<double> params; |
---|
| 67 | }; |
---|
| 68 | |
---|
| 69 | class SubProduction { |
---|
| 70 | public: |
---|
| 71 | vector<Condition> conditions; |
---|
| 72 | vector<ActionStrP> actions; |
---|
| 73 | }; |
---|
| 74 | |
---|
| 75 | class PrimitiveProduction : public Action { |
---|
| 76 | public: |
---|
| 77 | PrimitiveProduction(const SString command); |
---|
| 78 | const SString getF1Genotype(const vector<double> params); |
---|
| 79 | const list<ActionP> getActionList(const vector<double> params); |
---|
| 80 | const SString getF8Representation(); |
---|
| 81 | protected: |
---|
| 82 | SString f1command; |
---|
| 83 | SString f8command; |
---|
| 84 | }; |
---|
| 85 | |
---|
| 86 | class ParamProduction : public Action { |
---|
| 87 | public: |
---|
| 88 | ParamProduction(const SString paramName); |
---|
| 89 | const SString getF1Genotype(const vector<double> params); |
---|
| 90 | const list<ActionP> getActionList(const vector<double> params); |
---|
| 91 | const SString getF8Representation(); |
---|
| 92 | protected: |
---|
| 93 | SString paramName; |
---|
| 94 | }; |
---|
| 95 | |
---|
| 96 | class NeuronProduction : public Action { |
---|
| 97 | public: |
---|
| 98 | NeuronProduction(SString body); |
---|
| 99 | const SString getF1Genotype(const vector<double> params); |
---|
| 100 | const list<ActionP> getActionList(const vector<double> params); |
---|
| 101 | const SString getF8Representation(); |
---|
| 102 | protected: |
---|
| 103 | SString body; |
---|
| 104 | }; |
---|
| 105 | |
---|
| 106 | /** |
---|
| 107 | * Pozycje liczone od 1 a nie od 0! |
---|
| 108 | */ |
---|
| 109 | class ParameterCollection { |
---|
| 110 | public: |
---|
| 111 | const double getValue(int position); |
---|
| 112 | const double getValue(SString name); |
---|
| 113 | const SString getParameterName(int position); |
---|
| 114 | const int getParameterPosition(SString name); //zwróci index liczony od 1! |
---|
| 115 | void setValue(int position, double value); |
---|
| 116 | void setValue(SString name, double value); |
---|
| 117 | void addParameter(SString name, int position = -1, double value = 0.0); |
---|
| 118 | const int size(); |
---|
| 119 | void removeParameter(int position); |
---|
| 120 | void removeParameter(SString name); |
---|
| 121 | bool paramExist(SString name); |
---|
| 122 | protected: |
---|
| 123 | vector<string> parameters; |
---|
| 124 | map<string, double> paramValues; |
---|
| 125 | }; |
---|
| 126 | |
---|
| 127 | class Production : public Action { |
---|
| 128 | public: |
---|
| 129 | ParameterCollection parameters; |
---|
| 130 | vector<SubProduction> subproductions; |
---|
| 131 | |
---|
| 132 | Production(); |
---|
| 133 | ~Production() {}; |
---|
| 134 | const SString getF1Genotype(const vector<double> params); |
---|
| 135 | const list<ActionP> getActionList(const vector<double> params); |
---|
| 136 | const SString getF8Representation(); |
---|
| 137 | }; |
---|
| 138 | |
---|
| 139 | class Lsystem { |
---|
| 140 | public: |
---|
| 141 | int iterations; |
---|
| 142 | map<string, double> startParams; |
---|
| 143 | map<string, Production*> productions; |
---|
| 144 | vector<NeuronProduction*> neuronProductions; |
---|
| 145 | string firstProductionName; |
---|
| 146 | |
---|
| 147 | Lsystem(); |
---|
| 148 | ~Lsystem(); |
---|
| 149 | PrimitiveProduction* getPrimitiveProduction(SString name); |
---|
| 150 | ParamProduction* getParamProduction(SString name); |
---|
| 151 | SString toString(); |
---|
| 152 | vector<Action*> getAllActions(bool normal, bool primitives, bool params, bool neurons); |
---|
| 153 | protected: |
---|
| 154 | map<string, PrimitiveProduction*> primitiveProductions; |
---|
| 155 | map<string, ParamProduction*> paramProductions; |
---|
| 156 | |
---|
| 157 | void removeEmptySubproductionsAndProductions(); |
---|
| 158 | }; |
---|
| 159 | |
---|
| 160 | class GenoConv_F8ToF1 : public GenoConverter { |
---|
| 161 | public: |
---|
| 162 | GenoConv_F8ToF1() { |
---|
| 163 | name = "f8 to f1 converter"; |
---|
| 164 | in_format = '8'; |
---|
| 165 | out_format = '1'; |
---|
| 166 | mapsupport = 0; |
---|
| 167 | info = "ble"; |
---|
[25] | 168 | maxF1Length = 500; |
---|
[1] | 169 | } |
---|
| 170 | |
---|
[25] | 171 | GenoConv_F8ToF1(int f1LengthLimit) { |
---|
| 172 | name = "f8 to f1 converter"; |
---|
| 173 | in_format = '8'; |
---|
| 174 | out_format = '1'; |
---|
| 175 | mapsupport = 0; |
---|
| 176 | info = "ble"; |
---|
| 177 | maxF1Length = f1LengthLimit; |
---|
| 178 | } |
---|
| 179 | |
---|
[1] | 180 | ~GenoConv_F8ToF1() {} |
---|
| 181 | |
---|
| 182 | SString convert(SString &in, MultiMap *map); |
---|
| 183 | bool checkSyntax(const char *geno); |
---|
| 184 | vector<SString> readProductionNames(const SString &in); |
---|
| 185 | //Lsystem* createLsystem(const SString &in); |
---|
| 186 | Lsystem* createLsystem(SString in); |
---|
| 187 | protected: |
---|
| 188 | bool parseInput(const char* src, Lsystem* lsys); |
---|
[25] | 189 | int maxF1Length; |
---|
[1] | 190 | }; |
---|
| 191 | |
---|
| 192 | #endif |
---|