Changeset 513 for cpp/frams/genetics


Ignore:
Timestamp:
05/23/16 13:52:53 (9 years ago)
Author:
Maciej Komosinski
Message:

checkValidity() and validate() are now aware of genotype name

Location:
cpp/frams/genetics
Files:
9 edited

Legend:

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

    r375 r513  
    8686
    8787
    88 int Geno_f4::validate(char *& geno)
     88int Geno_f4::validate(char *& geno, const char *genoname)
    8989{
    9090        // convert geno to tree, then try to validate 20 times
     
    100100
    101101
    102 int Geno_f4::checkValidity(const char * geno)
     102int Geno_f4::checkValidity(const char * geno, const char *genoname)
    103103{
    104104        f4_node root;
  • cpp/frams/genetics/f4/oper_f4.h

    r286 r513  
    3333public:
    3434        Geno_f4();
    35         int validate(char *&);
    36         int checkValidity(const char *);
     35        int checkValidity(const char *, const char *genoname);
     36        int validate(char *&, const char *genoname);
    3737        int mutate(char *& g, float & chg, int &method);
    3838        int crossOver(char *&g1, char *&g2, float& chg1, float& chg2);
  • cpp/frams/genetics/f9/oper_f9.cpp

    r348 r513  
    2626}
    2727
    28 int GenoOper_f9::checkValidity(const char* gene)
     28int GenoOper_f9::checkValidity(const char* gene, const char *genoname)
    2929{
    3030        if (!gene[0]) return 1; //empty is not valid
     
    3636
    3737///Remove all invalid letters from the genotype
    38 int GenoOper_f9::validate(char *&gene)
     38int GenoOper_f9::validate(char *&gene, const char *genoname)
    3939{
    4040        SString validated; //new genotype (everything except turtle_commands_f9 is skipped)
  • cpp/frams/genetics/f9/oper_f9.h

    r286 r513  
    1313public:
    1414        GenoOper_f9();
    15         int checkValidity(const char *);
    16         int validate(char *&);
    17         int mutate(char *&g,float& chg,int &method);
    18         int crossOver(char *&g1,char *&g2,float& chg1,float& chg2);
     15        int checkValidity(const char *, const char *genoname);
     16        int validate(char *&, const char *genoname);
     17        int mutate(char *&g, float& chg, int &method);
     18        int crossOver(char *&g1, char *&g2, float& chg1, float& chg2);
    1919        uint32_t style(const char *g, int pos);
    20         const char* getSimplest() {return "R";}
     20        const char* getSimplest() { return "R"; }
    2121
    2222        double mut_prob; //mutation probability
  • cpp/frams/genetics/fF/oper_fF.cpp

    r286 r513  
    2626}
    2727
    28 int GenoOper_fF::checkValidity(const char* gene)
     28int GenoOper_fF::checkValidity(const char* gene, const char *genoname)
    2929{
    3030        fF_growth_params par;
     
    3232}
    3333
    34 int GenoOper_fF::validate(char *&gene)
     34int GenoOper_fF::validate(char *&gene, const char *genoname)
    3535{
    3636        fF_growth_params par; //is initialized with default values
  • cpp/frams/genetics/fF/oper_fF.h

    r286 r513  
    1313public:
    1414        GenoOper_fF();
    15         int checkValidity(const char *);
    16         int validate(char *&);
     15        int checkValidity(const char *, const char *genoname);
     16        int validate(char *&, const char *genoname);
    1717        int mutate(char *&g, float& chg, int &method);
    1818        int crossOver(char *&g1, char *&g2, float& chg1, float& chg2);
    1919        uint32_t style(const char *g, int pos);
    20         const char* getSimplest() { return "6, 1.05, 1.05, 1.05, 0, 0, 0"; }
     20        const char* getSimplest() { return "6, "/*"1, 1, 1, "*/"1.05, 1.05, 1.05, 0, 0, 0"; }
    2121
    2222        double xover_proportion;
  • cpp/frams/genetics/genman.cpp

    r467 r513  
    203203        int check1;
    204204        if (!gf) { canvalidate = false; return GENOPER_NOOPER; }
    205         else check1 = gf->checkValidity(gg);
     205        else check1 = gf->checkValidity(gg,g.getName().c_str());
    206206        if (!canvalidate) return check1; //just checking
    207207        if (check1 == GENOPER_OK) { canvalidate = false; return check1; }
    208208        char *g2 = strdup(gg);
    209         if (gf->validate(g2) == GENOPER_NOOPER) { free(g2); canvalidate = false; return check1; }
     209        if (gf->validate(g2,g.getName().c_str()) == GENOPER_NOOPER) { free(g2); canvalidate = false; return check1; }
    210210        if (check1 == GENOPER_NOOPER) //disaster: cannot check because there is no check operator
    211211        {
    212212                g.setGene(g2); free(g2); canvalidate = false; return GENOPER_NOOPER;
    213213        }
    214         int check2 = gf->checkValidity(g2);
     214        int check2 = gf->checkValidity(g2, "validated");
    215215        if (check2 == GENOPER_OK) g.setGene(g2);
    216216        free(g2);
     
    238238                return Geno(SString::empty(), -1, SString::empty(), SString::sprintf("GENOPER_NOOPER: Validate(): don't know how to handle genetic format %c", format));
    239239        char *g2 = strdup(geny.getGene().c_str()); //copy for validation
    240         int res = gf->validate(g2);
     240        int res = gf->validate(g2, geny.getName().c_str());
    241241        SString sg2 = g2;
    242242        free(g2);
     
    537537        {
    538538                string l;
    539                 if (oper_fx_list[i]->checkValidity("") != GENOPER_NOOPER) l += " checkValidity";
     539                if (oper_fx_list[i]->checkValidity("","") != GENOPER_NOOPER) l += " checkValidity";
    540540                if (oper_fx_list[i]->getSimplest())
    541541                {
    542542                        g = strdup(oper_fx_list[i]->getSimplest());
    543543                        g2 = strdup(g);
    544                         if (oper_fx_list[i]->validate(g) != GENOPER_NOOPER) l += " validate";
     544                        if (oper_fx_list[i]->validate(g,"") != GENOPER_NOOPER) l += " validate";
    545545                        if (oper_fx_list[i]->mutate(g, f1, m) != GENOPER_NOOPER) l += " mutate";
    546546                        if (oper_fx_list[i]->crossOver(g, g2, f1, f2) != GENOPER_NOOPER) l += " crossover";
  • cpp/frams/genetics/genoconv.h

    r286 r513  
    5050
    5151        /// You have to reimplement this method.
    52         /// If your converter cannot do its job, return empty string
    53         /// (return SString();), any other return value is assumed
    54         /// to be output genotype.
     52        /// If your converter cannot do its job, return empty string - return SString();
     53        /// Any other return value is assumed to be output genotype.
    5554        /// @param map if not null, mapping informaton is requested, converter should add conversion map to this object
    5655        virtual SString convert(SString &i, MultiMap *map) { return SString(); }
  • cpp/frams/genetics/oper_fx.h

    r287 r513  
    9292/**Checks a genotype for minor mistakes and major errors.
    9393\param geno genotype to be checked
     94\param genoname name of the genotype to be checked
    9495\retval error_position 1-based (or 1 if no exact error position known)
    9596\retval GENOPER_OK when the genotype is fully valid, and can be translated by the converter with \b no modifications nor tweaks*/
    96    virtual int checkValidity(const char *geno) {return GENOPER_NOOPER;}
     97   virtual int checkValidity(const char *geno, const char *genoname) { return GENOPER_NOOPER; }
    9798
    9899/**Validates a genotype. The purpose of this function is to validate
     
    100101to introduce entirely new genes in place of an error.
    101102\param geno input/output: genotype to be validated
     103\param genoname name of the genotype to be validated
    102104\retval GENOPER_OK must be returned in any case ("did my best to validate")*/
    103    virtual int validate(char *&geno) {return GENOPER_NOOPER;}
     105   virtual int validate(char *&geno, const char *genoname) { return GENOPER_NOOPER; }
    104106
    105107/**Mutates a genotype. Mutation should always change something.
Note: See TracChangeset for help on using the changeset viewer.