Ignore:
Timestamp:
09/09/23 15:10:49 (8 months ago)
Author:
Maciej Komosinski
Message:

fH, fB, fL: improved default parameter values, syntax coloring and code logic

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/fL/fL_oper.cpp

    r1075 r1273  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2023  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    88#include <algorithm>
    99
     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
    1017#define FIELDSTRUCT Geno_fL
    1118static ParamEntry geno_fL_paramtab[] =
     
    1421        {"Genetics: fL: Probabilities of mutating axiom and rules", },
    1522        {"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 of random 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 or one 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 adding stick", },
    24         {"fL_mut_add_neuro", 2, 0, " - addition of neuron", "f 0 1 0.2", FIELD(addtypes[FL_ADD_NEURO]), "Probability of adding neuron", },
    25         {"fL_mut_add_conn", 2, 0, " - addition of neuron connection", "f 0 1 0.2", FIELD(addtypes[FL_ADD_CONN]), "Probability of adding connection", },
    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 and stick", },
    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 in genotype", },
    29 
    30         {"fL_mut_worddefaddition", 2, 0, "Addition of new word definition", "f 0 1 0.05", FIELD(operations[FL_ADD_WDEF]), "Probability of adding new 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 for existing word", },
    32         {"fL_mut_rulecond", 2, 0, "Modification of rule condition", "f 0 1 0.1", FIELD(operations[FL_CHG_COND]), "Probability of modifying random 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 from axiom 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 in word", },
    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 in word", },
    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 in successor)", },
     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)", },
    4148        { 0, },
    4249};
     
    6673        if (builder.countSticksInSequence(&builder.genotype) == 0)
    6774        {
    68                 return GENOPER_OPFAIL;
     75                return 1;
    6976        }
    7077        double neededtime = 0;
    7178        Model *m = builder.developModel(neededtime);
    72         if (!m)
    73         {
    74                 return GENOPER_OPFAIL;
     79        if (m == NULL)
     80        {
     81                return 1;
    7582        }
    7683        if (!m->isValid())
    7784        {
    7885                delete m;
    79                 return GENOPER_OPFAIL;
     86                return 1;
    8087        }
    8188        delete m;
    82 
    8389
    8490        return GENOPER_OK;
     
    9399        if (err != 0)
    94100        {
    95                 return err;
     101                return GENOPER_OK;
    96102        }
    97103        double neededtime = 0;
    98104        Model *m = builder.developModel(neededtime);
     105        if (m == NULL)
     106        {
     107                return GENOPER_OK;
     108        }
    99109        if (!m->isValid())
    100110        {
    101111                delete m;
    102                 return GENOPER_OPFAIL;
     112                return GENOPER_OK;
    103113        }
    104114        if (neededtime != builder.time)
     
    171181        else
    172182        {
    173                 int rid = rndUint(creature->rules.size());
     183                int rid = rndUint((unsigned int)creature->rules.size());
    174184                list = &creature->rules[rid]->objsucc;
    175185                numparams = creature->rules[rid]->objpred->npar;
     
    303313                if (creature->rules.size() > 0)
    304314                {
    305                         int ruleid = rndUint(creature->rules.size());
     315                        int ruleid = rndUint((unsigned int)creature->rules.size());
    306316                        if (!creature->rules[ruleid]->condeval)
    307317                        {
     
    340350                if (wordswithnorules.size() > 0)
    341351                {
    342                         int predid = rndUint(wordswithnorules.size());
     352                        int predid = rndUint((unsigned int)wordswithnorules.size());
    343353                        fL_Rule *newrule = new fL_Rule(0, 0);
    344354                        fL_Word *pred = new fL_Word();
     
    352362                else if (creature->rules.size() > 0)
    353363                {
    354                         int ruleid = rndUint(creature->rules.size());
     364                        int ruleid = rndUint((unsigned int)creature->rules.size());
    355365                        fL_Rule *newrule = new fL_Rule(0, 0);
    356366                        fL_Word *pred = new fL_Word();
     
    455465                else
    456466                {
    457                         int rndid = rndUint(list->size());
     467                        int rndid = rndUint((unsigned int)list->size());
    458468                        std::list<fL_Word *>::iterator it = list->begin();
    459469                        std::advance(it, rndid);
     
    482492                int tmp = 0;
    483493                std::list<fL_Word *> *list = selectRandomSequence(creature, numpars, tmp);
    484                 int rndid = rndUint(list->size());
     494                int rndid = rndUint((unsigned int)list->size());
    485495                std::list<fL_Word *>::iterator it = list->begin();
    486496                std::advance(it, rndid);
     
    531541                int tmp = 0;
    532542                std::list<fL_Word *> *list = selectRandomSequence(creature, numpars, tmp);
    533                 int rndid = rndUint(list->size());
     543                int rndid = rndUint((unsigned int)list->size());
    534544                std::list<fL_Word *>::iterator selectedword = list->begin();
    535545                std::advance(selectedword, rndid);
     
    545555                        int numpars = 0;
    546556                        std::list<fL_Word *> *list = selectRandomSequence(creature, numpars, tmp);
    547                         int rndid = rndUint(list->size());
     557                        int rndid = rndUint((unsigned int)list->size());
    548558                        std::list<fL_Word *>::iterator it = list->begin();
    549559                        std::advance(it, rndid);
     
    577587                                if (available.size() > 0)
    578588                                {
    579                                         int newnameid = rndUint(available.size());
     589                                        int newnameid = rndUint((unsigned int)available.size());
    580590                                        (*selectedword)->name = available[newnameid]->name;
    581591                                }
     
    752762                for (int i = 0; i < numselrules; i++)
    753763                {
    754                         int rulid = rndUint(from->rules.size());
     764                        int rulid = rndUint((unsigned int)from->rules.size());
    755765                        fL_Rule *rul = from->rules[rulid];
    756766                        fL_Rule *newrule = new fL_Rule(0, 0);
     
    894904        else if (strchr("<>$[]&\\ @|*", ch) != NULL) // other allowed symbols and special neuron symbols
    895905        {
    896                 style = GENSTYLE_CS(GENCOLOR_TEXT, ch=='[' || ch==']' ? GENSTYLE_BOLD : GENSTYLE_NONE);
     906                style = GENSTYLE_CS(GENCOLOR_TEXT, ch == '[' || ch == ']' ? GENSTYLE_BOLD : GENSTYLE_NONE);
    897907        }
    898908        return style;
Note: See TracChangeset for help on using the changeset viewer.