Changeset 1227 for cpp/frams/genetics/f4/f4_oper.h
- Timestamp:
- 04/27/23 04:04:06 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/genetics/f4/f4_oper.h
r779 r1227 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 17Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2023 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 33 33 //@} 34 34 35 /** @name Codes for specific F4_MOD neuron mutation subtypes (not included in mutation_method_names, all are considered F4_MOD there) */ 36 //@{ 37 #define F4_MODNEU_CONN 0 38 #define F4_MODNEU_WEIGHT 1 39 #define F4_MODNEU_COUNT 2 40 //@} 41 35 42 class Geno_f4 : public GenoOperators 36 43 { … … 48 55 // mutation probabilities 49 56 double prob[F4_COUNT]; ///<relative probabilities of selecting mutation types in f4 genotype 50 double probadd[F4_ADD_COUNT]; ///<relative probabilities of selecting mutation addition subtypes 57 double probadd[F4_ADD_COUNT]; ///<relative probabilities of selecting addition mutation subtypes 58 double probmodneu[F4_MODNEU_COUNT]; ///<relative probabilities of selecting neuron mutation subtypes 59 paInt mut_max_rep; ///maximum allowed number of repetitions for the '#' repetition gene 51 60 52 61 SString excluded_modifiers; ///<Modifiers that are excluded in mutation process … … 63 72 * @return GENOOPER_OK if genotype is valid, GENOPER_REPAIR if genotype can be repaired, GENOPER_OPFAIL if genotype can't be repaired 64 73 */ 65 int ValidateRec(f4_ node *geno, int retrycount) const;74 int ValidateRec(f4_Node *geno, int retrycount) const; 66 75 67 76 /** … … 86 95 * @return GENOPER_OK if mutation was performed successfully, GENOPER_FAIL otherwise 87 96 */ 88 int MutateOne(f4_ node *& g, int &method) const;97 int MutateOne(f4_Node *& g, int &method) const; 89 98 90 99 /** 91 * Creates a random connection to an existing neuron or creates an additional 100 * Finds all neurons in g (in the order of ordNode()) and returns their neuroclasses in a vector. 101 * Additionally, looks for the needle_neuron node and returns its index (in the list of the returned vector) as found_index, 102 * or -1 if not found (for example, it was not a neuroclass node or not added to the "g" tree). 103 * @param g root node 104 * @param needle_neuron neuroclass node to look for in all nodes 105 * @param found_index returned index of needle 106 * @return all nodes that are neurons 107 */ 108 static vector<NeuroClass*> findAllNeuronsAndNode(f4_Node * const & g, f4_Node* const &needle_neuron, int &found_index); 109 110 /** 111 * Finds indexes of a given neuron and another random (output- or input-providing) neuron in the list of all neurons present in the "g" tree. 112 * @param g root node 113 * @param neuron neuroclass node to look for in all nodes in g 114 * @param other_has_output if true, other neuron will provide output; otherwise, it will accept input(s) 115 * @param neuron_index returned index of neuron 116 * @param other_neuron_index returned index of a random neuron that provides an output or accepts inputs 117 * @return true if succeeded, false otherwise 118 */ 119 static bool findConnectionNeuronIndexes(f4_Node * const &g, f4_Node *neuron, bool other_has_output, int &neuron_index, int &other_neuron_index); 120 121 /** 122 * Creates a random connection to an existing neuron and randomizes connection weight 92 123 * sensor for a neuron. 93 124 * @param nn neuron class node 94 * @param n euid id of aneuron95 * @param neulist list of genotype neuron classes125 * @param nn_index index of the nn neuron 126 * @param other_index index of the neuron providing output, to get input from 96 127 */ 97 void linkNodeMakeRandom(f4_node *nn, int neuid, std::vector<NeuroClass*> neulist) const; 98 99 /** 100 * Changes connection to an existing neuron or creates an additional 101 * sensor for neuron. 102 * @param nn neuron connection node 103 * @param neuid id of a neuron 104 * @param neulist list of genotype neuron classes 105 */ 106 void linkNodeChangeRandom(f4_node *nn, int neuid, std::vector<NeuroClass*> neulist) const; 128 void connectionNodeChangeRandom(f4_Node *nn, int nn_index, int other_index) const; 107 129 108 130 /** … … 110 132 * @param nn neuron node 111 133 */ 112 void nparNodeMakeRandom(f4_ node *nn) const;134 void nparNodeMakeRandom(f4_Node *nn) const; 113 135 114 136 /** … … 116 138 * @param nn repetition node 117 139 */ 118 void repeatNodeChangeRandom(f4_ node *nn) const;140 void repeatNodeChangeRandom(f4_Node *nn) const; 119 141 120 142 /** … … 124 146 * @return GENOPER_OK if performed successful mutation, GENOPER_FAIL otherwise 125 147 */ 126 int MutateOneValid(f4_ node *&g, int &method) const;148 int MutateOneValid(f4_Node *&g, int &method) const; 127 149 128 150 /** … … 134 156 * @param chg percentage of the first parent in offspring (the second parent has the rest) 135 157 */ 136 int CrossOverOne(f4_ node *g1, f4_node *g2, float chg) const;158 int CrossOverOne(f4_Node *g1, f4_Node *g2, float chg) const; 137 159 }; 138 160
Note: See TracChangeset
for help on using the changeset viewer.