Changeset 899 for cpp/frams/genetics/genooperators.cpp
 Timestamp:
 11/30/19 02:13:25 (12 days ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

cpp/frams/genetics/genooperators.cpp
r896 r899 76 76 } 77 77 78 int GenoOperators::selectRandomProperty(Neuro *n)78 int GenoOperators::selectRandomProperty(Neuro *n) 79 79 { 80 80 int neuext = n>extraProperties().getPropCount(), … … 129 129 if (strcmp(n, "fo") == 0 && strcmp(na, "Force") == 0) newval = CustomRnd(distrib_force); else 130 130 { 131 double mn, mx, df;132 getMinMaxDef(&p, i, mn, mx, df);133 newval = mutateCreep(p.type(i)[0], oldval, mn, mx, true);131 double mn, mx, df; 132 getMinMaxDef(&p, i, mn, mx, df); 133 newval = mutateCreep(p.type(i)[0], oldval, mn, mx, true); 134 134 } 135 135 return true; … … 195 195 double v1 = p1[i]; 196 196 double v2 = p2[i]; 197 p1[i] = v1 *proportion + v2*(1  proportion);198 p2[i] = v2 *proportion + v1*(1  proportion);197 p1[i] = v1 * proportion + v2 * (1  proportion); 198 p2[i] = v2 * proportion + v1 * (1  proportion); 199 199 } 200 200 } … … 208 208 double v1 = p1.getDouble(i1); 209 209 double v2 = p2.getDouble(i2); 210 p1.setDouble(i1, v1 *proportion + v2*(1  proportion));211 p2.setDouble(i2, v2 *proportion + v1*(1  proportion));210 p1.setDouble(i1, v1 * proportion + v2 * (1  proportion)); 211 p2.setDouble(i2, v2 * proportion + v1 * (1  proportion)); 212 212 } 213 213 else 214 214 if (type1 == 'd' && type2 == 'd') 215 215 { 216 int v1 = p1.getInt(i1);217 int v2 = p2.getInt(i2);218 setIntFromDoubleWithProbabilisticDithering(p1, i1, v1*proportion + v2*(1  proportion));219 setIntFromDoubleWithProbabilisticDithering(p2, i2, v2*proportion + v1*(1  proportion));216 int v1 = p1.getInt(i1); 217 int v2 = p2.getInt(i2); 218 setIntFromDoubleWithProbabilisticDithering(p1, i1, v1 * proportion + v2 * (1  proportion)); 219 setIntFromDoubleWithProbabilisticDithering(p2, i2, v2 * proportion + v1 * (1  proportion)); 220 220 } 221 221 else … … 232 232 } 233 233 234 NeuroClass *GenoOperators::getRandomNeuroClass()235 { 236 vector<NeuroClass *> active;234 NeuroClass *GenoOperators::getRandomNeuroClass() 235 { 236 vector<NeuroClass *> active; 237 237 for (int i = 0; i < Neuro::getClassCount(); i++) 238 238 if (Neuro::getClass(i)>genactive) … … 241 241 } 242 242 243 NeuroClass *GenoOperators::getRandomNeuroClassWithOutput()244 { 245 vector<NeuroClass *> active;243 NeuroClass *GenoOperators::getRandomNeuroClassWithOutput() 244 { 245 vector<NeuroClass *> active; 246 246 for (int i = 0; i < Neuro::getClassCount(); i++) 247 247 if (Neuro::getClass(i)>genactive && Neuro::getClass(i)>getPreferredOutput() != 0) … … 250 250 } 251 251 252 NeuroClass *GenoOperators::getRandomNeuroClassWithInput()253 { 254 vector<NeuroClass *> active;252 NeuroClass *GenoOperators::getRandomNeuroClassWithInput() 253 { 254 vector<NeuroClass *> active; 255 255 for (int i = 0; i < Neuro::getClassCount(); i++) 256 256 if (Neuro::getClass(i)>genactive && Neuro::getClass(i)>getPreferredInputs() != 0) … … 259 259 } 260 260 261 NeuroClass *GenoOperators::getRandomNeuroClassWithOutputAndNoInputs()262 { 263 vector<NeuroClass *> active;261 NeuroClass *GenoOperators::getRandomNeuroClassWithOutputAndNoInputs() 262 { 263 vector<NeuroClass *> active; 264 264 for (int i = 0; i < Neuro::getClassCount(); i++) 265 265 if (Neuro::getClass(i)>genactive && Neuro::getClass(i)>getPreferredOutput() != 0 && Neuro::getClass(i)>getPreferredInputs() == 0) … … 268 268 } 269 269 270 int GenoOperators::getRandomNeuroClassWithOutput(const vector<NeuroClass *>&NClist)270 int GenoOperators::getRandomNeuroClassWithOutput(const vector<NeuroClass *> &NClist) 271 271 { 272 272 vector<int> allowed; … … 277 277 } 278 278 279 int GenoOperators::getRandomNeuroClassWithInput(const vector<NeuroClass *>&NClist)279 int GenoOperators::getRandomNeuroClassWithInput(const vector<NeuroClass *> &NClist) 280 280 { 281 281 vector<int> allowed; … … 301 301 } 302 302 303 NeuroClass * GenoOperators::parseNeuroClass(char*&s)303 NeuroClass *GenoOperators::parseNeuroClass(char *&s) 304 304 { 305 305 int maxlen = (int)strlen(s); 306 306 int NClen = 0; 307 307 NeuroClass *NC = NULL; 308 for (int i = 0; i <Neuro::getClassCount(); i++)308 for (int i = 0; i < Neuro::getClassCount(); i++) 309 309 { 310 310 const char *ncname = Neuro::getClass(i)>name.c_str(); 311 311 int ncnamelen = (int)strlen(ncname); 312 if (maxlen >= ncnamelen && ncnamelen >NClen && (strncmp(s, ncname, ncnamelen) == 0))312 if (maxlen >= ncnamelen && ncnamelen > NClen && (strncmp(s, ncname, ncnamelen) == 0)) 313 313 { 314 314 NC = Neuro::getClass(i); … … 320 320 } 321 321 322 Neuro *GenoOperators::findNeuro(const Model *m, const NeuroClass *nc)322 Neuro *GenoOperators::findNeuro(const Model *m, const NeuroClass *nc) 323 323 { 324 324 if (!m) return NULL; … … 328 328 } 329 329 330 int GenoOperators::neuroClassProp(char *&s, NeuroClass *nc, bool also_v1_N_props)330 int GenoOperators::neuroClassProp(char *&s, NeuroClass *nc, bool also_v1_N_props) 331 331 { 332 332 int len = (int)strlen(s); … … 335 335 { 336 336 Param p = nc>getProperties(); 337 for (int i = 0; i <p.getPropCount(); i++)337 for (int i = 0; i < p.getPropCount(); i++) 338 338 { 339 339 const char *n = p.id(i); 340 340 int l = (int)strlen(n); 341 if (len >= l && l >Len && (strncmp(s, n, l) == 0)) { I = 100 + i; Len = l; }341 if (len >= l && l > Len && (strncmp(s, n, l) == 0)) { I = 100 + i; Len = l; } 342 342 if (also_v1_N_props) //recognize old properties symbols /=! 343 343 { … … 352 352 Neuro n; 353 353 Param p = n.extraProperties(); 354 for (int i = 0; i <p.getPropCount(); i++)354 for (int i = 0; i < p.getPropCount(); i++) 355 355 { 356 356 const char *n = p.id(i); 357 357 int l = (int)strlen(n); 358 if (len >= l && l >Len && (strncmp(s, n, l) == 0)) { I = i; Len = l; }358 if (len >= l && l > Len && (strncmp(s, n, l) == 0)) { I = i; Len = l; } 359 359 } 360 360 s += Len; … … 389 389 } 390 390 391 char *GenoOperators::strchrn0(const char *str, char ch)392 { 393 return ch == 0 ? NULL : strchr((char *)str, ch);391 char *GenoOperators::strchrn0(const char *str, char ch) 392 { 393 return ch == 0 ? NULL : strchr((char *)str, ch); 394 394 } 395 395 … … 398 398 return isupper(firstchar)  firstchar == ''  firstchar == '@'  firstchar == '*'; 399 399 } 400
Note: See TracChangeset
for help on using the changeset viewer.