Changeset 671 for cpp/frams/genetics/f4
- Timestamp:
- 08/18/17 15:24:59 (7 years ago)
- Location:
- cpp/frams/genetics/f4
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/genetics/f4/conv_f4.cpp
r534 r671 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-201 5Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2017 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 179 179 // coordinates are left to be computed by Model 180 180 sprintf(tmpLine, "p:fr=%g,ing=%g,as=%g", 181 /*1.0/C->P.mass,*/ C->P.friction, C->P.ingest , C->P.assim181 /*1.0/C->P.mass,*/ C->P.friction, C->P.ingestion, C->P.assimilation 182 182 //C->firstend.x, C->firstend.y, C->firstend.z 183 183 ); … … 196 196 sprintf(tmpLine, "p:fr=%g,ing=%g,as=%g", 197 197 //C->lastend.x, C->lastend.y, C->lastend.z 198 /*"vol=" 1.0/C->P.mass,*/ C->P.friction, C->P.ingest , C->P.assim198 /*"vol=" 1.0/C->P.mass,*/ C->P.friction, C->P.ingestion, C->P.assimilation 199 199 ); 200 200 partidx = singleStepBuild(tmpLine, &range); … … 212 212 // relative position -- always (len, 0, 0), along the stick 213 213 // this is optional! 214 C->P.len ,214 C->P.length, 215 215 // relative rotation 216 216 C->xrot, C->zrot, 217 217 //C->P.ruch, // rotstif 218 C->P. odpor218 C->P.stamina 219 219 ); 220 220 partidx = singleStepBuild(tmpLine, &range); … … 241 241 { 242 242 if (1 == C->ctrl) 243 sprintf(tmpLine, "n:j=%d,d=\"@:p=%g\"", C->dadlink->joint_refno, C->P. ruch);243 sprintf(tmpLine, "n:j=%d,d=\"@:p=%g\"", C->dadlink->joint_refno, C->P.muscle_power); 244 244 else 245 sprintf(tmpLine, "n:j=%d,d=\"|:p=%g,r=%g\"", C->dadlink->joint_refno, C->P. ruch, C->mz);245 sprintf(tmpLine, "n:j=%d,d=\"|:p=%g,r=%g\"", C->dadlink->joint_refno, C->P.muscle_power, C->mz); 246 246 partidx = singleStepBuild(tmpLine, &range); 247 247 if (partidx < 0) return -32; -
cpp/frams/genetics/f4/f4_general.cpp
r375 r671 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-201 5Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2017 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 20 20 f4_Props::f4_Props() 21 21 { 22 len = 1.0;23 curv = 0.0;24 mass= 1.0;22 length = 1.0; 23 curvedness = 0.0; 24 weight = 1.0; 25 25 friction = 0.4; 26 ruch = 0.25; // bio27 assim = 0.25; // bio28 odpor = 0.25; // bio29 ingest = 0.25; // bio26 muscle_power = 0.25; // biol 27 assimilation = 0.25; // biol 28 stamina = 0.25; // biol 29 ingestion = 0.25; // biol 30 30 twist = 0.0; 31 energ = 1.0;31 energy = 1.0; 32 32 normalizeBiol4(); 33 33 } … … 35 35 void f4_Props::normalizeBiol4() 36 36 { 37 // must sum to 1 38 double sum = ruch + assim + odpor + ingest; 39 if (0 == sum) 40 { 41 ruch = assim = odpor = ingest = 0.25; 42 } 43 else { 44 ruch /= sum; 45 assim /= sum; 46 odpor /= sum; 47 ingest /= sum; 37 // make them sum to 1 38 double sum = muscle_power + assimilation + stamina + ingestion; 39 if (sum == 0) 40 { 41 muscle_power = assimilation = stamina = ingestion = 0.25; 42 } 43 else 44 { 45 muscle_power /= sum; 46 assimilation /= sum; 47 stamina /= sum; 48 ingestion /= sum; 48 49 } 49 50 } … … 53 54 switch (modif) 54 55 { 55 case 'L': len += (2.5 - len) * 0.3;56 len = min(len, Model::getMaxJoint().d.x); break;57 case 'l': len += (0.3 - len) * 0.3;58 len = max(len, Model::getMinJoint().d.x); break;59 case 'C': curv += (2.0 - curv) * 0.25; break;60 case 'c': curv += (-2.0 - curv) * 0.25; break;56 case 'L': length += (2.5 - length) * 0.3; 57 length = min(length, Model::getMaxJoint().d.x); break; 58 case 'l': length += (0.3 - length) * 0.3; 59 length = max(length, Model::getMinJoint().d.x); break; 60 case 'C': curvedness += (2.0 - curvedness) * 0.25; break; 61 case 'c': curvedness += (-2.0 - curvedness) * 0.25; break; 61 62 case 'Q': twist += (1.58 - twist) * 0.3; break; 62 63 case 'q': twist += (-1.58 - twist) * 0.3; break; 63 case 'A': assim += (1 - assim) * 0.8; normalizeBiol4(); break;64 case 'a': assim -= assim* 0.4; normalizeBiol4(); break;65 case 'I': ingest += (1 - ingest) * 0.8; normalizeBiol4(); break;66 case 'i': ingest -= ingest* 0.4; normalizeBiol4(); break;67 case 'S': odpor += (1 - odpor) * 0.8; normalizeBiol4(); break;68 case 's': odpor -= odpor* 0.4; normalizeBiol4(); break;69 case 'M': ruch += (1 - ruch) * 0.8; normalizeBiol4(); break;70 case 'm': ruch -= ruch* 0.4; normalizeBiol4(); break;64 case 'A': assimilation += (1 - assimilation) * 0.8; normalizeBiol4(); break; 65 case 'a': assimilation -= assimilation * 0.4; normalizeBiol4(); break; 66 case 'I': ingestion += (1 - ingestion) * 0.8; normalizeBiol4(); break; 67 case 'i': ingestion -= ingestion * 0.4; normalizeBiol4(); break; 68 case 'S': stamina += (1 - stamina) * 0.8; normalizeBiol4(); break; 69 case 's': stamina -= stamina * 0.4; normalizeBiol4(); break; 70 case 'M': muscle_power += (1 - muscle_power) * 0.8; normalizeBiol4(); break; 71 case 'm': muscle_power -= muscle_power * 0.4; normalizeBiol4(); break; 71 72 case 'F': friction += (4 - friction) * 0.2; break; 72 73 case 'f': friction -= friction * 0.2; break; 73 case 'W': mass += (2.0 - mass) * 0.3; break;74 case 'w': mass += (0.5 - mass) * 0.3; break;75 case 'E': energ += (10.0 - energ) * 0.1; break;76 case 'e': energ -= energ* 0.1; break;74 case 'W': weight += (2.0 - weight) * 0.3; break; 75 case 'w': weight += (0.5 - weight) * 0.3; break; 76 case 'E': energy += (10.0 - energy) * 0.1; break; 77 case 'e': energy -= energy * 0.1; break; 77 78 } 78 79 } … … 80 81 void f4_Props::adjust() 81 82 { 82 len = 0.5*len + 0.5*stdProps.len;83 curv = 0.66 * curv;83 length = 0.5*length + 0.5*stdProps.length; 84 curvedness = 0.66 * curvedness; 84 85 twist = 0.66 * twist; 85 86 } … … 88 89 89 90 90 void rolling_dec(double * v) { 91 void rolling_dec(double * v) 92 { 91 93 *v -= 0.7853; // 0.7853981 45 degrees 92 94 } 93 void rolling_inc(double * v) { 95 96 void rolling_inc(double * v) 97 { 94 98 *v += 0.7853; // 0.7853981 45 degrees 95 99 } … … 106 110 if (stopchar == s[i]) // bumped into stopchar 107 111 return i; 108 if (i < slen - 1) 109 { // s[i] is not the last char112 if (i < slen - 1) // s[i] is not the last char 113 { 110 114 if (s[i] == '(') 111 115 { … … 183 187 184 188 185 f4_Cell::f4_Cell(f4_Cells * nO, int nname, f4_node * ngeno, f4_node * ngcur, 186 f4_Cell * ndad, int nangle, f4_Props newP) 189 f4_Cell::f4_Cell(f4_Cells * nO, int nname, f4_node * ngeno, f4_node * ngcur, f4_Cell * ndad, int nangle, f4_Props newP) 187 190 { 188 191 name = nname; … … 218 221 { 219 222 // make sure it is a stick (and not a stick f4_Cell!) 220 if (T_STICK4 == ndad->type) { 223 if (T_STICK4 == ndad->type) 224 { 221 225 //firstend = ndad->lastend; 222 226 //OM = ndad->OM; … … 279 283 280 284 // error: sticks cannot divide 281 if (T_STICK4 == type) { 285 if (T_STICK4 == type) 286 { 282 287 // cannot fix 283 288 org->setError(gcur->pos); … … 286 291 287 292 // undiff divides 288 if (T_UNDIFF4 == type) { 293 if (T_UNDIFF4 == type) 294 { 289 295 // commacount is set only when daughter turns into X 290 296 // daughter cell … … 292 298 f4_Props newP = P; 293 299 newP.adjust(); 294 tmp = new f4_Cell(org, org->nc, genot, gcur->child2, 295 this, commacount, newP); 300 tmp = new f4_Cell(org, org->nc, genot, gcur->child2, this, commacount, newP); 296 301 tmp->repeat = repeat; 297 302 repeat.null(); … … 310 315 // duplicate links 311 316 f4_CellLink * ll; 312 for (i = 0; i < nolink; i++) { 317 for (i = 0; i < nolink; i++) 318 { 313 319 ll = links[i]; 314 320 tmp->addlink(ll->from, ll->w, ll->t); … … 334 340 gcur = repeat.first()->node->child; 335 341 } 336 else { 342 else 343 { 337 344 // continue 338 345 gcur = repeat.first()->node->child2; … … 341 348 break; 342 349 } 343 else { 350 else 351 { 344 352 repeat.pop(); 345 353 } 346 354 } 347 else { 355 else 356 { 348 357 // error: still undiff 349 358 if (T_UNDIFF4 == type) … … 351 360 // fix it: insert an 'X' 352 361 f4_node * insertnode = new f4_node('X', NULL, gcur->pos); 353 if (org->setRepairInsert(gcur->pos, gcur, insertnode)) 354 // not in repair mode, release 362 if (org->setRepairInsert(gcur->pos, gcur, insertnode)) // not in repair mode, release 355 363 delete insertnode; 356 364 return 1; … … 383 391 case 'r': case 'R': 384 392 // error: if neuron 385 if (T_NEURON4 == type) { 393 if (T_NEURON4 == type) 394 { 386 395 // fix: delete it 387 396 org->setRepairRemove(gcur->pos, gcur); 388 397 return 1; // stop 389 398 } 390 switch (gcur->name) { 399 switch (gcur->name) 400 { 391 401 case 'r': rolling_dec(&rolling); break; 392 402 case 'R': rolling_inc(&rolling); break; … … 406 416 case 'e': case 'E': 407 417 // error: if neuron 408 if (T_NEURON4 == type) { 418 if (T_NEURON4 == type) 419 { 409 420 // fix: delete it 410 421 org->setRepairRemove(gcur->pos, gcur); … … 418 429 // turn undiff. cell into a stick 419 430 // error: already differentiated 420 if (T_UNDIFF4 != type) { 431 if (T_UNDIFF4 != type) 432 { 421 433 // fix: delete this node 422 434 org->setRepairRemove(gcur->pos, gcur); … … 425 437 type = T_STICK4; 426 438 // fix dad commacount and own anglepos 427 if (NULL != dadlink) { 439 if (NULL != dadlink) 440 { 428 441 dadlink->commacount++; 429 442 anglepos = dadlink->commacount; … … 436 449 // turn undiff. cell into a neuron 437 450 // error: already differentiated 438 if (T_UNDIFF4 != type) { 451 if (T_UNDIFF4 != type) 452 { 439 453 // fix: delete this node 440 454 org->setRepairRemove(gcur->pos, gcur); … … 442 456 } 443 457 // error: if no previous 444 if (NULL == dadlink) { 458 if (NULL == dadlink) 459 { 445 460 // fix: delete it 446 461 org->setRepairRemove(gcur->pos, gcur); … … 461 476 if ('|' == gcur->name) j = 2; // bend 462 477 // error: not a neuron (undiff) 463 if (T_UNDIFF4 == type) { 478 if (T_UNDIFF4 == type) 479 { 464 480 // fix: delete it 465 481 org->setRepairRemove(gcur->pos, gcur); … … 467 483 } 468 484 // error: not a neuron (stick) 469 if (T_NEURON4 != type) { 485 if (T_NEURON4 != type) 486 { 470 487 // fix: delete it 471 488 org->setRepairRemove(gcur->pos, gcur); … … 473 490 } 474 491 // error: already has control 475 if (ctrl != 0) { 492 if (ctrl != 0) 493 { 476 494 // fix: delete it 477 495 org->setRepairRemove(gcur->pos, gcur); … … 486 504 // link to neuron 487 505 // error: not a neuron 488 if (T_NEURON4 != type) { 506 if (T_NEURON4 != type) 507 { 489 508 // fix: delete it 490 509 org->setRepairRemove(gcur->pos, gcur); … … 495 514 relfrom = gcur->l1; 496 515 w = gcur->f1; 497 if (t > 0) { 516 if (t > 0) 517 { 498 518 // * or G 499 519 tneu = NULL; … … 504 524 // find own index 505 525 j = 0; k = 0; 506 for (i = 0; i < org->nc; i++) { 526 for (i = 0; i < org->nc; i++) 527 { 507 528 if (org->C[i]->type == T_NEURON4) k++; 508 529 if (org->C[i] == this) { j = k - 1; break; } … … 514 535 // find that neuron 515 536 k = 0; 516 for (i = 0; i < org->nc; i++) { 537 for (i = 0; i < org->nc; i++) 538 { 517 539 if (org->C[i]->type == T_NEURON4) k++; 518 540 if (j == (k - 1)) break; … … 523 545 // add link 524 546 // error: could not add link (too many?) 525 if (addlink(tneu, w, t)) { 547 if (addlink(tneu, w, t)) 548 { 526 549 // cannot fix 527 550 org->setError(gcur->pos); … … 535 558 active = 0; 536 559 j = 0; 537 for (i = 0; i<org->nc; i++) { 560 for (i = 0; i < org->nc; i++) 561 { 538 562 if (org->C[i]->active) j++; 539 563 } 540 if (j >0)564 if (j > 0) 541 565 return 0; // there is other active, halt, try again 542 566 // no more actives, cannot add link, ignore, but treat not as an error … … 547 571 // neuron parameter 548 572 // error: not a neuron 549 if (T_NEURON4 != type) { 573 if (T_NEURON4 != type) 574 { 550 575 // fix: delete it 551 576 org->setRepairRemove(gcur->pos, gcur); … … 553 578 } 554 579 j = (int)gcur->l1; 555 switch ((char)gcur->i1) { 580 switch ((char)gcur->i1) 581 { 556 582 case '!': 557 583 if (j) force += (1.0 - force) * 0.2; … … 604 630 { 605 631 //f4_OrientMat rot; 606 int 632 int i; 607 633 608 634 if (recProcessedFlag) … … 635 661 mz = 1; 636 662 } 637 else { 663 else 664 { 638 665 //firstend = dadlink->lastend; 639 666 f4_Props Pdad = dadlink->P; … … 650 677 { 651 678 // rotation due to curvedness 652 zrot = Padj.curv; 653 } 654 else { 655 zrot = Padj.curv + 656 // SDK uses 3.141 instead of PI! 657 (anglepos * 1.0 / (dadlink->commacount + 1) - 0.5) * 3.141 * 2.0; 679 zrot = Padj.curvedness; 680 } 681 else 682 { 683 zrot = Padj.curvedness + (anglepos * 1.0 / (dadlink->commacount + 1) - 0.5) * M_PI * 2.0; 658 684 } 659 685 … … 722 748 723 749 // create ancestor cell 724 C[0] = new f4_Cell(this, 0, f4rootnode->child, f4rootnode->child, 725 NULL, 0, stdProps); 750 C[0] = new f4_Cell(this, 0, f4rootnode->child, f4rootnode->child, NULL, 0, stdProps); 726 751 nc = 1; 727 752 } … … 747 772 oldnc = nc; 748 773 ret = 0; 749 for (i = 0; i<oldnc; i++) { 774 for (i = 0; i < oldnc; i++) 775 { 750 776 ret2 = C[i]->onestep(); 751 if (ret2>0) { 777 if (ret2 > 0) 778 { 752 779 // error 753 780 C[i]->active = 0; // stop … … 776 803 // fix neuron attachements 777 804 for (i = 0; i < nc; i++) 778 if (C[i]->type == T_NEURON4) { 779 while (T_NEURON4 == C[i]->dadlink->type) { 805 { 806 if (C[i]->type == T_NEURON4) 807 { 808 while (T_NEURON4 == C[i]->dadlink->type) 809 { 780 810 C[i]->dadlink = C[i]->dadlink->dadlink; 781 811 } 782 812 } 813 } 783 814 784 815 // there should be no undiff. cells 785 816 // make undifferentiated cells sticks 786 817 for (i = 0; i < nc; i++) 787 if (C[i]->type == T_UNDIFF4) { 818 { 819 if (C[i]->type == T_UNDIFF4) 820 { 788 821 C[i]->type = T_STICK4; 789 822 //seterror(); 790 823 } 824 } 791 825 792 826 // recursive adjust … … 806 840 void f4_Cells::addCell(f4_Cell * newcell) 807 841 { 808 if (nc >= MAX4CELLS - 1) { 842 if (nc >= MAX4CELLS - 1) 843 { 809 844 delete newcell; 810 845 return; … … 823 858 void f4_Cells::setRepairRemove(int nerrpos, f4_node * rem) 824 859 { 825 if (!repair) { 860 if (!repair) 861 { 826 862 // not in repair mode, treat as repairable error 827 863 error = GENOPER_REPAIR; 828 864 errorpos = nerrpos; 829 865 } 830 else { 866 else 867 { 831 868 error = GENOPER_REPAIR; 832 869 errorpos = nerrpos; … … 837 874 int f4_Cells::setRepairInsert(int nerrpos, f4_node * parent, f4_node * insert) 838 875 { 839 if (!repair) { 876 if (!repair) 877 { 840 878 // not in repair mode, treat as repairable error 841 879 error = GENOPER_REPAIR; … … 843 881 return -1; 844 882 } 845 else { 883 else 884 { 846 885 error = GENOPER_REPAIR; 847 886 errorpos = nerrpos; … … 863 902 if (NULL == g2) 864 903 return; 865 if (g2 == repair_remove) { 904 if (g2 == repair_remove) 905 { 866 906 f4_node * oldgeno; 867 907 geno->removeChild(g2); 868 if (g2->child) { 908 if (g2->child) 909 { 869 910 // add g2->child as child to geno 870 911 if (1 == whichchild) geno->child = g2->child; … … 880 921 return; 881 922 } 882 if (g2 == repair_parent) { 923 if (g2 == repair_parent) 924 { 883 925 geno->removeChild(g2); 884 926 geno->addChild(repair_insert); … … 921 963 // adjust length, curvedness, etc. 922 964 tmpcel->P.adjust(); 923 while (tmpcel->P.len > thisti->P.len)965 while (tmpcel->P.length > thisti->P.length) 924 966 { 925 967 tmpcel->P.executeModifier('l'); 926 968 out += "l"; 927 969 } 928 while (tmpcel->P.len < thisti->P.len)970 while (tmpcel->P.length < thisti->P.length) 929 971 { 930 972 tmpcel->P.executeModifier('L'); 931 973 out += "L"; 932 974 } 933 while (tmpcel->P.curv > thisti->P.curv)975 while (tmpcel->P.curvedness > thisti->P.curvedness) 934 976 { 935 977 tmpcel->P.executeModifier('c'); 936 978 out += "c"; 937 979 } 938 while (tmpcel->P.curv < thisti->P.curv)980 while (tmpcel->P.curvedness < thisti->P.curvedness) 939 981 { 940 982 tmpcel->P.executeModifier('C'); 941 983 out += "C"; 942 984 } 943 while (thisti->rolling > 0.0f) { 985 while (thisti->rolling > 0.0f) 986 { 944 987 rolling_dec(&(thisti->rolling)); 945 988 out += "R"; 946 989 } 947 while (thisti->rolling < 0.0f) { 990 while (thisti->rolling < 0.0f) 991 { 948 992 rolling_inc(&(thisti->rolling)); 949 993 out += "r"; … … 955 999 // neurons attached to it 956 1000 for (i = 0; i < nc; i++) 957 if (C[i]->type == T_NEURON4) { 958 if (C[i]->dadlink == thisti) { 1001 { 1002 if (C[i]->type == T_NEURON4) 1003 { 1004 if (C[i]->dadlink == thisti) 1005 { 959 1006 thneu = C[i]; 960 1007 out += "["; … … 974 1021 if (4 == thneu->links[j]->t) out += "S"; 975 1022 } 976 else { 1023 else 1024 { 977 1025 sprintf(buf, "%d", thneu->links[j]->from->name - thneu->name); 978 1026 out += buf; 979 1027 } 980 1028 out += ":"; 981 // weight1029 // connection weight 982 1030 sprintf(buf, "%g", thneu->links[j]->w); 983 1031 out += buf; … … 986 1034 } 987 1035 } 1036 } 988 1037 989 1038 // sticks connected to it … … 993 1042 ccount = 1; 994 1043 for (i = 0; i < nc; i++) 1044 { 995 1045 if (C[i]->type == T_STICK4) 996 if (C[i]->dadlink == thisti) { 997 while (ccount < (C[i])->anglepos) { 1046 { 1047 if (C[i]->dadlink == thisti) 1048 { 1049 while (ccount < (C[i])->anglepos) 1050 { 998 1051 ccount++; 999 1052 out += ","; … … 1001 1054 toF1GenoRec(i, out); 1002 1055 } 1003 while (ccount < thisti->commacount) { 1056 } 1057 } 1058 1059 while (ccount < thisti->commacount) 1060 { 1004 1061 ccount++; 1005 1062 out += ","; … … 1012 1069 1013 1070 1014 // to organize a f4 genotype in a tree structure1071 // to organize an f4 genotype in a tree structure 1015 1072 1016 1073 f4_node::f4_node() … … 1043 1100 int f4_node::addChild(f4_node * nchi) 1044 1101 { 1045 if (NULL == child) { 1102 if (NULL == child) 1103 { 1046 1104 child = nchi; 1047 1105 return 0; 1048 1106 } 1049 if (NULL == child2) { 1107 if (NULL == child2) 1108 { 1050 1109 child2 = nchi; 1051 1110 return 0; … … 1056 1115 int f4_node::removeChild(f4_node * nchi) 1057 1116 { 1058 if (nchi == child2) { 1117 if (nchi == child2) 1118 { 1059 1119 child2 = NULL; 1060 1120 return 0; 1061 1121 } 1062 if (nchi == child) { 1122 if (nchi == child) 1123 { 1063 1124 child = NULL; 1064 1125 return 0; … … 1069 1130 int f4_node::childCount() 1070 1131 { 1071 if (NULL != child) { 1132 if (NULL != child) 1133 { 1072 1134 if (NULL != child2) return 2; 1073 1135 else return 1; 1074 1136 } 1075 else { 1137 else 1138 { 1076 1139 if (NULL != child2) return 1; 1077 1140 else return 0; … … 1092 1155 if (0 == n) return this; 1093 1156 n--; 1094 if (NULL != child) { 1157 if (NULL != child) 1158 { 1095 1159 n1 = child->count(); 1096 1160 if (n < n1) return child->ordNode(n); 1097 1161 n -= n1; 1098 1162 } 1099 if (NULL != child2) { 1163 if (NULL != child2) 1164 { 1100 1165 n1 = child2->count(); 1101 1166 if (n < n1) return child2->ordNode(n); … … 1119 1184 f4_node * nod = NULL; 1120 1185 maxlim = count(); 1121 for (i = 0; i < maxlim; i++) { 1186 for (i = 0; i < maxlim; i++) 1187 { 1122 1188 nod = randomNode(); 1123 1189 n = nod->count(); … … 1135 1201 { 1136 1202 out += "#"; 1137 if (i1 != 1) { 1203 if (i1 != 1) 1204 { 1138 1205 sprintf(buf2, "%d", i1); 1139 1206 out += buf2; … … 1142 1209 else { 1143 1210 // special case: neuron link 1144 if ('[' == name) { 1211 if ('[' == name) 1212 { 1145 1213 out += "["; 1146 if (i1 > 0) { 1214 if (i1 > 0) 1215 { 1147 1216 // sensor input 1148 1217 if (1 == i1) out += "*"; … … 1151 1220 if (4 == i1) out += "S"; 1152 1221 } 1153 else { 1222 else 1223 { 1154 1224 sprintf(buf2, "%ld", l1); 1155 1225 out += buf2; … … 1158 1228 out += buf2; 1159 1229 } 1160 else if (':' == name) { 1230 else if (':' == name) 1231 { 1161 1232 sprintf(buf2, ":%c%c:", l1 ? '+' : '-', (char)i1); 1162 1233 out += buf2; 1163 1234 } 1164 else { 1235 else 1236 { 1165 1237 buf2[0] = name; 1166 1238 buf2[1] = 0; … … 1194 1266 // copy back to string 1195 1267 // if new is longer, reallocate buf 1196 if (len + 1 > strlen(buf)) { 1268 if (len + 1 > strlen(buf)) 1269 { 1197 1270 buf = (char*)realloc(buf, len + 1); 1198 1271 } … … 1207 1280 copy->child = NULL; 1208 1281 copy->child2 = NULL; 1209 if (NULL != child) { 1282 if (NULL != child) 1283 { 1210 1284 copy->child = child->duplicate(); 1211 1285 copy->child->parent = copy; 1212 1286 } 1213 if (NULL != child2) { 1287 if (NULL != child2) 1288 { 1214 1289 copy->child2 = child2->duplicate(); 1215 1290 copy->child2->parent = copy; … … 1241 1316 par = parent; 1242 1317 if (gpos >= strlen(genot)) return 1; 1243 while (gpos < strlen(genot)) { 1318 while (gpos < strlen(genot)) 1319 { 1244 1320 //DB( printf(" processing '%c' %d %s\n", genot[gpos], gpos, genot); ) 1245 switch (genot[gpos]) { 1321 switch (genot[gpos]) 1322 { 1246 1323 case '<': 1247 1324 // cell division! … … 1255 1332 res = f4_processrec(genot, gpos + 1, par); 1256 1333 if (res) return res; 1257 if (gpos + j + 2 < strlen(genot)) { 1334 if (gpos + j + 2 < strlen(genot)) 1335 { 1258 1336 res = f4_processrec(genot, gpos + j + 2, par); 1259 1337 if (res) return res; 1260 1338 } 1261 else { // ran out 1339 else // ran out 1340 { 1262 1341 node1 = new f4_node('>', par, strlen(genot) - 1); 1263 1342 par = node1; … … 1287 1366 res = f4_processrec(genot, gpos, node1); 1288 1367 if (res) return res; 1289 if (oldpos + j + 2 < strlen(genot)) { 1368 if (oldpos + j + 2 < strlen(genot)) 1369 { 1290 1370 res = f4_processrec(genot, oldpos + j + 2, node1); 1291 1371 if (res) return res; 1292 1372 } 1293 else { // ran out 1373 else // ran out 1374 { 1294 1375 node1 = new f4_node('>', par, strlen(genot) - 1); 1295 1376 } … … 1344 1425 else if ('-' == tc1) j = 0; 1345 1426 else return gpos + 1 + 1; 1346 switch (tc2) { 1427 switch (tc2) 1428 { 1347 1429 case '!': case '=': case '/': break; 1348 1430 default: … … 1377 1459 // should end with a '>' 1378 1460 if (par) 1379 if ('>' != par->name) { 1461 { 1462 if ('>' != par->name) 1463 { 1380 1464 node1 = new f4_node('>', par, strlen(genot) - 1); 1381 1465 par = node1; 1382 1466 } 1467 } 1468 1383 1469 return 0; // OK 1384 1470 } … … 1394 1480 //DB( printf("test f4 "); ) 1395 1481 DB( 1396 if (root->child) { 1397 char * buf = (char*)malloc(300); 1398 DB(printf("(%d) ", root->child->count());) 1399 buf[0] = 0; 1400 root->child->sprintAdj(buf); 1401 DB(printf("%s\n", buf);) 1402 free(buf); 1482 if (root->child) 1483 { 1484 char * buf = (char*)malloc(300); 1485 DB(printf("(%d) ", root->child->count());) 1486 buf[0] = 0; 1487 root->child->sprintAdj(buf); 1488 DB(printf("%s\n", buf);) 1489 free(buf); 1403 1490 } 1404 1491 ) -
cpp/frams/genetics/f4/f4_general.h
r286 r671 28 28 void adjust(); 29 29 30 double len ; // length (dlug)31 double curv ; // curvedness (skr)32 double mass;30 double length; 31 double curvedness; 32 double weight; 33 33 double friction; 34 double ruch;35 double assim ;36 double odpor;37 double ingest ; // ingestion (wchl)34 double muscle_power; 35 double assimilation; 36 double stamina; 37 double ingestion; 38 38 double twist; 39 double energ ;39 double energy; 40 40 }; 41 41 -
cpp/frams/genetics/f4/oper_f4.cpp
r513 r671 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-201 5Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2017 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 231 231 // must pick a node with parent, and at least one child 232 232 // already picked a node, but repeat may be needed 233 for (int i = 0; i < 10; i++) { 233 for (int i = 0; i < 10; i++) 234 { 234 235 if ((NULL != n1->parent) && (g != n1->parent)) 235 236 if (NULL != n1->child) … … 247 248 n2 = n1->parent; 248 249 n2->removeChild(n1); 249 if (NULL != n1->child) { 250 if (NULL != n1->child) 251 { 250 252 n1->child->parent = n2; 251 253 n2->addChild(n1->child); 252 254 n1->child = NULL; 253 255 } 254 if (NULL != n1->child2) { 256 if (NULL != n1->child2) 257 { 255 258 n1->child2->parent = n2; 256 259 n2->addChild(n1->child2); … … 309 312 if (i >= 20) return GENOPER_OPFAIL; 310 313 } 311 switch (n1->name) { 314 switch (n1->name) 315 { 312 316 case '<': 313 317 // swap children … … 348 352 nn->i1 = i; 349 353 nn->l1 = 0; 350 if (0 == i) { 354 if (0 == i) 355 { 351 356 // relative input link 352 357 nn->l1 = (int)(4.0f * (rnd01 - 0.5f)); … … 407 412 if (prob1 < 0.5f) count++; 408 413 else count--; 409 if (count <1) count = 1;410 if (count >REP_MAXCOUNT) count = REP_MAXCOUNT;414 if (count < 1) count = 1; 415 if (count > REP_MAXCOUNT) count = REP_MAXCOUNT; 411 416 nn->i1 = count; 412 417 } … … 464 469 if (f4_processrec(g, 0, root) || root->childCount() != 1) 465 470 { 466 delete root; return GENOPER_OPFAIL; 471 delete root; 472 return GENOPER_OPFAIL; 467 473 } // could not convert or bad: fail 468 474 // mutate one node, set chg as this percent … … 470 476 if (MutateOneValid(root, method) != GENOPER_OK) 471 477 { 472 delete root; return GENOPER_OPFAIL; 478 delete root; 479 return GENOPER_OPFAIL; 473 480 } 474 481 // OK, convert back to string -
cpp/frams/genetics/f4/oper_f4.h
r513 r671 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-201 5Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2017 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4
Note: See TracChangeset
for help on using the changeset viewer.