Changeset 158 for cpp/frams/genetics


Ignore:
Timestamp:
03/01/14 22:40:49 (6 years ago)
Author:
sz
Message:

genetics: warn if properties cannot be mixed because of incompatible types

File:
1 edited

Legend:

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

    r146 r158  
    155155void GenoOperators::linearMix(ParamInterface &p1, int i1, ParamInterface &p2, int i2, double proportion)
    156156{
    157         if (p1.type(i1)[0] == 'f' && p2.type(i2)[0] == 'f')
     157        char type1 = p1.type(i1)[0];
     158        char type2 = p2.type(i2)[0];
     159        if (type1 == 'f' && type2 == 'f')
    158160        {
    159161                double v1 = p1.getDouble(i1);
     
    162164                p2.setDouble(i2, v2*proportion + v1*(1 - proportion));
    163165        }
    164         if (p1.type(i1)[0] == 'd' && p2.type(i2)[0] == 'd')
    165         {
    166                 int v1 = p1.getInt(i1);
    167                 int v2 = p2.getInt(i2);
    168                 setIntFromDoubleWithProbabilisticDithering(p1, i1, v1*proportion + v2*(1 - proportion));
    169                 setIntFromDoubleWithProbabilisticDithering(p2, i2, v2*proportion + v1*(1 - proportion));
    170         }
     166        else
     167                if (type1 == 'd' && type2 == 'd')
     168                {
     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                }
     174                else
     175                        FMprintf("GenoOperators", "linearMix", FMLV_WARN, "Cannot mix values of types '%c' and '%c'", type1, type2);
    171176}
    172177
     
    241246
    242247void GenoOperators::skipWS(char *&s)
    243 { if (!s) FramMessage("GenoOperators","skipWS","NULL reference!",1); else
    244      while (isWS(*s)) s++;
     248{
     249        if (s==NULL)
     250                FramMessage("GenoOperators", "skipWS", "NULL reference!", FMLV_WARN);
     251        else
     252        while (isWS(*s)) s++;
    245253}
    246254
Note: See TracChangeset for help on using the changeset viewer.