Ignore:
Timestamp:
02/26/14 20:21:22 (10 years ago)
Author:
sz
Message:

Genetics reorganization (affects ALL applications!):

  • Converters/Validators? are now configured/initialized in a more verbose but also less confusing way
  • At the same time, the PreconfiguredGenetics? object will help you avoid the increased complexity by creating the ready-to-use environment that is sufficient in 99% of cases (see the demos)
  • Format F genetics updated (work in progress)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/genman.cpp

    r139 r145  
    105105
    106106#ifdef USE_GENMAN_f0
    107         geno_fx_list.push_back(new Geno_f0);
     107        oper_fx_list.push_back(new Geno_f0);
    108108#endif
    109109#ifdef USE_GENMAN_f0FUZZY
    110         geno_fx_list.push_back(new Geno_f0Fuzzy);
     110        oper_fx_list.push_back(new Geno_f0Fuzzy);
    111111#endif
    112112#ifdef USE_GENMAN_f1
    113         geno_fx_list.push_back(new Geno_f1);
     113        oper_fx_list.push_back(new Geno_f1);
    114114#endif
    115115#ifdef USE_GENMAN_f2
    116         geno_fx_list.push_back(new Geno_f2);
     116        oper_fx_list.push_back(new Geno_f2);
    117117#endif
    118118#ifdef USE_GENMAN_f3
    119         geno_fx_list.push_back(new Geno_f3);
     119        oper_fx_list.push_back(new Geno_f3);
    120120#endif
    121121#ifdef USE_GENMAN_f4
    122         geno_fx_list.push_back(new Geno_f4);
     122        oper_fx_list.push_back(new Geno_f4);
    123123#endif
    124124#ifdef USE_GENMAN_f5
    125         geno_fx_list.push_back(new Geno_f5);
     125        oper_fx_list.push_back(new Geno_f5);
    126126#endif
    127127#ifdef USE_GENMAN_f6
    128         geno_fx_list.push_back(new Geno_f6);
     128        oper_fx_list.push_back(new Geno_f6);
    129129#endif
    130130#ifdef USE_GENMAN_f7
    131         geno_fx_list.push_back(new Geno_f7);
     131        oper_fx_list.push_back(new Geno_f7);
    132132#endif
    133133#ifdef USE_GENMAN_f8
    134         geno_fx_list.push_back(new Geno_f8);
     134        oper_fx_list.push_back(new Geno_f8);
    135135#endif
    136136#ifdef USE_GENMAN_f9
    137         geno_fx_list.push_back(new GenoOper_f9);
     137        oper_fx_list.push_back(new GenoOper_f9);
    138138#endif
    139139#ifdef USE_GENMAN_fF
    140         geno_fx_list.push_back(new GenoOper_fF);
    141 #endif
    142 
    143         seloper = new int[geno_fx_list.size()]; //may result in a little overhead if some of the operators on the geno_fx_list concern the same genetic format
     140        oper_fx_list.push_back(new GenoOper_fF);
     141#endif
     142
     143        seloper = new int[oper_fx_list.size()]; //may result in a little overhead if some of the operators on the oper_fx_list concern the same genetic format
    144144        int selopercount = 0;
    145         for (unsigned int i = 0; i < geno_fx_list.size(); i++)
    146         {
    147                 if (operformats.find(geno_fx_list[i]->supported_format) != -1) continue;
     145        for (unsigned int i = 0; i < oper_fx_list.size(); i++)
     146        {
     147                if (operformats.find(oper_fx_list[i]->supported_format) != -1) continue;
    148148                char tmp[10];
    149149                SString id, name, type = "~";
    150                 type += geno_fx_list[i]->name;
     150                type += oper_fx_list[i]->name;
    151151                int dup = 0;
    152                 for (unsigned int j = i + 1; j < geno_fx_list.size(); j++)
    153                         if (geno_fx_list[i]->supported_format == geno_fx_list[j]->supported_format)
     152                for (unsigned int j = i + 1; j < oper_fx_list.size(); j++)
     153                        if (oper_fx_list[i]->supported_format == oper_fx_list[j]->supported_format)
    154154                        {
    155                                 type += "~"; type += geno_fx_list[j]->name; dup++;
     155                                type += "~"; type += oper_fx_list[j]->name; dup++;
    156156                        }
    157157                sprintf(tmp, "d 0 %d ", dup);
    158158                type = SString(tmp) + type;
    159                 sprintf(tmp, "%c", geno_fx_list[i]->supported_format);
     159                sprintf(tmp, "%c", oper_fx_list[i]->supported_format);
    160160                id = "genoper_f"; id += tmp;
    161161                name = "Operators for f"; name += tmp;
    162162                seloper[selopercount] = 0;
    163                 operformats += geno_fx_list[i]->supported_format;
     163                operformats += oper_fx_list[i]->supported_format;
    164164                //printf("%x %s %s %s\n",&seloper[selopercount],(const char*)id,(const char*)type,(const char*)name);
    165165                seloperpar.addProperty(&seloper[selopercount++], id, type, name, "", PARAM_READONLY*(dup == 0));
     
    169169        par += &seloperpar;
    170170        par += &neuronsparam;
    171         for (unsigned int i = 0; i < geno_fx_list.size(); i++)
    172                 if (geno_fx_list[i]->par.getParamTab()) par += &geno_fx_list[i]->par;
     171        for (unsigned int i = 0; i < oper_fx_list.size(); i++)
     172                if (oper_fx_list[i]->par.getParamTab()) par += &oper_fx_list[i]->par;
    173173}
    174174
    175175GenMan::~GenMan()
    176176{
    177         for (unsigned int i = 0; i < geno_fx_list.size(); i++) delete geno_fx_list[i];
     177        for (unsigned int i = 0; i < oper_fx_list.size(); i++) delete oper_fx_list[i];
    178178        delete[] seloper;
    179179}
     
    181181void GenMan::setDefaults()
    182182{
    183         for (unsigned int i = 0; i < geno_fx_list.size(); i++)
    184         {
    185                 geno_fx_list[i]->par.setDefault();
    186                 geno_fx_list[i]->setDefaults();
     183        for (unsigned int i = 0; i < oper_fx_list.size(); i++)
     184        {
     185                oper_fx_list[i]->par.setDefault();
     186                oper_fx_list[i]->setDefaults();
    187187        }
    188188        localpar.setDefault();
     
    194194{
    195195        const char *gg = g.getGene();
    196         GenoOperators *gf = getGeno_f(g.getFormat());
     196        GenoOperators *gf = getOper_f(g.getFormat());
    197197        int check1;
    198198        if (!gf) { canvalidate = false; return GENOPER_NOOPER; }
     
    228228{
    229229        char format=geny.getFormat();
    230         GenoOperators *gf=getGeno_f(format);
     230        GenoOperators *gf=getOper_f(format);
    231231        if (gf==NULL)
    232232                return Geno(SString::empty(),-1,SString::empty(),SString::sprintf("GENOPER_NOOPER: Validate(): don't know how to handle genetic format %c",format));
     
    246246        int method; //mutation method
    247247        char format=g.getFormat();
    248         GenoOperators *gf=getGeno_f(format);
     248        GenoOperators *gf=getOper_f(format);
    249249        if (gf==NULL)
    250250                return Geno(SString::empty(),-1,SString::empty(),SString::sprintf("GENOPER_NOOPER: Mutate(): don't know how to handle genetic format %c",format));
     
    292292        char format = g1.getFormat();
    293293        if (format != g2.getFormat()) return Geno(SString::empty(), -1, SString::empty(), SString::sprintf("GENOPER_NOOPER: CrossOver() does not know how to handle parents with differing genetic formats (%c and %c)", format, g2.getFormat()));
    294         GenoOperators *gf = getGeno_f(format);
     294        GenoOperators *gf = getOper_f(format);
    295295        if (gf == NULL)
    296296                return Geno(SString::empty(), -1, SString::empty(), SString::sprintf("GENOPER_NOOPER: CrossOver(): don't know how to handle genetic format %c", format));
     
    358358        char format = g1.getFormat();
    359359        if (format != g2.getFormat()) return GENOPER_NOOPER;
    360         GenoOperators *gf = getGeno_f(format);
     360        GenoOperators *gf = getOper_f(format);
    361361        if (!gf) return GENOPER_NOOPER; else return gf->similarity(g1.getGene(), g2.getGene());
    362362}
     
    366366        Geno G(g);
    367367        if ((pos = G.mapStringToGen(pos)) == -1) return GENSTYLE_COMMENT;
    368         GenoOperators *gf = getGeno_f(G.getFormat());
     368        GenoOperators *gf = getOper_f(G.getFormat());
    369369        if (!gf) return GENSTYLE_CS(0, 0); //black & valid
    370370        else return gf->style(G.getGene(), pos);
     
    374374{
    375375        Geno G(g);
    376         GenoOperators *gf = getGeno_f(G.getFormat());
     376        GenoOperators *gf = getOper_f(G.getFormat());
    377377        SString geny = G.getGene();
    378378        for (unsigned int pos = 0; pos < strlen(g); pos++)
     
    448448Geno GenMan::GetSimplest(char format)
    449449{
    450         GenoOperators *gf = getGeno_f(format);
     450        GenoOperators *gf = getOper_f(format);
    451451        if (!gf) return Geno();
    452452        SString info = "The simplest genotype of format f"; info += format;
     
    458458{
    459459        int format = args[0].getInt() + 48;
    460         if (!getGeno_f(format))
     460        if (!getOper_f(format))
    461461                ret->setEmpty();
    462462        else
     
    466466const char *GenMan::GetOpName(char format)
    467467{
    468         GenoOperators *gf = getGeno_f(format);
     468        GenoOperators *gf = getOper_f(format);
    469469        if (!gf) return "n/a"; else return gf->name;
    470470}
    471471
    472 GenoOperators* GenMan::getGeno_f(char format)
     472GenoOperators* GenMan::getOper_f(char format)
    473473{
    474474        int ind = operformats.find(format);
    475475        if (ind == -1) return NULL;
    476476        int ktoryopformatu = seloper[ind];
    477         for (unsigned int i = 0; i < geno_fx_list.size(); i++)
    478                 if (geno_fx_list[i]->supported_format == format)
    479                         if (ktoryopformatu == 0) return geno_fx_list[i]; else ktoryopformatu--;
     477        for (unsigned int i = 0; i < oper_fx_list.size(); i++)
     478                if (oper_fx_list[i]->supported_format == format)
     479                        if (ktoryopformatu == 0) return oper_fx_list[i]; else ktoryopformatu--;
    480480        return NULL; //should never happen
    481481}
     
    519519{                      //should be updated to handle multiple operators for a single format
    520520        char *g, *g2;
    521         float f; int m;
     521        float f1, f2;
     522        int m;
    522523        FramMessage("GenMan", "Report", "The following genetic operators are available:", 0);
    523         for (unsigned int i = 0; i < geno_fx_list.size(); i++)
     524        for (unsigned int i = 0; i < oper_fx_list.size(); i++)
    524525        {
    525526                SString l;
    526                 if (geno_fx_list[i]->checkValidity("") != GENOPER_NOOPER) l += " checkValidity";
    527                 if (geno_fx_list[i]->getSimplest())
    528                 {
    529                         g = strdup(geno_fx_list[i]->getSimplest());
     527                if (oper_fx_list[i]->checkValidity("") != GENOPER_NOOPER) l += " checkValidity";
     528                if (oper_fx_list[i]->getSimplest())
     529                {
     530                        g = strdup(oper_fx_list[i]->getSimplest());
    530531                        g2 = strdup(g);
    531                         if (geno_fx_list[i]->validate(g) != GENOPER_NOOPER) l += " validate";
    532                         if (geno_fx_list[i]->mutate(g, f, m) != GENOPER_NOOPER) l += " mutate";
    533                         if (geno_fx_list[i]->crossOver(g, g2, f, f) != GENOPER_NOOPER) l += " crossover";
     532                        if (oper_fx_list[i]->validate(g) != GENOPER_NOOPER) l += " validate";
     533                        if (oper_fx_list[i]->mutate(g, f1, m) != GENOPER_NOOPER) l += " mutate";
     534                        if (oper_fx_list[i]->crossOver(g, g2, f1, f2) != GENOPER_NOOPER) l += " crossover";
    534535                        l += " getSimplest";
    535536                        free(g); free(g2);
    536537                }
    537                 //      if (geno_fx_list[i]->similarity("","")!=GENOPER_NOOPER) l+=" similarity";
     538                //      if (oper_fx_list[i]->similarity("","")!=GENOPER_NOOPER) l+=" similarity";
    538539                FMprintf("GenMan", "Report", 0, "format f%c (%s):%s",
    539                         geno_fx_list[i]->supported_format, (const char*)geno_fx_list[i]->name, (const char*)l);
     540                        oper_fx_list[i]->supported_format, (const char*)oper_fx_list[i]->name, (const char*)l);
    540541        }
    541542}
Note: See TracChangeset for help on using the changeset viewer.