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

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

Cosmetic

File size: 4.0 KB
RevLine 
[958]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
[969]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
[958]29//@}
30
31
32const int PARENT_COUNT = 2;
33
[1006]34
35
[958]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        GenoOper_fS();
46
47        int crossOver(char *&g1, char *&g2, float &chg1, float &chg2);
48
49        int checkValidity(const char *geno, const char *genoname);
50
51        int mutate(char *&geno, float &chg, int &method);
52
53        uint32_t style(const char *g, int pos);
54
55        const char* getSimplest();
56
57        /**
58         * Remove connections to the subtree that will be removed from genotype
59         * @param geno An fS_Genotype
60         * @param sub A subtree that will be removed from genotype
61         * @param subStart An index of the first neuron in the removed genotype
62         */
63        void rearrangeConnectionsBeforeCrossover(fS_Genotype *geno, Node *sub, int &subStart);
64
65        /**
66         *
67         * @param geno An fS_Genotype
68         * @param sub A subtree that was added to genotype
69         * @param subOldStart An index of the first neuron in the subtree when it was in old genotype
70         */
71        void rearrangeConnectionsAfterCrossover(fS_Genotype *geno, Node *sub, int subOldStart);
72
73
74        /**
75         * Performs add part mutation on genotype
76         * @return true if mutation succeeded, false otherwise
77         */
[1000]78        bool addPart(fS_Genotype &geno, const vector<Part::Shape> &availablePartShapes, bool mutateSize = true);
[958]79
80        /**
81         * Performs remove part type mutation on genotype
82         * @return true if mutation succeeded, false otherwise
83         */
84        bool removePart(fS_Genotype &geno);
85
86        /**
87         * Performs change part type mutation on genotype
88         * @return true if mutation succeeded, false otherwise
89         */
[1000]90        bool changePartType(fS_Genotype &geno, const vector<Part::Shape> &availablePartShapes);
[958]91
92        /**
[969]93         * Changes the type of one joint in genotype
[958]94         * @return true if mutation succeeded, false otherwise
95         */
[969]96        bool changeJoint(fS_Genotype &geno);
[958]97
98        /**
99         * Performs add param mutation on genotype
100         * @return true if mutation succeeded, false otherwise
101         */
102        bool addParam(fS_Genotype &geno);
103
104        /**
105         * Performs remove param mutation on genotype
106         * @return true if mutation succeeded, false otherwise
107         */
108        bool removeParam(fS_Genotype &geno);
109
110        /**
111         * Performs change param mutation on genotype
112         * @return true if mutation succeeded, false otherwise
113         */
114        bool changeParam(fS_Genotype &geno);
115
116        /**
[1017]117         * Changes the value of specified parameter.
118         * The state of the node must be previously calculated
119         * @param node - the node on which parameter is modified
120         * @param key - the key of parameter
121         * @return
122         */
123        bool mutateParamValue(Node *node, string key);
124
125        /**
[958]126         * Performs change modifier mutation on genotype
127         * @return true if mutation succeeded, false otherwise
128         */
129        bool changeModifier(fS_Genotype &geno);
130
131        bool addNeuro(fS_Genotype &geno);
132
133        bool removeNeuro(fS_Genotype &geno);
134
135        bool changeNeuroConnection(fS_Genotype &geno);
136
137        bool addNeuroConnection(fS_Genotype &geno);
138
139        bool removeNeuroConnection(fS_Genotype &geno);
140
141        bool changeNeuroParam(fS_Genotype &geno);
[1006]142
143        /**
[1056]144         * Change the value of the scale parameter by a given multiplier.
145         * Do not change the value if any of the scale restrictions is not satisfied.
[1006]146         * @param paramKey
147         * @param multiplier
148         * @param ensureCircleSection
[1056]149         * @return True if the parameter value was changed, false otherwise
[1006]150         */
[1030]151        bool mutateScaleParam(Node *node, string key, bool ensureCircleSection);
[958]152};
153
154#endif
Note: See TracBrowser for help on using the repository browser.