Changeset 803 for cpp/frams/genetics


Ignore:
Timestamp:
06/07/18 17:42:49 (6 years ago)
Author:
Maciej Komosinski
Message:

Performance improvements, including avoiding unnecessary passing of objects by value

Location:
cpp/frams/genetics
Files:
6 edited

Legend:

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

    r797 r803  
    189189}
    190190
    191 int fH_Builder::parseGenotype(SString genotype)
     191int fH_Builder::parseGenotype(const SString &genotype)
    192192{
    193193        // Firstly, number of dimensions is parsed
  • cpp/frams/genetics/fH/fH_general.h

    r797 r803  
    408408         * @return 0 if processing was successful, 1 if parsing of dimensions went wrong or one of genotype lines could not be parsed
    409409         */
    410         int parseGenotype(SString genotype);
     410        int parseGenotype(const SString &genotype);
    411411
    412412        /**
  • cpp/frams/genetics/fH/fH_oper.cpp

    r797 r803  
    255255                fH_Handle *handle = NULL;
    256256                method = FH_OPCOUNT + roulette(addoperations, FH_ADD_OPCOUNT);
     257                if (getActiveNeuroClassCount() == 0) method = FH_OPCOUNT + FH_ADD_STICK;
    257258                switch (method - FH_OPCOUNT)
    258259                {
     
    466467        {
    467468                nc = getRandomNeuroClass();
    468                 if (!nc) nc = Neuro::getClass("N");
     469                // checking of neuron class availability should be checked before
    469470        }
    470471
  • cpp/frams/genetics/fL/fL_general.cpp

    r797 r803  
    7373}
    7474
    75 bool fL_Builder::getNextObject(int &pos, SString src, SString &token)
     75bool fL_Builder::getNextObject(int &pos, const SString &src, SString &token)
    7676{
    7777        // if position exceeds length then return false
     
    130130}
    131131
    132 std::string fL_Builder::trimSpaces(std::string data)
     132std::string fL_Builder::trimSpaces(const std::string& data)
    133133{
    134134        size_t first = data.find_first_not_of(' ');
     
    141141}
    142142
    143 int fL_Builder::createWord(SString token, fL_Word *&word, int numparams, int begin, int end)
     143int fL_Builder::createWord(const SString &token, fL_Word *&word, int numparams, int begin, int end)
    144144{
    145145        SString wordn;
     
    229229}
    230230
    231 int fL_Builder::tokenize(SString sequence, std::list<fL_Word *> &result, int numparams, int begin, int end)
     231int fL_Builder::tokenize(const SString &sequence, std::list<fL_Word *> &result, int numparams, int begin, int end)
    232232{
    233233        int pos = 0;
     
    450450}
    451451
    452 int fL_Builder::processLine(fLElementType type, SString line, fL_Element *&obj, int linenumber, int begin, int end)
     452int fL_Builder::processLine(fLElementType type, const SString &line, fL_Element *&obj, int linenumber, int begin, int end)
    453453{
    454454        ParamEntry *tab;
     
    557557}
    558558
    559 int fL_Builder::parseGenotype(SString genotype)
     559int fL_Builder::parseGenotype(const SString &genotype)
    560560{
    561561        int pos = 0;
     
    13031303                        m->checkpoint();
    13041304                }
    1305                 if (maxwords != -1 && genotype.size() > (unsigned int)maxwords)
     1305                if (maxwords != -1 && ((int)genotype.size()) > maxwords)
    13061306                {
    13071307                        wordsexceeded = true;
  • cpp/frams/genetics/fL/fL_general.h

    r797 r803  
    315315         * @return string with trimmed spaces
    316316         */
    317         static std::string trimSpaces(std::string data);
     317        static std::string trimSpaces(const std::string& data);
    318318
    319319        /**
     
    328328         * @return 0 if processing ended successfully, 1-based position of error otherwise
    329329         */
    330         int processLine(fLElementType type, SString line, fL_Element *&obj, int linenumber, int begin, int end);
     330        int processLine(fLElementType type, const SString &line, fL_Element *&obj, int linenumber, int begin, int end);
    331331
    332332        /**
     
    343343         * @return 0 if processing finished successfully, 1-based position of error if it occured
    344344         */
    345         int parseGenotype(SString genotype);
     345        int parseGenotype(const SString &genotype);
    346346
    347347        /**
     
    365365         * @return true if new token is found, false if there is no more tokens or when there was parenthesis mismatch (if pos == -1, then it is parenthesis mismatch)
    366366         */
    367         bool getNextObject(int &pos, SString src, SString &token);
     367        bool getNextObject(int &pos, const SString &src, SString &token);
    368368
    369369        /**
     
    376376         * @return 0 if conversion went successfully, 1 when there is a problem with parsing
    377377         */
    378         int createWord(SString worddef, fL_Word *&word, int numparams, int begin, int end);
     378        int createWord(const SString &worddef, fL_Word *&word, int numparams, int begin, int end);
    379379
    380380        /**
     
    385385         * @return 0 if tokenizing finished successfully, 1 otherwise
    386386         */
    387         int tokenize(SString sequence, std::list<fL_Word *> &result, int numparams, int begin, int end);
     387        int tokenize(const SString &sequence, std::list<fL_Word *> &result, int numparams, int begin, int end);
    388388
    389389        /**
     
    452452         * @return pointer to the input neuron, or NULL if no neuron could be found
    453453         */
    454         Neuro *findInputNeuron(std::pair<std::list<fL_Word *>::iterator, Neuro *> currneu, fL_Word *attractor);
     454        Neuro* findInputNeuron(std::pair<std::list<fL_Word *>::iterator, Neuro *> currneu, fL_Word *attractor);
    455455
    456456        /**
  • cpp/frams/genetics/fL/fL_oper.cpp

    r797 r803  
    142142                        SString det;
    143143                        NeuroClass *cls = getRandomNeuroClass();
    144                         if (!cls) cls = Neuro::getClass("N");
     144                        //we do not check if this class
    145145                        det = cls->getName();
    146146                        Geno_fH::mutateNeuronProperties(det);
     
    202202                        return creature->words["S"];
    203203                case FL_ADD_NEURO:
    204                         return creature->words["N"];
     204                        if (getActiveNeuroClassCount() == 0)
     205                                return creature->words["S"];
     206                        else
     207                                return creature->words["N"];
    205208                case FL_ADD_CONN:
    206209                        return creature->words["C"];
Note: See TracChangeset for help on using the changeset viewer.