Changeset 1299


Ignore:
Timestamp:
03/29/24 23:34:00 (4 weeks ago)
Author:
Maciej Komosinski
Message:

More reasonable usage of size_t, int, and unsigned int, and their conversions

Location:
cpp/frams/genetics
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/fH/fH_general.cpp

    r1261 r1299  
    352352        }
    353353
    354         unsigned int stickscount = children->size() + 1;
     354        size_t stickscount = children->size() + 1;
    355355
    356356        MultiRange ranges;
     
    469469        // next stick is selected by minimum distance between first vector of its handle
    470470        // and second vector of any existing StickHandle in body
    471         int remaining = sticks.size() - 2;
     471        int remaining = int(sticks.size()) - 2;
    472472        while (remaining > 0)
    473473        {
     
    880880int fH_Builder::removeNeuronsWithInvalidClasses()
    881881{
    882         int count = neurons.size();
     882        int count = (int)neurons.size();
    883883        if (count == 0)
    884884        {
     
    913913
    914914        }
    915         return count - neurons.size();
     915        return count - (int)neurons.size();
    916916}
    917917
  • cpp/frams/genetics/fH/fH_oper.cpp

    r1273 r1299  
    237237
    238238        // used for computing chg
    239         unsigned int sumgenes = creature->sticks.size() + creature->neurons.size() + creature->connections.size();
     239        size_t sumgenes = creature->sticks.size() + creature->neurons.size() + creature->connections.size();
    240240
    241241        // if there is only one element in genotype (stick), then deletion would end
     
    401401unsigned int Geno_fH::getRandomHandle(fH_Builder *creature, fH_Handle *&handle, ParamEntry *&tab, bool skipalonestick)
    402402{
    403         unsigned int allhandlescount = creature->connections.size() + creature->neurons.size();
     403        size_t allhandlescount = creature->connections.size() + creature->neurons.size();
    404404        if (!skipalonestick || creature->sticks.size() > 1)
    405405        {
    406406                allhandlescount += creature->sticks.size();
    407407        }
    408         unsigned int toselect = rndUint(allhandlescount);
    409         if (toselect < creature->connections.size())
     408        int toselect = rndUint(allhandlescount);
     409        if ((size_t)toselect < creature->connections.size())
    410410        {
    411411                handle = creature->connections[toselect];
     
    413413                return toselect;
    414414        }
    415         else if (toselect - creature->connections.size() < creature->neurons.size())
    416         {
    417                 toselect -= creature->connections.size();
     415        else if (toselect - (int)creature->connections.size() < (int)creature->neurons.size())
     416        {
     417                toselect -= (int)creature->connections.size();
    418418                handle = creature->neurons[toselect];
    419419                tab = creature->neuronparamtab;
     420                if (toselect < 0)
     421                        logMessage("Geno_fH", "getRandomHandle", LOG_CRITICAL, "toselect<0");
    420422                return toselect;
    421423        }
    422         toselect -= creature->connections.size() + creature->neurons.size();
     424        toselect -= int(creature->connections.size() + creature->neurons.size());
    423425        handle = creature->sticks[toselect];
    424426        tab = creature->stickparamtab;
     427        if (toselect < 0)
     428                logMessage("Geno_fH", "getRandomHandle", LOG_CRITICAL, "toselect<0");
    425429        return toselect;
    426430}
  • cpp/frams/genetics/fL/fL_matheval.cpp

    r896 r1299  
    648648        if (type == 0)
    649649        {
    650                 count = operatorstrings.size();
     650                count = int(operatorstrings.size());
    651651        }
    652652        else if (type == 2)
    653653        {
    654                 count = operatorstrings.size() - arithmeticoperatorscount;
     654                count = int(operatorstrings.size()) - arithmeticoperatorscount;
    655655        }
    656656        randop += rndUint(count);
     
    662662        if (varcount > 0)
    663663        {
    664                 int currsize = postfixlist.size();
     664                size_t currsize = postfixlist.size();
    665665                int varid = rndUint(varcount);
    666666                postfixlist.push_back(vars[varid]);
     
    704704                std::list<Token *>::iterator it = postfixlist.begin();
    705705                // insertion can be applied from 1st occurrence
    706                 int insertlocation = 1 + rndUint(postfixlist.size() - 1);
     706                int insertlocation = 1 + rndUint((int)postfixlist.size() - 1);
    707707                std::advance(it, insertlocation);
    708708                Operator *rndop;
Note: See TracChangeset for help on using the changeset viewer.