source: cpp/frams/genetics/fH/fH_oper.h @ 792

Last change on this file since 792 was 780, checked in by Maciej Komosinski, 7 years ago

Added sources for genetic encodings fB, fH, fL

File size: 4.8 KB
Line 
1#ifndef _FH_OPER_H_
2#define _FH_OPER_H_
3
4#include "../genooperators.h"
5#include "fH_general.h"
6
7/** @name Codes for general fH mutation types */
8//@{
9#define FH_ADD     0 ///<Adding new handle
10#define FH_HANDLE  1 ///<Modifying vectors of handles
11#define FH_PROP    2 ///<Modifying properties of sticks/neurons/connections
12#define FH_DEL     3 ///<Deleting single handle from genotype. WARNING! this type of mutation must be last in defines, because later during mutation this method may be skipped due to the lack of genotypes to remove
13#define FH_OPCOUNT 4 ///<Count of mutation types
14//@}
15
16/** @name Codes for specific FH_ADD mutation subtypes */
17//@{
18#define FH_ADD_STICK 0 ///<Adding stick
19#define FH_ADD_NEURO 1 ///<Adding neuron
20#define FH_ADD_CONN  2 ///<Adding connection
21#define FH_ADD_OPCOUNT 3 ///<Count of addition types
22//@}
23
24class Geno_fH : public GenoOperators
25{
26private:
27        /**
28         * Mutates vectors and/or properties of a given handle.
29         * Properties and vector values are set with mutateCreep method, with respect to their
30         * minimal, maximal and default values. Only weights of connections are mutated
31         * with mutateNeuProperty.
32         * @param handle handle that has to be modified
33         * @param tab ParamTab holding definitions of properties of a given handle
34         * @param dimensions number of values stored in each vector of handle
35         * @param changedimensions true if values of vectors should be changed, false otherwise
36         * @param changeproperties true if values of properties should be changed, false otherwise
37         */
38        void mutateHandleValues(fH_Handle *handle, ParamEntry *tab, int dimensions, bool changedimensions, bool changeproperties);
39
40        /**
41         * Creates new handle with random vectors and one mutated property. Vector values are
42         * set to values from [-1,1] - probabilities of each values are evenly distributed.
43         * It also creates required obj for handle and initializes it with default
44         * values.
45         * @param handle the handle for which obj is created and mutation is performed
46         * @param tab the corresponding ParamTab for handle
47         * @param dimensions number of values in vectors
48         */
49        void createHandleVectors(fH_Handle *handle, ParamEntry *tab, int dimensions);
50
51        /**
52         * Mutates "details" property of neurons. First it tries to parse neuron class
53         * given in "details" field. It it fails, or "userandomclass" parameter is set
54         * to true, then new available class is picked (or "N", if there are no
55         * available classes). When neuron class is established, method iterates through
56         * neuron properties and mutates them with mutateNeuProperty method.
57         * @param handle handle that has to be modified
58         * @param tab ParamTab holding definitions of properties of a given handle
59         * @param userandomclass true if method should find random class, false if current class or "N" should be used
60         */
61        void mutateNeuronHandleProperties(fH_NeuronHandle *handle, ParamEntry *tab, bool userandomclass = false);
62
63        /**
64         * Mutates single double property in par, accessed by id. If property is weight
65         * of connection, then it is mutated with mutateNeuProperty.
66         * @param id numerical id of property in Param
67         * @param par Param with properties to modify
68         * @param type used to determine if property is weight of connection
69         */
70        void changeDoubleProperty(int id, Param &par, fHBodyType type);
71
72        /**
73         * Gets random handle and corresponding ParamTab from a given body. Both pointers
74         * are returned in parameters "handle" and "tab" respectively. Parameter
75         * "skipalonestick" should be set if method selects handle for deleting (valid
76         * body should have at least one stick).
77         * @param creature Builder object with parsed genotype, from which random handle is selected
78         * @param handle reference to pointer pointing to selected handle
79         * @param tab reference to pointer pointing to corresponding ParamTab
80         * @param skipalonestick true if method should skip only stick during random selection of handles, false if method should randomly choose handle from all available handles
81         * @return position of handle pointer in vector of handles of same type in Builder (if selected handle is of STICK type, then returned value is its position in "sticks" vector of Builder)
82         */
83        unsigned int getRandomHandle(fH_Builder *creature, fH_Handle *&handle, ParamEntry *&tab, bool skipalonestick = false);
84
85public:
86        double operations[FH_OPCOUNT];    ///<relative probabilities of selecting mutation types in fH genotype
87        double addoperations[FH_ADD_OPCOUNT]; ///<relative probabilities of selecting mutation addition subtypes
88
89        Geno_fH();
90
91        int checkValidity(const char *geno, const char *genoname);
92
93        int validate(char *&geno, const char *genoname);
94
95        int mutate(char *&geno, float& chg, int &method);
96
97        int crossOver(char *&g1, char *&g2, float& chg1, float& chg2);
98
99        virtual const char* getSimplest() { return "3\nj:"; }
100
101        uint32_t style(const char *geno, int pos);
102};
103
104#endif //_FH_OPER_H_
Note: See TracBrowser for help on using the repository browser.