- Timestamp:
- 04/27/23 03:55:33 (20 months ago)
- Location:
- cpp/frams/genetics
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/genetics/genooperators.cpp
r1032 r1226 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-202 0Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2023 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 313 313 } 314 314 315 NeuroClass *GenoOperators::getRandomNeuroClassWithOutputAnd NoInputs(Model::ShapeType for_shape_type)315 NeuroClass *GenoOperators::getRandomNeuroClassWithOutputAndWantingNoInputs(Model::ShapeType for_shape_type) 316 316 { 317 317 vector<NeuroClass *> active; … … 320 320 NeuroClass *nc = Neuro::getClass(i); 321 321 if (nc->isShapeTypeSupported(for_shape_type) && nc->genactive && nc->getPreferredOutput() != 0 && nc->getPreferredInputs() == 0) 322 active.push_back(nc); 323 } 324 if (active.size() == 0) return NULL; else return active[rndUint(active.size())]; 325 } 326 327 NeuroClass *GenoOperators::getRandomNeuroClassWithOutputAndWantingNoOrAnyInputs(Model::ShapeType for_shape_type) 328 { 329 vector<NeuroClass *> active; 330 for (int i = 0; i < Neuro::getClassCount(); i++) 331 { 332 NeuroClass *nc = Neuro::getClass(i); 333 if (nc->isShapeTypeSupported(for_shape_type) && nc->genactive && nc->getPreferredOutput() != 0 && nc->getPreferredInputs() <= 0) // getPreferredInputs() should be 0 or -1 (any) 322 334 active.push_back(nc); 323 335 } … … 353 365 { 354 366 if (!strchrn0(excluded, choices[i])) allowed_count++; 355 if (allowed_count == rnd_index) return i ;367 if (allowed_count == rnd_index) return int(i); 356 368 } 357 369 return -1; //never happens 358 370 } 359 371 360 NeuroClass *GenoOperators::parseNeuroClass(char *&s )372 NeuroClass *GenoOperators::parseNeuroClass(char *&s, ModelEnum::ShapeType supported_shapetype) 361 373 { 362 374 int maxlen = (int)strlen(s); … … 365 377 for (int i = 0; i < Neuro::getClassCount(); i++) 366 378 { 367 const char *ncname = Neuro::getClass(i)->name.c_str(); 368 int ncnamelen = (int)strlen(ncname); 369 if (maxlen >= ncnamelen && ncnamelen > NClen && (strncmp(s, ncname, ncnamelen) == 0)) 370 { 371 NC = Neuro::getClass(i); 372 NClen = ncnamelen; 379 NeuroClass *nci = Neuro::getClass(i); 380 if (!nci->isShapeTypeSupported(supported_shapetype)) 381 continue; 382 const char *nciname = nci->name.c_str(); 383 int ncinamelen = (int)strlen(nciname); 384 if (maxlen >= ncinamelen && ncinamelen > NClen && (strncmp(s, nciname, ncinamelen) == 0)) 385 { 386 NC = nci; 387 NClen = ncinamelen; 373 388 } 374 389 } -
cpp/frams/genetics/genooperators.h
r1032 r1226 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-202 0Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2023 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 202 202 static NeuroClass* getRandomNeuroClassWithOutput(Model::ShapeType for_shape_type); ///<returns random neuroclass with output or NULL when no active classes. 203 203 static NeuroClass* getRandomNeuroClassWithInput(Model::ShapeType for_shape_type); ///<returns random neuroclass with input or NULL when no active classes. 204 static NeuroClass* getRandomNeuroClassWithOutputAndNoInputs(Model::ShapeType for_shape_type); ///<returns random sensor or NULL when no active classes. 204 static NeuroClass* getRandomNeuroClassWithOutputAndWantingNoInputs(Model::ShapeType for_shape_type); ///<returns random sensor or NULL when no active classes. Note: only neuroclasses that prefer 0 inputs are considered, not those that prefer any number of inputs (thus including 0) - see getRandomNeuroClassWithOutputAndWantingNoOrAnyInputs(). 205 static NeuroClass* getRandomNeuroClassWithOutputAndWantingNoOrAnyInputs(Model::ShapeType for_shape_type); ///<returns random neuron or NULL when no active classes. Note: both neuroclasses that prefer 0 inputs and those that prefer any number of inputs (thus including 0) are considered. 205 206 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 206 207 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 207 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.208 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.208 static int getRandomChar(const char *choices, const char *excluded); ///<returns index of a random character from \e choices excluding \e excluded, or -1 when everything is excluded or \e choices is empty. 209 static NeuroClass* parseNeuroClass(char *&s, ModelEnum::ShapeType supported_shapetype); ///<returns the longest matching neuroclass that satisfies supported_shapetype (ModelEnum::SHAPETYPE_BALL_AND_STICK or ModelEnum::SHAPETYPE_SOLIDS) or NULL if the string does not begin with an appropriate neuroclass name. Advances the \e s pointer if the neuroclass is found. 209 210 static Neuro* findNeuro(const Model *m, const NeuroClass *nc); ///<returns pointer to first Neuro of class \e nc, or NULL if there is no such Neuro. 210 static int neuroClassProp(char *&s, NeuroClass *nc, bool also_v1_N_props = false); ///<returns 0-based extraproperty of NeuroClass or NEUROCLASS_PROP_OFFSET-based standard property of NeuroClass, or -1 if the string does not begin with a valid property name. Advance \e s pointer if success.211 static int neuroClassProp(char *&s, NeuroClass *nc, bool also_v1_N_props = false); ///<returns 0-based extraproperty of NeuroClass or NEUROCLASS_PROP_OFFSET-based standard property of NeuroClass, or -1 if the string does not begin with a valid property name. Advance the \e s pointer if success. 211 212 static bool isWS(const char c); ///<is \e c a whitespace char? 212 213 static void skipWS(char *&s); ///<advances pointer \e s skipping whitespaces.
Note: See TracChangeset
for help on using the changeset viewer.