Ignore:
Timestamp:
11/30/19 01:30:22 (4 years ago)
Author:
Maciej Komosinski
Message:

Replaced #defined macros for popular random-related operations with functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/fL/fL_matheval.cpp

    r821 r896  
    613613void MathEvaluation::mutateValueOrVariable(MathEvaluation::Number *&currval, bool usetime)
    614614{
    615         if (randomN(2) == 0 && varcount > 0) // use variable
     615        if (rndUint(2) == 0 && varcount > 0) // use variable
    616616        {
    617617                if (currval && currval->type == TokenType::NUMBER)
     
    619619                        delete currval;
    620620                }
    621                 int var = randomN(varcount + (usetime ? 1 : 0));
     621                int var = rndUint(varcount + (usetime ? 1 : 0));
    622622                if (varcount == var) // time is used
    623623                {
     
    633633                if (!currval || currval->type == TokenType::VARIABLE)
    634634                {
    635                         currval = new Number(rnd01);
     635                        currval = new Number(rndDouble(1));
    636636                }
    637637                else
    638638                {
    639                         currval->value = rnd01;
     639                        currval->value = rndDouble(1);
    640640                }
    641641        }
     
    654654                count = operatorstrings.size() - arithmeticoperatorscount;
    655655        }
    656         randop += randomN(count);
     656        randop += rndUint(count);
    657657        return operators[operatorstrings[randop]];
    658658}
     
    663663        {
    664664                int currsize = postfixlist.size();
    665                 int varid = randomN(varcount);
     665                int varid = rndUint(varcount);
    666666                postfixlist.push_back(vars[varid]);
    667                 if (randomN(2) == 0 && varcount > 1)
    668                 {
    669                         int varid2 = randomN(varcount - 1);
     667                if (rndUint(2) == 0 && varcount > 1)
     668                {
     669                        int varid2 = rndUint(varcount - 1);
    670670                        if (varid2 >= varid) varid2++;
    671671                        postfixlist.push_back(vars[varid2]);
     
    673673                else
    674674                {
    675                         Number *num = new Number(rnd01);
     675                        Number *num = new Number(rndDouble(1));
    676676                        postfixlist.push_back(num);
    677677                }
    678                 int opid = arithmeticoperatorscount + randomN(comparisonoperatorscount);
     678                int opid = arithmeticoperatorscount + rndUint(comparisonoperatorscount);
    679679                postfixlist.push_back(operators[operatorstrings[opid]]);
    680680                if (currsize > 0)
     
    689689        if (postfixlist.size() == 0)
    690690        {
    691                 Number *val = new Number(rnd01);
     691                Number *val = new Number(rndDouble(1));
    692692                postfixlist.push_back(val);
    693693                return -1;
    694694        }
    695         int method = randomN(postfixlist.size() < MAX_MUT_FORMULA_SIZE ? MATH_MUT_COUNT : MATH_MUT_COUNT - 1);
     695        int method = rndUint(postfixlist.size() < MAX_MUT_FORMULA_SIZE ? MATH_MUT_COUNT : MATH_MUT_COUNT - 1);
    696696        switch (method)
    697697        {
     
    704704                std::list<Token *>::iterator it = postfixlist.begin();
    705705                // insertion can be applied from 1st occurrence
    706                 int insertlocation = 1 + randomN(postfixlist.size() - 1);
     706                int insertlocation = 1 + rndUint(postfixlist.size() - 1);
    707707                std::advance(it, insertlocation);
    708708                Operator *rndop;
     
    732732                        id++;
    733733                }
    734                 int randid = randomN(numbersineval.size());
     734                int randid = rndUint(numbersineval.size());
    735735                Number *numptr = (Number *)(*numbersineval[randid]);
    736736                mutateValueOrVariable(numptr, usetime);
     
    750750                if (ops.size() > 0)
    751751                {
    752                         int randid = randomN(ops.size());
     752                        int randid = rndUint(ops.size());
    753753                        Operator *rndop;
    754754                        if (randid == (int)ops.size() - 1)
     
    783783                if (firstofpairs.size() > 0)
    784784                {
    785                         int rndid = randomN(firstofpairs.size());
     785                        int rndid = rndUint(firstofpairs.size());
    786786                        if ((*firstofpairs[rndid])->type == TokenType::NUMBER)
    787787                        {
Note: See TracChangeset for help on using the changeset viewer.