Changeset 6 for cpp/f8-to-f1


Ignore:
Timestamp:
05/15/09 22:08:41 (15 years ago)
Author:
mwajcht
Message:

added some static structures; CHANGE_CONDITION_SIGN mutation now changes relation to the random one, not just the opposite

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

Legend:

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

    r1 r6  
    1919
    2020#define GENO_F8_DEBUG 1 //0 - off, 1 - on
     21
     22#define FIELDSTRUCT Geno_f8
     23
     24static ParamEntry GENO8param_tab[]=
     25{
     26{"Genetics: f8",1,F8_OPERATION_COUNT,},
     27{"f8_mut_chg_begin_arg", 0, 0, "Change beginning argument", "f 0 100 8", FIELD(operation[F8_CHANGE_BEGINNING_ARG]),"mutation: probability of changing a beginning argument", },
     28{"f8_mut_chg_arg", 0, 0, "Change argument", "f 0 100 8", FIELD(operation[F8_CHANGE_ARG]),"mutation: probability of changing a production's argument", },
     29{"f8_mut_del_comm", 0, 0, "Delete command", "f 0 100 8", FIELD(operation[F8_DELETE_COMMAND]),"mutation: probability of deleting a command", },
     30{"f8_mut_insert_comm", 0, 0, "Insert commands", "f 0 100 9", FIELD(operation[F8_INSERT_COMMANDS]),"mutation: probability of inserting commands", },
     31{"f8_mut_enc", 0, 0, "Encapsulate commands", "f 0 100 10",FIELD(operation[F8_ENCAPSULATE]),"mutation: probability of encapsulating commands", },
     32{"f8_mut_chg_cond_sign", 0, 0, "Change condition sign", "f 0 100 8",FIELD(operation[F8_CHANGE_CONDITION_SIGN]),"mutation: probability of changing a condition sign", },
     33{"f8_mut_add_param", 0, 0, "Add parameter", "f 0 100 9", 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", },
     35{"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 8", FIELD(operation[F8_CHANGE_ITERATIONS_NUMBER]),"mutation: probability of changing an iterations number", },
     37{"f8_mut_del_param", 0, 0, "Delete parameter", "f 0 100 8", FIELD(operation[F8_DELETE_PARAMETER]),"mutation: probability of deleting a parameter", },
     38{"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", },
     40{"f8_mut_del_loop", 0, 0, "Delete loop", "f 0 100 0", FIELD(operation[F8_DELETE_LOOP]),"mutation: probability of deleting a loop", },
     41{0,},
     42};
     43
     44#undef FIELDSTRUCT
    2145
    2246ProductionInfo::ProductionInfo(SString name, int paramCount) {
     
    3862        this->simpleCommandLetters.push_back('^');
    3963        this->converter = new GenoConv_F8ToF1();
     64       
     65        par.setParamTab(GENO8param_tab);
     66        par.select(this);
     67        par.setDefault();
     68       
     69        /*mutation_method_names = new char*[F8_OPERATION_COUNT - 1];
     70        int index = 0;
     71        mutation_method_names[index++]="changed beginning argument";
     72        mutation_method_names[index++]="changed argument";
     73        mutation_method_names[index++]="deleted command";
     74        mutation_method_names[index++]="inserted command";
     75        mutation_method_names[index++]="encapsulated command";
     76        mutation_method_names[index++]="changed condition sign";
     77        mutation_method_names[index++]="added parameter";
     78        mutation_method_names[index++]="added condition";
     79        mutation_method_names[index++]="added subproduction";
     80        mutation_method_names[index++]="changed iterations number";
     81        mutation_method_names[index++]="deleted parameter";
     82        mutation_method_names[index++]="deleted condition";
     83        mutation_method_names[index++]="added loop";
     84        mutation_method_names[index++]="deleted loop";
     85        */
    4086       
    4187#ifdef GENO_F8_DEBUG > 0
     
    511557                int random2 = randomN(randomSubproduction->conditions.size());
    512558                Condition *c = &(randomSubproduction->conditions.at(random2));
    513                 c->relation = (c->relation == r_greater) ? r_lessEqual :
    514                                 (c->relation == r_greaterEqual) ? r_less :
    515                                 (c->relation == r_less) ? r_greaterEqual :
    516                                 (c->relation == r_lessEqual) ? r_greater :
    517                                 (c->relation == r_equal) ? r_different :
    518                                 r_equal;
     559                c->relation = this->getDifferentCondition(c->relation);
    519560                chg = 2.0 / (float) in.len();
    520561        }
     
    11571198}
    11581199
     1200RelationType Geno_f8::getDifferentCondition(RelationType type) {
     1201        RelationType types[5];
     1202        int randomType = randomN(5);
     1203        if (type == r_greater) {
     1204                types[0] = r_greaterEqual;
     1205                types[1] = r_equal;
     1206                types[2] = r_different;
     1207                types[3] = r_lessEqual;
     1208                types[4] = r_less;
     1209        } else if (type == r_greaterEqual) {
     1210                types[0] = r_greater;
     1211                types[1] = r_equal;
     1212                types[2] = r_different;
     1213                types[3] = r_lessEqual;
     1214                types[4] = r_less;
     1215        } else if (type == r_equal) {
     1216                types[0] = r_greater;
     1217                types[1] = r_greaterEqual;
     1218                types[2] = r_different;
     1219                types[3] = r_lessEqual;
     1220                types[4] = r_less;
     1221        } else if (type == r_different) {
     1222                types[0] = r_greater;
     1223                types[1] = r_greaterEqual;
     1224                types[2] = r_equal;
     1225                types[3] = r_lessEqual;
     1226                types[4] = r_less;
     1227        } else if (type == r_lessEqual) {
     1228                types[0] = r_greater;
     1229                types[1] = r_greaterEqual;
     1230                types[2] = r_equal;
     1231                types[3] = r_different;
     1232                types[4] = r_less;
     1233        } else if (type == r_less) {
     1234                types[0] = r_greater;
     1235                types[1] = r_greaterEqual;
     1236                types[2] = r_equal;
     1237                types[3] = r_different;
     1238                types[4] = r_lessEqual;
     1239        }
     1240        return types[randomType];
     1241}
     1242
    11591243SString Geno_f8::removeProductionCalls(const SString production) const {
    11601244        SString line = trimSString(production);
  • cpp/f8-to-f1/geno_f8.h

    r1 r6  
    9494        SString addParameterToCalls(const SString line, SString &prodName);
    9595        SString deleteParameterFromCalls(const SString line, SString &prodName, int paramIdx);
     96private:
     97        RelationType getDifferentCondition(RelationType type);
    9698};
    9799
Note: See TracChangeset for help on using the changeset viewer.