Changeset 348 for cpp/frams/genetics
- Timestamp:
- 04/09/15 23:51:28 (10 years ago)
- Location:
- cpp/frams/genetics
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/genetics/f1/conv_f1.cpp
r319 r348 102 102 SString GenoConv_f1::convert(SString &i,MultiMap *map) 103 103 { 104 const char* g= (const char*)i;104 const char* g=i.c_str(); 105 105 Builder builder(g,map?1:0); 106 106 builder.model.open(); … … 403 403 lastNeuroClassParam(); 404 404 //special handling: muscle properties (can be overwritten by subsequent property assignments) 405 if (!strcmp(cls->getName() ,"|"))405 if (!strcmp(cls->getName().c_str(),"|")) 406 406 { 407 407 neuro_cls_param->setDoubleById("p",lastjoint_muscle_power); 408 408 neuro_cls_param->setDoubleById("r",props.bendrange); 409 409 } 410 else if (!strcmp(cls->getName() ,"@"))410 else if (!strcmp(cls->getName().c_str(),"@")) 411 411 { 412 412 neuro_cls_param->setDoubleById("p",lastjoint_muscle_power); … … 485 485 SString name(begin,colon-begin); 486 486 SString value(colon+1,end-(colon+1)); 487 addClassParam(name ,value);488 } 489 } 487 addClassParam(name.c_str(),value.c_str()); 488 } 489 } -
cpp/frams/genetics/f4/f4_general.cpp
r287 r348 714 714 // transform geno from string to nodes 715 715 f4rootnode = new f4_node(); 716 res = f4_processrec( (const char*)genome, (unsigned)0, f4rootnode);716 res = f4_processrec(genome.c_str(), (unsigned)0, f4rootnode); 717 717 if ((res < 0) || (1 != f4rootnode->childCount())) 718 718 { … … 1197 1197 buf = (char*)realloc(buf, len + 1); 1198 1198 } 1199 strcpy(buf, (const char*)out);1199 strcpy(buf, out.c_str()); 1200 1200 } 1201 1201 -
cpp/frams/genetics/f9/oper_f9.cpp
r319 r348 42 42 if (strchr(turtle_commands_f9, gene[i])) validated += gene[i]; //validated contains only turtle_commands_f9 43 43 free(gene); 44 gene = strdup(validated ); //reallocate44 gene = strdup(validated.c_str()); //reallocate 45 45 return GENOPER_OK; 46 46 } … … 84 84 } 85 85 free(gene); 86 gene = strdup(newgeno ); //reallocate86 gene = strdup(newgeno.c_str()); //reallocate 87 87 } 88 88 -
cpp/frams/genetics/fF/conv_fF.cpp
r319 r348 39 39 { 40 40 fF_growth_params gp; 41 if (!gp.load(in )) //invalid input genotype?41 if (!gp.load(in.c_str())) //invalid input genotype? 42 42 return ""; //so we return an invalid f0 genotype 43 43 -
cpp/frams/genetics/fF/fF_genotype.h
r286 r348 43 43 SString tmp; 44 44 param.save2(tmp, NULL/*object containing default values for comparison*/, false/*add CR*/, false/*force field names*/); 45 return string( (const char*)tmp);45 return string(tmp.c_str()); 46 46 } 47 47 }; -
cpp/frams/genetics/fT/oper_fTest.cpp
r319 r348 77 77 if (strchr("ATGC", gene[i])) validated += gene[i]; //validated contains only ATGC 78 78 free(gene); 79 gene = strdup(validated ); //reallocate79 gene = strdup(validated.c_str()); //reallocate 80 80 return GENOPER_OK; 81 81 } -
cpp/frams/genetics/genman.cpp
r344 r348 199 199 { 200 200 SString ggs=g.getGene(); 201 const char *gg = ggs ;201 const char *gg = ggs.c_str(); 202 202 GenoOperators *gf = getOper_f(g.getFormat()); 203 203 int check1; … … 237 237 if (gf == NULL) 238 238 return Geno(SString::empty(), -1, SString::empty(), SString::sprintf("GENOPER_NOOPER: Validate(): don't know how to handle genetic format %c", format)); 239 char *g2 = strdup(geny.getGene() ); //copy for validation239 char *g2 = strdup(geny.getGene().c_str()); //copy for validation 240 240 int res = gf->validate(g2); 241 241 SString sg2 = g2; … … 263 263 while (!ok) 264 264 { 265 char *gn = strdup(gv.getGene() ); //copy for mutation265 char *gn = strdup(gv.getGene().c_str()); //copy for mutation 266 266 chg = 0; 267 267 if (gf->mutate(gn, chg, method) == GENOPER_OK) … … 284 284 if (!ok && (count - pcount > 100)) 285 285 { 286 FMprintf("GenMan", "Mutate", 2, "Tried 100x and failed: %s", (const char*)g.getGene());286 FMprintf("GenMan", "Mutate", 2, "Tried 100x and failed: %s", g.getGene().c_str()); 287 287 return Geno("", -1, "", "GENOPER_OPFAIL: Mutate() tried 100x and failed"); 288 288 } 289 289 } 290 290 mutchg += chg; 291 if (history) saveLink( (const char*)g.getGene(), "", (const char*)gv.getGene(), chg);291 if (history) saveLink(g.getGene().c_str(), "", gv.getGene().c_str(), chg); 292 292 SString mutinfo; 293 if (extmutinfo == 0) mutinfo = SString::sprintf("%.2f%% mutation of '%s'", 100 * chg, (const char*)g.getName()); else294 if (extmutinfo == 1) mutinfo = SString::sprintf("%.2f%% mutation(%d) of '%s'", 100 * chg, method, (const char*)g.getName()); else295 mutinfo = SString::sprintf("%.2f%% mutation(%s) of '%s'", 100 * chg, gf->mutation_method_names ? gf->mutation_method_names[method] : "unspecified method name", (const char*)g.getName());293 if (extmutinfo == 0) mutinfo = SString::sprintf("%.2f%% mutation of '%s'", 100 * chg, g.getName().c_str()); else 294 if (extmutinfo == 1) mutinfo = SString::sprintf("%.2f%% mutation(%d) of '%s'", 100 * chg, method, g.getName().c_str()); else 295 mutinfo = SString::sprintf("%.2f%% mutation(%s) of '%s'", 100 * chg, gf->mutation_method_names ? gf->mutation_method_names[method] : "unspecified method name", g.getName().c_str()); 296 296 gv.setComment(mutinfo); 297 297 return gv; … … 324 324 { 325 325 float chg1, chg2; 326 char *g1n = strdup(g1.getGene() ); //copy for crossover327 char *g2n = strdup(g2.getGene() ); //copy for crossover326 char *g1n = strdup(g1.getGene().c_str()); //copy for crossover 327 char *g2n = strdup(g2.getGene().c_str()); //copy for crossover 328 328 chg1 = chg2 = 0; 329 329 if (gf->crossOver(g1n, g2n, chg1, chg2) == GENOPER_OK) … … 351 351 if (!ok && (count - pcount > 100)) 352 352 { 353 FMprintf("GenMan", "CrossOver", 2, "Tried 100x and failed: %s and %s", (const char*)g1.getGene(), (const char*)g2.getGene());353 FMprintf("GenMan", "CrossOver", 2, "Tried 100x and failed: %s and %s", g1.getGene().c_str(), g2.getGene().c_str()); 354 354 return Geno("", -1, "", "GENOPER_OPFAIL: CrossOver() tried 100x and failed"); 355 355 } … … 357 357 // result in g1v 358 358 xochg += chg; 359 if (history) saveLink( (const char*)g1.getGene(), (const char*)g2.getGene(), (const char*)g1v.getGene(), chg);359 if (history) saveLink(g1.getGene().c_str(), g2.getGene().c_str(), g1v.getGene().c_str(), chg); 360 360 SString xoinfo = SString::sprintf("Crossing over of '%s' (%.2f%%) and '%s' (%.2f%%)", 361 (const char*)g1.getName(), 100 * chg, (const char*)g2.getName(), 100 * (1 - chg));361 g1.getName().c_str(), 100 * chg, g2.getName().c_str(), 100 * (1 - chg)); 362 362 g1v.setComment(xoinfo); 363 363 return g1v; … … 369 369 if (format != g2.getFormat()) return GENOPER_NOOPER; 370 370 GenoOperators *gf = getOper_f(format); 371 if (!gf) return GENOPER_NOOPER; else return gf->similarity(g1.getGene() , g2.getGene());371 if (!gf) return GENOPER_NOOPER; else return gf->similarity(g1.getGene().c_str(), g2.getGene().c_str()); 372 372 } 373 373 … … 378 378 GenoOperators *gf = getOper_f(G.getFormat()); 379 379 if (!gf) return GENSTYLE_CS(0, 0); //black & valid 380 else return gf->style(G.getGene() , pos);380 else return gf->style(G.getGene().c_str(), pos); 381 381 } 382 382 … … 391 391 if (posmapped == -1) styletab[pos] = GENSTYLE_COMMENT; 392 392 else if (!gf) styletab[pos] = GENSTYLE_CS(0, 0); //black & valid 393 else styletab[pos] = gf->style(geny , posmapped);393 else styletab[pos] = gf->style(geny.c_str(), posmapped); 394 394 } 395 395 } … … 448 448 void GenMan::p_htmlize(ExtValue *args, ExtValue *ret) 449 449 { 450 ret->setString(HTMLize(args->getString() ));450 ret->setString(HTMLize(args->getString().c_str())); 451 451 } 452 452 453 453 void GenMan::p_htmlizeshort(ExtValue *args, ExtValue *ret) 454 454 { 455 ret->setString(HTMLizeShort(args->getString() ));455 ret->setString(HTMLizeShort(args->getString().c_str())); 456 456 } 457 457 -
cpp/frams/genetics/geno.cpp
r346 r348 7 7 #include <frams/model/model.h> 8 8 9 GenoConvManager *Geno::converters = NULL; 10 11 THREAD_LOCAL_DEF(Geno::Validators, geno_validators); 12 13 Geno::Validators& Geno::getValidators() {return tlsGetRef(geno_validators);} 9 THREAD_LOCAL_DEF_PTR(Geno::Validators, geno_validators); 10 THREAD_LOCAL_DEF_PTR(GenoConvManager, geno_converters); 11 12 Geno::Validators* Geno::getValidators() {return tlsGetPtr(geno_validators);} 13 GenoConvManager* Geno::getConverters() {return tlsGetPtr(geno_converters);} 14 15 Geno::Validators* Geno::useValidators(Validators* val) 16 {return tlsSetPtr(geno_validators,val);} 17 GenoConvManager* Geno::useConverters(GenoConvManager* gcm) 18 {return tlsSetPtr(geno_converters,gcm);} 14 19 15 20 void Geno::init(const SString& genstring, char genformat, const SString& genname, const SString& comment) … … 78 83 if (!name.len()) name = genname; 79 84 if (!txt.len()) txt = comment; 80 multiline = (strchr( (const char*)gen, '\n') != 0);85 multiline = (strchr(gen.c_str(), '\n') != 0); 81 86 // mapoutshift...? 82 87 } … … 237 242 if (isvalid >= 0) return; 238 243 if (gen.len() == 0) { isvalid = 0; return; } 239 Validators& vals=getValidators(); 240 FOREACH(GenoValidator*, v, vals) 244 Validators* vals=getValidators(); 245 if (vals!=NULL) 246 { 247 FOREACH(GenoValidator*, v, (*vals)) 241 248 if ((isvalid = v->testGenoValidity(*this)) >= 0) 242 249 return; 250 } 243 251 isvalid = 0; 244 252 FMprintf("Geno", "validate", FMLV_WARN, "Wrong configuration? No genotype validators defined for genetic format f%c.", format); … … 255 263 if (otherformat == getFormat()) { if (converter_missing) *converter_missing = false; return *this; } 256 264 #ifndef NO_GENOCONVMANAGER 265 GenoConvManager *converters=getConverters(); 257 266 if (converters) 258 267 { -
cpp/frams/genetics/geno.h
r346 r348 118 118 119 119 // managing global Geno-related objects (used for validation and conversion) 120 static Validators& getValidators(); 121 static void addValidator(GenoValidator* gv,int at_position=9999) { getValidators().insert(at_position,gv); } 122 static void removeValidator(GenoValidator* gv) { getValidators() -= gv; } 123 static void useConverters(GenoConvManager& gcm) { converters = &gcm; } 124 static GenoConvManager &getConverters() { return *converters; } 125 protected: 126 static GenoConvManager *converters; 120 static Validators* useValidators(Validators* val); 121 static Validators* getValidators(); 122 123 static GenoConvManager* useConverters(GenoConvManager* gcm); 124 static GenoConvManager* getConverters(); 127 125 }; 128 126 -
cpp/frams/genetics/oper_fx.cpp
r286 r348 192 192 for (int i = 0; i<Neuro::getClassCount(); i++) 193 193 { 194 const char *n = Neuro::getClass(i)->name ;194 const char *n = Neuro::getClass(i)->name.c_str(); 195 195 int l = (int)strlen(n); 196 196 if (len >= l && l>Len && (strncmp(s, n, l) == 0)) { I = Neuro::getClass(i); Len = l; } -
cpp/frams/genetics/preconfigured.h
r346 r348 18 18 DefaultGenoConvManager gcm; 19 19 GenMan genman; 20 Geno::Validators validators; 20 21 ModelGenoValidator model_validator; //validation through conversion 21 22 … … 23 24 { 24 25 gcm.addDefaultConverters(); //without converters, the application would only handle "format 0" genotypes 25 Geno::useConverters( gcm);26 Geno::useConverters(&gcm); 26 27 27 Geno::addValidator(&genman); //primary validation: use the extended validity checking (through dedicated genetic operators) 28 Geno::addValidator(&model_validator); //secondary validation: this simple validator handles all cases when there is no dedicated genetic validation operator, but a converter for a particular format is available. Converters may be less strict in detecting invalid genotypes but using them and checking whether they produced a valid f0 genotype is also some way to tell whether the initial genotype was valid. Otherwise, without dedicated genetic validation operator, we would have no validity check at all. 29 } 30 }; 31 32 /** Initialization procedure for applications adding their own validators */ 33 class PreconfiguredGenetics_NoValidators 34 { 35 public: 36 DefaultGenoConvManager gcm; 37 38 PreconfiguredGenetics_NoValidators() 39 { 40 gcm.addDefaultConverters(); //without converters, the application would only handle "format 0" genotypes 41 Geno::useConverters(gcm); 28 Geno::useValidators(&validators); 29 validators+=&genman; //primary validation: use the extended validity checking (through dedicated genetic operators) 30 validators+=&model_validator; //secondary validation: this simple validator handles all cases when there is no dedicated genetic validation operator, but a converter for a particular format is available. Converters may be less strict in detecting invalid genotypes but using them and checking whether they produced a valid f0 genotype is also some way to tell whether the initial genotype was valid. Otherwise, without dedicated genetic validation operator, we would have no validity check at all. 42 31 } 43 32 }; 44 33 45 34 #endif 46
Note: See TracChangeset
for help on using the changeset viewer.