Changeset 1232


Ignore:
Timestamp:
05/02/23 17:12:24 (19 months ago)
Author:
Maciej Komosinski
Message:

The validate() function may now attempt to repair genotypes without syntax errors (i.e., fully parsed into a correct f4_Node tree), but with semantic errors

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

Legend:

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

    r1231 r1232  
    795795}
    796796
    797 void f4_Cells::setRepairRemove(int nerrpos, f4_Node *rem)
    798 {
     797void f4_Cells::setRepairRemove(int nerrpos, f4_Node *to_remove)
     798{
     799        errorcode = GENOPER_REPAIR;
     800        errorpos = nerrpos;
    799801        if (!repair)
    800802        {
    801803                // not in repair mode, treat as repairable error
    802                 errorcode = GENOPER_REPAIR;
    803                 errorpos = nerrpos;
    804804        }
    805805        else
    806806        {
    807                 errorcode = GENOPER_REPAIR;
    808                 errorpos = nerrpos;
    809                 repair_remove = rem;
    810         }
    811 }
    812 
    813 int f4_Cells::setRepairInsert(int nerrpos, f4_Node *parent, f4_Node *insert)
    814 {
     807                repair_remove = to_remove;
     808        }
     809}
     810
     811int f4_Cells::setRepairInsert(int nerrpos, f4_Node *parent, f4_Node *to_insert)
     812{
     813        errorcode = GENOPER_REPAIR;
     814        errorpos = nerrpos;
    815815        if (!repair)
    816816        {
    817817                // not in repair mode, treat as repairable error
    818                 errorcode = GENOPER_REPAIR;
    819                 errorpos = nerrpos;
    820818                return -1;
    821819        }
    822820        else
    823821        {
    824                 errorcode = GENOPER_REPAIR;
    825                 errorpos = nerrpos;
    826822                repair_parent = parent;
    827                 repair_insert = insert;
     823                repair_insert = to_insert;
    828824                return 0;
    829825        }
     
    14231419        int res = f4_processRecur(genot, pos, root);
    14241420        if (res > 0)
    1425                 return res; //error
    1426         else if (genot[pos] == 0) //parsed until the end - OK!
    1427                 return 0;
    1428         else return pos + 1; //junk, unparsed genes after successful parsing, for example /*4*/<X>N:N>whatever or /*4*/<X>X>>>
     1421                return res; //parsing error
     1422        else if (genot[pos] != 0)
     1423                return pos + 1; //parsing OK but junk, unparsed genes left, for example /*4*/<X>N:N>whatever or /*4*/<X>X>>>
     1424        else
     1425                return 0; //parsing OK and parsed until the end
    14291426}
    14301427
  • cpp/frams/genetics/f4/f4_general.h

    r1231 r1232  
    303303         * Sets the element of genotype to be repaired by removal.
    304304         * @param nerrpos position of an error in genotype
    305          * @param rem the f4_Node to be removed from the genotype tree in order to repair
    306          */
    307         void setRepairRemove(int nerrpos, f4_Node *rem);
     305         * @param to_remove the f4_Node to be removed from the genotype tree in order to repair
     306         */
     307        void setRepairRemove(int nerrpos, f4_Node *to_remove);
    308308
    309309        /**
     
    311311         * @param nerrpos position of an error in genotype
    312312         * @param parent the parent of a new element
    313          * @param insert the element to be inserted
     313         * @param to_insert the element to be inserted
    314314         * @return 0 if repair can be performed, or -1 otherwise because the repair flag wasn't set in the constructor
    315315         */
    316         int setRepairInsert(int nerrpos, f4_Node *parent, f4_Node *insert);
     316        int setRepairInsert(int nerrpos, f4_Node *parent, f4_Node *to_insert);
    317317
    318318        /**
  • cpp/frams/genetics/f4/f4_oper.cpp

    r1231 r1232  
    1616// TODO the behavior of neuron input indexes during mutation seems badly implemented (see also TREAT_BAD_CONNECTIONS_AS_INVALID_GENO). Are they kept properly maintained when nodes are added and removed? This could be done well because during mutation we operate on the tree structure with cross-references between nodes (so they should not be affected by local changes in the tree), and then convert the tree back to string. Yet, the f4_Node.conn_from is an integer and these fields in nodes do not seem to be maintained on tree node adding/removal... change these integer offsets to references to node objects? But actually, do the offsets that constitute relative connection references concern the f4_Node tree structure (and all these sophisticated calculations of offsets during mutation are useful) or rather they concern the f4_Cells development? verify all situations in f4_Cell::oneStep(), case '['.
    1717// TODO add simplifying sequences of modifiers (so capital and small letter cancel out, like in f1) - but seems like each single modifier is a separate f4_Node? and perhaps we don't want to use the repair mechanism for this... maybe mutations, when they add/modify/remove a modifier node, should be "cleaning" the tree by removing nodes when they encounter contradictory modifiers on the same subpath, and also limit the number of modifiers of each type just like in f1? To avoid sequences like ...<X>llmlIilImmimiimmimifmfl<fifmmimilimmmiimiliffmfliIfififlliflimfliffififmiffmfliflifmIlimimiflimfiffmllliflmimifllifliliflifmIlimimiflimfiffmllliflmimifllfmIlimimiflimfiffmllliflmimiflliflimimmiflimfliffmiflifmfiffllIlififliffififmiffmfliflifIliflimimflimflfflimimifllfflifllfflimlififfiiffifIr<r<...
     18// TODO in mutation, adding the '#' gene does not seem to be effective. The gene is added and genotypes are valid, but hardly ever #n is effective, i.e., it hardly ever multiplicates body or brain parts... investigate!
    1819// TODO add support for properties of (any class of) neurons - not just sigmoid/force/intertia (':' syntax) for N
    1920// TODO add mapping genotype character ranges for neural [connections]
     
    123124        f4_Node root;
    124125        int res = f4_process(geno, &root);
    125         if (res == 0 || root.childCount() != 1) return GENOPER_OK; // either parsing says the genotype is OK or the resulting tree will not be repairable (fatal flaw; root must have exactly one child) - do not attempt repair
    126 
    127         // here we have a genotype with res>0 (for sure has some error) and root.childCount()==1 (still something was parsed into a tree)
     126        if (root.childCount() != 1) return GENOPER_OK; // the resulting tree will not be repairable (fatal flaw; root must have exactly one child) - do not even attempt repair
     127
     128        // here we have a genotype with root.childCount()==1 (meaning some part was successfully parsed into a tree) and either res==0 (syntax was correct, semantics we don't know) or res>0 (for sure has some error)
    128129        const int VALIDATE_TRIALS = 20;
    129130        res = ValidateRecur(&root, VALIDATE_TRIALS);
Note: See TracChangeset for help on using the changeset viewer.