[286] | 1 | // This file is a part of Framsticks SDK. http://www.framsticks.com/ |
---|
| 2 | // Copyright (C) 1999-2015 Maciej Komosinski and Szymon Ulatowski. |
---|
| 3 | // See LICENSE.txt for details. |
---|
[138] | 4 | |
---|
[391] | 5 | #include <common/loggers/loggertostdout.h> |
---|
[145] | 6 | #include <frams/genetics/preconfigured.h> |
---|
[138] | 7 | |
---|
| 8 | void printGen(Geno &g) |
---|
| 9 | { |
---|
[955] | 10 | printf("Genotype: %s\nFormat: %s\nValid: %s\nComment: %s\n", |
---|
| 11 | g.getGenes().c_str(), g.getFormat().c_str(), g.isValid() ? "yes" : "no", g.getComment().len() == 0 ? "(empty)" : g.getComment().c_str()); |
---|
[138] | 12 | } |
---|
| 13 | |
---|
| 14 | void printGenAndTitle(Geno &g, const char* title) |
---|
| 15 | { |
---|
| 16 | printf("\n--------------------- %s: ---------------------\n", title); |
---|
| 17 | printGen(g); |
---|
| 18 | } |
---|
| 19 | |
---|
| 20 | /* Demonstrates various genetic operators applied to a sample genotype. See also oper_fx.cpp. */ |
---|
| 21 | int main(int argc, char *argv[]) |
---|
| 22 | { |
---|
[375] | 23 | LoggerToStdout messages_to_stdout(LoggerBase::Enable); |
---|
[145] | 24 | PreconfiguredGenetics genetics; |
---|
[138] | 25 | |
---|
[145] | 26 | rndGetInstance().randomize(); |
---|
| 27 | genetics.genman.p_report(NULL, NULL); |
---|
| 28 | |
---|
[139] | 29 | const char* src = (argc > 1) ? argv[1] : "/*9*/UUU"; |
---|
[138] | 30 | Geno gsrc(src, -1, "First"); |
---|
| 31 | printGenAndTitle(gsrc, "source genotype (gsrc)"); |
---|
[955] | 32 | SString format = gsrc.getFormat(); |
---|
[138] | 33 | |
---|
[532] | 34 | Geno gmut = genetics.genman.mutate(gsrc); |
---|
[138] | 35 | printGenAndTitle(gmut, "mutated (gmut)"); |
---|
| 36 | |
---|
[532] | 37 | Geno gxover = genetics.genman.crossOver(gsrc, gmut); |
---|
[138] | 38 | printGenAndTitle(gxover, "crossed over (gsrc and gmut)"); |
---|
| 39 | |
---|
[532] | 40 | Geno gsimplest = genetics.genman.getSimplest(format); |
---|
[138] | 41 | printGenAndTitle(gsimplest, "simplest"); |
---|
| 42 | |
---|
[955] | 43 | Geno ginvalid("IT'S REALLY WRONG", format.c_str()); |
---|
[138] | 44 | printGenAndTitle(ginvalid, "invalid"); |
---|
| 45 | |
---|
[532] | 46 | Geno gvalidated = genetics.genman.validate(ginvalid); |
---|
[139] | 47 | printGenAndTitle(gvalidated, "validated"); |
---|
[138] | 48 | |
---|
[534] | 49 | printf("\nHTMLized: %s\n", genetics.genman.HTMLize(gvalidated.getGenes().c_str()).c_str()); |
---|
[138] | 50 | |
---|
| 51 | return 0; |
---|
| 52 | } |
---|