Changeset 935 for cpp/frams


Ignore:
Timestamp:
05/29/20 15:20:29 (5 years ago)
Author:
Maciej Komosinski
Message:

Utility functions that provide a set of all neuron classes fulfilling given criteria now also filter neuron classes by the desired Model shape type (BALL_AND_STICK or SOLIDS)

Location:
cpp/frams
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/f4/f4_oper.cpp

    r899 r935  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2017  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    164164                        {
    165165                                // make neuron
    166                                 NeuroClass *rndclass = GenoOperators::getRandomNeuroClass();
     166                                NeuroClass *rndclass = GenoOperators::getRandomNeuroClass(Model::SHAPE_BALL_AND_STICK);
    167167                                if (rndclass == NULL)
    168168                                {
     
    434434        {
    435435                // '*', 'G', 'T', or 'S', 1/4 chance each
    436                 nc = GenoOperators::getRandomNeuroClassWithOutputAndNoInputs();
     436                nc = GenoOperators::getRandomNeuroClassWithOutputAndNoInputs(Model::SHAPE_BALL_AND_STICK);
    437437        }
    438438        if (nc != NULL)
     
    470470                if (rndDouble(1) < 0.2f)
    471471                {
    472                         cl = GenoOperators::getRandomNeuroClassWithOutputAndNoInputs();
     472                        cl = GenoOperators::getRandomNeuroClassWithOutputAndNoInputs(Model::SHAPE_BALL_AND_STICK);
    473473                        if (cl != NULL)
    474474                        {
  • cpp/frams/genetics/fB/fB_oper.cpp

    r896 r935  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2019  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    287287                int rndid = rndUint(tokenized.size()); // select random insertion point
    288288                std::advance(it, rndid);
    289                 NeuroClass *cls = getRandomNeuroClass();
     289                NeuroClass *cls = getRandomNeuroClass(Model::SHAPE_BALL_AND_STICK);
    290290                if (cls)
    291291                {
  • cpp/frams/genetics/fH/fH_oper.cpp

    r896 r935  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    255255                fH_Handle *handle = NULL;
    256256                method = FH_OPCOUNT + roulette(addoperations, FH_ADD_OPCOUNT);
    257                 if (getActiveNeuroClassCount() == 0) method = FH_OPCOUNT + FH_ADD_STICK;
     257                if (getActiveNeuroClassCount(Model::SHAPE_BALL_AND_STICK) == 0) method = FH_OPCOUNT + FH_ADD_STICK;
    258258                switch (method - FH_OPCOUNT)
    259259                {
     
    466466        if (userandomclass)
    467467        {
    468                 nc = getRandomNeuroClass();
     468                nc = getRandomNeuroClass(Model::SHAPE_BALL_AND_STICK);
    469469                // checking of neuron class availability should be checked before
    470470        }
     
    503503uint32_t Geno_fH::style(const char *g, int pos)
    504504{
    505    char ch=g[pos];
    506    uint32_t style=GENSTYLE_CS(0,GENSTYLE_NONE); //default, should be changed below
    507 
    508    int pp=pos; //detect comment line
    509    while (pp>1 && g[pp-1]!='\n') pp--;
    510    if (g[pp]=='#') return GENSTYLE_RGBS(0,220,0,GENSTYLE_NONE); //comment line
    511 
    512    if (pos==0 || g[pos-1]=='\n' || ch==':' || ch==',') style=GENSTYLE_CS(0,GENSTYLE_BOLD); else
    513      if (ch=='\"') style=GENSTYLE_RGBS(150,0,0,GENSTYLE_BOLD); else
    514      {
    515       int cudz=0,neuclass=1; //ile cudz. do poczatku linii; czy w nazwie neuroklasy?
    516       while (pos>0)
    517       {
    518          pos--;
    519          if (g[pos]=='\"') cudz++;
    520          if (cudz==0 && (g[pos]==':' || g[pos]==',')) neuclass=0;
    521          if (g[pos]=='\n') break;
    522       }
    523       if (cudz%2)
    524       {
    525          if (neuclass) style=GENSTYLE_RGBS(150,0,150,GENSTYLE_BOLD); else //neuroclass
    526            if (isalpha(ch)) style=GENSTYLE_RGBS(255,140,0,GENSTYLE_BOLD); else //property
    527              style=GENSTYLE_RGBS(200,0,0,GENSTYLE_NONE);
    528       } else
    529         if (isalpha(ch)) style=GENSTYLE_RGBS(0,0,200,GENSTYLE_BOLD);
    530      }
    531    return style;
    532 }
     505        char ch = g[pos];
     506        uint32_t style = GENSTYLE_CS(0, GENSTYLE_NONE); //default, should be changed below
     507
     508        int pp = pos; //detect comment line
     509        while (pp > 1 && g[pp - 1] != '\n') pp--;
     510        if (g[pp] == '#') return GENSTYLE_RGBS(0, 220, 0, GENSTYLE_NONE); //comment line
     511
     512        if (pos == 0 || g[pos - 1] == '\n' || ch == ':' || ch == ',') style = GENSTYLE_CS(0, GENSTYLE_BOLD); else
     513                if (ch == '\"') style = GENSTYLE_RGBS(150, 0, 0, GENSTYLE_BOLD); else
     514                {
     515                        int cudz = 0, neuclass = 1; //ile cudz. do poczatku linii; czy w nazwie neuroklasy?
     516                        while (pos > 0)
     517                        {
     518                                pos--;
     519                                if (g[pos] == '\"') cudz++;
     520                                if (cudz == 0 && (g[pos] == ':' || g[pos] == ',')) neuclass = 0;
     521                                if (g[pos] == '\n') break;
     522                        }
     523                        if (cudz % 2)
     524                        {
     525                                if (neuclass) style = GENSTYLE_RGBS(150, 0, 150, GENSTYLE_BOLD); else //neuroclass
     526                                        if (isalpha(ch)) style = GENSTYLE_RGBS(255, 140, 0, GENSTYLE_BOLD); else //property
     527                                                style = GENSTYLE_RGBS(200, 0, 0, GENSTYLE_NONE);
     528                        }
     529                        else
     530                                if (isalpha(ch)) style = GENSTYLE_RGBS(0, 0, 200, GENSTYLE_BOLD);
     531                }
     532        return style;
     533}
  • cpp/frams/genetics/fL/fL_oper.cpp

    r896 r935  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2019  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    141141                {
    142142                        SString det;
    143                         NeuroClass *cls = getRandomNeuroClass();
     143                        NeuroClass *cls = getRandomNeuroClass(Model::SHAPE_BALL_AND_STICK);
    144144                        det = cls->getName();
    145145                        Geno_fH::mutateNeuronProperties(det);
     
    201201                        return creature->words["S"];
    202202                case FL_ADD_NEURO:
    203                         if (getActiveNeuroClassCount() == 0)
     203                        if (getActiveNeuroClassCount(Model::SHAPE_BALL_AND_STICK) == 0)
    204204                                return creature->words["S"];
    205205                        else
  • cpp/frams/genetics/genooperators.cpp

    r899 r935  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    223223}
    224224
    225 int GenoOperators::getActiveNeuroClassCount()
     225int GenoOperators::getActiveNeuroClassCount(Model::ShapeType for_shape_type)
    226226{
    227227        int count = 0;
    228228        for (int i = 0; i < Neuro::getClassCount(); i++)
    229                 if (Neuro::getClass(i)->genactive)
     229        {
     230                NeuroClass *nc = Neuro::getClass(i);
     231                if (nc->isShapeTypeSupported(for_shape_type) && nc->genactive)
    230232                        count++;
     233        }
    231234        return count;
    232235}
    233236
    234 NeuroClass *GenoOperators::getRandomNeuroClass()
     237NeuroClass *GenoOperators::getRandomNeuroClass(Model::ShapeType for_shape_type)
    235238{
    236239        vector<NeuroClass *> active;
    237240        for (int i = 0; i < Neuro::getClassCount(); i++)
    238                 if (Neuro::getClass(i)->genactive)
    239                         active.push_back(Neuro::getClass(i));
     241        {
     242                NeuroClass *nc = Neuro::getClass(i);
     243                if (nc->isShapeTypeSupported(for_shape_type) && nc->genactive)
     244                        active.push_back(nc);
     245        }
    240246        if (active.size() == 0) return NULL; else return active[rndUint(active.size())];
    241247}
    242248
    243 NeuroClass *GenoOperators::getRandomNeuroClassWithOutput()
     249NeuroClass *GenoOperators::getRandomNeuroClassWithOutput(Model::ShapeType for_shape_type)
    244250{
    245251        vector<NeuroClass *> active;
    246252        for (int i = 0; i < Neuro::getClassCount(); i++)
    247                 if (Neuro::getClass(i)->genactive && Neuro::getClass(i)->getPreferredOutput() != 0)
    248                         active.push_back(Neuro::getClass(i));
     253        {
     254                NeuroClass *nc = Neuro::getClass(i);
     255                if (nc->isShapeTypeSupported(for_shape_type) && nc->genactive && nc->getPreferredOutput() != 0)
     256                        active.push_back(nc);
     257        }
    249258        if (active.size() == 0) return NULL; else return active[rndUint(active.size())];
    250259}
    251260
    252 NeuroClass *GenoOperators::getRandomNeuroClassWithInput()
     261NeuroClass *GenoOperators::getRandomNeuroClassWithInput(Model::ShapeType for_shape_type)
    253262{
    254263        vector<NeuroClass *> active;
    255264        for (int i = 0; i < Neuro::getClassCount(); i++)
    256                 if (Neuro::getClass(i)->genactive && Neuro::getClass(i)->getPreferredInputs() != 0)
    257                         active.push_back(Neuro::getClass(i));
     265        {
     266                NeuroClass *nc = Neuro::getClass(i);
     267                if (nc->isShapeTypeSupported(for_shape_type) && nc->genactive && nc->getPreferredInputs() != 0)
     268                        active.push_back(nc);
     269        }
    258270        if (active.size() == 0) return NULL; else return active[rndUint(active.size())];
    259271}
    260272
    261 NeuroClass *GenoOperators::getRandomNeuroClassWithOutputAndNoInputs()
     273NeuroClass *GenoOperators::getRandomNeuroClassWithOutputAndNoInputs(Model::ShapeType for_shape_type)
    262274{
    263275        vector<NeuroClass *> active;
    264276        for (int i = 0; i < Neuro::getClassCount(); i++)
    265                 if (Neuro::getClass(i)->genactive && Neuro::getClass(i)->getPreferredOutput() != 0 && Neuro::getClass(i)->getPreferredInputs() == 0)
    266                         active.push_back(Neuro::getClass(i));
     277        {
     278                NeuroClass *nc = Neuro::getClass(i);
     279                if (nc->isShapeTypeSupported(for_shape_type) && nc->genactive && nc->getPreferredOutput() != 0 && nc->getPreferredInputs() == 0)
     280                        active.push_back(nc);
     281        }
    267282        if (active.size() == 0) return NULL; else return active[rndUint(active.size())];
    268283}
  • cpp/frams/genetics/genooperators.h

    r899 r935  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    193193        static void linearMix(vector<double> &p1, vector<double> &p2, double proportion); ///<mixes two real-valued vectors; inherited proportion should be within [0,1]; 1.0 does not change values (all inherited), 0.5 causes both vectors to become their average, 0.0 swaps values (none inherited).
    194194        static void linearMix(ParamInterface &p1, int i1, ParamInterface &p2, int i2, double proportion); ///<mixes i1'th and i2'th properties of p1 and p2; inherited proportion should be within [0,1]; 1.0 does not change values (all inherited), 0.5 causes both properties to become their average, 0.0 swaps values (none inherited). For integer properties applies random "dithering" when necessary.
    195         static int getActiveNeuroClassCount(); ///<returns active class count
    196         static NeuroClass* getRandomNeuroClass(); ///<returns random neuroclass or NULL when no active classes.
    197         static NeuroClass* getRandomNeuroClassWithOutput(); ///<returns random neuroclass with output or NULL when no active classes.
    198         static NeuroClass* getRandomNeuroClassWithInput(); ///<returns random neuroclass with input or NULL when no active classes.
    199         static NeuroClass* getRandomNeuroClassWithOutputAndNoInputs(); ///<returns random sensor or NULL when no active classes.
    200         static int getRandomNeuroClassWithOutput(const vector<NeuroClass*>& NClist); ///<returns index of random NeuroClass from the NClist or -1 (no neurons on the list that provide output) \e NClist list of available neuron classes
    201         static int getRandomNeuroClassWithInput(const vector<NeuroClass*>& NClist); ///<returns index of random NeuroClass from the NClist or -1 (no neurons on the list that want input(s)) \e NClist list of available neuron classes
     195        static int getActiveNeuroClassCount(Model::ShapeType for_shape_type); ///<returns active class count
     196        static NeuroClass* getRandomNeuroClass(Model::ShapeType for_shape_type); ///<returns random neuroclass or NULL when no active classes.
     197        static NeuroClass* getRandomNeuroClassWithOutput(Model::ShapeType for_shape_type); ///<returns random neuroclass with output or NULL when no active classes.
     198        static NeuroClass* getRandomNeuroClassWithInput(Model::ShapeType for_shape_type); ///<returns random neuroclass with input or NULL when no active classes.
     199        static NeuroClass* getRandomNeuroClassWithOutputAndNoInputs(Model::ShapeType for_shape_type); ///<returns random sensor or NULL when no active classes.
     200        static int getRandomNeuroClassWithOutput(const vector<NeuroClass*>& NClist); ///<returns index of random NeuroClass from the NClist or -1 when no neurons in the list provide output \e NClist list of available neuron classes
     201        static int getRandomNeuroClassWithInput(const vector<NeuroClass*>& NClist); ///<returns index of random NeuroClass from the NClist or -1 when no neurons in the list want input(s) \e NClist list of available neuron classes
    202202        static int getRandomChar(const char *choices, const char *excluded); ///<returns index of a random character from 'choices' excluding 'excluded', or -1 when everything is excluded or 'choices' is empty.
    203203        static NeuroClass* parseNeuroClass(char *&s); ///<returns longest matching neuroclass or NULL if the string does not begin with a valid neuroclass name. Advances \e s pointer.
     
    208208        static bool areAlike(char*, char*); ///<compares two text strings skipping whitespaces. Returns 1 when equal, 0 when different.
    209209        static char* strchrn0(const char *str, char ch); ///<like strchr, but does not find zero char in \e str.
    210         static bool canStartNeuroClassName(const char firstchar); ///<determines if \e firstchar may start NeuroClass name. If not, it may start NeuroClass' (or Neuro's) property name.
     210        static bool canStartNeuroClassName(const char firstchar); ///<determines if \e firstchar may start NeuroClass name. If not, it might start NeuroClass' (or Neuro's) property name.
    211211        //@}
    212212};
  • cpp/frams/model/model.h

    r932 r935  
    5454        */
    5555
    56 class Model : public DestrBase
     56class Model : public DestrBase, public ModelEnum
    5757{
    5858protected:
     
    9393
    9494public:
    95         enum ShapeType { SHAPE_BALL_AND_STICK = 0, SHAPE_SOLIDS = 1, SHAPE_UNKNOWN, SHAPE_ILLEGAL };
    9695        /// used in internalCheck()
    9796        enum CheckType {
     
    407406        ///////////////////////////
    408407
    409         static Part &getMinPart();
    410         static Part &getMaxPart();
    411         static Part &getDefPart();
     408        static Part_MinMaxDef &getMinPart();
     409        static Part_MinMaxDef &getMaxPart();
     410        static Part_MinMaxDef &getDefPart();
    412411        static Joint &getMinJoint();
    413412        static Joint &getMaxJoint();
  • cpp/frams/neuro/neurofactory.cpp

    r933 r935  
    2626        if (!nc) return 0;
    2727        if (!nc->active) return 0;
    28         if (!(nc->supported_shape_types & (1 << (int)shape_type)))
     28        if (!(nc->isShapeTypeSupported(shape_type)))
    2929        {
    3030                logPrintf("NeuroFactory", "createNeuroImpl", LOG_WARN,
Note: See TracChangeset for help on using the changeset viewer.