Changeset 670 for cpp


Ignore:
Timestamp:
08/12/17 01:55:25 (7 years ago)
Author:
Maciej Komosinski
Message:

Improved variable names and docs

Location:
cpp/frams/genetics
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/oper_fx.cpp

    r375 r670  
    121121                        if (strcmp(n, "fo") == 0 && strcmp(na, "Force") == 0) newval = CustomRnd(distrib_force); else
    122122                        {
    123                                 double mn, mx, df;
    124                                 getMinMaxDef(&p, i, mn, mx, df);
    125                                 newval = mutateCreep(p.type(i)[0], oldval, mn, mx);
     123                double mn, mx, df;
     124                getMinMaxDef(&p, i, mn, mx, df);
     125                newval = mutateCreep(p.type(i)[0], oldval, mn, mx);
    126126                        }
    127127        return true;
     
    141141        //reflect:
    142142        if (result > mx) result = mx - (result - mx); else
    143                 if (result<mn) result = mn + (mn - result);
     143                if (result < mn) result = mn + (mn - result);
    144144        //absorb (just in case 'result' exceeded the allowed range so much):
    145         if (result>mx) result = mx; else
     145        if (result > mx) result = mx; else
    146146                if (result < mn) result = mn;
    147147        return result;
     
    167167                if (type1 == 'd' && type2 == 'd')
    168168                {
    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));
     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));
    173173                }
    174174                else
     
    187187NeuroClass* GenoOperators::parseNeuroClass(char*& s)
    188188{
    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;
    192192        for (int i = 0; i<Neuro::getClassCount(); i++)
    193193        {
    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;
    200204}
    201205
     
    252256                logMessage("GenoOperators", "skipWS", LOG_WARN, "NULL reference!");
    253257        else
    254         while (isWS(*s)) s++;
     258                while (isWS(*s)) s++;
    255259}
    256260
  • cpp/frams/genetics/oper_fx.h

    r513 r670  
    192192   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.
    193193   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.
    195195   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.
    196196   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.