Changeset 145


Ignore:
Timestamp:
02/26/14 20:21:22 (10 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
Files:
2 added
24 edited

Legend:

Unmodified
Added
Removed
  • cpp/common/nonstd_math.cpp

    r135 r145  
    6666
    6767#ifdef __BORLANDC__
     68// there was once a problem like this:
     69// http://qc.embarcadero.com/wc/qcmain.aspx?d=5128
     70// http://www.delorie.com/djgpp/doc/libc/libc_112.html
     71// ? http://www.c-jump.com/CIS77/reference/Intel/CIS77_24319002/pg_0211.htm
     72// ? http://www.jaist.ac.jp/iscenter-new/mpc/altix/altixdata/opt/intel/vtune/doc/users_guide/mergedProjects/analyzer_ec/mergedProjects/reference_olh/mergedProjects/instructions/instruct32_hh/vc100.htm
     73// ? http://www.plantation-productions.com/Webster/www.artofasm.com/Linux/HTML/RealArithmetica2.html
     74// http://blogs.msdn.com/b/oldnewthing/archive/2008/07/03/8682463.aspx
     75// where each cast of a double into an int would cause an exception.
     76// But it was resolved by restarting windows and cleaning all intermediate compilation files :o (restarting windows was the key element! restarting BC++Builder and deleting files would not help)
    6877
    6978#include "framsg.h"
  • cpp/frams/Makefile-GDK-files

    r141 r145  
    44ALL_DIRS={common,frams,frams/canvas,frams/config,frams/errmgr,frams/genetics,frams/genetics/f0,frams/genetics/f1,frams/genetics/f2,frams/genetics/f3,frams/genetics/f4,frams/genetics/f5,frams/genetics/f6,frams/genetics/f7,frams/genetics/f8,frams/genetics/f9,frams/genetics/fF,frams/model,frams/neuro,frams/neuro/impl,frams/param,frams/test,frams/util,frams/vm/classes,frams/virtfile,frams/_demos}
    55
    6 GENOCONV_GDK_OBJS=frams/genetics/f1/conv_f1.o frams/genetics/f9/conv_f9.o frams/genetics/fF/conv_fF.o
     6GENOCONV_GDK_OBJS=frams/genetics/defgenoconv.o frams/genetics/f1/conv_f1.o frams/genetics/f9/conv_f9.o frams/genetics/fF/conv_fF.o frams/genetics/fF/fF_genotype.o
    77
    88GENMAN_COMMON_OBJS=frams/genetics/genman.o frams/param/mutableparam.o frams/param/mutparamlist.o frams/neuro/geneticneuroparam.o frams/neuro/neurolibparam.o frams/vm/classes/genoobj.o frams/model/autoname.o
    99GENMAN_GDK_OBJS=$(GENMAN_COMMON_OBJS) frams/genetics/f9/oper_f9.o frams/genetics/fF/oper_fF.o
    1010
    11 GDK_OBJS=frams/util/list.o frams/util/advlist.o frams/param/param.o frams/util/sstring.o frams/util/sstringutils.o frams/util/3d.o frams/vm/classes/3dobject.o frams/model/model.o frams/model/modelparts.o frams/neuro/neurolibrary.o frams/genetics/geno.o frams/genetics/genoconv.o frams/util/extvalue.o frams/vm/classes/collectionobj.o frams/util/hashtable.o common/framsg.o frams/util/callbacks.o frams/param/syntparam.o frams/util/multirange.o frams/util/multimap.o frams/param/paramtabobj.o frams/genetics/defgenoconv.o frams/errmgr/errmanager.o frams/param/paramobj.o frams/genetics/oper_fx.o common/nonstd_math.o frams/errmgr/stderrors.o common/Convert.o frams/util/rndutil.o
     11GDK_OBJS=frams/util/list.o frams/util/advlist.o frams/param/param.o frams/util/sstring.o frams/util/sstringutils.o frams/util/3d.o frams/vm/classes/3dobject.o frams/model/model.o frams/model/modelparts.o frams/neuro/neurolibrary.o frams/genetics/geno.o frams/genetics/genoconv.o frams/util/extvalue.o frams/vm/classes/collectionobj.o frams/util/hashtable.o common/framsg.o frams/util/callbacks.o frams/param/syntparam.o frams/util/multirange.o frams/util/multimap.o frams/param/paramtabobj.o frams/errmgr/errmanager.o frams/param/paramobj.o frams/genetics/oper_fx.o common/nonstd_math.o frams/errmgr/stderrors.o common/Convert.o frams/util/rndutil.o
    1212
    1313
    1414#### gdk_tests
    1515
    16 GDK_TEST_OBJS= frams/_demos/gdk_test.o frams/errmgr/stdouterr.o frams/virtfile/virtfile.o  $(GDK_OBJS) $(GENOCONV_GDK_OBJS)
     16GDK_TEST_OBJS= frams/_demos/gdk_test.o frams/errmgr/stdouterr.o frams/virtfile/virtfile.o  $(GDK_OBJS) $(GENOCONV_GDK_OBJS) $(GENMAN_GDK_OBJS)
    1717
    18 MULTILINE_F0_OBJS=frams/_demos/multiline_f0_test.o frams/virtfile/stringfile.o frams/virtfile/virtfile.o frams/errmgr/stdouterr.o $(GDK_OBJS) $(GENOCONV_GDK_OBJS)
     18MULTILINE_F0_OBJS=frams/_demos/multiline_f0_test.o frams/virtfile/stringfile.o frams/virtfile/virtfile.o frams/errmgr/stdouterr.o $(GDK_OBJS) $(GENOCONV_GDK_OBJS) $(GENMAN_GDK_OBJS)
    1919
    2020F0_VARIANTS_OBJS=frams/_demos/f0_variants_test.o frams/virtfile/stringfile.o frams/virtfile/virtfile.o frams/errmgr/stdouterr.o   $(GDK_OBJS) $(GENOCONV_GDK_OBJS)
     
    2828NEURO_TEST_OBJS= frams/_demos/neuro_test.o frams/errmgr/stdouterr.o frams/virtfile/virtfile.o \
    2929        frams/neuro/neuroimpl.o frams/neuro/neurofactory.o frams/neuro/impl/neuroimpl-simple.o frams/neuro/impl/neuroimpl-channels.o \
    30         frams/neuro/impl/neuroimpl-fuzzy.o frams/neuro/impl/neuroimpl-fuzzy-f0.o  $(GDK_OBJS) $(GENOCONV_GDK_OBJS)
     30        frams/neuro/impl/neuroimpl-fuzzy.o frams/neuro/impl/neuroimpl-fuzzy-f0.o  $(GDK_OBJS) $(GENOCONV_GDK_OBJS) $(GENMAN_GDK_OBJS)
    3131
    32 FULL_PROPS_OBJS= frams/_demos/full_props.o frams/errmgr/stdouterr.o frams/virtfile/virtfile.o  frams/virtfile/stdiofile.o common/nonstd_stdio.o $(GDK_OBJS) $(GENOCONV_GDK_OBJS)
     32FULL_PROPS_OBJS= frams/_demos/full_props.o frams/errmgr/stdouterr.o frams/virtfile/virtfile.o  frams/virtfile/stdiofile.o common/nonstd_stdio.o $(GDK_OBJS) $(GENOCONV_GDK_OBJS) $(GENMAN_GDK_OBJS)
    3333
    3434SERIAL_TEST_OBJS= frams/_demos/serial_test.o frams/virtfile/virtfile.o  $(GDK_OBJS) $(GENOCONV_GDK_OBJS)
     
    3636PART_SHAPES_OBJS= frams/_demos/part_shapes.o frams/virtfile/virtfile.o  $(GDK_OBJS) $(GENOCONV_GDK_OBJS)
    3737
    38 NEURO_LAYOUT_TEST_OBJS= frams/_demos/neuro_layout_test.o frams/virtfile/virtfile.o frams/errmgr/stdouterr.o $(GDK_OBJS) $(GENOCONV_GDK_OBJS) frams/canvas/nn_layout_model.o frams/canvas/nn_simple_layout.o frams/canvas/nn_smart_layout.o
     38NEURO_LAYOUT_TEST_OBJS= frams/_demos/neuro_layout_test.o frams/virtfile/virtfile.o frams/errmgr/stdouterr.o $(GDK_OBJS) $(GENOCONV_GDK_OBJS) $(GENMAN_GDK_OBJS) frams/canvas/nn_layout_model.o frams/canvas/nn_simple_layout.o frams/canvas/nn_smart_layout.o
    3939
    4040GENOOPER_TEST_OBJS=frams/_demos/genooper_test.o frams/virtfile/virtfile.o frams/errmgr/stdouterr.o $(GDK_OBJS) $(GENOCONV_GDK_OBJS) $(GENMAN_GDK_OBJS)
  • 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        {
  • cpp/frams/genetics/defgenoconv.cpp

    r139 r145  
    4141#endif
    4242
    43 DefaultGenoConvManager::DefaultGenoConvManager()
     43void DefaultGenoConvManager::addDefaultConverters()
    4444{
    4545#ifdef USE_GENCONV_f10
  • cpp/frams/genetics/defgenoconv.h

    r121 r145  
    88#include "genoconv.h"
    99
    10 /// This GenoConvManager automatically registers the "standard" converters available in the GDK.
    11 /// All you have to do is create a single instance of this class somewhere in your application.
    12 /// @see genotest.cpp
     10/// This GenoConvManager subclass allows you to add all "standard" converters in one go
    1311class DefaultGenoConvManager: public GenoConvManager
    1412{
    1513  public:
    16 DefaultGenoConvManager();
     14void addDefaultConverters();///< add all converters configured in gen-config file
    1715};
    1816
  • cpp/frams/genetics/f9/oper_f9.cpp

    r120 r145  
    44
    55#include "oper_f9.h"
    6 #include <frams/genetics/f9/conv_f9.h>
     6#include "conv_f9.h"
    77#include <common/nonstd.h> //randomN, rnd01
    88
  • cpp/frams/genetics/fF/fF_genotype.h

    r140 r145  
    88#include <stdio.h>
    99#include "common/stl-util.h"
    10 
     10#include <frams/param/param.h>
    1111
    1212struct fF_growth_params
    1313{
    1414        int number_of_chambers;
    15         double scalex, scaley, scalez; //scaling factors
    16         double translation; //translation factor, TF range [−1; 1]
     15        double scalex, scaley, scalez;
     16        double translation;
    1717        double angle1, angle2;
    1818
     19        static ParamEntry paramtab[];
     20        Param param;
     21
    1922        fF_growth_params()
     23                :param(paramtab, this)
    2024        {
    2125                reset();
     
    2428        void reset()
    2529        {
    26                 number_of_chambers = 1;
    27                 scalex = scaley = scalez = 1;
    28                 translation = 1;
    29                 angle1 = angle2 = 0;
     30                param.setDefault();
    3031        }
    3132
    3233        bool load(const char* serialized)
    3334        {
    34                 return sscanf(serialized, "%d %lf %lf %lf %lf %lf %lf", &number_of_chambers, &scalex, &scaley, &scalez, &translation, &angle1, &angle2) == 7;
     35                SString s = serialized;
     36                int p = 0; //position in string
     37                return ((param.load2(s, p)==7) && (p==s.len()));
    3538        }
    3639
    3740        string save()
    3841        {
    39                 return ssprintf("%d %f %f %f %f %f %f", number_of_chambers, scalex, scaley, scalez, translation, angle1, angle2);
     42                SString tmp;
     43                param.save2(tmp, NULL/*object containing default values for comparison*/, false/*add CR*/, false/*force field names*/);
     44                return string((const char*)tmp);
    4045        }
    4146};
  • cpp/frams/genetics/fF/oper_fF.cpp

    r140 r145  
    44
    55#include "oper_fF.h"
    6 #include <frams/genetics/f9/conv_f9.h>
     6#include "fF_genotype.h"
    77#include <common/nonstd.h> //randomN, rnd01
    88
    99
    10 //THIS FILE NEEDS UPDATE. OLD, UNRELATED SOURCES BELOW (COPIED FROM f9).
    11 
    1210#define FIELDSTRUCT GenoOper_fF
    13 static ParamEntry GENOf9param_tab[]=
     11static ParamEntry GENOfFparam_tab[] =
    1412{
    15         {"Genetics: fF",1,1,},
    16         {"fF_mut",0,0,"Mutation probability","f 0 1 0.1",FIELD(mut_prob),"How many genes should be mutated during single mutation (1=all genes, 0.1=ten percent)",},
    17         {0,},
     13        { "Genetics: fF", 1, 1, },
     14        { "fF_xover", 0, 0, "Averaging crossover proportion", "f 0 0.5 0.5", FIELD(xover_proportion), "0.5 => children are averaged parents.\n0.2 => children are only 20% different from parents.\n0 => each child is identical to one parent (no crossover).", },
     15        { 0, },
    1816};
    1917#undef FIELDSTRUCT
     
    2220GenoOper_fF::GenoOper_fF()
    2321{
    24         par.setParamTab(GENOf9param_tab);
     22        par.setParamTab(GENOfFparam_tab);
    2523        par.select(this);
    2624        par.setDefault();
    27         supported_format='F';
     25        supported_format = 'F';
    2826}
    2927
    3028int GenoOper_fF::checkValidity(const char* gene)
    3129{
    32         return GENOPER_OK;
    33         if (!gene[0]) return 1; //empty is not valid
    34         bool ok=true;
    35         int i;
    36         for(i=0;i<strlen(gene);i++) if (!strchr(turtle_commands_f9,gene[i])) {ok=false; break;}
    37         return ok ? GENOPER_OK : i+1;
     30        fF_growth_params par;
     31        return par.load(gene) ? GENOPER_OK : 1;
    3832}
    3933
    40 ///Remove all invalid letters from the genotype
    4134int GenoOper_fF::validate(char *&gene)
    4235{
    43         SString validated; //new genotype (everything except turtle_commands_f9 is skipped)
    44         for(int i=0;i<strlen(gene);i++)
    45                 if (strchr(turtle_commands_f9,gene[i])) validated+=gene[i];  //validated contains only turtle_commands_f9
     36        fF_growth_params par; //is initialized with default values
     37        par.load(gene); //loads as much as possible, other fields remain with default values
     38        string validated = par.save();
    4639        free(gene);
    47         gene=strdup(validated); //reallocate
     40        gene = strdup(validated.c_str()); //reallocate
    4841        return GENOPER_OK;
    4942}
    5043
    51 ///Very simple mutation
    52 int GenoOper_fF::mutate(char *&gene,float &chg,int &method)
     44//Creep-mutate one property
     45int GenoOper_fF::mutate(char *&gene, float &chg, int &method)
    5346{
    54         method=0;
    55         int changes=0,len=strlen(gene);
    56         int symbols=strlen(turtle_commands_f9);
    57 
    58         for(int i=0;i<len;i++)
     47        method = 0;
     48        fF_growth_params par;
     49        par.load(gene);
     50        int which = randomN(par.param.getPropCount());
     51        bool mutated_ok = GenoOperators::mutatePropertyNaive(par.param, which);
     52        if (mutated_ok)
    5953        {
    60                 if (rnd01<mut_prob) //normalize prob with the length of the genotype
    61                 {
    62                         char oldgene=gene[i];
    63                         gene[i]=turtle_commands_f9[randomN(symbols)];
    64                         if (gene[i]!=oldgene) changes++;
    65                 }
     54                string saved = par.save();
     55                free(gene);
     56                gene = strdup(saved.c_str()); //reallocate
     57                chg = 1.0f / par.param.getPropCount();
     58                return GENOPER_OK;
    6659        }
    67 
    68         if (rnd01<mut_prob) //add or delete a random char
     60        else
    6961        {
    70                 SString newgeno(gene);
    71                 if (randomN(2)==0) //add
    72                 {
    73                         int symbols=strlen(turtle_commands_f9);
    74                         int p=randomN(len+1);  //random location
    75                         //printf("before add: %s\n",(const char*)newgeno);
    76                         newgeno=newgeno.substr(0,p)+SString(turtle_commands_f9+randomN(symbols),1)+newgeno.substr(p);
    77                         //printf("after add: %s\n",(const char*)newgeno);
    78                         changes++;
    79                 } else if (len>1) //delete
    80                 {
    81                         int p=randomN(len);  //random location
    82                         //printf("before delete: %s\n",(const char*)newgeno);
    83                         newgeno=newgeno.substr(0,p)+newgeno.substr(p+1);
    84                         //printf("after delete: %s\n",(const char*)newgeno);
    85                         changes++;
    86                 }
    87                 free(gene);
    88                 gene=strdup(newgeno); //reallocate
     62                chg = 0;
     63                return GENOPER_OPFAIL;
    8964        }
    90 
    91         chg=(float)changes/len;
    92         return changes>0?GENOPER_OK:GENOPER_OPFAIL; //no changes => OPFAIL so that genman will call mutate again
    9365}
    9466
    95 ///A simple one-point crossover
    96 int GenoOper_fF::crossOver(char *&g1,char *&g2,float& chg1,float& chg2)
     67///Averaging crossover
     68int GenoOper_fF::crossOver(char *&g1, char *&g2, float& chg1, float& chg2)
    9769{
    98         int len1=strlen(g1),len2=strlen(g2);
    99         int p1=randomN(len1);  //random cut point for first genotype
    100         int p2=randomN(len2);  //random cut point for second genotype
    101         char *child1=(char*)malloc(p1+len2-p2+1);
    102         char *child2=(char*)malloc(p2+len1-p1+1);
    103         strncpy(child1,g1,p1);   strcpy(child1+p1,g2+p2);
    104         strncpy(child2,g2,p2);   strcpy(child2+p2,g1+p1);
    105         free(g1); g1=child1;
    106         free(g2); g2=child2;
    107         chg1=(float)p1/strlen(child1);
    108         chg2=(float)p2/strlen(child2);
     70        //g1 = strdup("1,0.5,0.5,0.5,0.5,1,1"); //testing...
     71        //g2 = strdup("4,1,  1,  1,  1,  2,2"); //testing...
     72        //xover_proportion = 0.1; //testing...
     73        fF_growth_params par1;
     74        par1.load(g1);
     75        fF_growth_params par2;
     76        par2.load(g2);
     77        chg1 = xover_proportion;
     78        chg2 = 1 - xover_proportion;
     79        for (int i = 0; i < par1.param.getPropCount(); i++)
     80                GenoOperators::linearMix(par1.param, i, par2.param, i, xover_proportion);
     81        string saved = par1.save();
     82        free(g1);
     83        g1 = strdup(saved.c_str()); //reallocate
     84        saved = par2.save();
     85        free(g2);
     86        g2 = strdup(saved.c_str()); //reallocate
    10987        return GENOPER_OK;
    11088}
     
    11391unsigned long GenoOper_fF::style(const char *g, int pos)
    11492{
    115         char ch=g[pos];
    116         unsigned long style=GENSTYLE_CS(0,GENSTYLE_INVALID); //default, should be changed below
    117         char *ptr=strchr((char*)turtle_commands_f9,ch);
    118         if (ptr)
    119         {
    120                 int pos=ptr-turtle_commands_f9;
    121                 int axis=pos/2;
    122                 style=GENSTYLE_RGBS(axis==0?200:0,axis==1?200:0,axis==2?200:0,GENSTYLE_NONE);
    123         }
     93        char ch = g[pos];
     94        unsigned long style = GENSTYLE_CS(0, GENSTYLE_INVALID); //default, should be changed below
     95        if (strchr("-.e 0123456789", ch) != NULL)
     96                style = GENSTYLE_CS(GENCOLOR_NUMBER, GENSTYLE_NONE);
     97        else if (ch == ',')
     98                style = GENSTYLE_RGBS(0, 0, 0, GENSTYLE_BOLD);
    12499        return style;
    125100}
  • cpp/frams/genetics/fF/oper_fF.h

    r140 r145  
    1818        int crossOver(char *&g1, char *&g2, float& chg1, float& chg2);
    1919        unsigned long style(const char *g, int pos);
    20         const char* getSimplest() { return "5 0.9 0.8 0.7 0.7 0.3 0.7"; }
     20        const char* getSimplest() { return "6,0.8,0.85,0.9,0.6,0.3,0.7"; }
    2121
    22         double mut_prob; //mutation probability
     22        double xover_proportion;
    2323};
    2424
  • cpp/frams/genetics/genman.cpp

    r139 r145  
    105105
    106106#ifdef USE_GENMAN_f0
    107         geno_fx_list.push_back(new Geno_f0);
     107        oper_fx_list.push_back(new Geno_f0);
    108108#endif
    109109#ifdef USE_GENMAN_f0FUZZY
    110         geno_fx_list.push_back(new Geno_f0Fuzzy);
     110        oper_fx_list.push_back(new Geno_f0Fuzzy);
    111111#endif
    112112#ifdef USE_GENMAN_f1
    113         geno_fx_list.push_back(new Geno_f1);
     113        oper_fx_list.push_back(new Geno_f1);
    114114#endif
    115115#ifdef USE_GENMAN_f2
    116         geno_fx_list.push_back(new Geno_f2);
     116        oper_fx_list.push_back(new Geno_f2);
    117117#endif
    118118#ifdef USE_GENMAN_f3
    119         geno_fx_list.push_back(new Geno_f3);
     119        oper_fx_list.push_back(new Geno_f3);
    120120#endif
    121121#ifdef USE_GENMAN_f4
    122         geno_fx_list.push_back(new Geno_f4);
     122        oper_fx_list.push_back(new Geno_f4);
    123123#endif
    124124#ifdef USE_GENMAN_f5
    125         geno_fx_list.push_back(new Geno_f5);
     125        oper_fx_list.push_back(new Geno_f5);
    126126#endif
    127127#ifdef USE_GENMAN_f6
    128         geno_fx_list.push_back(new Geno_f6);
     128        oper_fx_list.push_back(new Geno_f6);
    129129#endif
    130130#ifdef USE_GENMAN_f7
    131         geno_fx_list.push_back(new Geno_f7);
     131        oper_fx_list.push_back(new Geno_f7);
    132132#endif
    133133#ifdef USE_GENMAN_f8
    134         geno_fx_list.push_back(new Geno_f8);
     134        oper_fx_list.push_back(new Geno_f8);
    135135#endif
    136136#ifdef USE_GENMAN_f9
    137         geno_fx_list.push_back(new GenoOper_f9);
     137        oper_fx_list.push_back(new GenoOper_f9);
    138138#endif
    139139#ifdef USE_GENMAN_fF
    140         geno_fx_list.push_back(new GenoOper_fF);
    141 #endif
    142 
    143         seloper = new int[geno_fx_list.size()]; //may result in a little overhead if some of the operators on the geno_fx_list concern the same genetic format
     140        oper_fx_list.push_back(new GenoOper_fF);
     141#endif
     142
     143        seloper = new int[oper_fx_list.size()]; //may result in a little overhead if some of the operators on the oper_fx_list concern the same genetic format
    144144        int selopercount = 0;
    145         for (unsigned int i = 0; i < geno_fx_list.size(); i++)
    146         {
    147                 if (operformats.find(geno_fx_list[i]->supported_format) != -1) continue;
     145        for (unsigned int i = 0; i < oper_fx_list.size(); i++)
     146        {
     147                if (operformats.find(oper_fx_list[i]->supported_format) != -1) continue;
    148148                char tmp[10];
    149149                SString id, name, type = "~";
    150                 type += geno_fx_list[i]->name;
     150                type += oper_fx_list[i]->name;
    151151                int dup = 0;
    152                 for (unsigned int j = i + 1; j < geno_fx_list.size(); j++)
    153                         if (geno_fx_list[i]->supported_format == geno_fx_list[j]->supported_format)
     152                for (unsigned int j = i + 1; j < oper_fx_list.size(); j++)
     153                        if (oper_fx_list[i]->supported_format == oper_fx_list[j]->supported_format)
    154154                        {
    155                                 type += "~"; type += geno_fx_list[j]->name; dup++;
     155                                type += "~"; type += oper_fx_list[j]->name; dup++;
    156156                        }
    157157                sprintf(tmp, "d 0 %d ", dup);
    158158                type = SString(tmp) + type;
    159                 sprintf(tmp, "%c", geno_fx_list[i]->supported_format);
     159                sprintf(tmp, "%c", oper_fx_list[i]->supported_format);
    160160                id = "genoper_f"; id += tmp;
    161161                name = "Operators for f"; name += tmp;
    162162                seloper[selopercount] = 0;
    163                 operformats += geno_fx_list[i]->supported_format;
     163                operformats += oper_fx_list[i]->supported_format;
    164164                //printf("%x %s %s %s\n",&seloper[selopercount],(const char*)id,(const char*)type,(const char*)name);
    165165                seloperpar.addProperty(&seloper[selopercount++], id, type, name, "", PARAM_READONLY*(dup == 0));
     
    169169        par += &seloperpar;
    170170        par += &neuronsparam;
    171         for (unsigned int i = 0; i < geno_fx_list.size(); i++)
    172                 if (geno_fx_list[i]->par.getParamTab()) par += &geno_fx_list[i]->par;
     171        for (unsigned int i = 0; i < oper_fx_list.size(); i++)
     172                if (oper_fx_list[i]->par.getParamTab()) par += &oper_fx_list[i]->par;
    173173}
    174174
    175175GenMan::~GenMan()
    176176{
    177         for (unsigned int i = 0; i < geno_fx_list.size(); i++) delete geno_fx_list[i];
     177        for (unsigned int i = 0; i < oper_fx_list.size(); i++) delete oper_fx_list[i];
    178178        delete[] seloper;
    179179}
     
    181181void GenMan::setDefaults()
    182182{
    183         for (unsigned int i = 0; i < geno_fx_list.size(); i++)
    184         {
    185                 geno_fx_list[i]->par.setDefault();
    186                 geno_fx_list[i]->setDefaults();
     183        for (unsigned int i = 0; i < oper_fx_list.size(); i++)
     184        {
     185                oper_fx_list[i]->par.setDefault();
     186                oper_fx_list[i]->setDefaults();
    187187        }
    188188        localpar.setDefault();
     
    194194{
    195195        const char *gg = g.getGene();
    196         GenoOperators *gf = getGeno_f(g.getFormat());
     196        GenoOperators *gf = getOper_f(g.getFormat());
    197197        int check1;
    198198        if (!gf) { canvalidate = false; return GENOPER_NOOPER; }
     
    228228{
    229229        char format=geny.getFormat();
    230         GenoOperators *gf=getGeno_f(format);
     230        GenoOperators *gf=getOper_f(format);
    231231        if (gf==NULL)
    232232                return Geno(SString::empty(),-1,SString::empty(),SString::sprintf("GENOPER_NOOPER: Validate(): don't know how to handle genetic format %c",format));
     
    246246        int method; //mutation method
    247247        char format=g.getFormat();
    248         GenoOperators *gf=getGeno_f(format);
     248        GenoOperators *gf=getOper_f(format);
    249249        if (gf==NULL)
    250250                return Geno(SString::empty(),-1,SString::empty(),SString::sprintf("GENOPER_NOOPER: Mutate(): don't know how to handle genetic format %c",format));
     
    292292        char format = g1.getFormat();
    293293        if (format != g2.getFormat()) return Geno(SString::empty(), -1, SString::empty(), SString::sprintf("GENOPER_NOOPER: CrossOver() does not know how to handle parents with differing genetic formats (%c and %c)", format, g2.getFormat()));
    294         GenoOperators *gf = getGeno_f(format);
     294        GenoOperators *gf = getOper_f(format);
    295295        if (gf == NULL)
    296296                return Geno(SString::empty(), -1, SString::empty(), SString::sprintf("GENOPER_NOOPER: CrossOver(): don't know how to handle genetic format %c", format));
     
    358358        char format = g1.getFormat();
    359359        if (format != g2.getFormat()) return GENOPER_NOOPER;
    360         GenoOperators *gf = getGeno_f(format);
     360        GenoOperators *gf = getOper_f(format);
    361361        if (!gf) return GENOPER_NOOPER; else return gf->similarity(g1.getGene(), g2.getGene());
    362362}
     
    366366        Geno G(g);
    367367        if ((pos = G.mapStringToGen(pos)) == -1) return GENSTYLE_COMMENT;
    368         GenoOperators *gf = getGeno_f(G.getFormat());
     368        GenoOperators *gf = getOper_f(G.getFormat());
    369369        if (!gf) return GENSTYLE_CS(0, 0); //black & valid
    370370        else return gf->style(G.getGene(), pos);
     
    374374{
    375375        Geno G(g);
    376         GenoOperators *gf = getGeno_f(G.getFormat());
     376        GenoOperators *gf = getOper_f(G.getFormat());
    377377        SString geny = G.getGene();
    378378        for (unsigned int pos = 0; pos < strlen(g); pos++)
     
    448448Geno GenMan::GetSimplest(char format)
    449449{
    450         GenoOperators *gf = getGeno_f(format);
     450        GenoOperators *gf = getOper_f(format);
    451451        if (!gf) return Geno();
    452452        SString info = "The simplest genotype of format f"; info += format;
     
    458458{
    459459        int format = args[0].getInt() + 48;
    460         if (!getGeno_f(format))
     460        if (!getOper_f(format))
    461461                ret->setEmpty();
    462462        else
     
    466466const char *GenMan::GetOpName(char format)
    467467{
    468         GenoOperators *gf = getGeno_f(format);
     468        GenoOperators *gf = getOper_f(format);
    469469        if (!gf) return "n/a"; else return gf->name;
    470470}
    471471
    472 GenoOperators* GenMan::getGeno_f(char format)
     472GenoOperators* GenMan::getOper_f(char format)
    473473{
    474474        int ind = operformats.find(format);
    475475        if (ind == -1) return NULL;
    476476        int ktoryopformatu = seloper[ind];
    477         for (unsigned int i = 0; i < geno_fx_list.size(); i++)
    478                 if (geno_fx_list[i]->supported_format == format)
    479                         if (ktoryopformatu == 0) return geno_fx_list[i]; else ktoryopformatu--;
     477        for (unsigned int i = 0; i < oper_fx_list.size(); i++)
     478                if (oper_fx_list[i]->supported_format == format)
     479                        if (ktoryopformatu == 0) return oper_fx_list[i]; else ktoryopformatu--;
    480480        return NULL; //should never happen
    481481}
     
    519519{                      //should be updated to handle multiple operators for a single format
    520520        char *g, *g2;
    521         float f; int m;
     521        float f1, f2;
     522        int m;
    522523        FramMessage("GenMan", "Report", "The following genetic operators are available:", 0);
    523         for (unsigned int i = 0; i < geno_fx_list.size(); i++)
     524        for (unsigned int i = 0; i < oper_fx_list.size(); i++)
    524525        {
    525526                SString l;
    526                 if (geno_fx_list[i]->checkValidity("") != GENOPER_NOOPER) l += " checkValidity";
    527                 if (geno_fx_list[i]->getSimplest())
    528                 {
    529                         g = strdup(geno_fx_list[i]->getSimplest());
     527                if (oper_fx_list[i]->checkValidity("") != GENOPER_NOOPER) l += " checkValidity";
     528                if (oper_fx_list[i]->getSimplest())
     529                {
     530                        g = strdup(oper_fx_list[i]->getSimplest());
    530531                        g2 = strdup(g);
    531                         if (geno_fx_list[i]->validate(g) != GENOPER_NOOPER) l += " validate";
    532                         if (geno_fx_list[i]->mutate(g, f, m) != GENOPER_NOOPER) l += " mutate";
    533                         if (geno_fx_list[i]->crossOver(g, g2, f, f) != GENOPER_NOOPER) l += " crossover";
     532                        if (oper_fx_list[i]->validate(g) != GENOPER_NOOPER) l += " validate";
     533                        if (oper_fx_list[i]->mutate(g, f1, m) != GENOPER_NOOPER) l += " mutate";
     534                        if (oper_fx_list[i]->crossOver(g, g2, f1, f2) != GENOPER_NOOPER) l += " crossover";
    534535                        l += " getSimplest";
    535536                        free(g); free(g2);
    536537                }
    537                 //      if (geno_fx_list[i]->similarity("","")!=GENOPER_NOOPER) l+=" similarity";
     538                //      if (oper_fx_list[i]->similarity("","")!=GENOPER_NOOPER) l+=" similarity";
    538539                FMprintf("GenMan", "Report", 0, "format f%c (%s):%s",
    539                         geno_fx_list[i]->supported_format, (const char*)geno_fx_list[i]->name, (const char*)l);
     540                        oper_fx_list[i]->supported_format, (const char*)oper_fx_list[i]->name, (const char*)l);
    540541        }
    541542}
  • cpp/frams/genetics/genman.h

    r138 r145  
    77
    88#include <common/nonstd.h>
     9#include <common/nonstd_stl.h>
    910#include <frams/param/mutableparam.h>
    1011#include <frams/param/mutparamlist.h>
     
    1213#include "geno.h"
    1314#include "oper_fx.h"
    14 #include <string>
    15 #include <vector>
    1615
    1716#define GENSTYLE_COMMENT GENSTYLE_RGBS(0,150,0,GENSTYLE_BOLD)
     
    2019{
    2120        int count;
    22         std::string g1, g2;
     21        string g1, g2;
    2322        float chg;
    2423        float fit;
     
    5352        Geno GetSimplest(char format); ///<returns pointer to the simplest genotype of \e format or empty Geno()
    5453        const char *GetOpName(char format); ///<returns pointer to the active operator set for \e format
     54        const vector<GenoOperators*>& GetOperators() const { return oper_fx_list; } ///<returns the list of available genetic operators
    5555private:
    56         std::vector<GenoOperators*> geno_fx_list;
    57         void saveLink(std::string prz, std::string pot, float& chg);
    58         GenoOperators* getGeno_f(char format);
     56        vector<GenoOperators*> oper_fx_list;
     57        void saveLink(string prz, string pot, float& chg);
     58        GenoOperators* getOper_f(char format);
    5959        SString HTMLize(const char *g, bool shorten);
    6060public:
    61         std::vector<GenoLink> GenoLinkList;
     61        vector<GenoLink> GenoLinkList;
    6262        int history; //remember history?
    6363        int hilite; //syntax highlighting (Style)
     
    6666        int valid_m, valid_xo, validated_m, validated_xo, invalid_m, invalid_xo, failed_m, failed_xo;
    6767        double mutchg, xochg;
    68         SListTempl<char> operformats; //the list of supported_format, in the order same as in seloperpar
     68        SListTempl<char> operformats; //the list of supported_format, in the same order as in seloperpar
    6969        int* seloper; //fields for seloperpar
    7070        Param localpar, localstats;
  • cpp/frams/genetics/geno.cpp

    r121 r145  
    44
    55#include "geno.h"
     6#include "genoconv.h"
    67#include <frams/model/model.h>
    78
    89SListTempl<GenoValidator*> Geno::validators;
     10GenoConvManager *Geno::converters=NULL;
    911
    1012void Geno::init(const SString& genstring,char genformat,const SString& genname,const SString& comment)
     
    209211SString Geno::getComment(void) const {return txt;}
    210212
    211 class ModelGenoValidator: public GenoValidator
    212 {
    213 public:
    214         ModelGenoValidator();
    215         int testGenoValidity(Geno& g);
    216 };
    217 
    218 ModelGenoValidator::ModelGenoValidator()
    219 {
    220 Geno::validators+=this;
    221 }
    222 
    223213int ModelGenoValidator::testGenoValidity(Geno& g)
    224214{
     
    234224        }
    235225}
    236 
    237 static ModelGenoValidator default_validator;
    238226
    239227void Geno::validate()
     
    256244if (otherformat==getFormat()) return *this;
    257245#ifndef NO_GENOCONVMANAGER
    258 if ((otherformat=='0')&&(!m))
    259         {
    260         if (!f0gen)
    261                 f0gen=new Geno(GenoConvManager::globalConvert(*this,otherformat));
    262         return *f0gen;
    263         }
    264 else
    265         return GenoConvManager::globalConvert(*this,otherformat,m);
    266 #else
     246if (converters)
     247        {
     248        if ((otherformat=='0')&&(!m))
     249                {
     250                if (!f0gen)
     251                        f0gen=new Geno(converters->convert(*this,otherformat));
     252                return *f0gen;
     253        }
     254        else
     255                return converters->convert(*this,otherformat,m);
     256        }
     257#endif
    267258return (otherformat==getFormat())?*this:Geno(0,0,0,"GenConvManager not available");
    268 #endif
    269259}
    270260
  • cpp/frams/genetics/geno.h

    r121 r145  
    1111class MultiMap;
    1212class Geno;
     13class GenoConvManager;
    1314
    1415class GenoValidator
     
    1819};
    1920
     21/// basic GenoValidator that works by building a Model from any Geno (by converting to f0)
     22/// validation fails when the model can't be built or the genotype can't be converted
     23class ModelGenoValidator: public GenoValidator
     24{
     25public:
     26        int testGenoValidity(Geno& g);
     27};
     28
    2029/// basic information about a single genotype.
    2130class Geno: public DestrBase
    2231{
     32friend class Simulator;//needs to access validators directly
    2333SString gen;
    2434SString name;
     
    103113
    104114void* owner;
     115
     116// managing global Geno-related objects (used for validation and conversion)
     117static void addValidator(GenoValidator* gv) {validators+=gv;}
     118static void removeValidator(GenoValidator* gv) {validators-=gv;}
     119static void useConverters(GenoConvManager& gcm) {converters=&gcm;}
     120static GenoConvManager &getConverters() {return *converters;}
     121  protected:
     122static GenoConvManager *converters;
    105123static SListTempl<GenoValidator*> validators;
    106124};
  • cpp/frams/genetics/genoconv.cpp

    r121 r145  
    8282        :param(this)
    8383{
    84 if (!globalobject) globalobject=this;
    8584}
    8685
     
    8988GenoConverter *gc;
    9089for (converters.start();gc=(GenoConverter*)converters();) delete gc;
    91 if (globalobject==this) globalobject=NULL;
    92 }
    93 
    94 GenoConvManager *GenoConvManager::globalobject=NULL;
     90}
    9591
    9692void GenoConvManager::addConverter(GenoConverter *gc)
     
    217213return Geno(tmp, format, in.getName(), in.getComment());
    218214}
    219 
    220 Geno GenoConvManager::globalConvert(Geno &in,char format,MultiMap *map)
    221 {
    222 if (globalobject) return globalobject->convert(in,format,map);
    223 if (format==in.getFormat()) return in;
    224 return Geno(0,0,0,"GenConvManager not initialized");
    225 }
    226 
    227 /////////////////////////////////
  • cpp/frams/genetics/genoconv.h

    r121 r145  
    7373friend class GenoConvParam;
    7474SList converters;
    75 static GenoConvManager *globalobject;
    7675public:
    7776GenoConvManager();
    7877~GenoConvManager();
    7978class GenoConvParam param;
    80 /// select an object for use as global GenoConvManager
    81 void useManager(GenoConvManager *m) {globalobject=m;}
    82 /// get global converter
    83 static GenoConvManager *getGlobalObject() {return globalobject;}
    8479/// make a genotype in other format. genotype will be invalid
    8580/// if GenoConvManager cannot convert it.
    8681Geno convert(Geno &in,char format,MultiMap *map=0);
    87 /// static conversion function (uses global GenoConvManager)
    88 static Geno globalConvert(Geno &in,char format,MultiMap *map=0);
    89 /// register GenoConverter
     82/// register GenoConverter, the added object will be automatically deleted when GenoConvManager is destructed (call removeConverter() if this is not desirable)
    9083void addConverter(GenoConverter *conv);
    9184/// unregister GenoConverter
  • cpp/frams/genetics/oper_fx.h

    r139 r145  
    8181 public:
    8282   Param par;
    83    char supported_format; ///<genotype format which is supported by this class ('6' for Geno_f6, etc.). Must be initialized in constructor
     83   char supported_format; ///<genotype format which is supported by this class ('6' for GenoOper_f6, 'F' for GenoOper_fF, etc.). Must be initialized in constructor
    8484   SString name; ///<name of this set of genetic operators
    8585   char **mutation_method_names; ///<array of names for mutation methods. If initialized (by new char*[]), must have entries for each method index returned by mutate(geno,chg,METHOD).  If initialized, it is automatically freed by this destructor.
     
    187187   static double mutateCreepNoLimit(char type,double current,double mn,double mx); ///<returns \e current value creep-mutated with Gaussian distribution within [ \e mn , \e mx ] interval. Forced precision: 3 digits after comma. \e type must be either 'd' (integer) or 'f' (float/double).
    188188   static double mutateCreep(char type,double current,double mn,double mx); ///<just as mutateCreepNoLimit(), but forces mutated value into the [mn,mx] range using the 'reflect' approach.
     189   static void setIntFromDoubleWithProbabilisticDithering(ParamInterface &p, int index, double value); ///<sets a double value in an integer field; when a value is non-integer, applies random "dithering" so that both lower and higher integer value have some chance to be set.
     190   static void linearMix(ParamInterface &p1, int i1, ParamInterface &p2, int i2, double proportion); ///<mixes i1'th and i2'th properties of p1 and p2; proportion should be within [0,1]; 0.5 causes both properties to become their average. For integer properties applies random "dithering" when necessary.
    189191   static NeuroClass* getRandomNeuroClass(); ///<returns random neuroclass or NULL when no active classes.
    190192   static NeuroClass* parseNeuroClass(char *&s); ///<returns neuroclass or NULL if the string does not begin with a valid name. Advance \e s pointer.
Note: See TracChangeset for help on using the changeset viewer.