Changeset 196 for cpp/frams/genetics/f4/f4_general.h
- Timestamp:
- 03/25/14 03:22:37 (11 years ago)
- Location:
- cpp/frams/genetics/f4
- Files:
-
- 1 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/genetics/f4/f4_general.h
r193 r196 1 /* 2 * f4_general.h - f4 genotype functions. 3 * 4 * f4genotype - f4 format genotype conversions for FramSticks 5 * 6 * Copyright (C) 1999,2000 Adam Rotaru-Varga (adam_rotaru@yahoo.com) 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Lesser General Public 10 * License as published by the Free Software Foundation; either 11 * version 2.1 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public 19 * License along with this library; if not, write to the Free Software 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 * 22 */ 1 // This file is a part of the Framsticks GDK. 2 // Copyright (C) 2002-2014 Maciej Komosinski and Szymon Ulatowski. See LICENSE.txt for details. 3 // Refer to http://www.framsticks.com/ for further information. 4 5 // Copyright (C) 1999,2000 Adam Rotaru-Varga (adam_rotaru@yahoo.com), GNU LGPL 23 6 24 7 #ifndef _F4_GENERAL_H_ 25 8 #define _F4_GENERAL_H_ 26 9 27 #include "f4_orientmat.h"28 #include "3d.h"29 #include "sstring.h"30 #include "multirange.h"10 //#include "f4_orientmat.h" 11 #include <frams/util/3d.h> 12 #include <frams/util/sstring.h> 13 #include <frams/util/multirange.h> 31 14 32 15 #ifdef DMALLOC … … 37 20 class f4_Props 38 21 { 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 22 public: 23 // fill with default values 24 f4_Props(); 25 // must sum to 1 26 void normalizeBiol4(); 27 void executeModifier(char modif); 28 void adjust(); 29 30 double len; // length (dlug) 31 double curv; // curvedness (skr) 32 double mass; 33 double friction; 34 double ruch; 35 double assim; 36 double odpor; 37 double ingest; // ingestion (wchl) 38 double twist; 39 double energ; 57 40 }; 58 41 … … 85 68 { 86 69 public: 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 repeat_stack() { top=0; };103 inline void null() { top=0; };104 inline void push(repeat_ptr A) { if (top>=stackSize) return; ptr[top]=A; top++; };105 inline void pop() { if (top>0) top--; };106 inline repeat_ptr * first() { return &(ptr[top-(top>0)]); };107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 70 class repeat_ptr 71 { 72 public: 73 repeat_ptr() : node(NULL), count(-1) { }; 74 repeat_ptr(f4_node * a, int b) : node(a), count(b) { }; 75 inline void null() { node = NULL; count = -1; }; 76 inline bool isNull() const { return ((node == NULL) || (count <= 0)); }; 77 inline void dec() { count--; }; 78 f4_node * node; // ptr to repetition code 79 char count; // repetition counter 80 }; 81 82 class repeat_stack // a stack of repet_ptr's 83 { 84 public: 85 repeat_stack() { top = 0; }; 86 inline void null() { top = 0; }; 87 inline void push(repeat_ptr A) { if (top >= stackSize) return; ptr[top] = A; top++; }; 88 inline void pop() { if (top > 0) top--; }; 89 inline repeat_ptr * first() { return &(ptr[top - (top > 0)]); }; 90 static const int stackSize = 4; // max 4 nested levels 91 repeat_ptr ptr[stackSize]; 92 short int top; // top of the stack 93 }; 94 95 f4_Cell(int nname, 96 f4_Cell * ndad, int nangle, f4_Props newP); 97 f4_Cell(f4_Cells * nO, int nname, f4_node * ngeno, f4_node * ngcur, 98 f4_Cell * ndad, int nangle, f4_Props newP); 99 ~f4_Cell(); 100 101 int onestep(); // execute one simulation step (till a division) 102 103 int addlink(f4_Cell * nfrom, double nw, long nt); 104 void adjustRec(); 105 106 int name; // name (number) 107 int type; // type 108 f4_Cell * dadlink; 109 f4_Cells * org; // uplink to organism 110 111 f4_node * genot; // genotype 112 f4_node * gcur; // current genotype execution pointer 113 int active; // whether development is still active 114 repeat_stack repeat; 115 int recProcessedFlag; // used during recursive traverse 116 // remember the genotype codes affecting this cell so far 117 MultiRange genoRange; 118 119 f4_Props P; // properties 120 int anglepos; // number of position within dad's children (,) 121 int childcount; // number of children 122 int commacount; // number of postitions at lastend (>=childcount) 123 double rolling; // rolling angle ('R') (around x) 124 double xrot; 125 double zrot; // horizontal rotation angle due to 126 // branching (around z) 127 //Pt3D firstend; // coord.s of first end (connects to parent) 128 //Pt3D lastend; // last end 129 //f4_OrientMat OM; 130 double mz; // freedom in z 131 long p2_refno; // number of last end part object, used in f0 132 long joint_refno; // number of the joint object, used in f0 133 long neuro_refno; // number of the neuro object, used in f0 134 135 long ctrl; // neuron type 136 double state; 137 double inertia; 138 double force; 139 double sigmo; 140 f4_CellLink* links[MAXINPUTS]; 141 int nolink; 159 142 }; 160 143 … … 164 147 { 165 148 public: 166 167 168 169 170 149 f4_CellLink(f4_Cell * nfrom, double nw, long nt); 150 f4_Cell * from; 151 // type: 0: input, 1 '*', 2 'G', 3 'T', 4 'S' 152 long t; 153 double w; 171 154 }; 172 155 … … 176 159 class f4_Cells 177 160 { 178 179 180 181 182 183 184 185 186 187 int geterror() { return error;};188 int geterrorpos() { return errorpos;};189 190 191 192 193 194 195 196 161 public: 162 f4_Cells(f4_node * genome, int nrepair); 163 f4_Cells(SString &genome, int nrepair); 164 ~f4_Cells(); 165 void addCell(f4_Cell * newcell); 166 void toF1Geno(SString &out); // output to f1 format, approximation 167 int onestep(); // simulate all parts for one step 168 int simulate(); // simulate development, return error (0 for ok) 169 // for error reporting / genotype fixing 170 int geterror() { return error; }; 171 int geterrorpos() { return errorpos; }; 172 void setError(int nerrpos); 173 void setRepairRemove(int nerrpos, f4_node * rem); 174 int setRepairInsert(int nerrpos, f4_node * parent, f4_node * insert); 175 void repairGeno(f4_node * geno, int whichchild); 176 177 // the cells 178 f4_Cell * C[MAX4CELLS]; 179 int nc; 197 180 198 181 private: 199 200 201 202 203 204 205 206 207 208 182 // for error reporting / genotype fixing 183 int repair; 184 int error; 185 int errorpos; 186 f4_node * repair_remove; 187 f4_node * repair_parent; 188 f4_node * repair_insert; 189 void toF1GenoRec(int curc, SString &out); 190 f4_Cell * tmpcel; // needed by toF1Geno 191 f4_node * f4rootnode; // used by constructor 209 192 }; 210 193 … … 216 199 { 217 200 public: 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 201 char name; // one-letter 'name' 202 f4_node * parent; // parent link, or NULL 203 f4_node * child; // child, or NULL 204 f4_node * child2; // second child, or NULL 205 int pos; // original position in string 206 int i1; // internal int parameter1 207 long l1; // internal long parameter1 208 double f1; // internal double parameter1 209 210 f4_node(); 211 f4_node(char nname, f4_node * nparent, int npos); 212 ~f4_node(); 213 int addChild(f4_node * nchi); 214 int removeChild(f4_node * nchi); 215 int childCount(); // return no of children, 0, 1, or 2 216 int count(); // return no of nodes (recursive) 217 f4_node * ordNode(int n); // returns the nth subnode (0-) 218 f4_node * randomNode(); // returns a random subnode 219 f4_node * randomNodeWithSize(int min, int max); // returns a random subnode with given size 220 void sprintAdj(char *& buf); // print recursively 221 f4_node * duplicate(); // create duplicate copy. recursive. 222 void destroy(); // release memory. recursive. 240 223 private: 241 224 void sprint(SString & out); // print recursively 242 225 }; 243 226
Note: See TracChangeset
for help on using the changeset viewer.