- Timestamp:
- 05/29/20 15:20:29 (4 years ago)
- Location:
- cpp/frams
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/genetics/f4/f4_oper.cpp
r899 r935 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 17Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 164 164 { 165 165 // make neuron 166 NeuroClass *rndclass = GenoOperators::getRandomNeuroClass( );166 NeuroClass *rndclass = GenoOperators::getRandomNeuroClass(Model::SHAPE_BALL_AND_STICK); 167 167 if (rndclass == NULL) 168 168 { … … 434 434 { 435 435 // '*', 'G', 'T', or 'S', 1/4 chance each 436 nc = GenoOperators::getRandomNeuroClassWithOutputAndNoInputs( );436 nc = GenoOperators::getRandomNeuroClassWithOutputAndNoInputs(Model::SHAPE_BALL_AND_STICK); 437 437 } 438 438 if (nc != NULL) … … 470 470 if (rndDouble(1) < 0.2f) 471 471 { 472 cl = GenoOperators::getRandomNeuroClassWithOutputAndNoInputs( );472 cl = GenoOperators::getRandomNeuroClassWithOutputAndNoInputs(Model::SHAPE_BALL_AND_STICK); 473 473 if (cl != NULL) 474 474 { -
cpp/frams/genetics/fB/fB_oper.cpp
r896 r935 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 19Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 287 287 int rndid = rndUint(tokenized.size()); // select random insertion point 288 288 std::advance(it, rndid); 289 NeuroClass *cls = getRandomNeuroClass( );289 NeuroClass *cls = getRandomNeuroClass(Model::SHAPE_BALL_AND_STICK); 290 290 if (cls) 291 291 { -
cpp/frams/genetics/fH/fH_oper.cpp
r896 r935 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 18Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 255 255 fH_Handle *handle = NULL; 256 256 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; 258 258 switch (method - FH_OPCOUNT) 259 259 { … … 466 466 if (userandomclass) 467 467 { 468 nc = getRandomNeuroClass( );468 nc = getRandomNeuroClass(Model::SHAPE_BALL_AND_STICK); 469 469 // checking of neuron class availability should be checked before 470 470 } … … 503 503 uint32_t Geno_fH::style(const char *g, int pos) 504 504 { 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 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 19Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 141 141 { 142 142 SString det; 143 NeuroClass *cls = getRandomNeuroClass( );143 NeuroClass *cls = getRandomNeuroClass(Model::SHAPE_BALL_AND_STICK); 144 144 det = cls->getName(); 145 145 Geno_fH::mutateNeuronProperties(det); … … 201 201 return creature->words["S"]; 202 202 case FL_ADD_NEURO: 203 if (getActiveNeuroClassCount( ) == 0)203 if (getActiveNeuroClassCount(Model::SHAPE_BALL_AND_STICK) == 0) 204 204 return creature->words["S"]; 205 205 else -
cpp/frams/genetics/genooperators.cpp
r899 r935 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 18Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 223 223 } 224 224 225 int GenoOperators::getActiveNeuroClassCount( )225 int GenoOperators::getActiveNeuroClassCount(Model::ShapeType for_shape_type) 226 226 { 227 227 int count = 0; 228 228 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) 230 232 count++; 233 } 231 234 return count; 232 235 } 233 236 234 NeuroClass *GenoOperators::getRandomNeuroClass( )237 NeuroClass *GenoOperators::getRandomNeuroClass(Model::ShapeType for_shape_type) 235 238 { 236 239 vector<NeuroClass *> active; 237 240 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 } 240 246 if (active.size() == 0) return NULL; else return active[rndUint(active.size())]; 241 247 } 242 248 243 NeuroClass *GenoOperators::getRandomNeuroClassWithOutput( )249 NeuroClass *GenoOperators::getRandomNeuroClassWithOutput(Model::ShapeType for_shape_type) 244 250 { 245 251 vector<NeuroClass *> active; 246 252 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 } 249 258 if (active.size() == 0) return NULL; else return active[rndUint(active.size())]; 250 259 } 251 260 252 NeuroClass *GenoOperators::getRandomNeuroClassWithInput( )261 NeuroClass *GenoOperators::getRandomNeuroClassWithInput(Model::ShapeType for_shape_type) 253 262 { 254 263 vector<NeuroClass *> active; 255 264 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 } 258 270 if (active.size() == 0) return NULL; else return active[rndUint(active.size())]; 259 271 } 260 272 261 NeuroClass *GenoOperators::getRandomNeuroClassWithOutputAndNoInputs( )273 NeuroClass *GenoOperators::getRandomNeuroClassWithOutputAndNoInputs(Model::ShapeType for_shape_type) 262 274 { 263 275 vector<NeuroClass *> active; 264 276 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 } 267 282 if (active.size() == 0) return NULL; else return active[rndUint(active.size())]; 268 283 } -
cpp/frams/genetics/genooperators.h
r899 r935 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 18Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 193 193 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). 194 194 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 count196 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 classes201 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 classes195 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 202 202 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. 203 203 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 208 static bool areAlike(char*, char*); ///<compares two text strings skipping whitespaces. Returns 1 when equal, 0 when different. 209 209 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 m aystart 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. 211 211 //@} 212 212 }; -
cpp/frams/model/model.h
r932 r935 54 54 */ 55 55 56 class Model : public DestrBase 56 class Model : public DestrBase, public ModelEnum 57 57 { 58 58 protected: … … 93 93 94 94 public: 95 enum ShapeType { SHAPE_BALL_AND_STICK = 0, SHAPE_SOLIDS = 1, SHAPE_UNKNOWN, SHAPE_ILLEGAL };96 95 /// used in internalCheck() 97 96 enum CheckType { … … 407 406 /////////////////////////// 408 407 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(); 412 411 static Joint &getMinJoint(); 413 412 static Joint &getMaxJoint(); -
cpp/frams/neuro/neurofactory.cpp
r933 r935 26 26 if (!nc) return 0; 27 27 if (!nc->active) return 0; 28 if (!(nc-> supported_shape_types & (1 << (int)shape_type)))28 if (!(nc->isShapeTypeSupported(shape_type))) 29 29 { 30 30 logPrintf("NeuroFactory", "createNeuroImpl", LOG_WARN,
Note: See TracChangeset
for help on using the changeset viewer.