Changeset 758
- Timestamp:
- 03/15/18 22:50:46 (7 years ago)
- Location:
- cpp/frams/genetics
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/genetics/oper_fx.cpp
r751 r758 212 212 for (int i = 0; i < Neuro::getClassCount(); i++) 213 213 if (Neuro::getClass(i)->genactive) 214 active.push_back(Neuro::getClass(i)); 215 if (active.size() == 0) return NULL; else return active[randomN(active.size())]; 216 } 217 218 NeuroClass* GenoOperators::getRandomNeuroClassWithOutput() 219 { 220 vector<NeuroClass*> active; 221 for (int i = 0; i < Neuro::getClassCount(); i++) 222 if (Neuro::getClass(i)->genactive && Neuro::getClass(i)->getPreferredOutput() != 0) 223 active.push_back(Neuro::getClass(i)); 224 if (active.size() == 0) return NULL; else return active[randomN(active.size())]; 225 } 226 227 NeuroClass* GenoOperators::getRandomNeuroClassWithInput() 228 { 229 vector<NeuroClass*> active; 230 for (int i = 0; i < Neuro::getClassCount(); i++) 231 if (Neuro::getClass(i)->genactive && Neuro::getClass(i)->getPreferredInputs() != 0) 232 active.push_back(Neuro::getClass(i)); 233 if (active.size() == 0) return NULL; else return active[randomN(active.size())]; 234 } 235 236 NeuroClass* GenoOperators::getRandomNeuroClassWithOutputAndNoInputs() 237 { 238 vector<NeuroClass*> active; 239 for (int i = 0; i < Neuro::getClassCount(); i++) 240 if (Neuro::getClass(i)->genactive && Neuro::getClass(i)->getPreferredOutput() != 0 && Neuro::getClass(i)->getPreferredInputs() == 0) 214 241 active.push_back(Neuro::getClass(i)); 215 242 if (active.size() == 0) return NULL; else return active[randomN(active.size())]; … … 342 369 } 343 370 344 bool GenoOperators:: isNeuroClassName(const char firstchar)371 bool GenoOperators::canStartNeuroClassName(const char firstchar) 345 372 { 346 373 return isupper(firstchar) || firstchar == '|' || firstchar == '@' || firstchar == '*'; -
cpp/frams/genetics/oper_fx.h
r751 r758 194 194 static void linearMix(ParamInterface &p1, int i1, ParamInterface &p2, int i2, double proportion); ///<mixes i1'th and i2'th properties of p1 and p2; inherited proportion should be within [0,1]; 1.0 does not change values (all inherited), 0.5 causes both properties to become their average, 0.0 swaps values (none inherited). For integer properties applies random "dithering" when necessary. 195 195 static NeuroClass* getRandomNeuroClass(); ///<returns random neuroclass or NULL when no active classes. 196 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) 197 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 NeuroClass* getRandomNeuroClassWithOutput(); ///<returns random neuroclass with output or NULL when no active classes. 197 static NeuroClass* getRandomNeuroClassWithInput(); ///<returns random neuroclass with input or NULL when no active classes. 198 static NeuroClass* getRandomNeuroClassWithOutputAndNoInputs(); ///<returns random sensor or NULL when no active classes. 199 static NeuroClass* getRandomSensorProb(float prob); ///<returns random sensor (only-output neuron class) with presented probability or NULL. \e prob probability of picking neuron class. 200 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) \e NClist list of available neuron classes 201 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)) \e NClist list of available neuron classes 198 202 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. 199 203 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. … … 204 208 static bool areAlike(char*, char*); ///<compares two text strings skipping whitespaces. Returns 1 when equal, 0 when different. 205 209 static char* strchrn0(const char *str, char ch); ///<like strchr, but does not find zero char in \e str. 206 static bool isNeuroClassName(const char firstchar); ///<determines if \e firstchar may start NeuroClass name. If not, it may start NeuroClass' (or Neuro's) property name.210 static bool canStartNeuroClassName(const char firstchar); ///<determines if \e firstchar may start NeuroClass name. If not, it may start NeuroClass' (or Neuro's) property name. 207 211 //@} 208 212 };
Note: See TracChangeset
for help on using the changeset viewer.