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

Last change on this file since 141 was 141, checked in by sz, 8 years ago

Improved genotype validation in geno_test and genooper_test (using GenMan?'s genetic operators)

  • Property svn:eol-style set to native
File size: 2.0 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#include <frams/genetics/defgenoconv.h>
8
9StdoutErrorHandler err;
10DefaultGenoConvManager gcm; //without this object the application would only handle "format 0" genotypes
11
12void printGen(Geno &g)
13{
14        printf("Genotype: %s\nFormat: %c\nValid: %s\nComment: %s\n",
15                (const char*)g.getGene(), g.getFormat(), g.isValid() ? "yes" : "no", g.getComment().len() == 0 ? "(empty)" : (const char*)g.getComment());
16}
17
18void printGenAndTitle(Geno &g, const char* title)
19{
20        printf("\n--------------------- %s: ---------------------\n", title);
21        printGen(g);
22}
23
24/* Demonstrates various genetic operators applied to a sample genotype. See also oper_fx.cpp. */
25int main(int argc, char *argv[])
26{
27        GenMan gm;
28        Geno::validators.insert(0,&gm); //GenMan is available in this application so let's use the extended validity checking!
29        // Note: insert() makes it the first validator in the list, this is important for formats that rely on genetic operators to perform reasonable validation,
30        // otherwise the default validator (genotype converter) would "win" and most converters are less strict in detecting invalid genotypes.
31        gm.p_report(NULL, NULL);
32
33        const char* src = (argc > 1) ? argv[1] : "/*9*/UUU";
34        Geno gsrc(src, -1, "First");
35        printGenAndTitle(gsrc, "source genotype (gsrc)");
36
37        Geno gmut = gm.Mutate(gsrc);
38        printGenAndTitle(gmut, "mutated (gmut)");
39
40        Geno gxover = gm.CrossOver(gsrc, gmut);
41        printGenAndTitle(gxover, "crossed over (gsrc and gmut)");
42
43        Geno gsimplest = gm.GetSimplest('9');
44        printGenAndTitle(gsimplest, "simplest");
45
46        Geno ginvalid("IT'S REALLY WRONG", '9');
47        printGenAndTitle(ginvalid, "invalid");
48
49        Geno gvalidated = gm.Validate(ginvalid);
50        printGenAndTitle(gvalidated, "validated");
51
52        printf("\nHTMLized: %s\n", (const char*)gm.HTMLize((const char*)gvalidated.getGene()));
53
54        return 0;
55}
Note: See TracBrowser for help on using the repository browser.