Changeset 145 for cpp/frams/genetics/genman.cpp
- Timestamp:
- 02/26/14 20:21:22 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/genetics/genman.cpp
r139 r145 105 105 106 106 #ifdef USE_GENMAN_f0 107 geno_fx_list.push_back(new Geno_f0);107 oper_fx_list.push_back(new Geno_f0); 108 108 #endif 109 109 #ifdef USE_GENMAN_f0FUZZY 110 geno_fx_list.push_back(new Geno_f0Fuzzy);110 oper_fx_list.push_back(new Geno_f0Fuzzy); 111 111 #endif 112 112 #ifdef USE_GENMAN_f1 113 geno_fx_list.push_back(new Geno_f1);113 oper_fx_list.push_back(new Geno_f1); 114 114 #endif 115 115 #ifdef USE_GENMAN_f2 116 geno_fx_list.push_back(new Geno_f2);116 oper_fx_list.push_back(new Geno_f2); 117 117 #endif 118 118 #ifdef USE_GENMAN_f3 119 geno_fx_list.push_back(new Geno_f3);119 oper_fx_list.push_back(new Geno_f3); 120 120 #endif 121 121 #ifdef USE_GENMAN_f4 122 geno_fx_list.push_back(new Geno_f4);122 oper_fx_list.push_back(new Geno_f4); 123 123 #endif 124 124 #ifdef USE_GENMAN_f5 125 geno_fx_list.push_back(new Geno_f5);125 oper_fx_list.push_back(new Geno_f5); 126 126 #endif 127 127 #ifdef USE_GENMAN_f6 128 geno_fx_list.push_back(new Geno_f6);128 oper_fx_list.push_back(new Geno_f6); 129 129 #endif 130 130 #ifdef USE_GENMAN_f7 131 geno_fx_list.push_back(new Geno_f7);131 oper_fx_list.push_back(new Geno_f7); 132 132 #endif 133 133 #ifdef USE_GENMAN_f8 134 geno_fx_list.push_back(new Geno_f8);134 oper_fx_list.push_back(new Geno_f8); 135 135 #endif 136 136 #ifdef USE_GENMAN_f9 137 geno_fx_list.push_back(new GenoOper_f9);137 oper_fx_list.push_back(new GenoOper_f9); 138 138 #endif 139 139 #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 format140 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 144 144 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; 148 148 char tmp[10]; 149 149 SString id, name, type = "~"; 150 type += geno_fx_list[i]->name;150 type += oper_fx_list[i]->name; 151 151 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) 154 154 { 155 type += "~"; type += geno_fx_list[j]->name; dup++;155 type += "~"; type += oper_fx_list[j]->name; dup++; 156 156 } 157 157 sprintf(tmp, "d 0 %d ", dup); 158 158 type = SString(tmp) + type; 159 sprintf(tmp, "%c", geno_fx_list[i]->supported_format);159 sprintf(tmp, "%c", oper_fx_list[i]->supported_format); 160 160 id = "genoper_f"; id += tmp; 161 161 name = "Operators for f"; name += tmp; 162 162 seloper[selopercount] = 0; 163 operformats += geno_fx_list[i]->supported_format;163 operformats += oper_fx_list[i]->supported_format; 164 164 //printf("%x %s %s %s\n",&seloper[selopercount],(const char*)id,(const char*)type,(const char*)name); 165 165 seloperpar.addProperty(&seloper[selopercount++], id, type, name, "", PARAM_READONLY*(dup == 0)); … … 169 169 par += &seloperpar; 170 170 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; 173 173 } 174 174 175 175 GenMan::~GenMan() 176 176 { 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]; 178 178 delete[] seloper; 179 179 } … … 181 181 void GenMan::setDefaults() 182 182 { 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(); 187 187 } 188 188 localpar.setDefault(); … … 194 194 { 195 195 const char *gg = g.getGene(); 196 GenoOperators *gf = get Geno_f(g.getFormat());196 GenoOperators *gf = getOper_f(g.getFormat()); 197 197 int check1; 198 198 if (!gf) { canvalidate = false; return GENOPER_NOOPER; } … … 228 228 { 229 229 char format=geny.getFormat(); 230 GenoOperators *gf=get Geno_f(format);230 GenoOperators *gf=getOper_f(format); 231 231 if (gf==NULL) 232 232 return Geno(SString::empty(),-1,SString::empty(),SString::sprintf("GENOPER_NOOPER: Validate(): don't know how to handle genetic format %c",format)); … … 246 246 int method; //mutation method 247 247 char format=g.getFormat(); 248 GenoOperators *gf=get Geno_f(format);248 GenoOperators *gf=getOper_f(format); 249 249 if (gf==NULL) 250 250 return Geno(SString::empty(),-1,SString::empty(),SString::sprintf("GENOPER_NOOPER: Mutate(): don't know how to handle genetic format %c",format)); … … 292 292 char format = g1.getFormat(); 293 293 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 = get Geno_f(format);294 GenoOperators *gf = getOper_f(format); 295 295 if (gf == NULL) 296 296 return Geno(SString::empty(), -1, SString::empty(), SString::sprintf("GENOPER_NOOPER: CrossOver(): don't know how to handle genetic format %c", format)); … … 358 358 char format = g1.getFormat(); 359 359 if (format != g2.getFormat()) return GENOPER_NOOPER; 360 GenoOperators *gf = get Geno_f(format);360 GenoOperators *gf = getOper_f(format); 361 361 if (!gf) return GENOPER_NOOPER; else return gf->similarity(g1.getGene(), g2.getGene()); 362 362 } … … 366 366 Geno G(g); 367 367 if ((pos = G.mapStringToGen(pos)) == -1) return GENSTYLE_COMMENT; 368 GenoOperators *gf = get Geno_f(G.getFormat());368 GenoOperators *gf = getOper_f(G.getFormat()); 369 369 if (!gf) return GENSTYLE_CS(0, 0); //black & valid 370 370 else return gf->style(G.getGene(), pos); … … 374 374 { 375 375 Geno G(g); 376 GenoOperators *gf = get Geno_f(G.getFormat());376 GenoOperators *gf = getOper_f(G.getFormat()); 377 377 SString geny = G.getGene(); 378 378 for (unsigned int pos = 0; pos < strlen(g); pos++) … … 448 448 Geno GenMan::GetSimplest(char format) 449 449 { 450 GenoOperators *gf = get Geno_f(format);450 GenoOperators *gf = getOper_f(format); 451 451 if (!gf) return Geno(); 452 452 SString info = "The simplest genotype of format f"; info += format; … … 458 458 { 459 459 int format = args[0].getInt() + 48; 460 if (!get Geno_f(format))460 if (!getOper_f(format)) 461 461 ret->setEmpty(); 462 462 else … … 466 466 const char *GenMan::GetOpName(char format) 467 467 { 468 GenoOperators *gf = get Geno_f(format);468 GenoOperators *gf = getOper_f(format); 469 469 if (!gf) return "n/a"; else return gf->name; 470 470 } 471 471 472 GenoOperators* GenMan::get Geno_f(char format)472 GenoOperators* GenMan::getOper_f(char format) 473 473 { 474 474 int ind = operformats.find(format); 475 475 if (ind == -1) return NULL; 476 476 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--; 480 480 return NULL; //should never happen 481 481 } … … 519 519 { //should be updated to handle multiple operators for a single format 520 520 char *g, *g2; 521 float f; int m; 521 float f1, f2; 522 int m; 522 523 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++) 524 525 { 525 526 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()); 530 531 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"; 534 535 l += " getSimplest"; 535 536 free(g); free(g2); 536 537 } 537 // if ( geno_fx_list[i]->similarity("","")!=GENOPER_NOOPER) l+=" similarity";538 // if (oper_fx_list[i]->similarity("","")!=GENOPER_NOOPER) l+=" similarity"; 538 539 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); 540 541 } 541 542 }
Note: See TracChangeset
for help on using the changeset viewer.