Changeset 1240


Ignore:
Timestamp:
05/10/23 01:28:06 (20 months ago)
Author:
Maciej Komosinski
Message:

Updated f4->f1 approximate converter

Location:
cpp/frams/genetics/f4
Files:
2 edited

Legend:

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

    r1236 r1240  
    3939        SString out = model->getF0Geno().getGenes();
    4040        delete model;
     41
     42        /* quick debugging test - print an approximate f1 conversion of every genotype converted to f0:
     43        GenoConv_F41_TestOnly conv41;
     44        SString f1 = conv41.convert(in, NULL, false);
     45        printf("f1 = %s\n", f1.c_str());
     46        */
     47
    4148        return out;
    4249}
     
    4552GenoConv_F41_TestOnly::GenoConv_F41_TestOnly()
    4653{
    47         name = "Only for testing, approximate f4->f1 converter"; //Do not use in production! (adam)
     54        name = "Only for testing, approximate f4->f1 converter";
     55        // Why approximate? for example, f1 does not allow to continue after branching: X(X,X)X  <-- the last X
     56        // Some modifier genes are also not perfectly converted.
     57        // And neuron properties are ignored...
    4858        in_format = '4';
    4959        out_format = '1';
  • cpp/frams/genetics/f4/f4_general.cpp

    r1239 r1240  
    679679                        return true; //so continue development!
    680680
    681         if (development_stagnation)
    682                 return false; //the same number of cells, no progress in development in any cell -> stagnation, end development
     681        //the same number of cells, no progress in development in any cell -> stagnation!
     682
     683        if (development_stagnation) // stagnation was already detected in the previous step, so end development!
     684        {
     685                for (int i = 0; i < cell_count; i++)
     686                        if (C[i]->gcur != NULL) // genotype execution pointer did not reach the end
     687                                logPrintf("f4_Cells", "oneStep", LOG_WARN, "Finishing the development of cells due to stagnation, but cell %d did not reach the end of development", i); //let's see an example of such a genotype and investigate...
     688                return false; //end development
     689        }
    683690        else
    684691        {
    685692                development_stagnation = true; //signal (force) f4_Cell's that wait for neural connection development to make a step, because all cells stagnated and waiting cells cannot hope for new neurons to be created
    686                 return true;
     693                return true; //one grace step. If there are some waiting cells, they must move on in the next step and set development_stagnation=false or set error. If development_stagnation is not set to false, we will finish development in the next step. This grace step may be unnecessary if there are no waiting cells, but we have no easy way to check this from here (although we could check if all cells' gcur==NULL... would this be always equivalent? Maybe some cells may stagnate with gcur!=NULL and they are not waiting for neural connections to develop and this does not mean an error? Added LOG_WARN above to detect such cases. Anyway, for gcur==NULL, f4_Cell.oneStep() exits immediately, so one grace step is not a big overhead.)
    687694        }
    688695}
     
    879886void f4_Cells::toF1GenoRec(int curc, SString &out)
    880887{
    881         int i, j, ccount;
    882         f4_Cell *thisti;
    883         f4_Cell *thneu;
    884         char buf[200];
    885 
    886888        if (curc >= cell_count) return;
    887889
    888890        if (C[curc]->type != CELL_STICK) return;
    889891
    890         thisti = C[curc];
     892        f4_Cell *thisti = C[curc];
    891893        if (thisti->dadlink != NULL)
    892894                *tmpcel = *(thisti->dadlink);
     
    929931
    930932        // neurons attached to it
    931         for (i = 0; i < cell_count; i++)
     933        for (int i = 0; i < cell_count; i++)
    932934        {
    933935                if (C[i]->type == CELL_NEURON)
     
    935937                        if (C[i]->dadlink == thisti)
    936938                        {
    937                                 thneu = C[i];
     939                                f4_Cell *thneu = C[i];
    938940                                out += "[";
    939                                 // ctrl
    940                                 //if (1 == thneu->ctrl) out += "@"; // old code; this can be easily generalized to any neuroclass if ever needed
    941                                 //if (2 == thneu->ctrl) out += "|";
    942                                 out += thneu->neuclass->name.c_str(); // not tested, but something like that
     941                                out += thneu->neuclass->name.c_str();
     942                                if (thneu->conns_count > 0)
     943                                        out += ", ";
    943944                                // connections
    944                                 for (j = 0; j < thneu->conns_count; j++)
    945                                 {
    946                                         if (j) out += ",";
     945                                for (int j = 0; j < thneu->conns_count; j++)
     946                                {
     947                                        if (j > 0) out += ", ";
     948                                        char buf[100];
    947949                                        sprintf(buf, "%d", thneu->conns[j]->from->nr - thneu->nr);
    948950                                        out += buf;
     
    961963                out += "(";
    962964
    963         ccount = 1;
    964         for (i = 0; i < cell_count; i++)
     965        int ccount = 1;
     966        for (int i = 0; i < cell_count; i++)
    965967        {
    966968                if (C[i]->type == CELL_STICK)
     
    13971399                {
    13981400                        //printf("any regular character '%c'\n", genot[pos_inout]);
    1399 #define F4_SIMPLIFY_MODIFIERS //avoid long sequences like ...<X>llmlIilImmimiimmimifmfl<fifmmimilimmmiimiliffmfliIfififlliflimfliffififmiffmflllfflimlififfiiffifIr<r<... - another option, instead of simplifying while parsing here, would be mutations: when they add/modify/remove a modifier node, they could "clean" the tree by removing nodes when they encounter contradictory modifiers on the same subpath, and also limit the number of modifiers just as GenoOperators::simplifiedModifiers() does.
     1401#define F4_SIMPLIFY_MODIFIERS //avoid long, redundant sequences like ...<X>llmlIilImmimiimmimifmfl<fifmmimilimmmiimiliffmfliIfififlliflimfliffififmiffmflllfflimlififfiiffifIr<r<...
    14001402#ifdef F4_SIMPLIFY_MODIFIERS
    14011403                        char *ptr = (char*)(genot + pos_inout);
Note: See TracChangeset for help on using the changeset viewer.