Changeset 532
- Timestamp:
- 07/19/16 18:11:24 (8 years ago)
- Location:
- cpp/frams
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/_demos/genooper_test.cpp
r391 r532 32 32 char format = gsrc.getFormat(); 33 33 34 Geno gmut = genetics.genman. Mutate(gsrc);34 Geno gmut = genetics.genman.mutate(gsrc); 35 35 printGenAndTitle(gmut, "mutated (gmut)"); 36 36 37 Geno gxover = genetics.genman. CrossOver(gsrc, gmut);37 Geno gxover = genetics.genman.crossOver(gsrc, gmut); 38 38 printGenAndTitle(gxover, "crossed over (gsrc and gmut)"); 39 39 40 Geno gsimplest = genetics.genman. GetSimplest(format);40 Geno gsimplest = genetics.genman.getSimplest(format); 41 41 printGenAndTitle(gsimplest, "simplest"); 42 42 … … 44 44 printGenAndTitle(ginvalid, "invalid"); 45 45 46 Geno gvalidated = genetics.genman. Validate(ginvalid);46 Geno gvalidated = genetics.genman.validate(ginvalid); 47 47 printGenAndTitle(gvalidated, "validated"); 48 48 -
cpp/frams/genetics/genman.cpp
r516 r532 210 210 if (check1 == GENOPER_NOOPER) //disaster: cannot check because there is no check operator 211 211 { 212 g.setGene (g2); free(g2); canvalidate = false; return GENOPER_NOOPER;212 g.setGeneOnly(g2); free(g2); canvalidate = false; return GENOPER_NOOPER; 213 213 } 214 214 int check2 = gf->checkValidity(g2, "validated"); 215 if (check2 == GENOPER_OK) g.setGene (g2);215 if (check2 == GENOPER_OK) g.setGeneOnly(g2); 216 216 free(g2); 217 217 if (check2 == GENOPER_OK) return check1; … … 231 231 } 232 232 233 Geno GenMan:: Validate(const Geno& geny)233 Geno GenMan::validate(const Geno& geny) 234 234 { 235 235 char format = geny.getFormat(); … … 247 247 } 248 248 249 Geno GenMan:: Mutate(const Geno& g)249 Geno GenMan::mutate(const Geno& g) 250 250 { 251 251 float chg; //how many changes … … 298 298 } 299 299 300 Geno GenMan:: CrossOver(const Geno& g1, const Geno& g2)300 Geno GenMan::crossOver(const Geno& g1, const Geno& g2) 301 301 { 302 302 char format = g1.getFormat(); … … 364 364 } 365 365 366 float GenMan:: Similarity(const Geno& g1, const Geno& g2)366 float GenMan::similarity(const Geno& g1, const Geno& g2) 367 367 { 368 368 char format = g1.getFormat(); … … 372 372 } 373 373 374 uint32_t GenMan::Style(const char *g, int pos) 374 uint32_t GenMan::getStyle(const char *g, const Geno *G, int pos) 375 { 376 char format = G->getFormat(); 377 if (format == Geno::INVALID_FORMAT) 378 return GENSTYLE_RGBS(64, 64, 64, 0); // gray & "valid" (unknown format so we don't know what is valid and what is not) 379 if ((pos = G->mapStringToGen(pos)) == -1) return GENSTYLE_COMMENT; 380 GenoOperators *gf = getOper_f(format); 381 if (!gf) return GENSTYLE_CS(0, 0); //black & valid 382 else return gf->style(G->getGene().c_str(), pos); 383 } 384 385 uint32_t GenMan::getStyle(const char *g, int pos) 375 386 { 376 387 Geno G(g); 377 if ((pos = G.mapStringToGen(pos)) == -1) return GENSTYLE_COMMENT; 378 GenoOperators *gf = getOper_f(G.getFormat()); 379 if (!gf) return GENSTYLE_CS(0, 0); //black & valid 380 else return gf->style(G.getGene().c_str(), pos); 381 } 382 383 void GenMan::GetFullStyle(const char *g, uint32_t *styletab) 384 { 385 Geno G(g); 386 GenoOperators *gf = getOper_f(G.getFormat()); 387 SString geny = G.getGene(); 388 return getStyle(g, &G, pos); 389 } 390 391 void GenMan::getFullStyle(const char *g, const Geno *G, uint32_t *styletab) 392 { 393 char format = G->getFormat(); 394 if (format == Geno::INVALID_FORMAT) 395 { 396 for (unsigned int pos = 0; pos < strlen(g); pos++) 397 styletab[pos] = GENSTYLE_RGBS(64, 64, 64, 0); // gray & "valid" (unknown format so we don't know what is valid and what is not) 398 return; 399 } 400 GenoOperators *gf = getOper_f(format); 401 SString geny=G->getGene(); 388 402 for (unsigned int pos = 0; pos < strlen(g); pos++) 389 403 { 390 int posmapped = G .mapStringToGen(pos);404 int posmapped = G->mapStringToGen(pos); 391 405 if (posmapped == -1) styletab[pos] = GENSTYLE_COMMENT; 392 406 else if (!gf) styletab[pos] = GENSTYLE_CS(0, 0); //black & valid 393 407 else styletab[pos] = gf->style(geny.c_str(), posmapped); 394 } 408 //logPrintf("GenMan", "getFullStyle", 0, "%d char='%c' (%d) format=0x%08x", pos, g[pos], g[pos], styletab[pos]); 409 } 410 } 411 412 void GenMan::getFullStyle(const char *g, uint32_t *styletab) 413 { 414 Geno G(g); 415 getFullStyle(g, &G, styletab); 395 416 } 396 417 … … 406 427 bool shortened = false; 407 428 uint32_t *styletab = new uint32_t[len]; 408 GetFullStyle(g, styletab);429 getFullStyle(g, styletab); 409 430 string html = "\n<div style=\"background:white;padding:0.2em;font-family:arial,helvetica,sans-serif;font-size:90%\">"; 410 431 uint32_t prevstyle, prevcolor, style = 0, color = 0; … … 456 477 } 457 478 458 Geno GenMan:: GetSimplest(char format)479 Geno GenMan::getSimplest(char format) 459 480 { 460 481 GenoOperators *gf = getOper_f(format); … … 471 492 ret->setEmpty(); 472 493 else 473 *ret = GenoObj::makeDynamicObjectAndDecRef(new Geno( GetSimplest(format)));474 } 475 476 const char *GenMan:: GetOpName(char format)494 *ret = GenoObj::makeDynamicObjectAndDecRef(new Geno(getSimplest(format))); 495 } 496 497 const char *GenMan::getOpName(char format) 477 498 { 478 499 GenoOperators *gf = getOper_f(format); … … 560 581 ret->setEmpty(); 561 582 else 562 *ret = GenoObj::makeDynamicObjectAndDecRef(new Geno( Validate(*g)));583 *ret = GenoObj::makeDynamicObjectAndDecRef(new Geno(validate(*g))); 563 584 } 564 585 … … 569 590 ret->setEmpty(); 570 591 else 571 *ret = GenoObj::makeDynamicObjectAndDecRef(new Geno( Mutate(*g)));592 *ret = GenoObj::makeDynamicObjectAndDecRef(new Geno(mutate(*g))); 572 593 } 573 594 … … 579 600 ret->setEmpty(); 580 601 else 581 *ret = GenoObj::makeDynamicObjectAndDecRef(new Geno(CrossOver(*g1, *g2))); 582 } 602 *ret = GenoObj::makeDynamicObjectAndDecRef(new Geno(crossOver(*g1, *g2))); 603 } 604 -
cpp/frams/genetics/genman.h
r467 r532 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-201 5Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2016 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 42 42 int testValidity(Geno &g, bool &canvalidate); 43 43 int testGenoValidity(Geno& g); //class GenoValidator (geno.h) 44 Geno Validate(const Geno&); ///<returns validated (if possible) genotype 45 Geno Mutate(const Geno&); //returns mutated genotype or empty if errors 46 Geno CrossOver(const Geno&, const Geno&); //returns xover genotype ("child") or empty if errors 47 float Similarity(const Geno&, const Geno&); //returns GENOPER_NOOPER or normalized similarity (1: identical, 0: different) 48 uint32_t Style(const char* g, int pos); //returns Style (and validity) of a genotype char. 49 void GetFullStyle(const char *g, uint32_t *styletab); //optimized. Fills styletab with styles for all genotype chars. sizeof(*styletab) must be at least strlen(g). 44 Geno validate(const Geno&); ///<returns validated (if possible) genotype 45 Geno mutate(const Geno&); //returns mutated genotype or empty if errors 46 Geno crossOver(const Geno&, const Geno&); //returns xover genotype ("child") or empty if errors 47 float similarity(const Geno&, const Geno&); //returns GENOPER_NOOPER or normalized similarity (1: identical, 0: different) 48 uint32_t getStyle(const char* g, int pos); //returns style (and validity) of a genotype char. 49 uint32_t getStyle(const char *g, const Geno *G, int pos); //returns style (and validity) of a genotype char. Assumes G is created from g. 50 void getFullStyle(const char *g, uint32_t *styletab); //optimized. Fills styletab with styles for all genotype chars. sizeof(*styletab) must be at least strlen(g). 51 void getFullStyle(const char *g, const Geno *G, uint32_t *styletab); //optimized. Assumes G is created from g. Fills styletab with styles for all genotype chars. sizeof(*styletab) must be at least strlen(g). 50 52 string HTMLize(const char *g); //returns colored genotype in HTML. 51 53 string HTMLizeShort(const char *g); //returns colored genotype (abbreviated if needed) in HTML. 52 Geno GetSimplest(char format); ///<returns pointer to the simplest genotype of \e format or empty Geno()53 const char * GetOpName(char format); ///<returns pointer to the active operator set for \e format54 Geno getSimplest(char format); ///<returns pointer to the simplest genotype of \e format or empty Geno() 55 const char *getOpName(char format); ///<returns pointer to the active operator set for \e format 54 56 const vector<GenoOperators*>& GetOperators() const { return oper_fx_list; } ///<returns the list of available genetic operators 55 57 private:
Note: See TracChangeset
for help on using the changeset viewer.