1 | // This file is a part of the Framsticks GDK. |
---|
2 | // Copyright (C) 2002-2014 Maciej Komosinski and Szymon Ulatowski. See LICENSE.txt for details. |
---|
3 | // Refer to http://www.framsticks.com/ for further information. |
---|
4 | |
---|
5 | #include <frams/genetics/genman.h> |
---|
6 | #include <frams/errmgr/stdouterr.h> |
---|
7 | |
---|
8 | StdoutErrorHandler err; |
---|
9 | |
---|
10 | void printGen(Geno &g) |
---|
11 | { |
---|
12 | printf("Genotype: %s\nFormat: %c\nValid: %s\nComment: %s\n", |
---|
13 | (const char*)g.getGene(), g.getFormat(), g.isValid() ? "yes" : "no", g.getComment().len() == 0 ? "(empty)" : (const char*)g.getComment()); |
---|
14 | } |
---|
15 | |
---|
16 | void printGenAndTitle(Geno &g, const char* title) |
---|
17 | { |
---|
18 | printf("\n--------------------- %s: ---------------------\n", title); |
---|
19 | printGen(g); |
---|
20 | } |
---|
21 | |
---|
22 | /* Demonstrates various genetic operators applied to a sample genotype. See also oper_fx.cpp. */ |
---|
23 | int main(int argc, char *argv[]) |
---|
24 | { |
---|
25 | GenMan gm; |
---|
26 | gm.p_report(NULL, NULL); |
---|
27 | |
---|
28 | const char* src = (argc > 1) ? argv[1] : "/*9*/UUU"; |
---|
29 | Geno gsrc(src, -1, "First"); |
---|
30 | printGenAndTitle(gsrc, "source genotype (gsrc)"); |
---|
31 | |
---|
32 | Geno gmut = gm.Mutate(gsrc); |
---|
33 | printGenAndTitle(gmut, "mutated (gmut)"); |
---|
34 | |
---|
35 | Geno gxover = gm.CrossOver(gsrc, gmut); |
---|
36 | printGenAndTitle(gxover, "crossed over (gsrc and gmut)"); |
---|
37 | |
---|
38 | Geno gsimplest = gm.GetSimplest('9'); |
---|
39 | printGenAndTitle(gsimplest, "simplest"); |
---|
40 | |
---|
41 | Geno ginvalid("IT'S REALLY WRONG", '9'); |
---|
42 | printGenAndTitle(ginvalid, "invalid"); |
---|
43 | |
---|
44 | Geno gvalidated = gm.Validate(ginvalid); |
---|
45 | printGenAndTitle(gvalidated, "validated"); |
---|
46 | |
---|
47 | printf("\nHTMLized: %s\n", (const char*)gm.HTMLize((const char*)gvalidated.getGene())); |
---|
48 | |
---|
49 | return 0; |
---|
50 | } |
---|