1 | // This file is a part of Framsticks SDK. http://www.framsticks.com/ |
---|
2 | // Copyright (C) 1999-2016 Maciej Komosinski and Szymon Ulatowski. |
---|
3 | // See LICENSE.txt for details. |
---|
4 | |
---|
5 | #ifndef _GENMAN_H_ |
---|
6 | #define _GENMAN_H_ |
---|
7 | |
---|
8 | #include <common/nonstd.h> |
---|
9 | #include <common/nonstd_stl.h> |
---|
10 | #include <frams/param/mutableparam.h> |
---|
11 | #include <frams/param/mutparamlist.h> |
---|
12 | #include <frams/neuro/geneticneuroparam.h> |
---|
13 | #include "geno.h" |
---|
14 | #include "genooperators.h" |
---|
15 | |
---|
16 | #define GENSTYLE_COMMENT GENSTYLE_RGBS(0,150,0,GENSTYLE_BOLD) |
---|
17 | |
---|
18 | struct GenoLink |
---|
19 | { |
---|
20 | int count; |
---|
21 | string parent1, parent2, child; //parent2 only used in crossover, it is "" in mutation |
---|
22 | float chg; |
---|
23 | float fit; |
---|
24 | }; |
---|
25 | |
---|
26 | class GenMan : public GenoValidator |
---|
27 | { |
---|
28 | public: |
---|
29 | GenMan(); |
---|
30 | ~GenMan(); |
---|
31 | void setDefaults(); |
---|
32 | /** |
---|
33 | if canvalidate==false, returns GENOPER_NOOPER (cannot test), GENOPER_OK (\e g is valid), or 1-based error position. |
---|
34 | if canvalidate==true, returns |
---|
35 | - GENOPER_OK and canvalidate==false if \e g was already valid |
---|
36 | - GENOPER_NOOPER and canvalidate==false if \e g was (probably) validated but couldn't checkValidity |
---|
37 | - 1-based error position and canvalidate==false if \e g was invalid and couldn't validate |
---|
38 | - 1-based error position and canvalidate==true if \e g was invalid and was validated successfully |
---|
39 | |
---|
40 | Note: 1-based error position is always related to pure genotype (g.GetGene()), without the leading comment |
---|
41 | */ |
---|
42 | int testValidity(Geno &g, bool &canvalidate); |
---|
43 | int testGenoValidity(Geno& g); //class GenoValidator (geno.h) |
---|
44 | Geno validate(const Geno&); ///<returns validated (if possible) genotype |
---|
45 | Geno mutate(const Geno&); //returns mutated genotype or empty if errors |
---|
46 | Geno crossOver(const Geno&, const Geno&); //returns xover genotype ("child") or empty if errors |
---|
47 | float similarity(const Geno&, const Geno&); //returns GENOPER_NOOPER or normalized similarity (1: identical, 0: different) |
---|
48 | uint32_t getStyle(const char* g, int pos); //returns style (and validity) of a genotype char. |
---|
49 | uint32_t getStyle(const char *g, const Geno *G, int pos); //returns style (and validity) of a genotype char. Assumes G is created from g. |
---|
50 | void getFullStyle(const char *g, uint32_t *styletab); //optimized. Fills styletab with styles for all genotype chars. sizeof(*styletab) must be at least strlen(g). |
---|
51 | void getFullStyle(const char *g, const Geno *G, uint32_t *styletab); //optimized. Assumes G is created from g. Fills styletab with styles for all genotype chars. sizeof(*styletab) must be at least strlen(g). |
---|
52 | string HTMLize(const char *g); //returns colored genotype in HTML. |
---|
53 | string HTMLizeShort(const char *g); //returns colored genotype (abbreviated if needed) in HTML. |
---|
54 | Geno getSimplest(const SString& format); ///<returns pointer to the simplest genotype of \e format or empty Geno() |
---|
55 | const char *getOpName(const SString& format); ///<returns pointer to the active operator set for \e format |
---|
56 | const vector<GenoOperators*>& GetOperators() const { return oper_fx_list; } ///<returns the list of available genetic operators |
---|
57 | private: |
---|
58 | vector<GenoOperators*> oper_fx_list; |
---|
59 | void saveLink(const string parent1, const string parent2, const string child, const float chg); |
---|
60 | GenoOperators* getOper_f(const SString& format); |
---|
61 | string HTMLize(const char *g, bool shorten); |
---|
62 | int findOperFormatIndex(const SString& format); |
---|
63 | public: |
---|
64 | vector<GenoLink> GenoLinkList; |
---|
65 | int history; //remember history? |
---|
66 | int hilite; //syntax highlighting (Style) |
---|
67 | int extmutinfo; //extended info: the info field of the genotype will contain the name of the mutation method |
---|
68 | int count; //# of the last genetic operation |
---|
69 | int valid_m, valid_xo, validated_m, validated_xo, invalid_m, invalid_xo, failed_m, failed_xo; |
---|
70 | double mutchg, xochg; |
---|
71 | SListTempl<SString*> operformats; //the list of supported_format, in the same order as in seloperpar (raw SString* taken from oper_fx_list, not owned by operformats) |
---|
72 | int* seloper; //fields for seloperpar |
---|
73 | Param localpar, localstats; |
---|
74 | MutableParam seloperpar; |
---|
75 | GeneticNeuroParam neuronsparam; |
---|
76 | MutableParamList par; |
---|
77 | #define STATRICKCLASS GenMan |
---|
78 | PARAMPROCDEF(p_clearStats); |
---|
79 | PARAMPROCDEF(p_report); |
---|
80 | PARAMPROCDEF(p_htmlize); |
---|
81 | PARAMPROCDEF(p_htmlizeshort); |
---|
82 | PARAMPROCDEF(p_validate); |
---|
83 | PARAMPROCDEF(p_mutate); |
---|
84 | PARAMPROCDEF(p_crossover); |
---|
85 | PARAMPROCDEF(p_getsimplest); |
---|
86 | #undef STATRICKCLASS |
---|
87 | void clearStats(); |
---|
88 | static void onDelGen(void*, intptr_t); |
---|
89 | }; |
---|
90 | |
---|
91 | |
---|
92 | #endif |
---|