Ignore:
Timestamp:
06/22/23 03:52:39 (10 months ago)
Author:
Maciej Komosinski
Message:

f4: three #define's -> enum, minor refactorizations, added comments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/f4/f4_general.cpp

    r1249 r1259  
    3737{
    3838        nr = nnr;
    39         type = CELL_UNDIFF;
     39        type = f4_Cell_type::CELL_UNDIFF;
    4040        dadlink = ndad;
    4141        org = NULL;
     
    6262        {
    6363                // make sure it is a stick (and not a stick f4_Cell!)
    64                 if (ndad->type == CELL_STICK)
     64                if (ndad->type == f4_Cell_type::CELL_STICK)
    6565                {
    6666                        //firstend = ndad->lastend;
     
    6868                        ndad->stickchildcount++;
    6969                }
    70                 if (ndad->type == CELL_NEURON)
     70                if (ndad->type == f4_Cell_type::CELL_NEURON)
    7171                {
    7272                        inertia = ndad->inertia;
     
    8484{
    8585        nr = nnr;
    86         type = CELL_UNDIFF;
     86        type = f4_Cell_type::CELL_UNDIFF;
    8787        dadlink = ndad;
    8888        org = nO;
     
    112112        {
    113113                // make sure it is a stick (and not a stick f4_Cell!)
    114                 if (ndad->type == CELL_STICK)
     114                if (ndad->type == f4_Cell_type::CELL_STICK)
    115115                {
    116116                        //firstend = ndad->lastend;
     
    118118                        ndad->stickchildcount++;
    119119                }
    120                 if (ndad->type == CELL_NEURON)
     120                if (ndad->type == f4_Cell_type::CELL_NEURON)
    121121                {
    122122                        inertia = ndad->inertia;
     
    173173
    174174                                // error: sticks cannot divide
    175                                 if (type == CELL_STICK)
     175                                if (type == f4_Cell_type::CELL_STICK)
    176176                                {
    177177                                        // cannot fix
     
    181181
    182182                                // undiff divides
    183                                 if (type == CELL_UNDIFF)
     183                                if (type == f4_Cell_type::CELL_UNDIFF)
    184184                                {
    185185                                        // commacount is set only when daughter turns into X
     
    194194                                }
    195195                                // a neuron divides: create a new, duplicate connections
    196                                 if (type == CELL_NEURON)
     196                                if (type == f4_Cell_type::CELL_NEURON)
    197197                                {
    198198                                        // daughter cell
     
    203203                                        repeat.clear();
    204204                                        // it is a neuron from start
    205                                         tmp->type = CELL_NEURON;
     205                                        tmp->type = f4_Cell_type::CELL_NEURON;
    206206                                        // it has the same type as the parent neuron
    207207                                        tmp->neuclass = neuclass;
     
    257257                                {
    258258                                        // error: still undiff
    259                                         if (type == CELL_UNDIFF)
     259                                        if (type == f4_Cell_type::CELL_UNDIFF)
    260260                                        {
    261261                                                // fix it: insert an 'X'
     
    301301                        {
    302302                                // error: if neuron
    303                                 if (type == CELL_NEURON)
     303                                if (type == f4_Cell_type::CELL_NEURON)
    304304                                {
    305305                                        // fix: delete it
     
    331331                        {
    332332                                // error: if neuron
    333                                 if (type == CELL_NEURON) //some neurons have the same single-letter names as modifiers (for example G,S,D), but they are supposed to have is_neuroclass==true so they should indeed not be handled here
     333                                if (type == f4_Cell_type::CELL_NEURON) //some neurons have the same single-letter names as modifiers (for example G,S,D), but they are supposed to have is_neuroclass==true so they should indeed not be handled here
    334334                                {//however, what we see here is actually modifiers such as IdqEbWL (so not valid neuroclasses) that occurred within an already differentiated cell of type==CELL_NEURON.
    335335                                        //printf("Handled as a modifier, but type==CELL_NEURON: '%c'\n", name);
     
    346346                                // turn undiff. cell into a stick
    347347                                // error: already differentiated
    348                                 if (type != CELL_UNDIFF)
     348                                if (type != f4_Cell_type::CELL_UNDIFF)
    349349                                {
    350350                                        // fix: delete this node
     
    352352                                        return;  // error code set -> stop further cells development
    353353                                }
    354                                 type = CELL_STICK;
     354                                type = f4_Cell_type::CELL_STICK;
    355355                                // fix dad commacount and own anglepos
    356356                                if (dadlink != NULL)
     
    367367                                // connection to neuron
    368368                                // error: not a neuron
    369                                 if (type != CELL_NEURON)
     369                                if (type != f4_Cell_type::CELL_NEURON)
    370370                                {
    371371                                        // fix: delete it
     
    384384                                for (int i = 0; i < org->cell_count; i++)
    385385                                {
    386                                         if (org->C[i]->type == CELL_NEURON) neu_counter++;
     386                                        if (org->C[i]->type == f4_Cell_type::CELL_NEURON) neu_counter++;
    387387                                        if (org->C[i] == this) { this_index = neu_counter - 1; break; }
    388388                                }
     
    398398                                for (from = 0; from < org->cell_count; from++)
    399399                                {
    400                                         if (org->C[from]->type == CELL_NEURON) neu_counter++;
     400                                        if (org->C[from]->type == f4_Cell_type::CELL_NEURON) neu_counter++;
    401401                                        if (from_index == (neu_counter - 1)) break;
    402402                                }
     
    457457                                // neuron parameter
    458458                                // error: not a neuron
    459                                 if (type != CELL_NEURON)
     459                                if (type != f4_Cell_type::CELL_NEURON)
    460460                                {
    461461                                        // fix: delete it
     
    513513                {
    514514                        genoRange.add(gcur->pos, gcur->pos + int(gcur->name.length()) + 2 - 1); // +2 for N:
    515                         if (type != CELL_UNDIFF)
     515                        if (type != f4_Cell_type::CELL_UNDIFF)
    516516                        {
    517517                                // fix: delete this node
     
    527527                        }
    528528                        neuclass = gcur->neuclass;
    529                         type = CELL_NEURON;
     529                        type = f4_Cell_type::CELL_NEURON;
    530530                        // change of type also halts development, to give other
    531531                        // cells a chance for adjustment.  Namely, it is important
     
    567567        {
    568568                if (org->C[i]->dadlink == this)
    569                         if (org->C[i]->type == CELL_STICK)
     569                        if (org->C[i]->type == f4_Cell_type::CELL_STICK)
    570570                                stickchildcount++;
    571571        }
     
    575575        else
    576576                P.muscle_bend_range = 1.0 / std::max(1, dadlink->stickchildcount); //bend range in f1: 0, 1 (line XX[|]) -> 100%, 2 (Y-shape X(X[|],X)) -> 50%, 3 (cross X(X[|],X,X)) -> 33%
    577         //MacKo 2023-05: but shouldn't this formula ^^ also take commacount into consideration, like in f1?
    578 
    579         if (type == CELL_STICK)
     577        //MacKo 2023-05: but shouldn't this formula ^^ also take commacount into consideration, like in f1? Note: in f0, the range of a newly added muscle has the default value (1.0) until modified by mutation, and the range can be set to any value completely unrelated to the junction where the muscle is located. In f1, the range of a newly added muscle depends on the number of branches (commas) in the junction including empty branches (see also conv_f1_f0_branch_muscle_range), but can be overridden by the genotype due to mutation and any value can be directly set just as in f0 - e.g. X[|,r:0.8] - so the value based on the number of commas only serves as a default. Compared to f0 and f1, f4 enforces a specific range here and this cannot be changed in any way, because as of now (2023-05) there is no support to mutate neural properties except for the N neuron.
     578
     579        if (type == f4_Cell_type::CELL_STICK)
    580580        {
    581581                if (dadlink == NULL)
     
    716716        for (int i = 0; i < cell_count; i++)
    717717        {
    718                 if (C[i]->type == CELL_NEURON)
    719                 {
    720                         while (C[i]->dadlink->type == CELL_NEURON)
     718                if (C[i]->type == f4_Cell_type::CELL_NEURON)
     719                {
     720                        while (C[i]->dadlink->type == f4_Cell_type::CELL_NEURON)
    721721                        {
    722722                                C[i]->dadlink = C[i]->dadlink->dadlink;
     
    729729        for (int i = 0; i < cell_count; i++)
    730730        {
    731                 if (C[i]->type == CELL_UNDIFF)
    732                 {
    733                         C[i]->type = CELL_STICK;
     731                if (C[i]->type == f4_Cell_type::CELL_UNDIFF)
     732                {
     733                        C[i]->type = f4_Cell_type::CELL_STICK;
    734734                        //setError();
    735735                }
     
    764764                switch (c->type)
    765765                {
    766                 case CELL_UNDIFF: type = "undiff"; break;
    767                 case CELL_STICK:  type = "STICK"; break;
    768                 case CELL_NEURON: type = string("NEURON:") + c->neuclass->name.c_str(); break;
    769                 default: type = std::to_string(c->type);
     766                case f4_Cell_type::CELL_UNDIFF: type = "undiff"; break;
     767                case f4_Cell_type::CELL_STICK:  type = "STICK"; break;
     768                case f4_Cell_type::CELL_NEURON: type = string("NEURON:") + c->neuclass->name.c_str(); break;
     769                default: type = std::to_string(static_cast<int>(c->type));
    770770                }
    771771                const char *status = c->gcur == c->old_gcur ? (c->gcur != NULL ? "no progress" : "") : (c->gcur != NULL ? "progress" : "finished"); //progress or no progress means the cell is yielding = not finished but decided to halt development and wait for other cells. New cells may be created in case of "no progress" status.
     
    893893        if (curc >= cell_count) return;
    894894
    895         if (C[curc]->type != CELL_STICK) return;
     895        if (C[curc]->type != f4_Cell_type::CELL_STICK) return;
    896896
    897897        f4_Cell *thisti = C[curc];
     
    899899                *tmpcel = *(thisti->dadlink);
    900900
    901         // adjust length, curvedness, etc.
     901        // Adjust length, curvedness, etc.
    902902        tmpcel->P.propagateAlong(false);
     903
     904        // The sequence of "while" loops below is a fast and simple heuristic (decrease as long as the value is too big, then increase as long as the value is too small).
     905        // However, since every different sequence of upper- and lower-case modifiers produces a different value of a given property,
     906        // all 2^N sequences should be tested to discover the best approximation of the target value of a given property using N modifiers.
     907        // This issue is TODO if anybody needed this function (and modifier sequences it produces) for any serious use. Also, add support for Qq.
     908        // See also GenoOperators::simplifiedModifiers() and geneprops_test.cpp.
    903909        while (tmpcel->P.length > thisti->P.length)
    904910        {
     
    938944        for (int i = 0; i < cell_count; i++)
    939945        {
    940                 if (C[i]->type == CELL_NEURON)
     946                if (C[i]->type == f4_Cell_type::CELL_NEURON)
    941947                {
    942948                        if (C[i]->dadlink == thisti)
     
    971977        for (int i = 0; i < cell_count; i++)
    972978        {
    973                 if (C[i]->type == CELL_STICK)
     979                if (C[i]->type == f4_Cell_type::CELL_STICK)
    974980                {
    975981                        if (C[i]->dadlink == thisti)
Note: See TracChangeset for help on using the changeset viewer.