- Timestamp:
- 08/19/17 02:43:11 (7 years ago)
- Location:
- cpp/frams/genetics
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/genetics/oper_fx.cpp
r670 r673 176 176 } 177 177 178 179 178 NeuroClass* GenoOperators::getRandomNeuroClass() 180 179 { 181 SListTempl<NeuroClass*> active;180 vector<NeuroClass*> active; 182 181 for (int i = 0; i < Neuro::getClassCount(); i++) 183 if (Neuro::getClass(i)->genactive) active += Neuro::getClass(i); 184 if (active.size() == 0) return NULL; else return active(randomN(active.size())); 182 if (Neuro::getClass(i)->genactive) 183 active.push_back(Neuro::getClass(i)); 184 if (active.size() == 0) return NULL; else return active[randomN(active.size())]; 185 } 186 187 int GenoOperators::getRandomNeuroClassWithOutput(const vector<NeuroClass*>& NClist) 188 { 189 vector<int> allowed; 190 for (size_t i = 0; i < NClist.size(); i++) 191 if (NClist[i]->getPreferredOutput() != 0) //this NeuroClass provides output 192 allowed.push_back(i); 193 if (allowed.size() == 0) return -1; else return allowed[randomN(allowed.size())]; 194 } 195 196 int GenoOperators::getRandomNeuroClassWithInput(const vector<NeuroClass*>& NClist) 197 { 198 vector<int> allowed; 199 for (size_t i = 0; i < NClist.size(); i++) 200 if (NClist[i]->getPreferredInputs() != 0) //this NeuroClass wants one input connection or more 201 allowed.push_back(i); 202 if (allowed.size() == 0) return -1; else return allowed[randomN(allowed.size())]; 203 } 204 205 int GenoOperators::getRandomChar(const char *choices, const char *excluded) 206 { 207 int allowed_count = 0; 208 for (size_t i = 0; i < strlen(choices); i++) if (!strchrn0(excluded, choices[i])) allowed_count++; 209 if (allowed_count == 0) return -1; //no char is allowed 210 int rnd_index = randomN(allowed_count) + 1; 211 allowed_count = 0; 212 for (size_t i = 0; i < strlen(choices); i++) 213 { 214 if (!strchrn0(excluded, choices[i])) allowed_count++; 215 if (allowed_count == rnd_index) return i; 216 } 217 return -1; //never happens 185 218 } 186 219 -
cpp/frams/genetics/oper_fx.h
r670 r673 87 87 88 88 /**Used to perform initializations of Param parameters that are not handled by the Param itself 89 (i.e. string parameters need tobe initialized here)*/89 (i.e. string parameters or fields that require some complex logic may be initialized here)*/ 90 90 virtual void setDefaults() {} 91 91 … … 192 192 static void linearMix(ParamInterface &p1, int i1, ParamInterface &p2, int i2, double proportion); ///<mixes i1'th and i2'th properties of p1 and p2; proportion should be within [0,1]; 0.5 causes both properties to become their average. For integer properties applies random "dithering" when necessary. 193 193 static NeuroClass* getRandomNeuroClass(); ///<returns random neuroclass or NULL when no active classes. 194 static int getRandomNeuroClassWithOutput(const vector<NeuroClass*>& NClist); //returns index of random neuroclass from the NClist or -1 (no neurons on the list that provide output) 195 static int getRandomNeuroClassWithInput(const vector<NeuroClass*>& NClist); //returns index of random neuroclass from the NClist or -1 (no neurons on the list that want input(s)) 196 static int getRandomChar(const char *choices, const char *excluded); ///<returns index of a random character from 'choices' excluding 'excluded', or -1 when everything is excluded or 'choices' is empty. 194 197 static NeuroClass* parseNeuroClass(char *&s); ///<returns longest matching neuroclass or NULL if the string does not begin with a valid neuroclass name. Advances \e s pointer. 195 198 static Neuro* findNeuro(const Model *m,const NeuroClass *nc); ///<returns pointer to first Neuro of class \e nc, or NULL if there is no such Neuro.
Note: See TracChangeset
for help on using the changeset viewer.