[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 | |
---|
| 32 | const int PARENT_COUNT = 2; |
---|
| 33 | |
---|
| 34 | class GenoOper_fS : public GenoOperators |
---|
| 35 | { |
---|
| 36 | public: |
---|
| 37 | static const int crossOverTries = 100; |
---|
| 38 | double prob[FS_OPCOUNT]; |
---|
| 39 | paInt ensureCircleSection; |
---|
| 40 | paInt useElli, useCub, useCyl; |
---|
| 41 | paInt strongAddPart; |
---|
| 42 | |
---|
| 43 | GenoOper_fS(); |
---|
| 44 | |
---|
| 45 | int crossOver(char *&g1, char *&g2, float &chg1, float &chg2); |
---|
| 46 | |
---|
| 47 | int checkValidity(const char *geno, const char *genoname); |
---|
| 48 | |
---|
| 49 | int mutate(char *&geno, float &chg, int &method); |
---|
| 50 | |
---|
| 51 | uint32_t style(const char *g, int pos); |
---|
| 52 | |
---|
| 53 | const char* getSimplest(); |
---|
| 54 | |
---|
| 55 | /** |
---|
| 56 | * Remove connections to the subtree that will be removed from genotype |
---|
| 57 | * @param geno An fS_Genotype |
---|
| 58 | * @param sub A subtree that will be removed from genotype |
---|
| 59 | * @param subStart An index of the first neuron in the removed genotype |
---|
| 60 | */ |
---|
| 61 | void rearrangeConnectionsBeforeCrossover(fS_Genotype *geno, Node *sub, int &subStart); |
---|
| 62 | |
---|
| 63 | /** |
---|
| 64 | * |
---|
| 65 | * @param geno An fS_Genotype |
---|
| 66 | * @param sub A subtree that was added to genotype |
---|
| 67 | * @param subOldStart An index of the first neuron in the subtree when it was in old genotype |
---|
| 68 | */ |
---|
| 69 | void rearrangeConnectionsAfterCrossover(fS_Genotype *geno, Node *sub, int subOldStart); |
---|
| 70 | |
---|
| 71 | |
---|
| 72 | /** |
---|
| 73 | * Performs add part mutation on genotype |
---|
| 74 | * @return true if mutation succeeded, false otherwise |
---|
| 75 | */ |
---|
| 76 | bool addPart(fS_Genotype &geno, string availableTypes = "ECR", bool mutateSize = true); |
---|
| 77 | |
---|
| 78 | /** |
---|
| 79 | * Performs remove part type mutation on genotype |
---|
| 80 | * @return true if mutation succeeded, false otherwise |
---|
| 81 | */ |
---|
| 82 | bool removePart(fS_Genotype &geno); |
---|
| 83 | |
---|
| 84 | /** |
---|
| 85 | * Performs change part type mutation on genotype |
---|
| 86 | * @return true if mutation succeeded, false otherwise |
---|
| 87 | */ |
---|
| 88 | bool changePartType(fS_Genotype &geno, string availableTypes = "ECR"); |
---|
| 89 | |
---|
| 90 | /** |
---|
[969] | 91 | * Changes the type of one joint in genotype |
---|
[958] | 92 | * @return true if mutation succeeded, false otherwise |
---|
| 93 | */ |
---|
[969] | 94 | bool changeJoint(fS_Genotype &geno); |
---|
[958] | 95 | |
---|
| 96 | /** |
---|
| 97 | * Performs add param mutation on genotype |
---|
| 98 | * @return true if mutation succeeded, false otherwise |
---|
| 99 | */ |
---|
| 100 | bool addParam(fS_Genotype &geno); |
---|
| 101 | |
---|
| 102 | /** |
---|
| 103 | * Performs remove param mutation on genotype |
---|
| 104 | * @return true if mutation succeeded, false otherwise |
---|
| 105 | */ |
---|
| 106 | bool removeParam(fS_Genotype &geno); |
---|
| 107 | |
---|
| 108 | /** |
---|
| 109 | * Performs change param mutation on genotype |
---|
| 110 | * @return true if mutation succeeded, false otherwise |
---|
| 111 | */ |
---|
| 112 | bool changeParam(fS_Genotype &geno); |
---|
| 113 | |
---|
| 114 | /** |
---|
| 115 | * Performs change modifier mutation on genotype |
---|
| 116 | * @return true if mutation succeeded, false otherwise |
---|
| 117 | */ |
---|
| 118 | bool changeModifier(fS_Genotype &geno); |
---|
| 119 | |
---|
| 120 | bool addNeuro(fS_Genotype &geno); |
---|
| 121 | |
---|
| 122 | bool removeNeuro(fS_Genotype &geno); |
---|
| 123 | |
---|
| 124 | bool changeNeuroConnection(fS_Genotype &geno); |
---|
| 125 | |
---|
| 126 | bool addNeuroConnection(fS_Genotype &geno); |
---|
| 127 | |
---|
| 128 | bool removeNeuroConnection(fS_Genotype &geno); |
---|
| 129 | |
---|
| 130 | bool changeNeuroParam(fS_Genotype &geno); |
---|
| 131 | }; |
---|
| 132 | |
---|
| 133 | #endif |
---|