Changeset 145 for cpp/frams/_demos


Ignore:
Timestamp:
02/26/14 20:21:22 (11 years ago)
Author:
sz
Message:

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)
Location:
cpp/frams/_demos
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/_demos/f0_variants_test.cpp

    r121 r145  
    88#include <frams/virtfile/stdiofile.h>
    99
     10#include <frams/genetics/defgenoconv.h>
    1011#include <frams/model/model.h>
    11 #include <frams/genetics/defgenoconv.h>
    1212#include <frams/errmgr/stdouterr.h>
    13 
    14 StdoutErrorHandler err; //redirect model-related errors to stdout
    15 DefaultGenoConvManager gcm; //without this object the application would only handle "format 0" genotypes
    1613
    1714void save_as_f0(SString &gen,Model &m,bool omit_default_values)
     
    7774int main(int argc,char*argv[])
    7875{
     76StdoutErrorHandler err;//the default ErrorHandler constructor automatically registers this object to receive framsg messages (and in this case, redirect them to standard output)
     77
     78//without converters the application would only handle "format 0" genotypes
     79DefaultGenoConvManager gcm;
     80gcm.addDefaultConverters();
     81Geno::useConverters(gcm);
     82
     83ModelGenoValidator model_validator;
     84Geno::addValidator(&model_validator); //This simple validator handles all cases where a converter for a particular format is available but there is no genetic operator. Converters may be less strict in detecting invalid genotypes but it is better than nothing
     85
    7986SString gen(argc>1?argv[1]:"X[|G:1.23]");
    8087if (!strcmp(gen,"-"))
  • cpp/frams/_demos/full_props.cpp

    r121 r145  
    99
    1010#include <frams/model/model.h>
    11 #include <frams/genetics/defgenoconv.h>
    1211#include <frams/errmgr/stdouterr.h>
     12#include <frams/genetics/preconfigured.h>
    1313
    1414/**
     
    4747*/
    4848
    49 //optional:
    50 DefaultGenoConvManager gcm; //without this object the application would only handle "format 0" genotypes
    51 
    5249int main(int argc,char*argv[])
    5350{
    5451StdioFILE::setStdio();//setup VirtFILE::Vstdin/out/err
    5552StdoutErrorHandler err(ErrorHandlerBase::DontBlock,VirtFILE::Vstderr); //errors -> stderr, don't interfere with stdout
     53
     54PreconfiguredGenetics genetics;
    5655
    5756bool reverse=false;
  • cpp/frams/_demos/gdk_test.cpp

    r121 r145  
    99
    1010#include <frams/model/model.h>
    11 #include <frams/genetics/defgenoconv.h>
     11#include <frams/genetics/preconfigured.h>
    1212#include <frams/errmgr/stdouterr.h>
    1313
     
    1818
    1919StdoutErrorHandler err; //redirect model-related errors to stdout
    20 DefaultGenoConvManager gcm; //without this object the application would only handle "format 0" genotypes
     20PreconfiguredGenetics genetics;
    2121
    2222void printNiceBanner(const char* title)
     
    258258void findingConverters()
    259259{
    260 GenoConverter *gc=gcm.findConverters(0,'1');
     260GenoConverter *gc=Geno::getConverters().findConverters(0,'1');
    261261if (gc) printf("found converter accepting f1: \"%s\"\n",gc->name);
    262262SListTempl<GenoConverter*> found;
    263 gcm.findConverters(&found,-1,'0');
     263Geno::getConverters().findConverters(&found,-1,'0');
    264264printf("found %d converter(s) producing f0\n",found.size());
    265265}
  • cpp/frams/_demos/geno_test.cpp

    r141 r145  
    33// Refer to http://www.framsticks.com/ for further information.
    44
    5 #include <frams/genetics/geno.h>
    65#include <frams/virtfile/stdiofile.h>
    76#include <frams/util/sstringutils.h>
    8 #include <frams/genetics/defgenoconv.h>
    9 #include <frams/genetics/genman.h>
     7#include <frams/genetics/preconfigured.h>
    108
    119/**
     
    1614*/
    1715
    18 DefaultGenoConvManager gcm; //without this object the application would only handle "format 0" genotypes
    19 
    2016int main(int argc,char*argv[])
    2117{
    22 GenMan gm;
    23 Geno::validators.insert(0,&gm); //GenMan is available in this application so let's use the extended validity checking!
    24 // Note: insert() makes it the first validator in the list, this is important for formats that rely on genetic operators to perform reasonable validation,
    25 // otherwise the default validator (genotype converter) would "win" and most converters are less strict in detecting invalid genotypes.
     18PreconfiguredGenetics genetics;
     19
    2620if (argc<=1)
    2721        {
  • cpp/frams/_demos/genoconv_test.cpp

    r136 r145  
    1010#include "printconvmap.h"
    1111#include <frams/errmgr/stdouterr.h>
    12 
    13 StdoutErrorHandler err;
    1412
    1513/**
     
    119117int main(int argc,char *argv[])
    120118{
     119StdoutErrorHandler err;//the default ErrorHandler constructor automatically registers this object to receive framsg messages (and in this case, redirect them to standard output)
     120
    121121DefaultGenoConvManager gcm;
     122gcm.addDefaultConverters();
    122123gcm.addConverter(new GenoConv_Test());
    123124gcm.addConverter(new GenoConv_Test2());
    124125gcm.addConverter(new GenoConv_Test3());
     126Geno::useConverters(gcm);
     127
     128ModelGenoValidator model_validator;
     129Geno::addValidator(&model_validator);
    125130
    126131const char* src=(argc>1)?argv[1]:"X";
  • cpp/frams/_demos/genooper_test.cpp

    r141 r145  
    33// Refer to http://www.framsticks.com/ for further information.
    44
    5 #include <frams/genetics/genman.h>
    65#include <frams/errmgr/stdouterr.h>
    7 #include <frams/genetics/defgenoconv.h>
    8 
    9 StdoutErrorHandler err;
    10 DefaultGenoConvManager gcm; //without this object the application would only handle "format 0" genotypes
     6#include <frams/genetics/preconfigured.h>
    117
    128void printGen(Geno &g)
     
    2521int main(int argc, char *argv[])
    2622{
    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);
     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);
    3228
    3329        const char* src = (argc > 1) ? argv[1] : "/*9*/UUU";
    3430        Geno gsrc(src, -1, "First");
    3531        printGenAndTitle(gsrc, "source genotype (gsrc)");
     32        char format = gsrc.getFormat();
    3633
    37         Geno gmut = gm.Mutate(gsrc);
     34        Geno gmut = genetics.genman.Mutate(gsrc);
    3835        printGenAndTitle(gmut, "mutated (gmut)");
    3936
    40         Geno gxover = gm.CrossOver(gsrc, gmut);
     37        Geno gxover = genetics.genman.CrossOver(gsrc, gmut);
    4138        printGenAndTitle(gxover, "crossed over (gsrc and gmut)");
    4239
    43         Geno gsimplest = gm.GetSimplest('9');
     40        Geno gsimplest = genetics.genman.GetSimplest(format);
    4441        printGenAndTitle(gsimplest, "simplest");
    4542
    46         Geno ginvalid("IT'S REALLY WRONG", '9');
     43        Geno ginvalid("IT'S REALLY WRONG", format);
    4744        printGenAndTitle(ginvalid, "invalid");
    4845
    49         Geno gvalidated = gm.Validate(ginvalid);
     46        Geno gvalidated = genetics.genman.Validate(ginvalid);
    5047        printGenAndTitle(gvalidated, "validated");
    5148
    52         printf("\nHTMLized: %s\n", (const char*)gm.HTMLize((const char*)gvalidated.getGene()));
     49        printf("\nHTMLized: %s\n", (const char*)genetics.genman.HTMLize((const char*)gvalidated.getGene()));
    5350
    5451        return 0;
  • cpp/frams/_demos/multiline_f0_test.cpp

    r124 r145  
    88#include <frams/virtfile/stdiofile.h>
    99
     10#include <frams/genetics/preconfigured.h>
    1011#include <frams/model/model.h>
    11 #include <frams/genetics/defgenoconv.h>
    1212#include <frams/errmgr/stdouterr.h>
    1313#include <frams/virtfile/stringfile.h>
    1414
    15 StdoutErrorHandler err; //redirect model-related errors to stdout
    16 DefaultGenoConvManager gcm; //without this object the application would only handle "format 0" genotypes
    17 
    1815int main(int argc,char*argv[])
    1916{
     17StdoutErrorHandler err;//the default ErrorHandler constructor automatically registers this object to receive framsg messages (and in this case, redirect them to standard output)
     18PreconfiguredGenetics genetics;
     19
    2020SString gen(argc>1?argv[1]:"X[|G:1.23]");
    2121if (!strcmp(gen,"-"))
  • cpp/frams/_demos/neuro_layout_test.cpp

    r135 r145  
    33// Refer to http://www.framsticks.com/ for further information.
    44
    5 #include <frams/genetics/geno.h>
    65#include <frams/virtfile/stdiofile.h>
    76#include <frams/util/sstringutils.h>
    8 #include <frams/genetics/defgenoconv.h>
     7#include <frams/genetics/preconfigured.h>
    98#include <frams/model/model.h>
    109#include <frams/errmgr/stdouterr.h>
     
    2019 loader_test "data/walking.gen" "Walking Lizard" | neuro_layout_test -
    2120*/
    22 
    23 StdoutErrorHandler err; //redirect model-related errors to stdout
    24 DefaultGenoConvManager gcm; //without this object the application would only handle "format 0" genotypes
    2521
    2622// stl is fun? ;-) ForwardIterator implementation for element coordinates (required by min_element/max_element)
     
    8783int main(int argc,char*argv[])
    8884{
     85StdoutErrorHandler err;//the default ErrorHandler constructor automatically registers this object to receive framsg messages (and in this case, redirect them to standard output)
     86PreconfiguredGenetics genetics;
     87
    8988if (argc<=1)
    9089        {
  • cpp/frams/_demos/neuro_test.cpp

    r121 r145  
    66#include <frams/virtfile/stdiofile.h>
    77#include <frams/util/sstringutils.h>
    8 #include <frams/genetics/defgenoconv.h>
     8#include <frams/genetics/preconfigured.h>
    99#include <frams/neuro/neuroimpl.h>
    1010#include <frams/neuro/neurofactory.h>
     
    1515 Sample code: Neural network tester (can run your custom neurons)
    1616*/
    17 
    18 StdoutErrorHandler err; //redirect model-related errors to stdout
    19 DefaultGenoConvManager gcm; //without this object the application would only handle "format 0" genotypes
    2017
    2118#ifndef GDK_WITHOUT_FRAMS
     
    6360int main(int argc,char*argv[])
    6461{
     62StdoutErrorHandler err;//the default ErrorHandler constructor automatically registers this object to receive framsg messages (and in this case, redirect them to standard output)
     63PreconfiguredGenetics genetics;
     64
    6565if (argc<=1)
    6666        {
Note: See TracChangeset for help on using the changeset viewer.