source: cpp/frams/_demos/genooper_test.cpp @ 138

Last change on this file since 138 was 138, checked in by sz, 6 years ago

genetic operator example - frams/_demos/genooper_test.cpp

  • Property svn:eol-style set to native
File size: 1.5 KB
Line 
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
8StdoutErrorHandler err;
9
10void 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
16void 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. */
23int 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*/RRR";
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 fixed = gm.Validate(ginvalid);
45        printGenAndTitle(fixed, "validated");
46
47        printf("\nHTMLized: %s\n", (const char*)gm.HTMLize((const char*)fixed.getGene()));
48
49        return 0;
50}
Note: See TracBrowser for help on using the repository browser.