Changeset 821


Ignore:
Timestamp:
10/10/18 01:13:05 (5 years ago)
Author:
Maciej Komosinski
Message:

Performance and stability improvements in fB, fH, and fL; improved parsing and math evaluations in fL

Location:
cpp/frams/genetics
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/fB/fB_conv.cpp

    r802 r821  
    163163                                fHgenotype.getNextToken(fHpos, line, '\n');
    164164                                map->add(ranges[t][q].begin, ranges[t][q].end, lastpos, fHpos - 1);
     165                                lastpos = fHpos;
    165166                        }
    166167                }
  • cpp/frams/genetics/fB/fB_oper.cpp

    r802 r821  
    3939}
    4040
    41 bool Geno_fB::hasStick(SString genotype)
     41bool Geno_fB::hasStick(const SString &genotype)
    4242{
    4343        for (int i = 0; i < fB_GenoHelpers::geneCount(genotype); i++)
     
    194194}
    195195
    196 SString Geno_fB::detokenizeSequence(std::list<SString> tokenlist)
     196SString Geno_fB::detokenizeSequence(std::list<SString> *tokenlist)
    197197{
    198198        SString res = "";
    199         for (std::list<SString>::iterator it = tokenlist.begin(); it != tokenlist.end(); it++)
     199        for (std::list<SString>::iterator it = tokenlist->begin(); it != tokenlist->end(); it++)
    200200        {
    201201                res += (*it);
     
    204204}
    205205
    206 std::list<SString> Geno_fB::tokenizeSequence(SString genotype)
     206std::list<SString> Geno_fB::tokenizeSequence(const SString &genotype)
    207207{
    208208        std::list<SString> res;
     
    278278                        chg = (double)def.len() / line.len();
    279279                }
    280                 line = detokenizeSequence(tokenized);
     280                line = detokenizeSequence(&tokenized);
    281281                break;
    282282        }
     
    297297                        tokenized.insert(it, res);
    298298                        chg = (double)classdef.len() / line.len();
    299                         line = detokenizeSequence(tokenized);
     299                        line = detokenizeSequence(&tokenized);
    300300                        break;
    301301                }
     
    312312                letter.directWrite()[0] = 'a' + randomN(26);
    313313                tokenized.insert(it, letter);
    314                 line = detokenizeSequence(tokenized);
     314                line = detokenizeSequence(&tokenized);
    315315                break;
    316316        }
     
    323323                std::advance(it, rndid);
    324324                tokenized.erase(it);
    325                 line = detokenizeSequence(tokenized);
     325                line = detokenizeSequence(&tokenized);
    326326                break;
    327327        }
     
    363363//              SString result = line.substr(0, cuts[0]) + second +
    364364//                      line.substr(cuts[1], cuts[2] - cuts[1]) + first + line.substr(cuts[3]);
    365                 line = detokenizeSequence(res);
     365                line = detokenizeSequence(&res);
    366366                chg = (float)(cuts[3] - cuts[2] + cuts[1] - cuts[0]) / line.len();
    367367                break;
  • cpp/frams/genetics/fB/fB_oper.h

    r797 r821  
    3030{
    3131private:
    32         bool hasStick(SString genotype);
    33         SString detokenizeSequence(std::list<SString> tokenlist);
    34         std::list<SString> tokenizeSequence(SString genotype);
     32        bool hasStick(const SString &genotype);
     33        SString detokenizeSequence(std::list<SString> *tokenlist);
     34        std::list<SString> tokenizeSequence(const SString &genotype);
    3535
    3636public:
  • cpp/frams/genetics/fH/fH_general.cpp

    r803 r821  
    344344// Creature build functions
    345345
    346 Part * fH_StickHandle::createPart(ParamEntry *tab, std::vector<fH_StickHandle *> children, Model *model, bool createmapping)
     346Part * fH_StickHandle::createPart(ParamEntry *tab, std::vector<fH_StickHandle *> *children, Model *model, bool createmapping)
    347347{
    348348        Param par(tab, obj);
     
    353353        }
    354354
    355         unsigned int stickscount = children.size() + 1;
     355        unsigned int stickscount = children->size() + 1;
    356356
    357357        MultiRange ranges;
    358358        ranges.add(begin, end);
    359359
    360         for (fH_StickHandle *child : children)
     360        for (fH_StickHandle *child : (*children))
    361361        {
    362362                par.select(child->obj);
     
    753753                {
    754754                        vector<fH_StickHandle *> emptylist;
    755                         Part *firstpart = currstick->createPart(stickparamtab, emptylist, model, createmapping);
     755                        Part *firstpart = currstick->createPart(stickparamtab, &emptylist, model, createmapping);
    756756                        firstpart->p = Pt3D(0);
    757757                        currstick->firstpart = firstpart;
     
    847847                }
    848848                // create part from current stick and other sticks connected to this part
    849                 Part *secondpart = currstick->createPart(stickparamtab, children, model, createmapping);
     849                Part *secondpart = currstick->createPart(stickparamtab, &children, model, createmapping);
    850850                secondpart->p = secondposition;
    851851                currstick->secondpart = secondpart;
  • cpp/frams/genetics/fH/fH_general.h

    r803 r821  
    173173         * @return created part
    174174         */
    175         Part *createPart(ParamEntry *tab, std::vector<fH_StickHandle *> children, Model *model, bool createmapping);
     175        Part *createPart(ParamEntry *tab, std::vector<fH_StickHandle *> *children, Model *model, bool createmapping);
    176176
    177177        /**
  • cpp/frams/genetics/fL/fL_general.cpp

    r803 r821  
    488488                std::string message = "Error in parsing parameters at line:  " + std::to_string(linenumber);
    489489                logMessage("fL_Builder", "processLine", LOG_ERROR, message.c_str());
    490                 delete obj;
     490                if (obj != this) delete obj;
    491491                return begin + 1;
    492492        }
     
    13391339}
    13401340
    1341 int fL_Builder::countSticksInSequence(std::list<fL_Word *> sequence)
     1341int fL_Builder::countSticksInSequence(std::list<fL_Word *> *sequence)
    13421342{
    13431343        int count = 0;
    1344         for (std::list<fL_Word *>::iterator it = sequence.begin(); it != sequence.end(); it++)
     1344        for (std::list<fL_Word *>::iterator it = sequence->begin(); it != sequence->end(); it++)
    13451345        {
    13461346                if ((*it)->builtin && (*it)->name == "S")
  • cpp/frams/genetics/fL/fL_general.h

    r803 r821  
    482482         * @return number of sticks in sequence
    483483         */
    484         int countSticksInSequence(std::list<fL_Word *> sequence);
     484        int countSticksInSequence(std::list<fL_Word *> *sequence);
    485485
    486486        /**
  • cpp/frams/genetics/fL/fL_matheval.cpp

    r797 r821  
    116116        registerOperator(meqless, 1, Associativity::LEFT, "<=");
    117117        registerOperator(mequal, 1, Associativity::RIGHT, "=");
    118         registerOperator(mnotequal, 1, Associativity::RIGHT, "~");
     118        registerOperator(mnotequal, 1, Associativity::RIGHT, "<>");
    119119        registerOperator(mand, 0, Associativity::LEFT, "&");
    120120        registerOperator(mor, 0, Associativity::LEFT, "|");
  • cpp/frams/genetics/fL/fL_oper.cpp

    r803 r821  
    6464        }
    6565
    66         if (builder.countSticksInSequence(builder.genotype) == 0)
     66        if (builder.countSticksInSequence(&builder.genotype) == 0)
    6767        {
    6868                return GENOPER_OPFAIL;
     
    142142                        SString det;
    143143                        NeuroClass *cls = getRandomNeuroClass();
    144                         //we do not check if this class
    145144                        det = cls->getName();
    146145                        Geno_fH::mutateNeuronProperties(det);
     
    418417                        int ruleid = 0;
    419418                        std::list<fL_Word *> *list = selectRandomSequence(creature, numpars, ruleid);
    420                         if (ruleid == -1 && creature->countSticksInSequence((*list)) == 1)
     419                        if (ruleid == -1 && creature->countSticksInSequence(list) == 1)
    421420                        {
    422421                                if (list->size() > 1)
     
    540539                        }
    541540                        int chgtype = roulette(chgoperations, FL_CHG_COUNT);
    542                         if (creature->countSticksInSequence((*list)) == 1 && tmp == -1) // if sequence is axiom
     541                        if (creature->countSticksInSequence(list) == 1 && tmp == -1) // if sequence is axiom
    543542                        {
    544543                                fL_Word *worddef = randomWordDefinition(creature, roulette(addtypes, FL_ADD_COUNT - 1));
Note: See TracChangeset for help on using the changeset viewer.