source: cpp/frams/genetics/fS/fS_oper.h @ 1006

Last change on this file since 1006 was 1006, checked in by Maciej Komosinski, 4 years ago

Improved the fS encoding

File size: 3.8 KB
Line 
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_CHANGE_JOINT 3
18#define FS_ADD_PARAM 4
19#define FS_REM_PARAM 5
20#define FS_MOD_PARAM 6
21#define FS_MOD_MOD 7
22#define FS_ADD_NEURO 8
23#define FS_REM_NEURO 9
24#define FS_MOD_NEURO_CONNECTION 10
25#define FS_ADD_NEURO_CONNECTION 11
26#define FS_REM_NEURO_CONNECTION 12
27#define FS_MOD_NEURO_PARAMS 13
28#define FS_OPCOUNT 14
29//@}
30
31
32const int PARENT_COUNT = 2;
33
34
35
36class GenoOper_fS : public GenoOperators
37{
38public:
39        static const int crossOverTries = 100;
40        double prob[FS_OPCOUNT];
41        paInt ensureCircleSection;
42        paInt useElli, useCub,  useCyl;
43        paInt strongAddPart;
44
45        std::map<string, double> minValues;
46        std::map<string, double> maxValues;
47
48        GenoOper_fS();
49
50        int crossOver(char *&g1, char *&g2, float &chg1, float &chg2);
51
52        int checkValidity(const char *geno, const char *genoname);
53
54        int mutate(char *&geno, float &chg, int &method);
55
56        uint32_t style(const char *g, int pos);
57
58        const char* getSimplest();
59
60        /**
61         * Remove connections to the subtree that will be removed from genotype
62         * @param geno An fS_Genotype
63         * @param sub A subtree that will be removed from genotype
64         * @param subStart An index of the first neuron in the removed genotype
65         */
66        void rearrangeConnectionsBeforeCrossover(fS_Genotype *geno, Node *sub, int &subStart);
67
68        /**
69         *
70         * @param geno An fS_Genotype
71         * @param sub A subtree that was added to genotype
72         * @param subOldStart An index of the first neuron in the subtree when it was in old genotype
73         */
74        void rearrangeConnectionsAfterCrossover(fS_Genotype *geno, Node *sub, int subOldStart);
75
76
77        /**
78         * Performs add part mutation on genotype
79         * @return true if mutation succeeded, false otherwise
80         */
81        bool addPart(fS_Genotype &geno, const vector<Part::Shape> &availablePartShapes, bool mutateSize = true);
82
83        /**
84         * Performs remove part type mutation on genotype
85         * @return true if mutation succeeded, false otherwise
86         */
87        bool removePart(fS_Genotype &geno);
88
89        /**
90         * Performs change part type mutation on genotype
91         * @return true if mutation succeeded, false otherwise
92         */
93        bool changePartType(fS_Genotype &geno, const vector<Part::Shape> &availablePartShapes);
94
95        /**
96         * Changes the type of one joint in genotype
97         * @return true if mutation succeeded, false otherwise
98         */
99        bool changeJoint(fS_Genotype &geno);
100
101        /**
102         * Performs add param mutation on genotype
103         * @return true if mutation succeeded, false otherwise
104         */
105        bool addParam(fS_Genotype &geno);
106
107        /**
108         * Performs remove param mutation on genotype
109         * @return true if mutation succeeded, false otherwise
110         */
111        bool removeParam(fS_Genotype &geno);
112
113        /**
114         * Performs change param mutation on genotype
115         * @return true if mutation succeeded, false otherwise
116         */
117        bool changeParam(fS_Genotype &geno);
118
119        /**
120         * Performs change modifier mutation on genotype
121         * @return true if mutation succeeded, false otherwise
122         */
123        bool changeModifier(fS_Genotype &geno);
124
125        bool addNeuro(fS_Genotype &geno);
126
127        bool removeNeuro(fS_Genotype &geno);
128
129        bool changeNeuroConnection(fS_Genotype &geno);
130
131        bool addNeuroConnection(fS_Genotype &geno);
132
133        bool removeNeuroConnection(fS_Genotype &geno);
134
135        bool changeNeuroParam(fS_Genotype &geno);
136
137        /**
138         * Change the value of the size parameter by given multiplier
139         * Do not change the value if any of the size restrictions is not satisfied
140         * @param paramKey
141         * @param multiplier
142         * @param ensureCircleSection
143         * @return True if the parameter value was change, false otherwise
144         */
145        bool mutateSizeParam(Node *node, string key, bool ensureCircleSection);
146
147        void prepareParams();
148};
149
150#endif
Note: See TracBrowser for help on using the repository browser.