Changeset 1237
- Timestamp:
- 05/07/23 02:40:10 (16 months ago)
- Location:
- cpp/frams/genetics/f4
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/genetics/f4/f4_general.cpp
r1235 r1237 4 4 5 5 // Copyright (C) 1999,2000 Adam Rotaru-Varga (adam_rotaru@yahoo.com), GNU LGPL 6 // 2018, Grzegorz Latosinski, added support for new API for neuron types and development checkpoints6 // 2018, Grzegorz Latosinski, added development checkpoints and support for new API for neuron types 7 7 8 8 #include "f4_general.h" … … 145 145 } 146 146 147 148 /* return codes: 149 1 error at pos 150 0 halt development (yield) for a cycle 151 */ 152 int f4_Cell::oneStep() 147 void f4_Cell::oneStep() 153 148 { 154 149 while (gcur != NULL) … … 184 179 // cannot fix 185 180 org->setError(gcur->pos); 186 return 1; // stop181 return; // error code set -> stop further cells development 187 182 } 188 183 … … 224 219 // adjustments for this cell 225 220 gcur = gcur->child; 226 // halt development 227 return 0; 221 return; // error code not set -> halt this development and yield to other cells to develop 228 222 } 229 223 case '>': … … 271 265 if (org->setRepairInsert(gcur->pos, gcur, insertnode)) // not in repair mode, release 272 266 delete insertnode; 273 return 1;267 return; // error code set -> stop further cells development 274 268 } 275 269 repeat.clear(); … … 280 274 logPrintf("f4_Cell", "oneStep", LOG_WARN, "Ignoring junk genetic code: %d node(s) at position %d", remaining_nodes, gcur->child->pos); //let's see an example of such a genotype... 281 275 gcur = NULL; 282 return 0;276 return; // done development 283 277 } 284 278 } … … 294 288 // fix: delete it 295 289 org->setRepairRemove(gcur->pos, gcur); 296 return 1; // stop290 return; // error code set -> stop further cells development 297 291 } 298 292 repeat.push(repeat_ptr(gcur, gcur->reps)); … … 314 308 // fix: delete it 315 309 org->setRepairRemove(gcur->pos, gcur); 316 return 1; // stop310 return; // error code set -> stop further cells development 317 311 } 318 312 switch (name) … … 345 339 // fix: delete it 346 340 org->setRepairRemove(gcur->pos, gcur); 347 return 1; // stop341 return; // error code set -> stop further cells development 348 342 } 349 343 P.executeModifier(name); … … 359 353 // fix: delete this node 360 354 org->setRepairRemove(gcur->pos, gcur); 361 return 1; // stop355 return; // error code set -> stop further cells development 362 356 } 363 357 type = CELL_STICK; 364 358 // fix dad commacount and own anglepos 365 if ( NULL != dadlink)359 if (dadlink != NULL) 366 360 { 367 361 dadlink->commacount++; … … 370 364 // change of type halts developments, see comment at 'neuclasshandler' below 371 365 gcur = gcur->child; 372 return 0;366 return; // error code not set -> halt this development and yield to other cells to develop 373 367 } 374 368 case '[': … … 380 374 // fix: delete it 381 375 org->setRepairRemove(gcur->pos, gcur); 382 return 1; // stop376 return; // error code set -> stop further cells development 383 377 } 384 378 // input [%d:%g] … … 419 413 // cannot fix 420 414 org->setError(gcur->pos); 421 return 1; // stop415 return; // error code set -> stop further cells development 422 416 } 423 417 gcur = gcur->child; … … 434 428 active = false; // next time when we reach wait_conn, we will not count ourselves as active (if we were the last active cell, we got a chance to continue development for one development step only) 435 429 if (active_count > 0) 436 return 0; // there is at least one active (including ourselves), halt, try again 430 // there is at least one active (including ourselves), halt, try again 431 return; // error code not set -> halt this development and yield to other cells to develop 437 432 438 433 #ifdef TREAT_BAD_CONNECTIONS_AS_INVALID_GENO // MacKo 2023-04: there were so many invalid connections accumulating in the genotype (and stopping processing of the chain of gcur->child) that it looks like treating them as errors is better... in 2000's, Framsticks neurons were flexible when it comes to inputs and outputs (for example, when asked, muscles would provide an output too, and neurons that ignored inputs would still accept them when connected) so f4 could create connections pretty randomly, but after 2000's we attempt to respect neurons' getPreferredInputs() and getPreferredOutput() so the network of connections has more constraints. … … 450 445 active = true; //not sure if needed, but let this cell have the chance to continue for as long as many children in the tree are left 451 446 gcur = gcur->child; 452 return 0;447 return; // error code not set -> halt this development and yield to other cells to develop 453 448 } 454 449 else … … 456 451 //org->setError(gcur->pos); //in case setRepairRemove() would not always produce reasonable results 457 452 org->setRepairRemove(gcur->pos, gcur); //produces unexpected results? or NOT? TODO verify, some genotypes earlier produced strange outcomes of this repair (produced a valid genotype, but some neurons were multiplied/copied after repair - maybe because when a branch of '<' (or something else) is missing, the other branch is copied?) 458 return 1; // stop453 return; // error code set -> stop further cells development 459 454 } 460 455 #else … … 472 467 // fix: delete it 473 468 org->setRepairRemove(gcur->pos, gcur); 474 return 1; // stop469 return; // error code set -> stop further cells development 475 470 } 476 471 switch (gcur->prop_symbol) … … 496 491 default: 497 492 org->setRepairRemove(gcur->pos, gcur); 498 return 1; // stop493 return; // error code set -> stop further cells development 499 494 } 500 495 gcur = gcur->child; … … 502 497 } 503 498 case ' ': 504 { 505 // space has no effect, should not occur 499 case '\t': 500 case '\n': 501 case '\r': 502 { 503 // whitespace has no effect, should not occur 506 504 // fix: delete it 507 505 org->setRepairRemove(gcur->pos, gcur); 508 gcur = gcur->child; 509 break; 506 return; // error code set -> stop further cells development 510 507 } 511 508 default: … … 515 512 logMessage("f4_Cell", "oneStep", LOG_ERROR, buf.c_str()); 516 513 org->setRepairRemove(gcur->pos, gcur); 517 return 1;514 return; // error code set -> stop further cells development 518 515 } 519 516 } … … 526 523 // fix: delete this node 527 524 org->setRepairRemove(gcur->pos, gcur); 528 return 1; // stop525 return; // error code set -> stop further cells development 529 526 } 530 527 // error: if no previous … … 533 530 // fix: delete it 534 531 org->setRepairRemove(gcur->pos, gcur); 535 return 1; // stop532 return; // error code set -> stop further cells development 536 533 } 537 534 neuclass = gcur->neuclass; … … 541 538 // to wait for other cells to turn to neurons before adding connections 542 539 gcur = gcur->child; 543 return 0; //stop540 return; // error code not set -> halt this development and yield to other cells to develop 544 541 } 545 542 } 546 543 active = false; // done 547 return 0;548 544 } 549 545 … … 675 671 for (int i = 0; i < old_cell_count; i++) 676 672 { 677 int cellstep_ret =C[i]->oneStep(); //keeps calling independently of C[i]->active678 if ( cellstep_ret > 0)673 C[i]->oneStep(); //keeps calling independently of C[i]->active 674 if (errorcode != GENOPER_OK) 679 675 { 680 676 // error … … 685 681 for (int i = 0; i < cell_count; i++) //we check all cells, including newly created ones 686 682 if (C[i]->active) 687 return true; //at least one cell is still active. TODO maybe the development should stop NOT because of the "active" field (there is this strange "yielding" state too), but by observing the progress of all cells and continuing the development while (errorcode== 0 AND (gcur of at least one cell changed OR cell_count changed)) ? Also get rid of return 1/return 0, just observe error.683 return true; //at least one cell is still active. TODO maybe the development should stop NOT because of the "active" field (there is this strange "yielding" state too), but by observing the progress of all cells and continuing the development while (errorcode==GENOPER_OK AND (gcur of at least one cell changed OR cell_count changed)) ? 688 684 return false; 689 685 } -
cpp/frams/genetics/f4/f4_general.h
r1234 r1237 150 150 * differentiation or modification is performed on the cell. If current node is 151 151 * creating a connection between two neuron nodes and the input node is not 152 * yet developed, the simulation of the development of the current cell waits until 153 * the input node is created. The onestep method is deployed for every cell 154 * at least once. If one cell requires another one to develop, onestep 155 * should be deployed again on this cell. This method, unlike genotype tree 156 * creation, checks semantics. This means that this function will fail if: 152 * yet developed, the simulation of the development of the current cell returns 153 * to wait until the input node is created. The oneStep method is deployed for every cell 154 * at least once. If one cell requires another one to develop, oneStep 155 * should be deployed again on this cell. 156 * 157 * This method, unlike genotype tree creation, checks semantics. This means that 158 * this function will fail (set error code) if: 157 159 * - the cell differentiated as a stick will have branching node '<', 158 160 * - the undifferentiated cell will have termination node '>' (end of cell development without differentiation), … … 163 165 * - the neuron class is not valid. 164 166 * 165 * @return 0 if development was successful, 1 if there was an error in genotype tree 166 */ 167 int oneStep(); 167 * This function returns either because the development of this cell was completed, 168 * or it was halted (yielding to other cells), or the error code was set in the f4_Cells object in the org attribute. 169 */ 170 void oneStep(); 168 171 169 172 /**
Note: See TracChangeset
for help on using the changeset viewer.