Changeset 33 for cpp


Ignore:
Timestamp:
10/31/09 00:47:01 (14 years ago)
Author:
Maciej Komosinski
Message:

maximal f1 genotype length published as the f8->f1 converter parameter

Location:
cpp/f8-to-f1
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • cpp/f8-to-f1/conv_f8tof1.cpp

    r32 r33  
    172172        }
    173173        if (neurons) {
    174                 for (vector<NeuronProduction*>::iterator iter = this->neuronProductions.begin(); 
     174                for (vector<NeuronProduction*>::iterator iter = this->neuronProductions.begin();
    175175                         iter != this->neuronProductions.end(); iter++) {
    176176                        actions.push_back(*iter);
     
    283283        string sname = sstringToString(name);
    284284        if (position == -1) {
    285                 this->parameters.push_back(sname); 
     285                this->parameters.push_back(sname);
    286286                this->paramValues[sname] = value;
    287287        } else {
     
    516516}
    517517
     518
     519
     520
     521
     522
     523
     524
     525
     526#define FIELDSTRUCT GenoConv_F8ToF1
     527
     528static ParamEntry GENOCONVf8param_tab[]=
     529{
     530{"Genetics: f8: limits",1,1,},
     531{"f8conv_maxlen", 0, 0, "Maximal genotype length", "d 10 10000 500", FIELD(maxF1Length),"Maximal length of the resulting f1 genotype, in characters. If the f8 L-system produces longer f1 genotype, it will be considered incorrect.", },
     532{0,},
     533};
     534
     535#undef FIELDSTRUCT
     536
     537GenoConv_F8ToF1::GenoConv_F8ToF1()
     538{
     539        name = "f8 converter";
     540        in_format = '8';
     541        out_format = '1';
     542        mapsupport = 0;
     543        info = "Generative encoding";
     544        maxF1Length = 500;
     545        par.setParamTab(GENOCONVf8param_tab);
     546        par.select(this);
     547        par.setDefault();
     548}
     549
     550
    518551vector<SString> GenoConv_F8ToF1::readProductionNames(const SString &in) {
    519552        vector<SString> names;
     
    764797}
    765798#undef CONV_DEBUG
     799
  • cpp/f8-to-f1/conv_f8tof1.h

    r26 r33  
    217217        map<string, PrimitiveProduction*> primitiveProductions;
    218218        map<string, ParamProduction*> paramProductions;
    219        
     219
    220220        void removeEmptySubproductionsAndProductions();
    221221};
     222
     223
     224
     225
    222226
    223227/// Converter between f8 and f1 format
    224228class GenoConv_F8ToF1 : public GenoConverter {
    225229public:
    226         /// Default constructor
    227         GenoConv_F8ToF1() {
    228                 name = "f8 to f1 converter";
    229                 in_format = '8';
    230                 out_format = '1';
    231                 mapsupport = 0;
    232                 info = "ble";
    233                 maxF1Length = 500;
    234         }
    235        
    236         /// Constructor with parameter
    237         /// @param f1LengthLimit If resulting f1 genotype is longer than f1LengthLimit, converter aborts its job
    238         GenoConv_F8ToF1(int f1LengthLimit) {
    239                 name = "f8 to f1 converter";
    240                 in_format = '8';
    241                 out_format = '1';
    242                 mapsupport = 0;
    243                 info = "ble";
    244                 maxF1Length = f1LengthLimit;
    245         }
    246        
     230        Param par;
     231
     232        GenoConv_F8ToF1();
    247233        ~GenoConv_F8ToF1() {}
    248        
     234
    249235        SString convert(SString &in, MultiMap *map);
    250        
     236
    251237        /// check syntax of given f8 genotype
    252238        /// @param geno f8 genotype to be checked
    253239        bool checkSyntax(const char *geno);
    254        
     240
    255241        /// returns names of productions in a given genotype
    256242        /// @param in f8 genotype
    257243        vector<SString> readProductionNames(const SString &in);
    258244        //Lsystem* createLsystem(const SString &in);
    259        
     245
    260246        /// creates Lsystem object based on input genotype
    261247        /// @param f8 genotype
    262248        Lsystem* createLsystem(SString in);
     249
     250        int maxF1Length;
    263251protected:
    264252        bool parseInput(const char* src, Lsystem* lsys);
    265         int maxF1Length;
    266253};
    267254
  • cpp/f8-to-f1/geno_f8.cpp

    r30 r33  
    3232{"f8_mut_chg_cond_sign", 0, 0, "Change condition sign", "f 0 100 7",FIELD(operation[F8_CHANGE_CONDITION_SIGN]),"mutation: probability of changing a condition sign", },
    3333{"f8_mut_add_param", 0, 0, "Add parameter", "f 0 100 8", FIELD(operation[F8_ADD_PARAMETER]),"mutation: probability of adding a parameter to the production", },
    34 {"f8_mut_add_cond", 0, 0, "Add condition", "f 0 100 8", FIELD(operation[F8_ADD_CONDITION]),"mutation: probability of ading a condition to the subproduction", },
     34{"f8_mut_add_cond", 0, 0, "Add condition", "f 0 100 8", FIELD(operation[F8_ADD_CONDITION]),"mutation: probability of adding a condition to the subproduction", },
    3535{"f8_mut_add_subprod", 0, 0, "Add subproduction", "f 0 100 8", FIELD(operation[F8_ADD_SUBPRODUCTION]),"mutation: probability of adding a subproduction", },
    36 {"f8_mut_chg_iter_number", 0, 0, "Change iteration number", "f 0 100 7", FIELD(operation[F8_CHANGE_ITERATIONS_NUMBER]),"mutation: probability of changing an iterations number", },
     36{"f8_mut_chg_iter_number", 0, 0, "Change iteration number", "f 0 100 7", FIELD(operation[F8_CHANGE_ITERATIONS_NUMBER]),"mutation: probability of changing a number of iterations", },
    3737{"f8_mut_del_param", 0, 0, "Delete parameter", "f 0 100 8", FIELD(operation[F8_DELETE_PARAMETER]),"mutation: probability of deleting a parameter", },
    3838{"f8_mut_del_cond", 0, 0, "Delete condition", "f 0 100 8", FIELD(operation[F8_DELETE_CONDITION]),"mutation: probability of deleting a condition", },
    39 {"f8_mut_add_loop", 0, 0, "Add loop", "f 0 100 0", FIELD(operation[F8_ADD_LOOP]),"mutation: probability of ading a loop", },
     39{"f8_mut_add_loop", 0, 0, "Add loop", "f 0 100 0", FIELD(operation[F8_ADD_LOOP]),"mutation: probability of adding a loop", },
    4040{"f8_mut_del_loop", 0, 0, "Delete loop", "f 0 100 0", FIELD(operation[F8_DELETE_LOOP]),"mutation: probability of deleting a loop", },
    4141{"f8_mut_del_prod", 0, 0, "Delete production", "f 0 100 8", FIELD(operation[F8_DELETE_PRODUCTION]),"mutation: probability of deleting a production", },
     
    6363        this->simpleCommandLetters.push_back('^');
    6464        this->converter = new GenoConv_F8ToF1();
    65        
     65
    6666        par.setParamTab(GENO8param_tab);
    6767        par.select(this);
    6868        par.setDefault();
    69        
    70         /*mutation_method_names = new char*[F8_OPERATION_COUNT - 1];
     69
     70        /*mutation_method_names = new char*[F8_OPERATION_COUNT - 1]; //FIXME
    7171        int index = 0;
    7272        mutation_method_names[index++]="changed beginning argument";
     
    511511                                newActions.push_back(subproduction->actions[i]);
    512512                        }
    513                         for (i = firstActionIdx; i <= firstActionIdx + randomN(4) + 1 
     513                        for (i = firstActionIdx; i <= firstActionIdx + randomN(4) + 1
    514514                                 && i < subproduction->actions.size(); i++) { //1..4 actions
    515515                                newSubProd->actions.push_back(subproduction->actions[i]);
     
    551551       
    552552        delete lsystem;
    553        
     553
    554554        chg = (float) len / (float) in.len();
    555555        return mutated;
     
    569569                mutated += in;
    570570                chg = 0.0;
     571                delete lsystem;
    571572                return mutated;
    572573        }
    573        
    574         int counter = 0;
     574
    575575        vector<SString> productionNamesSS = this->converter->readProductionNames(in);
    576576        vector<string> productionNames;
     
    601601        //choose production to which we will append the contents of deleted production
    602602        string prodNameToAppendTo = productionNames[randomN(productionNames.size())];
    603        
     603
    604604        int len = 0;
    605        
     605
    606606        Production* deletedProd = lsystem->productions[prodNameToDelete];
    607607        Production* appendProd = lsystem->productions[prodNameToAppendTo];
     
    613613                }
    614614        }
    615        
     615
    616616        //copy subproductions
    617617        for (vector<SubProduction>::iterator subprodIter = deletedProd->subproductions.begin();
     
    639639        }
    640640        lsystem->productions.erase(string(prodNameToDelete));
    641        
     641
    642642        int paramCount = appendProd->parameters.size();
    643643        for (map<string, Production*>::iterator prodIter = lsystem->productions.begin();
     
    647647                        for (vector<ActionStrP>::iterator actionIter = (*subprodIter).actions.begin();
    648648                                 actionIter != (*subprodIter).actions.end(); actionIter++) {
    649                                 if ((*actionIter).action != NULL && (*actionIter).action->name != NULL) { 
     649                                if ((*actionIter).action != NULL && (*actionIter).action->name != NULL) {
    650650                                        if ((*actionIter).action->name == stringToSString(prodNameToDelete)) {
    651651                                                (*actionIter).action = appendProd;
     
    659659                                                }
    660660                                        }
    661                                        
     661
    662662                                }
    663663                        }
     
    665665        }
    666666        delete deletedProd;
    667                
    668        
     667
     668
    669669        mutated = lsystem->toString();
    670        
     670
    671671        delete lsystem;
    672        
     672
    673673        chg = (float) len / (float) in.len();
    674674        return mutated;
     
    677677SString Geno_f8::mutateChangeConditionSign(SString &in, float& chg) {
    678678        SString mutated;
    679        
     679
    680680        Lsystem *newLsystem = this->converter->createLsystem(in);
    681681        if (newLsystem == NULL) {
     
    684684                return mutated;
    685685        }
    686        
     686
    687687        map<int, SubProduction*> interestingSubproductions;
    688688        int counter = 0;
    689        
     689
    690690        for (map<string, Production*>::iterator prodIter = newLsystem->productions.begin();
    691691                 prodIter != newLsystem->productions.end(); prodIter++) {
     
    698698                }
    699699        }
    700        
     700
    701701        if (interestingSubproductions.size() > 0) {
    702702                int random1 = randomN(interestingSubproductions.size());
     
    707707                chg = 2.0 / (float) in.len();
    708708        }
    709        
     709
    710710        mutated = newLsystem->toString();
    711        
     711
    712712        delete newLsystem;
    713        
     713
    714714        return mutated;
    715715}
     
    717717SString Geno_f8::mutateAddParameter(SString &in, float& chg) {
    718718        SString mutated;
    719        
     719
    720720        Lsystem *lsystem = this->converter->createLsystem(in);
    721721        if (lsystem == NULL || lsystem->productions.size() == 0) {
     
    724724                return mutated;
    725725        }
    726        
     726
    727727        //cout << "addParameter 1" << endl;
    728728        int rnd = randomN(lsystem->productions.size());
    729729        int chglen = 0;
    730        
     730
    731731        SString prodName = "";
    732        
     732
    733733        int counter = 0;
    734734        for (map<string, Production*>::iterator prodIter = lsystem->productions.begin();
     
    746746                                }
    747747                        }
    748                        
     748
    749749                        if (prodName == stringToSString(lsystem->firstProductionName)) {
    750750                                lsystem->startParams[sstringToString(newParam)] = 0.0;
     
    10831083        (method == 13) ? "F8_ADD_LOOP" :
    10841084        (method == 14) ? "F8_DELETE_LOOP" :
    1085         (method == 15) ? "F8_OPERATION_COUNT" : "babol";
     1085        (method == 15) ? "F8_OPERATION_COUNT" : "*invalid*";
    10861086        //cout << "-------------------- " << mutationName << " --------------------" << endl;
    10871087#endif
  • cpp/f8-to-f1/geno_f8.h

    r30 r33  
    5252        Geno_f8();
    5353        ~Geno_f8();
    54        
    55         //probabilities of mutation operators
     54
     55        //probabilities of mutation operators
    5656        double operation[F8_OPERATION_COUNT];
    57        
     57
    5858        int checkValidity(const char * geno);
    5959        int validate(char * &geno);
     
    6262        unsigned long style(const char *g, int pos);
    6363        char* getSimplest();
    64        
     64
    6565        SString testMutate(SString &in, int method);
    6666protected:
    6767        GenoConv_F8ToF1 *converter;
    68         static const int maxTotalIterations = 200;
    69         static const int maxNormalIterations = 100;
    7068       
    7169        vector<char> simpleCommandLetters;
Note: See TracChangeset for help on using the changeset viewer.