Changeset 673 for cpp/frams/genetics/oper_fx.cpp
- Timestamp:
- 08/19/17 02:43:11 (8 years ago)
- File:
-
- 1 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
Note: See TracChangeset
for help on using the changeset viewer.