source: cpp/frams/genetics/genman.h @ 139

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

genetic operator example - frams/_demos/genooper_test.cpp

  • Property svn:eol-style set to native
File size: 3.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#ifndef _GENMAN_H_
6#define _GENMAN_H_
7
8#include <common/nonstd.h>
9#include <frams/param/mutableparam.h>
10#include <frams/param/mutparamlist.h>
11#include <frams/neuro/geneticneuroparam.h>
12#include "geno.h"
13#include "oper_fx.h"
14#include <string>
15#include <vector>
16
17#define GENSTYLE_COMMENT GENSTYLE_RGBS(0,150,0,GENSTYLE_BOLD)
18
19struct GenoLink
20{
21        int count;
22        std::string g1, g2;
23        float chg;
24        float fit;
25};
26
27class GenMan : public GenoValidator
28{
29public:
30        GenMan();
31        ~GenMan();
32        void setDefaults();
33        /**
34        if canvalidate==false, returns GENOPER_NOOPER (cannot test), GENOPER_OK (\e g is valid), or 1-based error position.
35        if canvalidate==true, returns
36        - GENOPER_OK and canvalidate==false if \e g was already valid
37        - GENOPER_NOOPER and canvalidate==false if \e g was (probably) validated but couldn't checkValidity
38        - 1-based error position and canvalidate==false if \e g was invalid and couldn't validate
39        - 1-based error position and canvalidate==true if \e g was invalid and was validated successfully
40
41        Note: 1-based error position is always related to pure genotype (g.GetGene()), without the leading comment
42        */
43        int testValidity(Geno &g, bool &canvalidate);
44        int testGenoValidity(Geno& g); //class GenoValidator (geno.h)
45        Geno Validate(const Geno&); ///<returns validated (if possible) genotype
46        Geno Mutate(const Geno&); //returns mutated genotype or empty if errors
47        Geno CrossOver(const Geno&, const Geno&); //returns xover genotype ("child") or empty if errors
48        float Similarity(const Geno&, const Geno&); //returns GENOPER_NOOPER or normalized similarity (1: identical, 0: different)
49        unsigned long Style(const char* g, int pos); //returns Style (and validity) of a genotype char.
50        void GetFullStyle(const char *g, unsigned long *styletab); //optimized. Fills styletab with styles for all genotype chars. sizeof(*styletab) must be at least strlen(g).
51        SString HTMLize(const char *g); //returns colored genotype in HTML.
52        SString HTMLizeShort(const char *g); //returns colored genotype (abbreviated if needed) in HTML.
53        Geno GetSimplest(char format); ///<returns pointer to the simplest genotype of \e format or empty Geno()
54        const char *GetOpName(char format); ///<returns pointer to the active operator set for \e format
55private:
56        std::vector<GenoOperators*> geno_fx_list;
57        void saveLink(std::string prz, std::string pot, float& chg);
58        GenoOperators* getGeno_f(char format);
59        SString HTMLize(const char *g, bool shorten);
60public:
61        std::vector<GenoLink> GenoLinkList;
62        int history; //remember history?
63        int hilite; //syntax highlighting (Style)
64        int extmutinfo; //extended info: the info field of the genotype will contain the name of the mutation method
65        int count; //# of the last genetic operation
66        int valid_m, valid_xo, validated_m, validated_xo, invalid_m, invalid_xo, failed_m, failed_xo;
67        double mutchg, xochg;
68        SListTempl<char> operformats; //the list of supported_format, in the order same as in seloperpar
69        int* seloper; //fields for seloperpar
70        Param localpar, localstats;
71        MutableParam seloperpar;
72        GeneticNeuroParam neuronsparam;
73        MutableParamList par;
74#define STATRICKCLASS GenMan
75        PARAMPROCDEF(p_clearStats);
76        PARAMPROCDEF(p_report);
77        PARAMPROCDEF(p_htmlize);
78        PARAMPROCDEF(p_htmlizeshort);
79        PARAMPROCDEF(p_validate);
80        PARAMPROCDEF(p_mutate);
81        PARAMPROCDEF(p_crossover);
82        PARAMPROCDEF(p_getsimplest);
83#undef STATRICKCLASS
84        void clearStats();
85        static void onDelGen(void*, long);
86};
87
88
89#endif
Note: See TracBrowser for help on using the repository browser.