1 | // This file is a part of Framsticks SDK. http://www.framsticks.com/ |
---|
2 | // Copyright (C) 2019-2020 Maciej Komosinski and Szymon Ulatowski. |
---|
3 | // See LICENSE.txt for details. |
---|
4 | |
---|
5 | #ifndef _FS_OPER_H_ |
---|
6 | #define _FS_OPER_H_ |
---|
7 | |
---|
8 | #include "fS_general.h" |
---|
9 | #include "../genooperators.h" |
---|
10 | |
---|
11 | |
---|
12 | /** @name Codes for general mutation types */ |
---|
13 | //@{ |
---|
14 | #define FS_ADD_PART 0 |
---|
15 | #define FS_REM_PART 1 |
---|
16 | #define FS_MOD_PART 2 |
---|
17 | #define FS_ADD_JOINT 3 |
---|
18 | #define FS_REM_JOINT 4 |
---|
19 | #define FS_ADD_PARAM 5 |
---|
20 | #define FS_REM_PARAM 6 |
---|
21 | #define FS_MOD_PARAM 7 |
---|
22 | #define FS_MOD_MOD 8 |
---|
23 | #define FS_ADD_NEURO 9 |
---|
24 | #define FS_REM_NEURO 10 |
---|
25 | #define FS_MOD_NEURO_CONNECTION 11 |
---|
26 | #define FS_ADD_NEURO_CONNECTION 12 |
---|
27 | #define FS_REM_NEURO_CONNECTION 13 |
---|
28 | #define FS_MOD_NEURO_PARAMS 14 |
---|
29 | #define FS_OPCOUNT 15 |
---|
30 | //@} |
---|
31 | |
---|
32 | |
---|
33 | const int PARENT_COUNT = 2; |
---|
34 | |
---|
35 | class GenoOper_fS : public GenoOperators |
---|
36 | { |
---|
37 | public: |
---|
38 | static const int crossOverTries = 100; |
---|
39 | double prob[FS_OPCOUNT]; |
---|
40 | paInt ensureCircleSection; |
---|
41 | paInt useElli, useCub, useCyl; |
---|
42 | paInt strongAddPart; |
---|
43 | |
---|
44 | GenoOper_fS(); |
---|
45 | |
---|
46 | int crossOver(char *&g1, char *&g2, float &chg1, float &chg2); |
---|
47 | |
---|
48 | int checkValidity(const char *geno, const char *genoname); |
---|
49 | |
---|
50 | int mutate(char *&geno, float &chg, int &method); |
---|
51 | |
---|
52 | uint32_t style(const char *g, int pos); |
---|
53 | |
---|
54 | const char* getSimplest(); |
---|
55 | |
---|
56 | /** |
---|
57 | * Remove connections to the subtree that will be removed from genotype |
---|
58 | * @param geno An fS_Genotype |
---|
59 | * @param sub A subtree that will be removed from genotype |
---|
60 | * @param subStart An index of the first neuron in the removed genotype |
---|
61 | */ |
---|
62 | void rearrangeConnectionsBeforeCrossover(fS_Genotype *geno, Node *sub, int &subStart); |
---|
63 | |
---|
64 | /** |
---|
65 | * |
---|
66 | * @param geno An fS_Genotype |
---|
67 | * @param sub A subtree that was added to genotype |
---|
68 | * @param subOldStart An index of the first neuron in the subtree when it was in old genotype |
---|
69 | */ |
---|
70 | void rearrangeConnectionsAfterCrossover(fS_Genotype *geno, Node *sub, int subOldStart); |
---|
71 | |
---|
72 | |
---|
73 | /** |
---|
74 | * Performs add part mutation on genotype |
---|
75 | * @return true if mutation succeeded, false otherwise |
---|
76 | */ |
---|
77 | bool addPart(fS_Genotype &geno, string availableTypes = "ECR", bool mutateSize = true); |
---|
78 | |
---|
79 | /** |
---|
80 | * Performs remove part type mutation on genotype |
---|
81 | * @return true if mutation succeeded, false otherwise |
---|
82 | */ |
---|
83 | bool removePart(fS_Genotype &geno); |
---|
84 | |
---|
85 | /** |
---|
86 | * Performs change part type mutation on genotype |
---|
87 | * @return true if mutation succeeded, false otherwise |
---|
88 | */ |
---|
89 | bool changePartType(fS_Genotype &geno, string availableTypes = "ECR"); |
---|
90 | |
---|
91 | /** |
---|
92 | * Performs add joint mutation on genotype |
---|
93 | * @return true if mutation succeeded, false otherwise |
---|
94 | */ |
---|
95 | bool addJoint(fS_Genotype &geno); |
---|
96 | |
---|
97 | /** |
---|
98 | * Performs remove mutation on genotype |
---|
99 | * @return true if mutation succeeded, false otherwise |
---|
100 | */ |
---|
101 | bool removeJoint(fS_Genotype &geno); |
---|
102 | |
---|
103 | /** |
---|
104 | * Performs add param mutation on genotype |
---|
105 | * @return true if mutation succeeded, false otherwise |
---|
106 | */ |
---|
107 | bool addParam(fS_Genotype &geno); |
---|
108 | |
---|
109 | /** |
---|
110 | * Performs remove param mutation on genotype |
---|
111 | * @return true if mutation succeeded, false otherwise |
---|
112 | */ |
---|
113 | bool removeParam(fS_Genotype &geno); |
---|
114 | |
---|
115 | /** |
---|
116 | * Performs change param mutation on genotype |
---|
117 | * @return true if mutation succeeded, false otherwise |
---|
118 | */ |
---|
119 | bool changeParam(fS_Genotype &geno); |
---|
120 | |
---|
121 | /** |
---|
122 | * Performs change modifier mutation on genotype |
---|
123 | * @return true if mutation succeeded, false otherwise |
---|
124 | */ |
---|
125 | bool changeModifier(fS_Genotype &geno); |
---|
126 | |
---|
127 | bool addNeuro(fS_Genotype &geno); |
---|
128 | |
---|
129 | bool removeNeuro(fS_Genotype &geno); |
---|
130 | |
---|
131 | bool changeNeuroConnection(fS_Genotype &geno); |
---|
132 | |
---|
133 | bool addNeuroConnection(fS_Genotype &geno); |
---|
134 | |
---|
135 | bool removeNeuroConnection(fS_Genotype &geno); |
---|
136 | |
---|
137 | bool changeNeuroParam(fS_Genotype &geno); |
---|
138 | }; |
---|
139 | |
---|
140 | #endif |
---|