Changeset 1273 for cpp/frams/genetics/fL
- Timestamp:
- 09/09/23 15:10:49 (15 months ago)
- Location:
- cpp/frams/genetics/fL
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/genetics/fL/fL_general.cpp
r973 r1273 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-202 0Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2023 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 9 9 #include <iterator> 10 10 11 const char *fL_part_names[FL_PART_PROPS_COUNT] = { " dn", "fr", "ing", "as" };12 const char *fL_part_fullnames[FL_PART_PROPS_COUNT] = { " details", "friction", "ingestion", "assimilation" };13 14 const char *fL_joint_names[FL_JOINT_PROPS_COUNT] = { " stif", "rotstif", "stam" };15 const char *fL_joint_fullnames[FL_JOINT_PROPS_COUNT] = { " stiffness", "rotationstiffness", "stamina" };11 const char *fL_part_names[FL_PART_PROPS_COUNT] = { "fr" }; // "dn", "ing", "as" }; 12 const char *fL_part_fullnames[FL_PART_PROPS_COUNT] = { "friction" }; // "density", "ingestion", "assimilation" }; 13 14 const char *fL_joint_names[FL_JOINT_PROPS_COUNT] = { "rotstif" }; //"stif", , "stam" }; //see the comment to fH_joint_names in fH_general.cpp 15 const char *fL_joint_fullnames[FL_JOINT_PROPS_COUNT] = { "rotation stiffness" }; //"stiffness", "stamina" }; 16 16 17 17 #define FIELDSTRUCT fL_Word … … 502 502 fL_Word *stick = new fL_Word(true); 503 503 stick->name = "S"; 504 stick->npar = 8;504 stick->npar = FL_PART_PROPS_COUNT + FL_JOINT_PROPS_COUNT + 1; //MacKo 2023-07: was hardcoded "8" but crashed when the number of props in Part and Joint was decreased; I think it should be like it is now (4+3+1 - or another value depending on prop counts) 505 505 for (int i = 0; i < FL_PART_PROPS_COUNT; i++) 506 506 { 507 507 stick->mut.addProperty(NULL, fL_part_names[i], "s", fL_part_fullnames[i], fL_part_fullnames[i], PARAM_CANOMITNAME, 0, -1); 508 508 } 509 510 509 for (int i = 0; i < FL_JOINT_PROPS_COUNT; i++) 511 510 { … … 1096 1095 { 1097 1096 delete newpart; 1098 logMessage("fL_Builder", "developModel", LOG_ERROR, 1099 "Error parsing word parameter"); 1097 logMessage("fL_Builder", "developModel", LOG_ERROR, "Error parsing word parameter"); 1100 1098 return 1; 1101 1099 } … … 1123 1121 if (word->parevals[FL_PART_PROPS_COUNT + i]->evaluateRPN(jointprop) != 0) 1124 1122 { 1125 logMessage("fL_Builder", "developModel", LOG_ERROR, 1126 "Error parsing word parameter"); 1123 logMessage("fL_Builder", "developModel", LOG_ERROR, "Error parsing word parameter"); 1127 1124 delete newjoint; 1128 1125 return 1; … … 1153 1150 } 1154 1151 model->addNeuro(neu); 1152 1153 1154 // MacKo 2023-07: embody (i.e., attach to body) sensors and effectors. 1155 // Ad hoc modification; should be reconsidered as it was added without reminding and understanding of the entire logic of the phenotype development and assumptions, and may not be "the best performing" or "the most reasonable" approach. Without this embodiment, genotypes with sensors and effectors not attached to body had warnings (such neurons "could not be initialized") so such genotypes were not accepted when creatwarnfail==1; even with creatwarnfail==0, non-embodied sensor and effector neurons were useless. 1156 //printf("Neuron: -------------- %s\n", details.c_str()); 1157 switch (neu->getClass()->getPreferredLocation()) 1158 { 1159 case NeuroClass::PrefLocation::PREFER_PART: //attach to currstate.currpart 1160 if (currstate.currpart != NULL) 1161 neu->attachToPart(currstate.currpart); 1162 break; 1163 case NeuroClass::PrefLocation::PREFER_JOINT: //attach to the last joint incident with currstate.currpart 1164 if (currstate.currpart != NULL) 1165 { 1166 Joint *j = NULL; 1167 for (int i = 0; i < model->getJointCount(); i++) 1168 { 1169 Joint *jj = model->getJoint(i); 1170 if (jj->part1 == currstate.currpart || jj->part2 == currstate.currpart) 1171 j = jj; 1172 } 1173 if (j != NULL) 1174 neu->attachToJoint(j); 1175 } 1176 break; 1177 default: 1178 break; 1179 } 1180 1181 1155 1182 if (using_mapping) neu->addMapping(IRange(word->begin, word->end)); 1156 1183 if (neu->getClass()->getPreferredInputs() != 0) … … 1251 1278 { 1252 1279 connsbuffer[i].second->addInput(connsbuffer[i].second, weight); 1253 if (using_mapping) neu->addMapping(1280 if (using_mapping) connsbuffer[i].second->addMapping( //MacKo 2023-07: changed 'neu' (which is NULL here so crashed) to connsbuffer[i].second (no guarantee this is a proper fix, only inspired by the analogy to the difference in both branches of "if" in the line above) 1254 1281 IRange((*connsbuffer[i].first)->begin, 1255 1282 (*connsbuffer[i].first)->end)); -
cpp/frams/genetics/fL/fL_general.h
r821 r1273 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 18Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2023 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 25 25 /** @name Constants used in fL methods */ 26 26 //@{ 27 #define FL_PART_PROPS_COUNT 4///<Count of part properties28 #define FL_JOINT_PROPS_COUNT 3///<Count of joint properties27 #define FL_PART_PROPS_COUNT 1 ///<Count of part properties 28 #define FL_JOINT_PROPS_COUNT 1 ///<Count of joint properties 29 29 #define FL_PE_NEURO_DET "d" ///<Id of details type definition in f0_neuro_paramtab 30 30 #define FL_PE_CONN_WEIGHT "w" ///<Id of weight type definition in f0_neuroconn_paramtab 31 31 #define FL_PE_CONN_ATTR "attr" ///<Id of attractor of neural connection 32 32 #define FL_DEFAULT_LENGTH 1.0 ///<Default length of a stick in fL encoding 33 #define FL_MINIMAL_LENGTH 0. 0///<Minimal length of a stick in fL encoding33 #define FL_MINIMAL_LENGTH 0.1 ///<Minimal length of a stick in fL encoding 34 34 #define FL_MAXIMAL_LENGTH 2.0 ///<Maximal length of a stick in fL encoding 35 35 #define FL_MAXITER "100.0" ///<Maximal iteration available in fL … … 404 404 405 405 /** 406 * Develop es L-System from given genotype and buildsFramsticks Model from it.407 * When using_checkpoints is enabled, method generatescheckpoint for each408 * step defined in t imestamp.409 * @param neededtime reference to a time value after stopping development (usually it will be equal to t ime specified in the time field, unless the number of allowed words will be exceeded earlier)406 * Develops an L-System from a given genotype and builds a Framsticks Model from it. 407 * When using_checkpoints is enabled, this method generates a checkpoint for each 408 * step defined in the timestamp. 409 * @param neededtime reference to a time value after stopping development (usually it will be equal to the time specified in the time field, unless the number of allowed words will be exceeded earlier) 410 410 * @return final model from a fL genotype 411 411 */ … … 413 413 414 414 /** 415 * Creates new checkpoint for a given model based on current state ofgenotype.416 * @param model reference to model417 * @return 0 if developing went successfully, 1 otherwise415 * Creates a new checkpoint for a given model based on the current state of the genotype. 416 * @param model reference to the model 417 * @return 0 if the development was successfull, 1 otherwise 418 418 */ 419 419 int buildModelFromSequence(Model *model); -
cpp/frams/genetics/fL/fL_oper.cpp
r1075 r1273 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-202 0Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2023 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 8 8 #include <algorithm> 9 9 10 11 12 //TODO fix: occasionally happens (note that fL extensively uses Param parsing, see fL_word_paramtab): Param.loadSingleLine: Unknown property 'Word.w0(n1' (ignored) 13 //TODO reconsider and maybe improve sensor and effector embodiment; see "MacKo 2023-07: embody" in fL_general.cpp. 14 15 16 10 17 #define FIELDSTRUCT Geno_fL 11 18 static ParamEntry geno_fL_paramtab[] = … … 14 21 {"Genetics: fL: Probabilities of mutating axiom and rules", }, 15 22 {"Genetics: fL: Probabilities of mutation types", }, 16 {"fL_maxdefinedwords", 0, 0, "Maximum number of defined words", "d 0 100 10", FIELD(maxdefinedwords), "Maximum number of words that can be defined in L-System", },17 18 {"fL_axm_mut_prob", 1, 0, "Axiom mutation", "f 0 1 0.2", FIELD(groupprobabilities[FL_AXM_WORD_MUT_PROB]), "Probability of performing mutation operations on axiom", },19 {"fL_rul_mut_prob", 1, 0, "Rule's successor mutation", "f 0 1 0.8", FIELD(groupprobabilities[FL_RUL_WORD_MUT_PROB]), "Probability of performing mutation operations on the successor ofrandom rule", },20 21 {"fL_mut_addition", 2, 0, "Addition of word to sequence", "f 0 1 0.2", FIELD(operations[FL_ADD_WORD]), "Probability of adding random existing word to the axiom orone of successors", },22 23 {"fL_mut_add_stick", 2, 0, " - addition of stick", "f 0 1 0.2", FIELD(addtypes[FL_ADD_STICK]), "Probability of addingstick", },24 {"fL_mut_add_neuro", 2, 0, " - addition of neuron", "f 0 1 0.2", FIELD(addtypes[FL_ADD_NEURO]), "Probability of addingneuron", },25 {"fL_mut_add_conn", 2, 0, " - addition of neuron connection", "f 0 1 0.2", FIELD(addtypes[FL_ADD_CONN]), "Probability of addingconnection", },26 {"fL_mut_add_rot", 2, 0, " - addition of rotation words", "f 0 1 0.2", FIELD(addtypes[FL_ADD_ROT]), "Probability of adding one of rotation words", },27 {"fL_mut_add_branch", 2, 0, " - addition of branched stick", "f 0 1 0.2", FIELD(addtypes[FL_ADD_BRANCH]), "Probability of adding branch with rotation andstick", },28 {"fL_mut_add_other", 2, 0, " - addition of defined words", "f 0 1 0.4", FIELD(addtypes[FL_ADD_OTHER]), "Probability of adding other word, defined ingenotype", },29 30 {"fL_mut_worddefaddition", 2, 0, "Addition of new word definition", "f 0 1 0.05", FIELD(operations[FL_ADD_WDEF]), "Probability of addingnew word definition to the genotype", },31 {"fL_mut_ruleaddition", 2, 0, "Addition of new rule definition", "f 0 1 0.1", FIELD(operations[FL_ADD_RULE]), "Probability of adding new rule definition forexisting word", },32 {"fL_mut_rulecond", 2, 0, "Modification of rule condition", "f 0 1 0.1", FIELD(operations[FL_CHG_COND]), "Probability of modifyingrandom rule condition", },33 34 {"fL_mut_changeword", 2, 0, "Change of random word", "f 0 1 0.3", FIELD(operations[FL_CHG_WORD]), "Probability of changing word name or formula of a random word fromaxiom or one of successors", },35 {"fL_mut_changeword_formula", 2, 0, " - change of formula", "f 0 1 0.7", FIELD(chgoperations[FL_CHG_WORD_FORMULA]), "Probability of changing formula inword", },36 {"fL_mut_changeword_name", 2, 0, " - change of name", "f 0 1 0.3", FIELD(chgoperations[FL_CHG_WORD_NAME]), "Probability of changing name inword", },37 38 {"fL_mut_changeiter", 2, 0, "Change of L-System iteration", "f 0 1 0.3", FIELD(operations[FL_CHG_ITER]), "Probability of changing number of iterations of L-Systems", },39 {"fL_mut_changeiter_step", 2, 0, "Step of iteration changing", "f 0 1 1.0", FIELD(iterchangestep), "Minimal step that should be used for changing iterations in L-Systems", },40 {"fL_mut_deletion", 2, 0, "Deletion of random word", "f 0 1 0.2", FIELD(operations[FL_DEL_WORD]), "Probability of deleting random word from axiom or random successor (also deletes rule if there is only one word insuccessor)", },23 {"fL_maxdefinedwords", 0, 0, "Maximum number of defined words", "d 0 100 10", FIELD(maxdefinedwords), "Maximum number of words that can be defined in the L-System", }, 24 25 {"fL_axm_mut_prob", 1, 0, "Axiom mutation", "f 0 100 4", FIELD(groupprobabilities[FL_AXM_WORD_MUT_PROB]), "Probability of performing mutation operations on axiom", }, 26 {"fL_rul_mut_prob", 1, 0, "Rule's successor mutation", "f 0 100 1", FIELD(groupprobabilities[FL_RUL_WORD_MUT_PROB]), "Probability of performing mutation operations on the successor of a random rule", }, 27 28 {"fL_mut_addition", 2, 0, "Addition of a word to a sequence", "f 0 100 4", FIELD(operations[FL_ADD_WORD]), "Probability of adding a random existing word to the axiom or to one of successors", }, 29 30 {"fL_mut_add_stick", 2, 0, " - addition of a stick", "f 0 100 1", FIELD(addtypes[FL_ADD_STICK]), "Probability of adding a stick", }, 31 {"fL_mut_add_neuro", 2, 0, " - addition of a neuron", "f 0 100 4", FIELD(addtypes[FL_ADD_NEURO]), "Probability of adding a neuron", }, 32 {"fL_mut_add_conn", 2, 0, " - addition of a neuron connection", "f 0 100 4", FIELD(addtypes[FL_ADD_CONN]), "Probability of adding a neuron connection", }, 33 {"fL_mut_add_rot", 2, 0, " - addition of rotation words", "f 0 100 2", FIELD(addtypes[FL_ADD_ROT]), "Probability of adding one of rotation words", }, 34 {"fL_mut_add_branch", 2, 0, " - addition of a branched stick", "f 0 100 4", FIELD(addtypes[FL_ADD_BRANCH]), "Probability of adding a branch with a rotation and a stick", }, 35 {"fL_mut_add_other", 2, 0, " - addition of defined words", "f 0 100 1", FIELD(addtypes[FL_ADD_OTHER]), "Probability of adding another word defined in the genotype", }, 36 37 {"fL_mut_worddefaddition", 2, 0, "Addition of a new word definition", "f 0 100 1", FIELD(operations[FL_ADD_WDEF]), "Probability of adding a new word definition to the genotype", }, 38 {"fL_mut_ruleaddition", 2, 0, "Addition of a new rule definition", "f 0 100 1", FIELD(operations[FL_ADD_RULE]), "Probability of adding a new rule definition for an existing word", }, 39 {"fL_mut_rulecond", 2, 0, "Modification of a rule condition", "f 0 100 1", FIELD(operations[FL_CHG_COND]), "Probability of modifying a random rule condition", }, 40 41 {"fL_mut_changeword", 2, 0, "Change a random word", "f 0 100 4", FIELD(operations[FL_CHG_WORD]), "Probability of changing a word name or a formula of a random word from an axiom or one of successors", }, 42 {"fL_mut_changeword_formula", 2, 0, " - change of a formula", "f 0 100 4", FIELD(chgoperations[FL_CHG_WORD_FORMULA]), "Probability of changing a formula in a word", }, 43 {"fL_mut_changeword_name", 2, 0, " - change of a name", "f 0 100 2", FIELD(chgoperations[FL_CHG_WORD_NAME]), "Probability of changing a name in a word", }, 44 45 {"fL_mut_changeiter", 2, 0, "Change the number of iterations", "f 0 100 1", FIELD(operations[FL_CHG_ITER]), "Probability of changing the number of iterations of the L-System", }, 46 {"fL_mut_changeiter_step", 2, 0, "Step of the iteration change", "f 0 1 1.0", FIELD(iterchangestep), "The minimal step that should be used for changing iterations in the L-System", }, 47 {"fL_mut_deletion", 2, 0, "Deletion of a random word", "f 0 100 4", FIELD(operations[FL_DEL_WORD]), "Probability of deleting a random word from an axiom or a random successor (also deletes the rule if there is only one word in the successor)", }, 41 48 { 0, }, 42 49 }; … … 66 73 if (builder.countSticksInSequence(&builder.genotype) == 0) 67 74 { 68 return GENOPER_OPFAIL;75 return 1; 69 76 } 70 77 double neededtime = 0; 71 78 Model *m = builder.developModel(neededtime); 72 if ( !m)73 { 74 return GENOPER_OPFAIL;79 if (m == NULL) 80 { 81 return 1; 75 82 } 76 83 if (!m->isValid()) 77 84 { 78 85 delete m; 79 return GENOPER_OPFAIL;86 return 1; 80 87 } 81 88 delete m; 82 83 89 84 90 return GENOPER_OK; … … 93 99 if (err != 0) 94 100 { 95 return err;101 return GENOPER_OK; 96 102 } 97 103 double neededtime = 0; 98 104 Model *m = builder.developModel(neededtime); 105 if (m == NULL) 106 { 107 return GENOPER_OK; 108 } 99 109 if (!m->isValid()) 100 110 { 101 111 delete m; 102 return GENOPER_O PFAIL;112 return GENOPER_OK; 103 113 } 104 114 if (neededtime != builder.time) … … 171 181 else 172 182 { 173 int rid = rndUint( creature->rules.size());183 int rid = rndUint((unsigned int)creature->rules.size()); 174 184 list = &creature->rules[rid]->objsucc; 175 185 numparams = creature->rules[rid]->objpred->npar; … … 303 313 if (creature->rules.size() > 0) 304 314 { 305 int ruleid = rndUint( creature->rules.size());315 int ruleid = rndUint((unsigned int)creature->rules.size()); 306 316 if (!creature->rules[ruleid]->condeval) 307 317 { … … 340 350 if (wordswithnorules.size() > 0) 341 351 { 342 int predid = rndUint( wordswithnorules.size());352 int predid = rndUint((unsigned int)wordswithnorules.size()); 343 353 fL_Rule *newrule = new fL_Rule(0, 0); 344 354 fL_Word *pred = new fL_Word(); … … 352 362 else if (creature->rules.size() > 0) 353 363 { 354 int ruleid = rndUint( creature->rules.size());364 int ruleid = rndUint((unsigned int)creature->rules.size()); 355 365 fL_Rule *newrule = new fL_Rule(0, 0); 356 366 fL_Word *pred = new fL_Word(); … … 455 465 else 456 466 { 457 int rndid = rndUint( list->size());467 int rndid = rndUint((unsigned int)list->size()); 458 468 std::list<fL_Word *>::iterator it = list->begin(); 459 469 std::advance(it, rndid); … … 482 492 int tmp = 0; 483 493 std::list<fL_Word *> *list = selectRandomSequence(creature, numpars, tmp); 484 int rndid = rndUint( list->size());494 int rndid = rndUint((unsigned int)list->size()); 485 495 std::list<fL_Word *>::iterator it = list->begin(); 486 496 std::advance(it, rndid); … … 531 541 int tmp = 0; 532 542 std::list<fL_Word *> *list = selectRandomSequence(creature, numpars, tmp); 533 int rndid = rndUint( list->size());543 int rndid = rndUint((unsigned int)list->size()); 534 544 std::list<fL_Word *>::iterator selectedword = list->begin(); 535 545 std::advance(selectedword, rndid); … … 545 555 int numpars = 0; 546 556 std::list<fL_Word *> *list = selectRandomSequence(creature, numpars, tmp); 547 int rndid = rndUint( list->size());557 int rndid = rndUint((unsigned int)list->size()); 548 558 std::list<fL_Word *>::iterator it = list->begin(); 549 559 std::advance(it, rndid); … … 577 587 if (available.size() > 0) 578 588 { 579 int newnameid = rndUint( available.size());589 int newnameid = rndUint((unsigned int)available.size()); 580 590 (*selectedword)->name = available[newnameid]->name; 581 591 } … … 752 762 for (int i = 0; i < numselrules; i++) 753 763 { 754 int rulid = rndUint( from->rules.size());764 int rulid = rndUint((unsigned int)from->rules.size()); 755 765 fL_Rule *rul = from->rules[rulid]; 756 766 fL_Rule *newrule = new fL_Rule(0, 0); … … 894 904 else if (strchr("<>$[]&\\ @|*", ch) != NULL) // other allowed symbols and special neuron symbols 895 905 { 896 style = GENSTYLE_CS(GENCOLOR_TEXT, ch =='[' || ch==']' ? GENSTYLE_BOLD : GENSTYLE_NONE);906 style = GENSTYLE_CS(GENCOLOR_TEXT, ch == '[' || ch == ']' ? GENSTYLE_BOLD : GENSTYLE_NONE); 897 907 } 898 908 return style;
Note: See TracChangeset
for help on using the changeset viewer.