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

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

A more complete implementation of fB, fH, fL

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