- Timestamp:
- 03/29/18 22:52:36 (7 years ago)
- Location:
- cpp/frams/genetics/f4
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/genetics/f4/f4_general.cpp
r760 r767 466 466 float w = gcur->f1; 467 467 f4_Cell *tneu = NULL; 468 if (t > 0) // sensors 468 if (t < 0) // wrong sensor 469 { 470 string buf = "wrong sensor in link '"; 471 buf.append(gcur->s1); 472 buf.append("'"); 473 logMessage("f4_Cell", "onestep", LOG_ERROR, buf.c_str()); 474 org->setRepairRemove(gcur->pos, gcur); 475 return 1; 476 } 477 else if (t > 0) // sensors 469 478 { 470 479 char *temp = (char*)gcur->s1.c_str(); … … 476 485 buf.append(gcur->s1); 477 486 buf.append("'"); 478 logMessage("f4_Cell", "onestep", LOG_ WARN, buf.c_str()); //TODO ask487 logMessage("f4_Cell", "onestep", LOG_ERROR, buf.c_str()); 479 488 org->setRepairRemove(gcur->pos, gcur); 480 489 return 1; … … 1227 1236 void f4_node::sprint(SString& out) 1228 1237 { 1229 string buf2 = "";1238 char buf2[20]; 1230 1239 // special case: repetition code 1231 1240 if (name == "#") … … 1234 1243 if (i1 != 1) 1235 1244 { 1236 sprintf( (char*)buf2.c_str(), "%d", i1);1237 out += buf2 .c_str();1245 sprintf(buf2, "%d", i1); 1246 out += buf2; 1238 1247 } 1239 1248 } … … 1250 1259 else 1251 1260 { 1252 sprintf( (char*)buf2.c_str(), "%ld", l1);1253 out += buf2 .c_str();1254 } 1255 sprintf( (char*)buf2.c_str(), ":%g]", f1);1256 out += buf2 .c_str();1261 sprintf(buf2, "%ld", l1); 1262 out += buf2; 1263 } 1264 sprintf(buf2, ":%g]", f1); 1265 out += buf2; 1257 1266 } 1258 1267 else if (name == ":") 1259 1268 { 1260 sprintf( (char*)buf2.c_str(), ":%c%c:", l1 ? '+' : '-', (char)i1);1261 out += buf2 .c_str();1269 sprintf(buf2, ":%c%c:", l1 ? '+' : '-', (char)i1); 1270 out += buf2; 1262 1271 } 1263 1272 else if (name == "@" || name == "|") … … 1265 1274 if (parent->name == "N") 1266 1275 { 1267 buf2 = name; 1268 out += buf2.c_str(); 1276 out += name.c_str(); 1269 1277 } 1270 1278 else 1271 1279 { 1272 1280 out += "N:"; 1273 buf2 = name; 1274 out += buf2.c_str(); 1281 out += name.c_str(); 1275 1282 } 1276 1283 } … … 1283 1290 out += "N:"; 1284 1291 } 1285 buf2 = name; 1286 out += buf2.c_str(); 1292 out += name.c_str(); 1287 1293 } 1288 1294 } … … 1402 1408 { 1403 1409 // repetition marker, 1 by default 1404 if (sscanf(genot + gpos, "#%d", &i) != 1) i = 1; 1410 ExtValue val; 1411 const char * end = val.parseNumber(genot + gpos + 1, ExtPType::TInt); 1412 if (end == NULL) i = 1; 1413 else i = val.getInt(); 1405 1414 // find out genotype start for continuation 1406 1415 j = scanrec(genot + gpos + 1, strlen(genot + gpos + 1), '>'); 1407 1416 // skip number 1408 1417 oldpos = gpos; 1409 gpos++; 1410 while ((genot[gpos] >= '0') && (genot[gpos] <= '9')) gpos++; 1418 gpos += end - (genot + gpos); 1419 //gpos++; 1420 //while ((genot[gpos] >= '0') && (genot[gpos] <= '9')) gpos++;node1 = new f4_node("#", par, oldpos); 1411 1421 node1 = new f4_node("#", par, oldpos); 1412 1422 node1->i1 = i; … … 1527 1537 end = parseConnectionWithNeuron(genot + gpos, neutype, w); 1528 1538 if (end == NULL) t = -1; 1529 t = 1;1539 else t = 1; 1530 1540 } 1531 1541 else -
cpp/frams/genetics/f4/f4_general.h
r760 r767 97 97 inline void dec() { count--; }; 98 98 f4_node *node; ///<pointer to the repetition code 99 charcount; ///<repetition counter99 int count; ///<repetition counter 100 100 }; 101 101 … … 140 140 * @param newP genotype properties of a given cell 141 141 */ 142 f4_Cell(int nname, 143 f4_Cell * ndad, int nangle, GeneProps newP); 142 f4_Cell(int nname, f4_Cell *ndad, int nangle, GeneProps newP); 144 143 /** 145 144 * Creates a new f4_Cell object. … … 152 151 * @param newP genotype properties of a given cell 153 152 */ 154 f4_Cell(f4_Cells *nO, int nname, f4_node *ngeno, f4_node *ngcur, 155 f4_Cell *ndad, int nangle, GeneProps newP); 153 f4_Cell(f4_Cells *nO, int nname, f4_node *ngeno, f4_node *ngcur, f4_Cell *ndad, int nangle, GeneProps newP); 156 154 157 155 ~f4_Cell(); 158 156 159 157 /** 160 * Performs one step of cell development. This method requirespointer to161 * f4_Cells object in org attribute. If the current node in genotype tree162 * represents branching, thenthe cell divides into two cells, unless the163 * cell was already differentiated into stick cell. Otherwisethe current164 * differentiation or modification is performed on cell. If current node is165 * creating a connection between two neuron nodes ,and the input node is not166 * yet developed, the n the simulation of current cell halts andwaits until167 * the input node will be developed. The onestep method is ran on eachcell168 * at least once and if one cell requires another to develop, thenonestep158 * Performs a single step of cell development. This method requires a pointer to 159 * the f4_Cells object in org attribute. If the current node in genotype tree 160 * is the branching character '<', the cell divides into two cells, unless the 161 * cell was already differentiated into the stick cell. Otherwise, the current 162 * differentiation or modification is performed on the cell. If current node is 163 * creating a connection between two neuron nodes and the input node is not 164 * yet developed, the simulation of the development of the current cell waits until 165 * the input node is created. The onestep method is deployed for every cell 166 * at least once. If one cell requires another one to develop, onestep 169 167 * should be deployed again on this cell. This method, unlike genotype tree 170 168 * creation, checks semantics. This means that this function will fail if: 171 * - the stick cell will have divide node,172 * - the undifferentiated cell will have '>' node (end of cell development),173 * - the stack of repetition marker '#' will be overflowed,169 * - the cell differentiated as a stick will have branching node '<', 170 * - the undifferentiated cell will have termination node '>' (end of cell development without differentiation), 171 * - the stack of repetition marker '#' will exceed maximum allowed value of repetition, 174 172 * - the stick modifiers, like rotation, will be applied on neuron cell, 175 173 * - the differentiated cell will be differentiated again, 176 * - the neuron class inside cell connection definitionis not a sensor,177 * - the connection between neurons c ouldnot be established,174 * - the neuron class inside cell connection (i.e. N[G:5]) is not a sensor, 175 * - the connection between neurons cannot be established, 178 176 * - the neuron class is not valid. 179 177 * 180 178 * @return 0 if development was successful, 1 if there was an error in genotype tree 181 179 */ 182 int onestep(); // execute one simulation step (till a division)183 184 /** 185 * Add link between this neuron cell and a given neuron cell. Ifnfrom object186 * is not given, than neuron type in nt holds thesensor type.180 int onestep(); 181 182 /** 183 * Adds a link between this neuron cell and a given neuron cell in nfrom. If the nfrom object 184 * is not given, neuron type in nt should be a sensor type. 187 185 * @param nfrom input neuron cell, or NULL if not given 188 186 * @param nw weight of connection … … 190 188 * @return 0 if link is established, -1 otherwise 191 189 */ 192 int addlink(f4_Cell * 190 int addlink(f4_Cell *nfrom, double nw, string nt); 193 191 194 192 /** … … 197 195 void adjustRec(); 198 196 199 int name; ///<name of cell (number)197 int name; ///<name of cell (number) 200 198 int type; ///<type 201 f4_Cell * dadlink;///<pointer to cell parent202 f4_Cells *org; ///<uplink to organism203 204 f4_node * genot;///<genotype tree205 f4_node * gcur;///<current genotype execution pointer206 int active; ///<whether development is still active199 f4_Cell *dadlink; ///<pointer to cell parent 200 f4_Cells *org; ///<uplink to organism 201 202 f4_node *genot; ///<genotype tree 203 f4_node *gcur; ///<current genotype execution pointer 204 int active; ///<determines whether development is still active 207 205 repeat_stack repeat; ///<stack holding repetition nodes and counters 208 int recProcessedFlag;///<used during recursive traverse206 int recProcessedFlag; ///<used during recursive traverse 209 207 MultiRange genoRange; ///<remember the genotype codes affecting this cell so far 210 208 211 GeneProps P;///<properties209 GeneProps P; ///<properties 212 210 int anglepos; ///<number of position within dad's children (,) 213 211 int childcount; ///<number of children … … 218 216 219 217 double mz; ///<freedom in z 220 int p2_refno; ///< number oflast end part object, used in f0221 int joint_refno; ///< number of the joint object, used in f0222 int neuro_refno; ///< number of the neuro object, used in f0218 int p2_refno; ///<the number of the last end part object, used in f0 219 int joint_refno; ///<the number of the joint object, used in f0 220 int neuro_refno; ///<the number of the neuro object, used in f0 223 221 224 222 int ctrl; ///<neuron type … … 227 225 double force; ///<force of neuron 228 226 double sigmo; ///<sigmoid of neuron 229 f4_CellLink *links[MAXINPUTS]; ///<array of neuron links227 f4_CellLink *links[MAXINPUTS]; ///<array of neuron links 230 228 int nolink; ///<number of links 231 NeuroClass * neuclass = NULL;///<pointer to neuron class229 NeuroClass *neuclass; ///<pointer to neuron class 232 230 }; 233 231 … … 239 237 public: 240 238 /** 241 * Constructor for f4_CellLink class. Parameter nfrom can representinput242 * neuron cell or be NULL, if connection has neuron cell definition inside.243 * The inside definition must be hold in nt parameter and a neuron class244 * must represent sensor.239 * Constructor for f4_CellLink class. Parameter nfrom represents input 240 * neuron cell or NULL if connection has defined sensor type inside, like "[G:5]". 241 * The name of sensor class defined inside neuron connection is stored in the nt 242 * parameter. 245 243 * @param nfrom pointer to input neuron cell or NULL 246 244 * @param nw weight of connection 247 245 * @param nt name of neuron class or empty string 248 246 */ 249 f4_CellLink(f4_Cell * 250 251 f4_Cell * 252 string t; ///<empty if fromcell is given, NeuroClass name otherwise253 double w;///<weight of connection247 f4_CellLink(f4_Cell *nfrom, double nw, string nt); 248 249 f4_Cell *from; ///<pointer to input neuron cell 250 string t; ///<empty if 'from' cell is given, NeuroClass name otherwise 251 double w; ///<weight of connection 254 252 }; 255 253 … … 257 255 // a collection of cells, like Organism, for developmental encoding 258 256 /** 259 * Class representing a collection of cells. It is equivalent oforganism.257 * A class representing a collection of cells. It is equivalent to an organism. 260 258 */ 261 259 class f4_Cells … … 268 266 * @param nrepair 0 if nothing to repair 269 267 */ 270 f4_Cells(f4_node * 268 f4_Cells(f4_node *genome, int nrepair); 271 269 272 270 /** … … 283 281 284 282 /** 285 * Adds new cell to organism.283 * Adds a new cell to organism. 286 284 * @param newcell cell to be added 287 285 */ 288 void addCell(f4_Cell * newcell); 289 290 /** 291 * Creates approximate genotype in f1 encoding and stores it in a given 292 * parameter. 293 * @param out the string in which approximate f1 genotype will be stored 286 void addCell(f4_Cell *newcell); 287 288 /** 289 * Creates an approximate genotype in the f1 encoding and stores it in a given parameter. 290 * @param out the string in which the approximate f1 genotype will be stored 294 291 */ 295 292 void toF1Geno(SString &out); 296 293 297 294 /** 298 * Performs single step of organism development. It runs each active cell299 * in organism.300 * @return 0 if all cells are developed, or1 otherwise295 * Performs a single step of organism development. It runs each active cell 296 * in the organism. 297 * @return 0 if all cells are developed, 1 otherwise 301 298 */ 302 299 int onestep(); 303 300 304 301 /** 305 * Performs full development of organism and returns error code if something302 * Performs the full development of organism and returns error code if something 306 303 * went wrong. 307 304 * @return 0 if organism developed successfully, error code if something went wrong … … 310 307 311 308 /** 312 * Returns error code of last simulation.309 * Returns error code of the last simulation. 313 310 * @return error code 314 311 */ … … 316 313 317 314 /** 318 * Returns position of error in genotype.319 * @return position of error315 * Returns position of an error in genotype. 316 * @return position of an error 320 317 */ 321 318 int geterrorpos() { return errorpos; }; 322 319 323 320 /** 324 * Sets error code GENOPER_OPFAIL for simulation on a given position.325 * @param nerrpos position of error321 * Sets error code GENOPER_OPFAIL for a simulation on a given position. 322 * @param nerrpos position of an error 326 323 */ 327 324 void setError(int nerrpos); … … 329 326 /** 330 327 * Sets the element of genotype to be repaired by removal. 331 * @param nerrpos position of error in genotype332 * @param rem the f4_node to be removed from genotype tree in order to repair333 */ 334 void setRepairRemove(int nerrpos, f4_node * 335 336 /** 337 * Sets repairing of genotype by inserting new node tocurrent genotype.338 * @param nerrpos position of error in genotype339 * @param parent the parent of new element328 * @param nerrpos position of an error in genotype 329 * @param rem the f4_node to be removed from the genotype tree in order to repair 330 */ 331 void setRepairRemove(int nerrpos, f4_node *rem); 332 333 /** 334 * Sets repairing of a genotype by inserting a new node to the current genotype. 335 * @param nerrpos position of an error in genotype 336 * @param parent the parent of a new element 340 337 * @param insert the element to be inserted 341 338 * @return 0 if repair can be performed, -1 otherwise (the repair flag wasn't set in constructor) 342 339 */ 343 int setRepairInsert(int nerrpos, f4_node * parent, f4_node *insert);344 345 /** 346 * Repairs genotype according to setRepairRemove or setRepairInsert method.347 * @param geno pointer to genotype tree340 int setRepairInsert(int nerrpos, f4_node *parent, f4_node *insert); 341 342 /** 343 * Repairs the genotype according to setRepairRemove or setRepairInsert methods. 344 * @param geno pointer to the genotype tree 348 345 * @param whichchild 1 if first child, 2 otherwise 349 346 */ 350 void repairGeno(f4_node * 347 void repairGeno(f4_node *geno, int whichchild); 351 348 352 349 // the cells 353 f4_Cell * C[MAX4CELLS]; ///<Array of all cells oforganism354 int nc; ///<Number of cells in organism350 f4_Cell *C[MAX4CELLS]; ///<Array of all cells of an organism 351 int nc; ///<Number of cells in an organism 355 352 356 353 private: … … 359 356 int error; 360 357 int errorpos; 361 f4_node * 362 f4_node * 363 f4_node * 358 f4_node *repair_remove; 359 f4_node *repair_parent; 360 f4_node *repair_insert; 364 361 void toF1GenoRec(int curc, SString &out); 365 f4_Cell * 366 f4_node * 362 f4_Cell *tmpcel; // needed by toF1Geno 363 f4_node *f4rootnode; // used by constructor 367 364 }; 368 365 369 366 370 367 /** 371 * Class to organize a f4 genotype in a tree structure.368 * A class to organize a f4 genotype in a tree structure. 372 369 */ 373 370 class f4_node … … 375 372 public: 376 373 string name; ///<one-letter 'name', multiple characters for classes 377 f4_node *parent; ///<parent link ,or NULL378 f4_node *child; ///<child ,or NULL379 f4_node *child2; ///<second child ,or NULL380 int pos; ///<original position instring381 int 382 int 383 double 374 f4_node *parent; ///<parent link or NULL 375 f4_node *child; ///<child or NULL 376 f4_node *child2; ///<second child or NULL 377 int pos; ///<original position in the string 378 int i1; ///<internal int parameter1 379 int l1; ///<internal long parameter1 380 double f1; ///<internal double parameter1 384 381 string s1; ///<internal string parameter1 385 382 386 /**387 * Default constructor.388 */389 383 f4_node(); 390 384 … … 392 386 * Multiple-character name constructor. 393 387 * @param nname string from genotype representing node 394 * @param nparent pointer to parent of node395 * @param npos position of node substring in genotype string396 */ 397 f4_node(string nname, f4_node * 398 399 /** 400 * One-character name constructor.388 * @param nparent pointer to parent of the node 389 * @param npos position of node substring in the genotype string 390 */ 391 f4_node(string nname, f4_node *nparent, int npos); 392 393 /** 394 * Single-character name constructor. 401 395 * @param nname character from genotype representing node 402 * @param nparent pointer to parent of node 403 * @param npos position of node character in genotype string 404 */ 405 f4_node(char nname, f4_node * nparent, int npos); 406 407 /** 408 * Desctructor of object. 409 */ 396 * @param nparent pointer to parent of the node 397 * @param npos position of node character in the genotype string 398 */ 399 f4_node(char nname, f4_node *nparent, int npos); 400 410 401 ~f4_node(); 411 402 412 403 /** 413 * Method for adding child to anode.414 * @param nchi child to be added tonode415 * @return 0 if child could be added, -1 otherwise416 */ 417 int addChild(f4_node *nchi);418 419 /** 420 * Method for removing child fromnode.421 * @param nchi child to be removed fromnode404 * Adds the child to the node. 405 * @param nchi the child to be added to the node 406 * @return 0 if the child could be added, -1 otherwise 407 */ 408 int addChild(f4_node *nchi); 409 410 /** 411 * Removes the child from the node. 412 * @param nchi the child to be removed from the node 422 413 * @return 0 if child could be removed, -1 otherwise 423 414 */ 424 int removeChild(f4_node *nchi);425 426 /** 427 * Returns number of children.415 int removeChild(f4_node *nchi); 416 417 /** 418 * Returns the number of children. 428 419 * @return 0, 1 or 2 429 420 */ 430 int 431 432 /** 433 * Returns number of nodes coming from this node in a recursive way.434 * @return number of nodes from this node435 */ 436 int 421 int childCount(); 422 423 /** 424 * Returns the number of nodes coming from this node in a recursive way. 425 * @return the number of nodes from this node 426 */ 427 int count(); 437 428 438 429 /** 439 430 * Returns the nth subnode (0-) 440 * @param n index of child to be found441 * @return pointer to nth subnode or NULL if not found431 * @param n index of the child to be found 432 * @return pointer to the nth subnode or NULL if not found 442 433 */ 443 434 f4_node * ordNode(int n); … … 450 441 451 442 /** 452 * Returns a random subnode with given size.443 * Returns a random subnode with a given size. 453 444 * @param min minimum size 454 445 * @param max maximum size 455 * @return a random subnode with given size or NULL446 * @return a random subnode with a given size or NULL 456 447 */ 457 448 f4_node * randomNodeWithSize(int min, int max); 458 449 459 450 /** 460 * Prints recursively t ree from a given node.461 * @param buf variable storingprinting result462 */ 463 void sprintAdj(char *& 464 465 /** 466 * Recursively copies genotype tree from this node.451 * Prints recursively the tree from a given node. 452 * @param buf variable to store printing result 453 */ 454 void sprintAdj(char *&buf); 455 456 /** 457 * Recursively copies the genotype tree from this node. 467 458 * @return pointer to a tree copy 468 459 */ … … 474 465 void destroy(); 475 466 private: 476 void sprint(SString & 467 void sprint(SString &out); // print recursively 477 468 }; 478 469 … … 480 471 481 472 /** 482 * Main function to perform conversion of f4 geno totree structure. Prepares473 * The main function for converting a string of f4 encoding to a tree structure. Prepares 483 474 * f4_node root of tree and runs f4_processrec function for it. 484 * @param geno string representingf4 genotype485 * @return pointer to f4_node object representingf4 tree root486 */ 487 f4_node * f4_processtree(const char * 488 489 /** 490 * Scans genotype string from a given position. This recursive method creates491 * tree of f4_node objects. The method extracteach potentially functional element492 * of genotype string to separate f4_nodes. Whenbranching character '<' occurs,493 * then f4_processrec is ran forlatest f4_node element. This method does not494 * analyse genotype semantically, it checks only ifsyntax is proper. The only495 * semantic aspect is neuron class name extraction, in whichthe GenoOperators496 * class is used to parse possible neuron class in genotype.497 * @param genot the string holding all genotype475 * @param geno the string representing an f4 genotype 476 * @return a pointer to the f4_node object representing the f4 tree root 477 */ 478 f4_node * f4_processtree(const char *geno); 479 480 /** 481 * Scans a genotype string starting from a given position. This recursive method creates 482 * a tree of f4_node objects. This method extracts each potentially functional element 483 * of a genotype string to a separate f4_nodes. When the branching character '<' occurs, 484 * f4_processrec is deployed for the latest f4_node element. This method does not 485 * analyse the genotype semantically, it only checks if the syntax is proper. The only 486 * semantic aspect is neuron class name extraction, where the GenoOperators 487 * class is used to parse the potential neuron class name. 488 * @param genot the string holding all the genotype 498 489 * @param pos0 the current position of processing in string 499 * @param current parent of analysed branch ofgenotype500 * @return 0 if processing was successful or position of error ingenotype501 */ 502 int f4_processrec(const char * genot, unsigned pos0, f4_node *parent);503 504 /** 505 * Function parses notation of neuron connection - it takes beginning ofconnection506 * definition, extracts relative position of input neurons and weight ofconnection.507 * After successful parsing it returns pointer to first character afterconnection508 * definition, or NULL if connection definition was not valid -lack of [, :, ]509 * characters or wrongvalue of relfrom or weight.510 * @param fragm the beginning of connection definition, it should be '[' character511 * @param relfrom the reference to int variable, in which relative position ofinput neuron will be stored512 * @param weight the reference to double variable, in which weight ofconnection will be stored513 * @return the pointer to first character in string after connection definition514 */ 515 const char * parseConnection(const char * fragm, int&relfrom, double &weight);516 517 /** 518 * Function parses notation of neuron connection with neuron definition - it519 * t akes beginning ofconnection definition, extracts the name of neuron class520 * that will be the input for current neuron and weight ofconnection.521 * After successful parsing it returns pointer to first character afterconnection522 * definition, or NULL if connection definition was not valid -lack of [, :, ]523 * characters, wrong value of weight orinvalid neuron class name.524 * @param fragm the beginning of connection definition, it should be '[' character525 * @param neutype the reference to string representing input neuron class name. The name of class is validated with GenoOperators::parseNeuroClass526 * @param weight the reference to double variable, in which weight ofconnection will be stored527 * @return the pointer to first character in string afterconnection definition528 */ 529 const char * parseConnectionWithNeuron(const char * fragm, string&neutype, double &weight);490 * @param current parent of the analysed branch of the genotype 491 * @return 0 if processing was successful, otherwise returns the position of an error in the genotype 492 */ 493 int f4_processrec(const char *genot, unsigned pos0, f4_node *parent); 494 495 /** 496 * Parses notation of the neuron connection - takes the beginning of the connection 497 * definition, extracts the relative position of input neurons and the weight of the connection. 498 * After successful parsing, returns the pointer to the first character after the connection 499 * definition, or NULL if the connection definition was not valid due to the lack of [, :, ] 500 * characters or an invalid value of relfrom or weight. 501 * @param fragm the beginning of connection definition, should be the '[' character 502 * @param relfrom the reference to an int variable in which the relative position of the input neuron will be stored 503 * @param weight the reference to a double variable in which the weight of the connection will be stored 504 * @return the pointer to the first character in string after connection definition 505 */ 506 const char * parseConnection(const char *fragm, int &relfrom, double &weight); 507 508 /** 509 * Parses the notation of the neuron connection with neuron definition - takes 510 * the beginning of the connection definition, extracts the name of neuron class 511 * that will be the input for the current neuron and the weight of the connection. 512 * After successful parsing, returns a pointer to the first character after the connection 513 * definition, or NULL if the connection definition was not valid due to the lack of [, :, ] 514 * characters, an invalid value of the weight or an invalid neuron class name. 515 * @param fragm the beginning of the connection definition, should be the '[' character 516 * @param neutype the reference to a string representing the input neuron class name. The name of the class is validated with GenoOperators::parseNeuroClass() 517 * @param weight the reference to a double variable in which the weight of the connection will be stored 518 * @return the pointer to the first character in string after the connection definition 519 */ 520 const char * parseConnectionWithNeuron(const char *fragm, string &neutype, double &weight); 530 521 531 522 #endif -
cpp/frams/genetics/f4/oper_f4.cpp
r760 r767 20 20 #define F4_MODIFIERS_VISUAL "" //not supported in f4 21 21 #define F4_MODIFIERS_RARE "EeWwAaSs" //expdef would need to handle these properly/specifically to ensure reasonable behavior, and hardly any expdef does. Modifying initial energy of a creature as a result of its genes (Ee) is in general not a good idea. Weight (Ww) works only in water, and in water sinking/going up should usually be caused by real "intentional" activity of a creature, not by its inherited weight. For assimilation (Aa), there is a dedicated parameter in CreaturesGroup. Stamina (Ss) is no longer needed as destructive collisions are not supported, and even if they were, some expdef would need to impose reasonable restrictions on the value of this parameter (e.g. similar to normalizeBiol4()) so there is some cost associated with it, and the specific consequences of destructions should be defined as needed. 22 #define F4_MODIFIERS " LlRrCcQqFfMmIi" F4_MODIFIERS_RARE F4_MODIFIERS_VISUAL22 #define F4_MODIFIERS ",LlRrCcQqFfMmIi" F4_MODIFIERS_RARE F4_MODIFIERS_VISUAL 23 23 const char *Geno_f4::all_modifiers = F4_MODIFIERS; 24 25 // codes that can be changed (apart from being added/deleted) 26 #define MUT_CHAN_CODES "<[#" 27 #define REP_MAXCOUNT 19 24 28 25 29 #define FIELDSTRUCT Geno_f4 … … 134 138 // ! the genotype is g->child (not g) ! 135 139 136 // codes that can be changed (apart being added/deleted)137 #define MUT_CHAN_CODES "<[#"138 #define ADD_SIMPLE_CODES ",XlLcCrRaAiIsSmMfFwWeEN@|"139 #define REP_MAXCOUNT 19140 141 140 // do the mutation 142 141 // pick a random node … … 176 175 else 177 176 { 178 f4_node *n4 = new f4_node(rndclass->getName().c_str(), n2, n2->pos); //TODO move this above177 f4_node *n4 = new f4_node(rndclass->getName().c_str(), n2, n2->pos); 179 178 if (rndclass->getPreferredInputs() != 0) 180 179 { … … 280 279 // choose a simple node from ADD_SIMPLE_CODES 281 280 n1->parent->removeChild(n1); 282 f4_node *n2 = new f4_node(ADD_SIMPLE_CODES[randomN(strlen(ADD_SIMPLE_CODES))], n1->parent, n1->parent->pos); 281 //f4_node *n2 = new f4_node(ADD_SIMPLE_CODES[randomN(strlen(ADD_SIMPLE_CODES))], n1->parent, n1->parent->pos); 282 int modifierid = GenoOperators::getRandomChar(all_modifiers, excluded_modifiers.c_str()); 283 f4_node *n2 = new f4_node(all_modifiers[modifierid], n1->parent, n1->parent->pos); 283 284 n2->addChild(n1); 284 285 n1->parent = n2; … … 717 718 } 718 719 719 720 721 720 uint32_t Geno_f4::style(const char *g, int pos) 722 721 { … … 727 726 #define STYL4CAT_DIGIT "0123456789." 728 727 #define STYL4CAT_REST "XN<># " 729 if (!strchr(STYL4CAT_MODIFIC STYL4CAT_NEUMOD STYL4CAT_DIGIT STYL4CAT_REST, ch)) 728 729 if (!isalpha(ch) && !isdigit(ch) && !strchr("<>-+[]:,.@|#*/=!\t",ch)) { 730 730 return GENSTYLE_CS(0, GENSTYLE_INVALID); 731 } 731 732 uint32_t style = GENSTYLE_CS(0, GENSTYLE_STRIKEOUT); //default, should be changed below 732 733 if (strchr("X ", ch)) style = GENSTYLE_CS(0, GENSTYLE_NONE); … … 737 738 if (strchr(STYL4CAT_MODIFIC, ch)) style = GENSTYLE_RGBS(100, 100, 100, GENSTYLE_NONE); 738 739 if (strchr(STYL4CAT_NEUMOD, ch)) style = GENSTYLE_RGBS(0, 150, 0, GENSTYLE_NONE); 740 if (isalpha(ch)) { 741 int p = pos; 742 while (p > 0) { 743 p--; 744 if (!isalpha(g[p])) { 745 if (isupper(g[p+1]) && (g[p] == ':' || g[p] == '[')) { // name of neuron class 746 style = GENSTYLE_RGBS(150,0,150,GENSTYLE_ITALIC); 747 } 748 else { // property 749 style = GENSTYLE_RGBS(255,140,0,GENSTYLE_BOLD); 750 } 751 } 752 } 753 } 739 754 return style; 740 755 }
Note: See TracChangeset
for help on using the changeset viewer.