- Timestamp:
- 11/30/19 02:13:25 (5 years ago)
- Location:
- cpp
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/common/nonstd_math.h
r896 r899 68 68 69 69 #endif 70 -
cpp/frams/genetics/f4/f4_oper.cpp
r896 r899 448 448 int relid = neuid - id; 449 449 nn->l1 = relid; 450 //nn->l1 = (int)(4.0f * (rnd 01- 0.5f));450 //nn->l1 = (int)(4.0f * (rndDouble(1) - 0.5f)); 451 451 } 452 452 // weight 453 453 nn->f1 = GenoOperators::mutateNeuProperty(nn->f1, NULL, -1); 454 //nn->f1 = 10.0f * (rnd 01- 0.5f);454 //nn->f1 = 10.0f * (rndDouble(1) - 0.5f); 455 455 } 456 456 … … 485 485 nn->l1 = neuid - id; 486 486 } 487 //nn->l1 += (int)(2.0f * (rnd 01- 0.5f));487 //nn->l1 += (int)(2.0f * (rndDouble(1) - 0.5f)); 488 488 break; 489 489 case 2: // change weight 490 490 nn->f1 = GenoOperators::mutateNeuProperty(nn->f1, NULL, -1); 491 //nn->f1 += 1.0f * (rnd 01- 0.5f);491 //nn->f1 += 1.0f * (rndDouble(1) - 0.5f); 492 492 break; 493 493 } … … 630 630 631 631 // decide number of nodes to mutate 632 n = (int)( 0.5f + rnd 01* maxToMut );632 n = (int)( 0.5f + rndDouble(1) * maxToMut ); 633 633 if (n<1) n=1; 634 634 if (n>totNodes) n=totNodes; -
cpp/frams/genetics/f9/f9_oper.cpp
r896 r899 5 5 #include "f9_oper.h" 6 6 #include "f9_conv.h" 7 #include <common/nonstd.h> //rndUint, rnd 017 #include <common/nonstd.h> //rndUint, rndDouble 8 8 9 9 -
cpp/frams/genetics/fF/fF_oper.cpp
r896 r899 5 5 #include "fF_oper.h" 6 6 #include "fF_genotype.h" 7 #include <common/nonstd.h> //rndUint, rnd 017 #include <common/nonstd.h> //rndUint, rndDouble 8 8 9 9 -
cpp/frams/genetics/fT/fTest_oper.cpp
r896 r899 4 4 5 5 #include "fTest_oper.h" 6 #include <common/nonstd.h> //randomN, rnd 016 #include <common/nonstd.h> //randomN, rndDouble 7 7 8 8 /** -
cpp/frams/genetics/fn/fn_oper.cpp
r896 r899 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-201 8Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2019 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 5 5 #include "fn_oper.h" 6 6 #include "fn_conv.h" 7 #include <common/nonstd.h> //rndUint, rnd 017 #include <common/nonstd.h> //rndUint, rndDouble 8 8 9 9 -
cpp/frams/genetics/genooperators.cpp
r896 r899 76 76 } 77 77 78 int GenoOperators::selectRandomProperty(Neuro *n)78 int GenoOperators::selectRandomProperty(Neuro *n) 79 79 { 80 80 int neuext = n->extraProperties().getPropCount(), … … 129 129 if (strcmp(n, "fo") == 0 && strcmp(na, "Force") == 0) newval = CustomRnd(distrib_force); else 130 130 { 131 double mn, mx, df;132 getMinMaxDef(&p, i, mn, mx, df);133 newval = mutateCreep(p.type(i)[0], oldval, mn, mx, true);131 double mn, mx, df; 132 getMinMaxDef(&p, i, mn, mx, df); 133 newval = mutateCreep(p.type(i)[0], oldval, mn, mx, true); 134 134 } 135 135 return true; … … 195 195 double v1 = p1[i]; 196 196 double v2 = p2[i]; 197 p1[i] = v1 *proportion + v2*(1 - proportion);198 p2[i] = v2 *proportion + v1*(1 - proportion);197 p1[i] = v1 * proportion + v2 * (1 - proportion); 198 p2[i] = v2 * proportion + v1 * (1 - proportion); 199 199 } 200 200 } … … 208 208 double v1 = p1.getDouble(i1); 209 209 double v2 = p2.getDouble(i2); 210 p1.setDouble(i1, v1 *proportion + v2*(1 - proportion));211 p2.setDouble(i2, v2 *proportion + v1*(1 - proportion));210 p1.setDouble(i1, v1 * proportion + v2 * (1 - proportion)); 211 p2.setDouble(i2, v2 * proportion + v1 * (1 - proportion)); 212 212 } 213 213 else 214 214 if (type1 == 'd' && type2 == 'd') 215 215 { 216 int v1 = p1.getInt(i1);217 int v2 = p2.getInt(i2);218 setIntFromDoubleWithProbabilisticDithering(p1, i1, v1*proportion + v2*(1 - proportion));219 setIntFromDoubleWithProbabilisticDithering(p2, i2, v2*proportion + v1*(1 - proportion));216 int v1 = p1.getInt(i1); 217 int v2 = p2.getInt(i2); 218 setIntFromDoubleWithProbabilisticDithering(p1, i1, v1 * proportion + v2 * (1 - proportion)); 219 setIntFromDoubleWithProbabilisticDithering(p2, i2, v2 * proportion + v1 * (1 - proportion)); 220 220 } 221 221 else … … 232 232 } 233 233 234 NeuroClass *GenoOperators::getRandomNeuroClass()235 { 236 vector<NeuroClass *> active;234 NeuroClass *GenoOperators::getRandomNeuroClass() 235 { 236 vector<NeuroClass *> active; 237 237 for (int i = 0; i < Neuro::getClassCount(); i++) 238 238 if (Neuro::getClass(i)->genactive) … … 241 241 } 242 242 243 NeuroClass *GenoOperators::getRandomNeuroClassWithOutput()244 { 245 vector<NeuroClass *> active;243 NeuroClass *GenoOperators::getRandomNeuroClassWithOutput() 244 { 245 vector<NeuroClass *> active; 246 246 for (int i = 0; i < Neuro::getClassCount(); i++) 247 247 if (Neuro::getClass(i)->genactive && Neuro::getClass(i)->getPreferredOutput() != 0) … … 250 250 } 251 251 252 NeuroClass *GenoOperators::getRandomNeuroClassWithInput()253 { 254 vector<NeuroClass *> active;252 NeuroClass *GenoOperators::getRandomNeuroClassWithInput() 253 { 254 vector<NeuroClass *> active; 255 255 for (int i = 0; i < Neuro::getClassCount(); i++) 256 256 if (Neuro::getClass(i)->genactive && Neuro::getClass(i)->getPreferredInputs() != 0) … … 259 259 } 260 260 261 NeuroClass *GenoOperators::getRandomNeuroClassWithOutputAndNoInputs()262 { 263 vector<NeuroClass *> active;261 NeuroClass *GenoOperators::getRandomNeuroClassWithOutputAndNoInputs() 262 { 263 vector<NeuroClass *> active; 264 264 for (int i = 0; i < Neuro::getClassCount(); i++) 265 265 if (Neuro::getClass(i)->genactive && Neuro::getClass(i)->getPreferredOutput() != 0 && Neuro::getClass(i)->getPreferredInputs() == 0) … … 268 268 } 269 269 270 int GenoOperators::getRandomNeuroClassWithOutput(const vector<NeuroClass *>&NClist)270 int GenoOperators::getRandomNeuroClassWithOutput(const vector<NeuroClass *> &NClist) 271 271 { 272 272 vector<int> allowed; … … 277 277 } 278 278 279 int GenoOperators::getRandomNeuroClassWithInput(const vector<NeuroClass *>&NClist)279 int GenoOperators::getRandomNeuroClassWithInput(const vector<NeuroClass *> &NClist) 280 280 { 281 281 vector<int> allowed; … … 301 301 } 302 302 303 NeuroClass * GenoOperators::parseNeuroClass(char*&s)303 NeuroClass *GenoOperators::parseNeuroClass(char *&s) 304 304 { 305 305 int maxlen = (int)strlen(s); 306 306 int NClen = 0; 307 307 NeuroClass *NC = NULL; 308 for (int i = 0; i <Neuro::getClassCount(); i++)308 for (int i = 0; i < Neuro::getClassCount(); i++) 309 309 { 310 310 const char *ncname = Neuro::getClass(i)->name.c_str(); 311 311 int ncnamelen = (int)strlen(ncname); 312 if (maxlen >= ncnamelen && ncnamelen >NClen && (strncmp(s, ncname, ncnamelen) == 0))312 if (maxlen >= ncnamelen && ncnamelen > NClen && (strncmp(s, ncname, ncnamelen) == 0)) 313 313 { 314 314 NC = Neuro::getClass(i); … … 320 320 } 321 321 322 Neuro *GenoOperators::findNeuro(const Model *m, const NeuroClass *nc)322 Neuro *GenoOperators::findNeuro(const Model *m, const NeuroClass *nc) 323 323 { 324 324 if (!m) return NULL; … … 328 328 } 329 329 330 int GenoOperators::neuroClassProp(char *&s, NeuroClass *nc, bool also_v1_N_props)330 int GenoOperators::neuroClassProp(char *&s, NeuroClass *nc, bool also_v1_N_props) 331 331 { 332 332 int len = (int)strlen(s); … … 335 335 { 336 336 Param p = nc->getProperties(); 337 for (int i = 0; i <p.getPropCount(); i++)337 for (int i = 0; i < p.getPropCount(); i++) 338 338 { 339 339 const char *n = p.id(i); 340 340 int l = (int)strlen(n); 341 if (len >= l && l >Len && (strncmp(s, n, l) == 0)) { I = 100 + i; Len = l; }341 if (len >= l && l > Len && (strncmp(s, n, l) == 0)) { I = 100 + i; Len = l; } 342 342 if (also_v1_N_props) //recognize old properties symbols /=! 343 343 { … … 352 352 Neuro n; 353 353 Param p = n.extraProperties(); 354 for (int i = 0; i <p.getPropCount(); i++)354 for (int i = 0; i < p.getPropCount(); i++) 355 355 { 356 356 const char *n = p.id(i); 357 357 int l = (int)strlen(n); 358 if (len >= l && l >Len && (strncmp(s, n, l) == 0)) { I = i; Len = l; }358 if (len >= l && l > Len && (strncmp(s, n, l) == 0)) { I = i; Len = l; } 359 359 } 360 360 s += Len; … … 389 389 } 390 390 391 char *GenoOperators::strchrn0(const char *str, char ch)392 { 393 return ch == 0 ? NULL : strchr((char *)str, ch);391 char *GenoOperators::strchrn0(const char *str, char ch) 392 { 393 return ch == 0 ? NULL : strchr((char *)str, ch); 394 394 } 395 395 … … 398 398 return isupper(firstchar) || firstchar == '|' || firstchar == '@' || firstchar == '*'; 399 399 } 400 -
cpp/frams/genetics/genooperators.h
r801 r899 198 198 static NeuroClass* getRandomNeuroClassWithInput(); ///<returns random neuroclass with input or NULL when no active classes. 199 199 static NeuroClass* getRandomNeuroClassWithOutputAndNoInputs(); ///<returns random sensor or NULL when no active classes. 200 static NeuroClass* getRandomSensorProb(float prob); ///<returns random sensor (only-output neuron class) with presented probability or NULL. \e prob probability of picking neuron class.201 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 202 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 -
cpp/frams/model/modelparts.cpp
r844 r899 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-201 7Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2019 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 74 74 } 75 75 76 void PartBase::setInfo(const SString & name, const SString&value)76 void PartBase::setInfo(const SString &name, const SString &value) 77 77 { 78 78 strSetField(info, name, value); 79 79 } 80 80 81 void PartBase::setInfo(const SString &name, int value)81 void PartBase::setInfo(const SString &name, int value) 82 82 { 83 83 setInfo(name, SString::valueOf(value)); 84 84 } 85 85 86 void PartBase::setInfo(const SString &name, double value)86 void PartBase::setInfo(const SString &name, double value) 87 87 { 88 88 setInfo(name, SString::valueOf(value)); 89 89 } 90 90 91 SString PartBase::getInfo(const SString &name)91 SString PartBase::getInfo(const SString &name) 92 92 { 93 93 return strGetField(info, name); … … 134 134 } 135 135 136 void NeuroClass::setGenActive(const char *genactive_classes[])137 { 138 for (const char **n = genactive_classes; *n; n++)139 { 140 NeuroClass *cls = Neuro::getClass(*n);136 void NeuroClass::setGenActive(const char *genactive_classes[]) 137 { 138 for (const char **n = genactive_classes; *n; n++) 139 { 140 NeuroClass *cls = Neuro::getClass(*n); 141 141 if (cls) cls->genactive = 1; 142 142 } … … 223 223 } 224 224 225 SString **Neuro::inputInfo(int i)225 SString **Neuro::inputInfo(int i) 226 226 { 227 227 if (i >= getInputCount()) return 0; … … 229 229 } 230 230 231 void Neuro::setInputInfo(int i, const SString &name, const SString &value)231 void Neuro::setInputInfo(int i, const SString &name, const SString &value) 232 232 { 233 233 SString **s = inputInfo(i); … … 237 237 } 238 238 239 void Neuro::setInputInfo(int i, const SString &name, int value)239 void Neuro::setInputInfo(int i, const SString &name, int value) 240 240 { 241 241 setInputInfo(i, name, SString::valueOf(value)); 242 242 } 243 243 244 void Neuro::setInputInfo(int i, const SString &name, double value)244 void Neuro::setInputInfo(int i, const SString &name, double value) 245 245 { 246 246 setInputInfo(i, name, SString::valueOf(value)); … … 255 255 } 256 256 257 SString Neuro::getInputInfo(int i, const SString &name)257 SString Neuro::getInputInfo(int i, const SString &name) 258 258 { 259 259 SString **s = inputInfo(i); … … 263 263 } 264 264 265 void Neuro::operator=(const Neuro &src)265 void Neuro::operator=(const Neuro &src) 266 266 { 267 267 refno = src.refno; … … 294 294 } 295 295 296 NeuroClass *Neuro::getClass(int classindex)296 NeuroClass *Neuro::getClass(int classindex) 297 297 { 298 298 return NeuroLibrary::staticlibrary.getClass(classindex); 299 299 } 300 300 301 NeuroClass * Neuro::getClass(const SString&classname)301 NeuroClass *Neuro::getClass(const SString &classname) 302 302 { 303 303 return NeuroLibrary::staticlibrary.findClass(classname); 304 304 } 305 305 306 int Neuro::getClassIndex(const NeuroClass *nc)307 { 308 return NeuroLibrary::staticlibrary.classes.find((void *)nc);309 } 310 311 NeuroClass *Neuro::getClass()306 int Neuro::getClassIndex(const NeuroClass *nc) 307 { 308 return NeuroLibrary::staticlibrary.classes.find((void *)nc); 309 } 310 311 NeuroClass *Neuro::getClass() 312 312 { 313 313 checkClass(); … … 315 315 } 316 316 317 void Neuro::setClass(NeuroClass *cl)317 void Neuro::setClass(NeuroClass *cl) 318 318 { 319 319 myclass = cl; … … 328 328 } 329 329 330 void Neuro::setDetails(const SString &details)330 void Neuro::setDetails(const SString &details) 331 331 { 332 332 int colon = details.indexOf(':'); … … 362 362 } 363 363 364 void Neuro::setClassName(const SString &clazz)364 void Neuro::setClassName(const SString &clazz) 365 365 { 366 366 myclassname = clazz; … … 368 368 } 369 369 370 int Neuro::addInput(Neuro *child, double weight, const SString *info)370 int Neuro::addInput(Neuro *child, double weight, const SString *info) 371 371 { 372 372 inputs += NInput(child, weight, (info && (info->len())) ? new SString(*info) : 0); … … 376 376 } 377 377 378 int Neuro::findInput(Neuro *child) const378 int Neuro::findInput(Neuro *child) const 379 379 { 380 380 for (int i = 0; i < inputs.size(); i++) … … 383 383 } 384 384 385 Neuro *Neuro::getInput(int i, double &weight) const385 Neuro *Neuro::getInput(int i, double &weight) const 386 386 { 387 387 if (i >= getInputCount()) return 0; … … 401 401 } 402 402 403 void Neuro::setInput(int i, Neuro *n)403 void Neuro::setInput(int i, Neuro *n) 404 404 { 405 405 NInput &inp = inputs(i); … … 407 407 } 408 408 409 void Neuro::setInput(int i, Neuro *n, double w)409 void Neuro::setInput(int i, Neuro *n, double w) 410 410 { 411 411 NInput &inp = inputs(i); … … 424 424 } 425 425 426 int Neuro::removeInput(Neuro *child)426 int Neuro::removeInput(Neuro *child) 427 427 { 428 428 int i = findInput(child); … … 463 463 } 464 464 465 int Neuro::findInputs(SList & result, const char* classname, const Part* part, const Joint*joint) const465 int Neuro::findInputs(SList &result, const char *classname, const Part *part, const Joint *joint) const 466 466 { 467 467 Neuro *nu; … … 476 476 if (classname) 477 477 if (nu->getClassName() != cn) continue; 478 result += (void *)nu;478 result += (void *)nu; 479 479 } 480 480 return result.size() - n0; 481 481 } 482 482 483 int Neuro::findOutputs(SList & result, const char* classname, const Part* part, const Joint*joint) const483 int Neuro::findOutputs(SList &result, const char *classname, const Part *part, const Joint *joint) const 484 484 { // not very efficient... 485 485 Neuro *nu, *inp; … … 498 498 if (inp == this) 499 499 { 500 result += (void*)nu;501 break;500 result += (void *)nu; 501 break; 502 502 } 503 503 } … … 576 576 } 577 577 578 void Part::operator=(const Part &src)578 void Part::operator=(const Part &src) 579 579 { 580 580 p = src.p; o = src.o; … … 612 612 Pt3D x = p2 - p1; 613 613 Pt3D dir(x.y, x.z, x.x); 614 p = p1 + x *0.5;614 p = p1 + x * 0.5; 615 615 rot.getAngles(x, dir); 616 616 } 617 617 618 Param &Part::getStaticParam()618 Param &Part::getStaticParam() 619 619 { 620 620 static Param p(f0_part_paramtab, 0, "Part"); … … 637 637 } 638 638 639 void Joint::operator=(const Joint &src)639 void Joint::operator=(const Joint &src) 640 640 { 641 641 rot = src.rot; … … 652 652 } 653 653 654 void Joint::attachToParts(Part * p1, Part*p2)654 void Joint::attachToParts(Part *p1, Part *p2) 655 655 { 656 656 part1 = p1; … … 695 695 } 696 696 697 Param &Joint::getStaticParam()697 Param &Joint::getStaticParam() 698 698 { 699 699 static Param p(f0_joint_paramtab, 0, "Joint"); … … 760 760 }; 761 761 762 Param &Neuro::getStaticParam()762 Param &Neuro::getStaticParam() 763 763 { 764 764 static Param p(f0_neuro_paramtab, 0, "NeuroDef"); -
cpp/frams/model/modelparts.h
r844 r899 24 24 class MultiRange; 25 25 26 typedef UserTags<Model, void *, 5> ModelUserTags;26 typedef UserTags<Model, void *, 5> ModelUserTags; 27 27 28 28 /** Common base for model elements. */ … … 31 31 public: 32 32 SString vis_style; 33 PartBase(const SString &s) :vis_style(s), mapped(0) {}33 PartBase(const SString &s) :vis_style(s), mapped(0) {} 34 34 ~PartBase(); 35 static SString getDefaultStyle() { return SString("none"); }35 static SString getDefaultStyle() { return SString("none"); } 36 36 MultiRange *mapped; 37 37 enum PartBaseFlags { Selected = 1 }; … … 48 48 49 49 void clearMapping(); 50 MultiRange *getMapping() { return mapped; }50 MultiRange *getMapping() { return mapped; } 51 51 void setMapping(const IRange &mr); 52 52 void addMapping(const IRange &mr); … … 54 54 void addMapping(const MultiRange &mr); 55 55 56 void setInfo(const SString & name, const SString&value);57 void setInfo(const SString &name, int value);58 void setInfo(const SString &name, double value);59 SString getInfo(const SString &name);56 void setInfo(const SString &name, const SString &value); 57 void setInfo(const SString &name, int value); 58 void setInfo(const SString &name, double value); 59 SString getInfo(const SString &name); 60 60 }; 61 61 … … 94 94 95 95 Part(enum Shape s = SHAPE_BALL_AND_STICK); 96 Part(const Part &src) :PartBase(getDefaultStyle()) { operator=(src); }97 void operator=(const Part &src);96 Part(const Part &src) :PartBase(getDefaultStyle()) { operator=(src); } 97 void operator=(const Part &src); 98 98 99 99 void setPositionAndRotationFromAxis(const Pt3D &p1, const Pt3D &p2); … … 101 101 void setRot(const Pt3D &r);///< set part.rot (rotation angles) and calculate part.o 102 102 103 static Param &getStaticParam();103 static Param &getStaticParam(); 104 104 }; 105 105 … … 128 128 129 129 Joint(); 130 Joint(const Joint &src) :PartBase(getDefaultStyle()) { operator=(src); }131 void operator=(const Joint &src);130 Joint(const Joint &src) :PartBase(getDefaultStyle()) { operator=(src); } 131 void operator=(const Joint &src); 132 132 133 133 /** connect two parts with this joint. … … 135 135 @see isDelta() 136 136 */ 137 void attachToParts(Part * p1, Part*p2);137 void attachToParts(Part *p1, Part *p2); 138 138 /// @see attachToParts(Part*,Part*) 139 139 void attachToParts(int p1, int p2); … … 168 168 Pt3D vcolor; 169 169 170 static Param &getStaticParam();170 static Param &getStaticParam(); 171 171 }; 172 172 173 173 #define JOINT_DELTA_MARKER 99999.0 174 174 175 ////////////////// NN ///////////////// 175 176 177 ////////////////// Neural Network ///////////////// 176 178 177 179 class NeuroClass; 178 180 179 typedef UserTags<NeuroClass, void *, 5> NeuroClassUserTags;181 typedef UserTags<NeuroClass, void *, 5> NeuroClassUserTags; 180 182 181 183 /** Information about neuron class. … … 184 186 { 185 187 bool ownedvectordata; 186 void operator=(const NeuroClass & nosuchthich){}188 void operator=(const NeuroClass &nosuchthich) {} 187 189 public: 188 190 SString name, longname, description; … … 207 209 /** class name for use in Neuro::setClassName(), Neuro::setDetails() (former 'moredata' field), 208 210 eg. "N","-",G" */ 209 const SString &getName() { return name; }211 const SString &getName() { return name; } 210 212 /** human friendly name, eg. "Neuron","Link","Gyroscope" */ 211 const SString &getLongName() { return longname; }213 const SString &getLongName() { return longname; } 212 214 /** long description */ 213 const SString &getDescription() { return description; }214 ParamEntry *getParamTab() { return props; }215 const SString &getDescription() { return description; } 216 ParamEntry *getParamTab() { return props; } 215 217 216 218 /** NeuroClass specific properties, recognized by all neurons of this class */ … … 240 242 } 241 243 */ 242 int *getSymbolGlyph()244 int *getSymbolGlyph() 243 245 { 244 246 return vectordata; … … 246 248 void setSymbolGlyph(int *data, bool owned = 1) 247 249 { 248 if (vectordata &&ownedvectordata) delete[]vectordata;250 if (vectordata && ownedvectordata) delete[]vectordata; 249 251 vectordata = data; ownedvectordata = owned; 250 252 } … … 282 284 283 285 static void resetActive(); ///< set default values of active and genactive for all classes 284 static void setGenActive(const char* classes[]); ///< set genactive for specified classes 285 }; 286 287 class Neuro; 288 289 /** Single processing unit in Framsticks NN. */ 286 static void setGenActive(const char *classes[]); ///< set genactive for specified classes 287 }; 288 289 290 291 292 293 294 /** Single processing unit in Framsticks neural network. */ 290 295 class Neuro : public PartBase 291 296 { … … 305 310 /** set myclass and make knownclass=true */ 306 311 void checkClass(); 307 SString **inputInfo(int i);312 SString **inputInfo(int i); 308 313 void defassign(); 309 314 … … 313 318 Param extraProperties(); 314 319 315 void setInputInfo(int i, const SString &name, const SString &value);316 void setInputInfo(int i, const SString &name, int value);317 void setInputInfo(int i, const SString &name, double value);320 void setInputInfo(int i, const SString &name, const SString &value); 321 void setInputInfo(int i, const SString &name, int value); 322 void setInputInfo(int i, const SString &name, double value); 318 323 SString getInputInfo(int i); 319 SString getInputInfo(int i, const SString &name);320 321 NeuroClass *getClass();322 void setClass(NeuroClass *);324 SString getInputInfo(int i, const SString &name); 325 326 NeuroClass *getClass(); 327 void setClass(NeuroClass *); 323 328 324 329 SString getClassParams() { return myclassparams; } 325 void setClassParams(const SString &cp) { myclassparams = cp; }330 void setClassParams(const SString &cp) { myclassparams = cp; } 326 331 327 332 SString getClassName(); 328 void setClassName(const SString &clazz);333 void setClassName(const SString &clazz); 329 334 330 335 /** return neuro unit details encoded as <CLASS> ":" <PROPERTIES> … … 351 356 @see getDetails() 352 357 */ 353 void setDetails(const SString &);358 void setDetails(const SString &); 354 359 355 360 #define STATRICKCLASS Neuro … … 377 382 Neuro(); 378 383 Neuro(double _state, double _inertia, double _force, double _sigmo); 379 Neuro(const Neuro &src) :PartBase(getDefaultStyle()) { operator=(src); }384 Neuro(const Neuro &src) :PartBase(getDefaultStyle()) { operator=(src); } 380 385 381 386 ~Neuro(); 382 387 383 void operator=(const Neuro &src);388 void operator=(const Neuro &src); 384 389 385 390 /** Attach this Neuro to the specified Part or detach it from the body if p==NULL. … … 387 392 @see getPart() 388 393 */ 389 void attachToPart(Part *p) { part = p; joint = 0; }394 void attachToPart(Part *p) { part = p; joint = 0; } 390 395 391 396 /** Attach this Neuro to the specified Joint or detach it from the body if p==NULL. … … 393 398 @see getJoint() 394 399 */ 395 void attachToJoint(Joint *j) { joint = j; part = 0; }400 void attachToJoint(Joint *j) { joint = j; part = 0; } 396 401 397 402 void attachToPart(int i); … … 422 427 423 428 /** @return the Neuro connected as i-th input */ 424 Neuro *getInput(int i) const { return (i >= inputs.size()) ? 0 : inputs(i).n; }429 Neuro *getInput(int i) const { return (i >= inputs.size()) ? 0 : inputs(i).n; } 425 430 /** @return the Neuro connected as i-th input. 426 431 @param weight 427 432 */ 428 Neuro *getInput(int i, double &weight) const;433 Neuro *getInput(int i, double &weight) const; 429 434 /** @return connectin weight for i-th input */ 430 435 double getInputWeight(int i) const; … … 432 437 void setInputWeight(int i, double weight); 433 438 /** connect i-th input with another neuron */ 434 void setInput(int i, Neuro *n);439 void setInput(int i, Neuro *n); 435 440 /** connect i-th input with another neuron */ 436 void setInput(int i, Neuro *n, double weight);441 void setInput(int i, Neuro *n, double weight); 437 442 /** add new input. @return its reference number */ 438 int addInput(Neuro * child, double weight = 1.0, const SString*info = 0);443 int addInput(Neuro *child, double weight = 1.0, const SString *info = 0); 439 444 /** @return reference number [0..InputCount-1] of the input 440 445 or -1 if 'child' is not connected with this Neuro.*/ 441 int findInput(Neuro *child) const;446 int findInput(Neuro *child) const; 442 447 void removeInput(paInt refno); 443 448 /** @return reference number of the child connection, like findInput() */ 444 int removeInput(Neuro *child);445 446 int findInputs(SList & result, const char* classname = 0, const Part* part = 0, const Joint*joint = 0) const;447 int findOutputs(SList & result, const char* classname = 0, const Part* part = 0, const Joint*joint = 0) const;449 int removeInput(Neuro *child); 450 451 int findInputs(SList &result, const char *classname = 0, const Part *part = 0, const Joint *joint = 0) const; 452 int findOutputs(SList &result, const char *classname = 0, const Part *part = 0, const Joint *joint = 0) const; 448 453 449 454 /* class database retrieval */ … … 453 458 */ 454 459 static SString getClassName(int classindex); 455 static NeuroClass *getClass(int classindex);456 static NeuroClass * getClass(const SString&classname);457 static int getClassIndex(const NeuroClass *nc);460 static NeuroClass *getClass(int classindex); 461 static NeuroClass *getClass(const SString &classname); 462 static int getClassIndex(const NeuroClass *nc); 458 463 459 464 // not really private, but you should not access those directly … … 468 473 Orient o; ///< rotation matrix calculated from "rot" 469 474 static ParamEntry emptyParamTab[]; 470 static Param &getStaticParam();475 static Param &getStaticParam(); 471 476 }; 472 477
Note: See TracChangeset
for help on using the changeset viewer.