Ignore:
Timestamp:
04/27/23 04:04:06 (12 months ago)
Author:
Maciej Komosinski
Message:

Improvements in f4:

  • fixed a bug where newly created cells in a given development step were not counted as in-active-development (overlooked), and if they were the only in-active-development cells, the development of an organism would stop
  • added one extra development step (#ifdef EXTRA_STEP_CELL_DEVELOPMENT) so that cells that became not in-active-development ("halted" or yielding, usually due to waiting for neurons to develop in other cells) would get a chance to continue development (important when we don't want to ignore invalid neuron connections, #ifdef TREAT_BAD_CONNECTIONS_AS_INVALID_GENO)
  • ensured that all connections in a cell are processed (earlier they could be skipped if the development of the cell was "halted" and all cells became not in-active-development)
  • got rid of neuron connection syntax [sensor:weight], now all neuron classes are handled in a uniform way and their [connections] too; the only allowed syntax is [input_index:weight]
  • unified handling of all neuroclasses during parsing, conversion and mutation
  • more correct syntax coloring
  • got rid of general-purpose fields (i1, i2, f1, s1) in class f4_node - now separate fields serve their individual purpose
  • rewritten creating and modifying neuron connections - it is more deliberate to satisfy neuron input/output preferences
  • some invalid neuron connections make a genotype invalid (previously invalid neuron connections were ignored and the genotype was considered valid)
  • added (surprisingly missing) simple debug printout functions to see the f4_Node tree structure and the developing f4_Cells
  • more informative variable and constant names
  • improved performance
File:
1 edited

Legend:

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

    r1212 r1227  
    9090        if (cells) delete cells;
    9191        cells = new f4_Cells(geno, 0);
    92         if (GENOPER_OK != cells->geterror())
    93         {
    94                 error = cells->geterror();
    95                 errorpos = cells->geterrorpos();
     92        if (GENOPER_OK != cells->getErrorCode())
     93        {
     94                error = cells->getErrorCode();
     95                errorpos = cells->getErrorPos();
    9696                //delete cells;
    9797                return error;
     
    9999
    100100        cells->simulate();
    101         if (GENOPER_OK != cells->geterror())
    102         {
    103                 error = cells->geterror();
    104                 errorpos = cells->geterrorpos();
     101        if (GENOPER_OK != cells->getErrorCode())
     102        {
     103                error = cells->getErrorCode();
     104                errorpos = cells->getErrorPos();
    105105                return error;
    106106        }
    107107
    108108        // reset recursive traverse flags
    109         for (i = 0; i < cells->nc; i++)
     109        for (i = 0; i < cells->cell_count; i++)
    110110                cells->C[i]->recProcessedFlag = 0;
    111111
     
    114114        // process every cell
    115115        int res;
    116         for (i = 0; i < cells->nc; i++)
     116        for (i = 0; i < cells->cell_count; i++)
    117117        {
    118118                res = buildModelRec(cells->C[i]);
    119119                if (res)
    120120                {
    121                         logMessage("f4_Model", "buildModelRec", 2, "Error in building Model");
     121                        logMessage("f4_Model", "buildFromF4", LOG_ERROR, "Error in building a Model");
    122122                        error = res;
    123123                        break;
     
    135135f4_Cell* f4_Model::getStick(f4_Cell *C)
    136136{
    137         if (T_STICK4 == C->type) return C;
     137        if (C->type == CELL_STICK) return C;
    138138        if (NULL != C->dadlink)
    139139                return getStick(C->dadlink);
    140140        // we have no more dadlinks, find any stick
    141         for (int i = 0; i < cells->nc; i++)
    142                 if (cells->C[i]->type == T_STICK4)
     141        for (int i = 0; i < cells->cell_count; i++)
     142                if (cells->C[i]->type == CELL_STICK)
    143143                        return cells->C[i];
    144144        // none!
    145         logMessage("f4_Model", "getStick", 2, "Not a single stick");
     145        logMessage("f4_Model", "getStick", LOG_ERROR, "Not a single stick");
    146146        return NULL;
    147147}
    148148
    149149
    150 /// updated by MacKo to follow new SDK standards (no more neuroitems)
    151150int f4_Model::buildModelRec(f4_Cell *C)
    152151{
     
    164163        // make sure parent is a stick
    165164        if (NULL != C->dadlink)
    166                 if (C->dadlink->type != T_STICK4)
    167                 {
    168                 C->dadlink = getStick(C->dadlink);
     165                if (C->dadlink->type != CELL_STICK)
     166                {
     167                        C->dadlink = getStick(C->dadlink);
    169168                }
    170169
     
    179178
    180179        range = C->genoRange;
    181         if (C->type == T_STICK4)
     180        if (C->type == CELL_STICK)
    182181        {
    183182                int jj_p1_refno;  // save for later
     
    190189                                /*1.0/C->P.mass,*/ C->P.friction, C->P.ingestion, C->P.assimilation
    191190                                //C->firstend.x, C->firstend.y, C->firstend.z
    192                                 );
     191                        );
    193192                        partidx = addFromString(PartType, tmpLine, &range);
    194193                        if (partidx < 0) return -1;
     
    207206                        //C->lastend.x, C->lastend.y, C->lastend.z
    208207                        /*"vol=" 1.0/C->P.mass,*/ C->P.friction, C->P.ingestion, C->P.assimilation
    209                         );
     208                );
    210209                partidx = addFromString(PartType, tmpLine, &range);
    211210                if (partidx < 0) return -2;
     
    227226                        //C->P.ruch,   // rotstif
    228227                        C->P.stamina
    229                         );
     228                );
    230229                partidx = addFromString(JointType, tmpLine, &range);
    231230                if (partidx < 0) return -13;
     
    234233        }
    235234
    236         if (C->type == T_NEURON4) ///<this case was updated by MacKo
     235        if (C->type == CELL_NEURON)
    237236        {
    238237                const char* nclass = C->neuclass->name.c_str();
     
    259258                        partno = C->dadlink->p2_refno;
    260259                        if ((partno < 0) || (partno >= getPartCount())) return -21;
     260
    261261                        if (strcmp(nclass, "N") == 0)
    262                         {
    263262                                sprintf(tmpLine, "p=%d,d=\"N:in=%g,fo=%g,si=%g\"", partno, C->inertia, C->force, C->sigmo);
    264                         }
    265263                        else
    266                         {
    267264                                sprintf(tmpLine, "p=%d,d=\"%s\"", partno, nclass);
    268                         }
     265
    269266                        partidx = addFromString(NeuronType, tmpLine, &range);
    270267                        if (partidx < 0) return -22;
     
    275272                {
    276273                        jointno = C->dadlink->joint_refno;
    277                         sprintf(tmpLine, "j=%d,d=\"%s\"", jointno, nclass);
     274
     275                        if (strcmp(nclass, "@") == 0)
     276                                sprintf(tmpLine, "j=%d,d=\"@:p=%g\"", jointno, C->P.muscle_power);
     277                        else if (strcmp(nclass, "|") == 0)
     278                                sprintf(tmpLine, "j=%d,d=\"|:p=%g,r=%g\"", jointno, C->P.muscle_power, C->mz);
     279                        else
     280                                sprintf(tmpLine, "j=%d,d=\"%s\"", jointno, nclass);
     281
    278282                        partidx = addFromString(NeuronType, tmpLine, &range);
    279283                        if (partidx < 0) return -32;
     
    283287                int n_refno = C->neuro_refno;
    284288
    285                 if ((strcmp(nclass,"N") == 0) && C->ctrl)
    286                 {
    287                         if (1 == C->ctrl)
    288                                 sprintf(tmpLine, "j=%d,d=\"@:p=%g\"", C->dadlink->joint_refno, C->P.muscle_power);
    289                         else
    290                                 sprintf(tmpLine, "j=%d,d=\"|:p=%g,r=%g\"", C->dadlink->joint_refno, C->P.muscle_power, C->mz);
    291                         partidx = addFromString(NeuronType, tmpLine, &range);
    292                         if (partidx < 0) return -32;
    293                         sprintf(tmpLine, "%d,%d", partidx, n_refno);
    294                         if (addFromString(NeuronConnectionType, tmpLine, &range) < 0) return -33;
    295                         this->checkpoint();
    296                 }
    297 
    298                 for (j = 0; j < C->nolink; j++)
    299                 {
    300                         if (NULL != C->links[j]->from)
    301                                 buildModelRec(C->links[j]->from);
     289                for (j = 0; j < C->conns_count; j++)
     290                {
     291                        if (C->conns[j]->from != NULL)
     292                                buildModelRec(C->conns[j]->from);
    302293
    303294                        tmpLine[0] = 0;
    304                         if (C->links[j]->from == NULL)
     295                        if (C->conns[j]->from == NULL)
    305296                        {
    306                                 const char* nclass = C->links[j]->t.c_str();
    307                                 char* temp = (char*)C->links[j]->t.c_str();
    308                                 NeuroClass *sensortest = GenoOperators::parseNeuroClass(temp);
    309                                 //backward compatibility for G*TS
    310                                 if (C->links[j]->t == "*" || C->links[j]->t == "S" || C->links[j]->t == "T")
    311                                 {
    312                                         partno = C->dadlink->p2_refno;
    313                                         sprintf(tmpLine, "p=%d,d=\"%s\"", partno, nclass);
    314                                 }
    315                                 else if (C->links[j]->t == "G")
    316                                 {
    317                                         jointno = C->dadlink->joint_refno;
    318                                         sprintf(tmpLine, "j=%d,d=\"%s\"", jointno, nclass);
    319                                 }                               
    320                                 else if (sensortest->getPreferredLocation() == 0)
    321                                 {
    322                                         sprintf(tmpLine, "d=\"%s\"",nclass);
    323                                 }
    324                                 else if (sensortest->getPreferredLocation() == 1)
    325                                 {
    326                                         partno = C->dadlink->p2_refno;
    327                                         sprintf(tmpLine, "p=%d,d=\"%s\"", partno, nclass);
    328                                 }
    329                                 else
    330                                 {
    331                                         jointno = C->dadlink->joint_refno;
    332                                         sprintf(tmpLine, "j=%d,d=\"%s\"", jointno, nclass);
    333                                 }
    334 
     297                                logMessage("f4_Model", "buildModelRec", LOG_ERROR, "Old code for sensors as inputs embedded in [connection]: C->conns[j]->from == NULL");
    335298                        }
    336299                        int from = -1;
    337                         if (tmpLine[0]) //input from receptor
    338                         {
    339                                 from = addFromString(NeuronType, tmpLine, &range);
    340                                 if (from < 0) return -34;
    341                                 this->checkpoint();
    342                         } /*could be 'else'...*/
    343 
    344                         if (NULL != C->links[j]->from) // input from another neuron
    345                                 from = C->links[j]->from->neuro_refno;
     300                        if (C->conns[j]->from != NULL) // input from another neuron
     301                                from = C->conns[j]->from->neuro_refno;
    346302                        if (from >= 0)
    347303                        {
    348                                 sprintf(tmpLine, "%d,%d,%g", n_refno, from, C->links[j]->w);
     304                                sprintf(tmpLine, "%d,%d,%g", n_refno, from, C->conns[j]->weight);
    349305                                if (addFromString(NeuronConnectionType, tmpLine, &range) < 0) return -35;
    350306                                this->checkpoint();
Note: See TracChangeset for help on using the changeset viewer.