Changeset 670
- Timestamp:
- 08/12/17 01:55:25 (7 years ago)
- Location:
- cpp/frams/genetics
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/genetics/oper_fx.cpp
r375 r670 121 121 if (strcmp(n, "fo") == 0 && strcmp(na, "Force") == 0) newval = CustomRnd(distrib_force); else 122 122 { 123 124 125 123 double mn, mx, df; 124 getMinMaxDef(&p, i, mn, mx, df); 125 newval = mutateCreep(p.type(i)[0], oldval, mn, mx); 126 126 } 127 127 return true; … … 141 141 //reflect: 142 142 if (result > mx) result = mx - (result - mx); else 143 if (result <mn) result = mn + (mn - result);143 if (result < mn) result = mn + (mn - result); 144 144 //absorb (just in case 'result' exceeded the allowed range so much): 145 if (result >mx) result = mx; else145 if (result > mx) result = mx; else 146 146 if (result < mn) result = mn; 147 147 return result; … … 167 167 if (type1 == 'd' && type2 == 'd') 168 168 { 169 170 171 172 169 int v1 = p1.getInt(i1); 170 int v2 = p2.getInt(i2); 171 setIntFromDoubleWithProbabilisticDithering(p1, i1, v1*proportion + v2*(1 - proportion)); 172 setIntFromDoubleWithProbabilisticDithering(p2, i2, v2*proportion + v1*(1 - proportion)); 173 173 } 174 174 else … … 187 187 NeuroClass* GenoOperators::parseNeuroClass(char*& s) 188 188 { 189 int len = (int)strlen(s);190 int Len = 0;191 NeuroClass * I= NULL;189 int maxlen = (int)strlen(s); 190 int NClen = 0; 191 NeuroClass *NC = NULL; 192 192 for (int i = 0; i<Neuro::getClassCount(); i++) 193 193 { 194 const char *n = Neuro::getClass(i)->name.c_str(); 195 int l = (int)strlen(n); 196 if (len >= l && l>Len && (strncmp(s, n, l) == 0)) { I = Neuro::getClass(i); Len = l; } 197 } 198 s += Len; 199 return I; 194 const char *ncname = Neuro::getClass(i)->name.c_str(); 195 int ncnamelen = (int)strlen(ncname); 196 if (maxlen >= ncnamelen && ncnamelen>NClen && (strncmp(s, ncname, ncnamelen) == 0)) 197 { 198 NC = Neuro::getClass(i); 199 NClen = ncnamelen; 200 } 201 } 202 s += NClen; 203 return NC; 200 204 } 201 205 … … 252 256 logMessage("GenoOperators", "skipWS", LOG_WARN, "NULL reference!"); 253 257 else 254 while (isWS(*s)) s++;258 while (isWS(*s)) s++; 255 259 } 256 260 -
cpp/frams/genetics/oper_fx.h
r513 r670 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 NeuroClass* parseNeuroClass(char *&s); ///<returns neuroclass or NULL if the string does not begin with a valid name. Advance\e s pointer.194 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 195 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. 196 196 static int neuroClassProp(char *&s,NeuroClass *nc,bool also_v1_N_props=false); ///<returns 0-based property number for \e neuroclass, 100-based extraproperty number for Neuro, or -1 if the string does not begin with a valid property name. Advance \e s pointer if success.
Note: See TracChangeset
for help on using the changeset viewer.