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

Last change on this file since 165 was 145, checked in by sz, 11 years ago

Genetics reorganization (affects ALL applications!):

  • Converters/Validators? are now configured/initialized in a more verbose but also less confusing way
  • At the same time, the PreconfiguredGenetics? object will help you avoid the increased complexity by creating the ready-to-use environment that is sufficient in 99% of cases (see the demos)
  • Format F genetics updated (work in progress)
  • Property svn:eol-style set to native
File size: 1.8 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/errmgr/stdouterr.h>
6#include <frams/genetics/preconfigured.h>
7
8void printGen(Geno &g)
9{
10        printf("Genotype: %s\nFormat: %c\nValid: %s\nComment: %s\n",
11                (const char*)g.getGene(), g.getFormat(), g.isValid() ? "yes" : "no", g.getComment().len() == 0 ? "(empty)" : (const char*)g.getComment());
12}
13
14void 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. */
21int main(int argc, char *argv[])
22{
23        StdoutErrorHandler err;//the default ErrorHandler constructor automatically registers this object to receive framsg messages (and in this case, redirect them to standard output)
24        PreconfiguredGenetics genetics;
25
26        rndGetInstance().randomize();
27        genetics.genman.p_report(NULL, NULL);
28
29        const char* src = (argc > 1) ? argv[1] : "/*9*/UUU";
30        Geno gsrc(src, -1, "First");
31        printGenAndTitle(gsrc, "source genotype (gsrc)");
32        char format = gsrc.getFormat();
33
34        Geno gmut = genetics.genman.Mutate(gsrc);
35        printGenAndTitle(gmut, "mutated (gmut)");
36
37        Geno gxover = genetics.genman.CrossOver(gsrc, gmut);
38        printGenAndTitle(gxover, "crossed over (gsrc and gmut)");
39
40        Geno gsimplest = genetics.genman.GetSimplest(format);
41        printGenAndTitle(gsimplest, "simplest");
42
43        Geno ginvalid("IT'S REALLY WRONG", format);
44        printGenAndTitle(ginvalid, "invalid");
45
46        Geno gvalidated = genetics.genman.Validate(ginvalid);
47        printGenAndTitle(gvalidated, "validated");
48
49        printf("\nHTMLized: %s\n", (const char*)genetics.genman.HTMLize((const char*)gvalidated.getGene()));
50
51        return 0;
52}
Note: See TracBrowser for help on using the repository browser.