- Timestamp:
- 11/30/19 01:30:22 (5 years ago)
- Location:
- cpp
- Files:
-
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/common/nonstd_math.cpp
r867 r896 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-201 5Maciej 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 "nonstd_math.h" 6 6 7 RandomGenerator &rndGetInstance()7 RandomGenerator &rndGetInstance() 8 8 { 9 9 static RandomGenerator rnd(0); -
cpp/common/nonstd_math.h
r835 r896 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 … … 21 21 //random number generator: 22 22 #include "random.h" 23 RandomGenerator &rndGetInstance();23 RandomGenerator &rndGetInstance(); 24 24 25 #define rnd01 (rndGetInstance().getDouble()) 26 #define rnd0N(limit) (rndGetInstance().getDouble()*(limit)) 27 #define randomN(limit) ((unsigned int)(rndGetInstance().getDouble()*(limit))) 28 #define setRandomSeed(seed) rndGetInstance().setSeed(seed) 29 #define setRandomRandomSeed() rndGetInstance().randomize() 30 25 inline double rndDouble(double limit_exclusive) { return rndGetInstance().getDouble() * limit_exclusive; } 26 inline unsigned int rndUint(unsigned int limit_exclusive) { return (unsigned int)(rndGetInstance().getDouble() * limit_exclusive); } //returns random from 0..limit_exclusive-1 27 inline void rndSetSeed(unsigned int seed) { rndGetInstance().setSeed(seed); } 28 inline unsigned int rndRandomizeSeed() { return rndGetInstance().randomize(); } 31 29 32 30 //floating point specific numbers … … 66 64 void fpExceptDisable(); 67 65 66 // std::lerp can be used since c++20 (and has some guaranteed properties probably better than this basic formula) but apparently it is not a template 67 template <typename Value, typename Linear> Value universal_lerp(Value a,Value b,Linear t) {return a*(1-t)+b*t;} 68 68 69 #endif 69 70 -
cpp/common/random.h
r886 r896 2 2 // Copyright (C) 1999-2018 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 #ifndef _COMMON_RANDOM_H_ 5 #define _COMMON_RANDOM_H_ 4 6 5 7 #ifdef _MSC_VER … … 140 142 } 141 143 }; 144 #endif -
cpp/frams/_demos/genomanipulation.cpp
r742 r896 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 … … 47 47 printf(" Current value of '%s' (%s) is '%s'\n", pi.id(i), pi.name(i), pi.get(i).c_str()); 48 48 char t[100]; 49 sprintf(t, "%g", minprop + (rnd01)*(maxprop - minprop));49 sprintf(t, "%g", minprop + rndDouble(maxprop - minprop)); 50 50 printf(" Setting new value... [ using ParamInterface::set() ]\n"); 51 51 pi.setFromString(i, t); -
cpp/frams/canvas/nn_simple_layout.cpp
r789 r896 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-201 5Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2019 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 26 26 for (i = 0; i < N; i++) 27 27 { 28 nn->SetXYWH(i, (int)rnd0N(300), (int)rnd0N(300), 50, 50);28 nn->SetXYWH(i, rndUint(300), rndUint(300), 50, 50); 29 29 } 30 30 } -
cpp/frams/genetics/f4/f4_general.cpp
r853 r896 1210 1210 int n = count(); 1211 1211 // pick a random node, between 0 and n-1 1212 return ordNode(r andomN(n));1212 return ordNode(rndUint(n)); 1213 1213 } 1214 1214 … … 1355 1355 { 1356 1356 int i, j, res, t; 1357 char tc1, tc2, tc3; // tc3 is only to ensure that in the end of neuron parameter definition1357 char tc1, tc2, tc3; // tc3 is only to ensure that neuron parameter definition is completed 1358 1358 int relfrom; 1359 1359 double w; -
cpp/frams/genetics/f4/f4_oper.cpp
r779 r896 158 158 // "X>" or "N>" 159 159 f4_node *n5 = NULL; 160 double pr = rnd 01;160 double pr = rndDouble(1); 161 161 pr -= 0.5; 162 162 if (pr < 0) n5 = new f4_node('X', n2, n2->pos); … … 204 204 n1->parent = n2; 205 205 // now with 50% chance swap children 206 if (r andomN(2) == 0)206 if (rndUint(2) == 0) 207 207 { 208 208 n3 = n2->child; … … 275 275 // choose a simple node from ADD_SIMPLE_CODES 276 276 n1->parent->removeChild(n1); 277 //f4_node *n2 = new f4_node(ADD_SIMPLE_CODES[r andomN(strlen(ADD_SIMPLE_CODES))], n1->parent, n1->parent->pos);277 //f4_node *n2 = new f4_node(ADD_SIMPLE_CODES[rndUint(strlen(ADD_SIMPLE_CODES))], n1->parent, n1->parent->pos); 278 278 int modifierid = GenoOperators::getRandomChar(all_modifiers, excluded_modifiers.c_str()); 279 279 f4_node *n2 = new f4_node(all_modifiers[modifierid], n1->parent, n1->parent->pos); … … 333 333 n2->removeChild(n1); 334 334 // n1 has two children. pick one randomly 50-50, destroy other 335 if (r andomN(2) == 0)335 if (rndUint(2) == 0) 336 336 { 337 337 n1->child->parent = n2; … … 429 429 430 430 // 35% chance one of *GTS 431 prob1 = rnd 01;431 prob1 = rndDouble(1); 432 432 prob1 -= 0.35f; 433 433 if (prob1 < 0) … … 468 468 case 0: // change type 469 469 // 80% for link, 20% for random sensor 470 if (rnd 01< 0.2f)470 if (rndDouble(1) < 0.2f) 471 471 { 472 472 cl = GenoOperators::getRandomNeuroClassWithOutputAndNoInputs(); … … 497 497 void Geno_f4::nparNodeMakeRandom(f4_node *nn) const 498 498 { 499 int sign = (int) (2.0f * rnd01);500 int param = (int) (3.0f * rnd01);499 int sign = (int)rndDouble(2); 500 int param = (int)rndDouble(3); 501 501 if (param > 2) param = 2; 502 502 nn->l1 = sign; … … 512 512 // change count 513 513 count = nn->i1; 514 prob1 = rnd 01;514 prob1 = rndDouble(1); 515 515 if (prob1 < 0.5f) count++; 516 516 else count--; … … 699 699 // decide amounts of crossover, 0.25-0.75 700 700 // adam: seems 0.1-0.9 -- MacKo 701 chg1 = 0.1 f + 0.8f*rnd01;702 chg2 = 0.1 f + 0.8f*rnd01;701 chg1 = 0.1 + rndDouble(0.8); 702 chg2 = 0.1 + rndDouble(0.8); 703 703 704 704 copy1 = root1.duplicate(); -
cpp/frams/genetics/f9/f9_oper.cpp
r779 r896 5 5 #include "f9_oper.h" 6 6 #include "f9_conv.h" 7 #include <common/nonstd.h> //r andomN, rnd017 #include <common/nonstd.h> //rndUint, rnd01 8 8 9 9 … … 55 55 for (int i = 0; i < len; i++) 56 56 { 57 if (rnd 01< mut_prob) //normalize prob with the length of the genotype57 if (rndDouble(1) < mut_prob) //normalize prob with the length of the genotype 58 58 { 59 59 char oldgene = gene[i]; 60 gene[i] = turtle_commands_f9[r andomN(symbols)];60 gene[i] = turtle_commands_f9[rndUint(symbols)]; 61 61 if (gene[i] != oldgene) changes++; 62 62 } 63 63 } 64 64 65 if (rnd 01< mut_prob) //add or delete a random char65 if (rndDouble(1) < mut_prob) //add or delete a random char 66 66 { 67 67 SString newgeno(gene); 68 if (r andomN(2) == 0) //add68 if (rndUint(2) == 0) //add 69 69 { 70 70 int symbols = strlen(turtle_commands_f9); 71 int p = r andomN(len + 1); //random location71 int p = rndUint(len + 1); //random location 72 72 //printf("before add: %s\n",(const char*)newgeno); 73 newgeno = newgeno.substr(0, p) + SString(turtle_commands_f9 + r andomN(symbols), 1) + newgeno.substr(p);73 newgeno = newgeno.substr(0, p) + SString(turtle_commands_f9 + rndUint(symbols), 1) + newgeno.substr(p); 74 74 //printf("after add: %s\n",(const char*)newgeno); 75 75 changes++; … … 77 77 else if (len > 1) //delete 78 78 { 79 int p = r andomN(len); //random location79 int p = rndUint(len); //random location 80 80 //printf("before delete: %s\n",(const char*)newgeno); 81 81 newgeno = newgeno.substr(0, p) + newgeno.substr(p + 1); … … 95 95 { 96 96 int len1 = strlen(g1), len2 = strlen(g2); 97 int p1 = r andomN(len1); //random cut point for first genotype98 int p2 = r andomN(len2); //random cut point for second genotype97 int p1 = rndUint(len1); //random cut point for first genotype 98 int p2 = rndUint(len2); //random cut point for second genotype 99 99 char *child1 = (char*)malloc(p1 + len2 - p2 + 1); 100 100 char *child2 = (char*)malloc(p2 + len1 - p1 + 1); -
cpp/frams/genetics/fB/fB_oper.cpp
r853 r896 246 246 { 247 247 std::list<SString> tokenized = tokenizeSequence(line); 248 int rndid = r andomN(tokenized.size()); // select random letter from genotype248 int rndid = rndUint(tokenized.size()); // select random letter from genotype 249 249 // increment/decrement character - when overflow happens, this method 250 250 // uses reflect method … … 254 254 if ((*it).len() == 1) 255 255 { 256 if (r andomN(2) == 0)256 if (rndUint(2) == 0) 257 257 { 258 258 if ((*it)[0] == 'a') (*it).directWrite()[0] = 'b'; … … 285 285 std::list<SString> tokenized = tokenizeSequence(line); 286 286 std::list<SString>::iterator it = tokenized.begin(); 287 int rndid = r andomN(tokenized.size()); // select random insertion point287 int rndid = rndUint(tokenized.size()); // select random insertion point 288 288 std::advance(it, rndid); 289 289 NeuroClass *cls = getRandomNeuroClass(); … … 306 306 chg = 1.0 / line.len(); 307 307 std::list<SString> tokenized = tokenizeSequence(line); 308 int rndid = r andomN(tokenized.size()); // select random insertion point308 int rndid = rndUint(tokenized.size()); // select random insertion point 309 309 std::list<SString>::iterator it = tokenized.begin(); 310 310 std::advance(it, rndid); 311 311 SString letter = "a"; 312 letter.directWrite()[0] = 'a' + r andomN(26);312 letter.directWrite()[0] = 'a' + rndUint(26); 313 313 tokenized.insert(it, letter); 314 314 line = detokenizeSequence(&tokenized); … … 320 320 std::list<SString> tokenized = tokenizeSequence(line); 321 321 std::list<SString>::iterator it = tokenized.begin(); 322 int rndid = r andomN(tokenized.size()); // select random deletion point322 int rndid = rndUint(tokenized.size()); // select random deletion point 323 323 std::advance(it, rndid); 324 324 tokenized.erase(it); … … 328 328 case FB_DUPLICATION: 329 329 { 330 int rndgene = r andomN(fB_GenoHelpers::geneCount(line));330 int rndgene = rndUint(fB_GenoHelpers::geneCount(line)); 331 331 int start, end; 332 332 SString gene = fB_GenoHelpers::getGene(rndgene, line, start, end); … … 342 342 for (int i = 0; i < 4; i++) 343 343 { 344 cuts[i] = r andomN(tokenized.size());344 cuts[i] = rndUint(tokenized.size()); 345 345 } 346 346 std::sort(cuts.begin(), cuts.end()); … … 407 407 { 408 408 // get random gene from first parent 409 int choice = r andomN(fB_GenoHelpers::geneCount(parent1));409 int choice = rndUint(fB_GenoHelpers::geneCount(parent1)); 410 410 int start, end; 411 411 SString gene = fB_GenoHelpers::getGene(choice, parent1, start, end); … … 414 414 chg2 = (float)parent2.len() / (float)child2.len(); 415 415 // do the same for second parent 416 choice = r andomN(fB_GenoHelpers::geneCount(parent2));416 choice = rndUint(fB_GenoHelpers::geneCount(parent2)); 417 417 gene = fB_GenoHelpers::getGene(choice, parent2, start, end); 418 418 child1 = gene + parent1; … … 428 428 // int start, end; 429 429 // SString gene = fB_GenoHelpers::getGene(i, parent1, start, end); 430 // if (r andomN(2) == 0)430 // if (rndUint(2) == 0) 431 431 // { 432 432 // child1 += gene; … … 445 445 // int start, end; 446 446 // SString gene = fB_GenoHelpers::getGene(i, parent2, start, end); 447 // if (r andomN(2) == 0)447 // if (rndUint(2) == 0) 448 448 // { 449 449 // child1 += gene; … … 474 474 i < fB_GenoHelpers::geneCountNoNested(parent2)) 475 475 { 476 if (r andomN(2) == 0)476 if (rndUint(2) == 0) 477 477 { 478 478 to1 = fB_GenoHelpers::getNonNestedGene(i, parent1, start, end); … … 489 489 else if (i < fB_GenoHelpers::geneCountNoNested(parent1)) 490 490 { 491 if (r andomN(2) == 0)491 if (rndUint(2) == 0) 492 492 { 493 493 to1 = fB_GenoHelpers::getNonNestedGene(i, parent1, start, end); … … 501 501 else // if (i < fB_GenoHelpers::geneCountNoNested(parent2)) 502 502 { 503 if (r andomN(2) == 0)503 if (rndUint(2) == 0) 504 504 { 505 505 to1 = fB_GenoHelpers::getNonNestedGene(i, parent2, start, end); -
cpp/frams/genetics/fF/fF_oper.cpp
r779 r896 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 "fF_oper.h" 6 6 #include "fF_genotype.h" 7 #include <common/nonstd.h> //r andomN, rnd017 #include <common/nonstd.h> //rndUint, rnd01 8 8 9 9 … … 49 49 par.load(gene); 50 50 static const int propsToMutate[] = fF_PROPS_TO_MUTATE; 51 int which = r andomN(ARRAY_LENGTH(propsToMutate));51 int which = rndUint(ARRAY_LENGTH(propsToMutate)); 52 52 bool mutated_ok = GenoOperators::mutatePropertyNaive(par.param, propsToMutate[which]); 53 53 if (mutated_ok) -
cpp/frams/genetics/fH/fH_oper.cpp
r803 r896 107 107 for (unsigned int i = 0; i < parent1->sticks.size(); i++) 108 108 { 109 if (r andomN(2) == 0)109 if (rndUint(2) == 0) 110 110 { 111 111 child1->sticks.push_back(parent1->sticks[i]); … … 120 120 for (unsigned int i = 0; i < parent2->sticks.size(); i++) 121 121 { 122 if (r andomN(2) == 0)122 if (rndUint(2) == 0) 123 123 { 124 124 child1->sticks.push_back(parent2->sticks[i]); … … 140 140 for (unsigned int i = 0; i < parent1->neurons.size(); i++) 141 141 { 142 if ((r andomN(2) == 0 || skip2) && !skip1)142 if ((rndUint(2) == 0 || skip2) && !skip1) 143 143 { 144 144 child1->neurons.push_back(parent1->neurons[i]); … … 153 153 for (unsigned int i = 0; i < parent2->neurons.size(); i++) 154 154 { 155 if ((r andomN(2) == 0 || skip2) && !skip1)155 if ((rndUint(2) == 0 || skip2) && !skip1) 156 156 { 157 157 child1->neurons.push_back(parent2->neurons[i]); … … 166 166 for (unsigned int i = 0; i < parent1->connections.size(); i++) 167 167 { 168 if ((r andomN(2) == 0 || skip2) && !skip1)168 if ((rndUint(2) == 0 || skip2) && !skip1) 169 169 { 170 170 child1->connections.push_back(parent1->connections[i]); … … 179 179 for (unsigned int i = 0; i < parent2->connections.size(); i++) 180 180 { 181 if ((r andomN(2) == 0 || skip2) && !skip1)181 if ((rndUint(2) == 0 || skip2) && !skip1) 182 182 { 183 183 child1->connections.push_back(parent2->connections[i]); … … 338 338 if (changedimensions) 339 339 { 340 int i = r andomN(2 * dimensions);340 int i = rndUint(2 * dimensions); 341 341 changeDoubleProperty(i, par, handle->type); 342 342 } … … 344 344 if (changeproperties) 345 345 { 346 int i = 2 * dimensions + r andomN(par.getPropCount() - 2 * dimensions);346 int i = 2 * dimensions + rndUint(par.getPropCount() - 2 * dimensions); 347 347 changeDoubleProperty(i, par, handle->type); 348 348 } … … 360 360 for (int i = 0; i < dimensions; i++) 361 361 { 362 par.setDouble(i, min + rnd 0N(max - min));363 par.setDouble(i + dimensions, min + rnd 0N(max - min));362 par.setDouble(i, min + rndDouble(max - min)); 363 par.setDouble(i + dimensions, min + rndDouble(max - min)); 364 364 } 365 365 handle->loadProperties(par); 366 366 if (handle->type != fHBodyType::NEURON) 367 367 { 368 int i = 2 * dimensions + r andomN(par.getPropCount() - 2 * dimensions);368 int i = 2 * dimensions + rndUint(par.getPropCount() - 2 * dimensions); 369 369 changeDoubleProperty(i, par, handle->type); 370 370 } … … 406 406 allhandlescount += creature->sticks.size(); 407 407 } 408 unsigned int toselect = r andomN(allhandlescount);408 unsigned int toselect = rndUint(allhandlescount); 409 409 if (toselect < creature->connections.size()) 410 410 { … … 436 436 if (par.getPropCount() > 0) 437 437 { 438 int i = r andomN(par.getPropCount());438 int i = rndUint(par.getPropCount()); 439 439 if (*par.type(i) == 'f') 440 440 { -
cpp/frams/genetics/fL/fL_matheval.cpp
r821 r896 613 613 void MathEvaluation::mutateValueOrVariable(MathEvaluation::Number *&currval, bool usetime) 614 614 { 615 if (r andomN(2) == 0 && varcount > 0) // use variable615 if (rndUint(2) == 0 && varcount > 0) // use variable 616 616 { 617 617 if (currval && currval->type == TokenType::NUMBER) … … 619 619 delete currval; 620 620 } 621 int var = r andomN(varcount + (usetime ? 1 : 0));621 int var = rndUint(varcount + (usetime ? 1 : 0)); 622 622 if (varcount == var) // time is used 623 623 { … … 633 633 if (!currval || currval->type == TokenType::VARIABLE) 634 634 { 635 currval = new Number(rnd 01);635 currval = new Number(rndDouble(1)); 636 636 } 637 637 else 638 638 { 639 currval->value = rnd 01;639 currval->value = rndDouble(1); 640 640 } 641 641 } … … 654 654 count = operatorstrings.size() - arithmeticoperatorscount; 655 655 } 656 randop += r andomN(count);656 randop += rndUint(count); 657 657 return operators[operatorstrings[randop]]; 658 658 } … … 663 663 { 664 664 int currsize = postfixlist.size(); 665 int varid = r andomN(varcount);665 int varid = rndUint(varcount); 666 666 postfixlist.push_back(vars[varid]); 667 if (r andomN(2) == 0 && varcount > 1)668 { 669 int varid2 = r andomN(varcount - 1);667 if (rndUint(2) == 0 && varcount > 1) 668 { 669 int varid2 = rndUint(varcount - 1); 670 670 if (varid2 >= varid) varid2++; 671 671 postfixlist.push_back(vars[varid2]); … … 673 673 else 674 674 { 675 Number *num = new Number(rnd 01);675 Number *num = new Number(rndDouble(1)); 676 676 postfixlist.push_back(num); 677 677 } 678 int opid = arithmeticoperatorscount + r andomN(comparisonoperatorscount);678 int opid = arithmeticoperatorscount + rndUint(comparisonoperatorscount); 679 679 postfixlist.push_back(operators[operatorstrings[opid]]); 680 680 if (currsize > 0) … … 689 689 if (postfixlist.size() == 0) 690 690 { 691 Number *val = new Number(rnd 01);691 Number *val = new Number(rndDouble(1)); 692 692 postfixlist.push_back(val); 693 693 return -1; 694 694 } 695 int method = r andomN(postfixlist.size() < MAX_MUT_FORMULA_SIZE ? MATH_MUT_COUNT : MATH_MUT_COUNT - 1);695 int method = rndUint(postfixlist.size() < MAX_MUT_FORMULA_SIZE ? MATH_MUT_COUNT : MATH_MUT_COUNT - 1); 696 696 switch (method) 697 697 { … … 704 704 std::list<Token *>::iterator it = postfixlist.begin(); 705 705 // insertion can be applied from 1st occurrence 706 int insertlocation = 1 + r andomN(postfixlist.size() - 1);706 int insertlocation = 1 + rndUint(postfixlist.size() - 1); 707 707 std::advance(it, insertlocation); 708 708 Operator *rndop; … … 732 732 id++; 733 733 } 734 int randid = r andomN(numbersineval.size());734 int randid = rndUint(numbersineval.size()); 735 735 Number *numptr = (Number *)(*numbersineval[randid]); 736 736 mutateValueOrVariable(numptr, usetime); … … 750 750 if (ops.size() > 0) 751 751 { 752 int randid = r andomN(ops.size());752 int randid = rndUint(ops.size()); 753 753 Operator *rndop; 754 754 if (randid == (int)ops.size() - 1) … … 783 783 if (firstofpairs.size() > 0) 784 784 { 785 int rndid = r andomN(firstofpairs.size());785 int rndid = rndUint(firstofpairs.size()); 786 786 if ((*firstofpairs[rndid])->type == TokenType::NUMBER) 787 787 { -
cpp/frams/genetics/fL/fL_oper.cpp
r853 r896 133 133 if (newword->name.startsWith("rot")) 134 134 { 135 double rot = 2 * rnd01;135 double rot = rndDouble(2); 136 136 MathEvaluation *eval = new MathEvaluation(0); 137 137 eval->convertString(SString::valueOf(rot).c_str()); … … 149 149 { 150 150 MathEvaluation *eval = new MathEvaluation(0); 151 eval->convertString(SString::valueOf( 2 * rnd01- 1).c_str());151 eval->convertString(SString::valueOf(rndDouble(2) - 1).c_str()); 152 152 newword->parevals[0] = eval; 153 153 } … … 171 171 else 172 172 { 173 int rid = r andomN(creature->rules.size());173 int rid = rndUint(creature->rules.size()); 174 174 list = &creature->rules[rid]->objsucc; 175 175 numparams = creature->rules[rid]->objpred->npar; … … 183 183 if (method == FL_ADD_OTHER && creature->builtincount < (int)creature->words.size()) 184 184 { 185 return creature->words[creature->wordnames[creature->builtincount + r andomN((int)creature->words.size() - creature->builtincount)]];185 return creature->words[creature->wordnames[creature->builtincount + rndUint((int)creature->words.size() - creature->builtincount)]]; 186 186 } 187 187 else … … 209 209 case FL_ADD_ROT: 210 210 { 211 int rottype = r andomN(3);211 int rottype = rndUint(3); 212 212 switch (rottype) 213 213 { … … 287 287 case FL_CHG_ITER: 288 288 { 289 if (r andomN(2) == 0)289 if (rndUint(2) == 0) 290 290 { 291 291 creature->time = creature->time + iterchangestep <= ExtValue::getDouble(FL_MAXITER) ? … … 303 303 if (creature->rules.size() > 0) 304 304 { 305 int ruleid = r andomN(creature->rules.size());305 int ruleid = rndUint(creature->rules.size()); 306 306 if (!creature->rules[ruleid]->condeval) 307 307 { … … 340 340 if (wordswithnorules.size() > 0) 341 341 { 342 int predid = r andomN(wordswithnorules.size());342 int predid = rndUint(wordswithnorules.size()); 343 343 fL_Rule *newrule = new fL_Rule(0,0); 344 344 fL_Word *pred = new fL_Word(); … … 352 352 else if (creature->rules.size() > 0) 353 353 { 354 int ruleid = r andomN(creature->rules.size());354 int ruleid = rndUint(creature->rules.size()); 355 355 fL_Rule *newrule = new fL_Rule(0, 0); 356 356 fL_Word *pred = new fL_Word(); … … 392 392 if (creature->countDefinedWords() <= maxdefinedwords) 393 393 { 394 int npar = r andomN(ExtValue::getInt(FL_MAXPARAMS, false));394 int npar = rndUint(ExtValue::getInt(FL_MAXPARAMS, false)); 395 395 for (int i = 0; i < maxdefinedwords; i++) 396 396 { … … 421 421 if (list->size() > 1) 422 422 { 423 int rndid = r andomN(list->size() - 1);423 int rndid = rndUint(list->size() - 1); 424 424 int j = 0; 425 425 std::list<fL_Word *>::iterator it = list->begin(); … … 455 455 else 456 456 { 457 int rndid = r andomN(list->size());457 int rndid = rndUint(list->size()); 458 458 std::list<fL_Word *>::iterator it = list->begin(); 459 459 std::advance(it, rndid); … … 482 482 int tmp = 0; 483 483 std::list<fL_Word *> *list = selectRandomSequence(creature, numpars, tmp); 484 int rndid = r andomN(list->size());484 int rndid = rndUint(list->size()); 485 485 std::list<fL_Word *>::iterator it = list->begin(); 486 486 std::advance(it, rndid); … … 512 512 fL_Branch *start = new fL_Branch(fL_Branch::BranchType::OPEN, 0, 0); 513 513 list->insert(it, start); 514 int rottype = r andomN(2);514 int rottype = rndUint(2); 515 515 switch (rottype) 516 516 { … … 531 531 int tmp = 0; 532 532 std::list<fL_Word *> *list = selectRandomSequence(creature, numpars, tmp); 533 int rndid = r andomN(list->size());533 int rndid = rndUint(list->size()); 534 534 std::list<fL_Word *>::iterator selectedword = list->begin(); 535 535 std::advance(selectedword, rndid); … … 545 545 int numpars = 0; 546 546 std::list<fL_Word *> *list = selectRandomSequence(creature, numpars, tmp); 547 int rndid = r andomN(list->size());547 int rndid = rndUint(list->size()); 548 548 std::list<fL_Word *>::iterator it = list->begin(); 549 549 std::advance(it, rndid); … … 577 577 if (available.size() > 0) 578 578 { 579 int newnameid = r andomN(available.size());579 int newnameid = rndUint(available.size()); 580 580 (*selectedword)->name = available[newnameid]->name; 581 581 } … … 593 593 if ((*selectedword)->npar > 0) 594 594 { 595 int randeval = r andomN((*selectedword)->npar);595 int randeval = rndUint((*selectedword)->npar); 596 596 Param par((*selectedword)->tab, (*selectedword)->data); 597 597 if ((*selectedword)->builtin && (*selectedword)->name == "N" … … 614 614 if (w->npar > 0) 615 615 { 616 int rndattr = r andomN(w->npar);616 int rndattr = rndUint(w->npar); 617 617 if (!w->parevals[rndattr]) 618 618 { … … 638 638 if (w->npar > 0) 639 639 { 640 int rndattr = r andomN(w->npar);640 int rndattr = rndUint(w->npar); 641 641 for (int i = 0; i < w->npar; i++) 642 642 { … … 752 752 for (int i = 0; i < numselrules; i++) 753 753 { 754 int rulid = r andomN(from->rules.size());754 int rulid = rndUint(from->rules.size()); 755 755 fL_Rule *rul = from->rules[rulid]; 756 756 fL_Rule *newrule = new fL_Rule(0, 0); … … 841 841 creature2template->parseGenotype(g2); 842 842 843 int numselrules = 1 + r andomN(XOVER_MAX_MIGRATED_RULES);843 int numselrules = 1 + rndUint(XOVER_MAX_MIGRATED_RULES); 844 844 numselrules = numselrules < (int)creature1->rules.size() ? numselrules : (int)creature1->rules.size(); 845 845 846 846 migrateRandomRules(creature1template, creature2, numselrules); 847 847 848 numselrules = 1 + r andomN(XOVER_MAX_MIGRATED_RULES);848 numselrules = 1 + rndUint(XOVER_MAX_MIGRATED_RULES); 849 849 numselrules = numselrules < (int)creature1->rules.size() ? numselrules : (int)creature1->rules.size(); 850 850 -
cpp/frams/genetics/fT/fTest_oper.cpp
r779 r896 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-201 5Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2019 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 88 88 int changes = 0, len = strlen(geno); 89 89 for (int i = 0; i < len; i++) 90 if (rnd 01< prob) //normalize prob with length of genotype90 if (rndDouble(1) < prob) //normalize prob with length of genotype 91 91 { 92 geno[i] = a[r andomN(4)];92 geno[i] = a[rndUint(4)]; 93 93 changes++; 94 94 } … … 101 101 { 102 102 int len1 = strlen(g1), len2 = strlen(g2); 103 int p1 = r andomN(len1); //random cut point for first genotype104 int p2 = r andomN(len2); //random cut point for second genotype103 int p1 = rndUint(len1); //random cut point for first genotype 104 int p2 = rndUint(len2); //random cut point for second genotype 105 105 char *child1 = (char*)malloc(p1 + len2 - p2 + 1); 106 106 char *child2 = (char*)malloc(p2 + len1 - p1 + 1); -
cpp/frams/genetics/fn/fn_oper.cpp
r809 r896 5 5 #include "fn_oper.h" 6 6 #include "fn_conv.h" 7 #include <common/nonstd.h> //r andomN, rnd017 #include <common/nonstd.h> //rndUint, rnd01 8 8 9 9 … … 80 80 if (mut_single_var) //mutate only one, randomly selected variable 81 81 { 82 int which = r andomN(values.size());82 int which = rndUint(values.size()); 83 83 values[which] = GenoOperators::mutateCreep('f', values[which], bound_low[which], bound_high[which], stddev[which], false); 84 84 chg = 1.0f / values.size(); … … 103 103 //xover_proportion = 0.1; //testing... 104 104 105 double proportion = xover_proportion_random ? 0.5 + rnd 0N(0.5) : xover_proportion;105 double proportion = xover_proportion_random ? 0.5 + rndDouble(0.5) : xover_proportion; 106 106 107 107 chg1 = proportion; -
cpp/frams/genetics/genman.cpp
r841 r896 362 362 { 363 363 char *gn; 364 if (g1n[0] && g2n[0]) if (r andomN(2) == 0) g1n[0] = 0; else g2n[0] = 0; //both provided? we want only one364 if (g1n[0] && g2n[0]) if (rndUint(2) == 0) g1n[0] = 0; else g2n[0] = 0; //both provided? we want only one 365 365 if (g1n[0]) { gn = g1n; chg = chg1; } 366 366 else { gn = g2n; chg = chg2; } -
cpp/frams/genetics/genooperators.cpp
r801 r896 38 38 int i; 39 39 for (i = 0; i < count; i++) sum += probtab[i]; 40 double sel = rnd 01*sum;40 double sel = rndDouble(sum); 41 41 for (sum = 0, i = 0; i < count; i++) { sum += probtab[i]; if (sel < sum) return i; } 42 42 return -1; … … 81 81 neucls = n->getClass() == NULL ? 0 : n->getClass()->getProperties().getPropCount(); 82 82 if (neuext + neucls == 0) return -1; //no properties in this neuron 83 int index = r andomN(neuext + neucls);83 int index = rndUint(neuext + neucls); 84 84 if (index >= neuext) index = index - neuext + 100; 85 85 return index; … … 142 142 { 143 143 result = int(result + 0.5); 144 if (result == current) result += r andomN(2) * 2 - 1; //force some change144 if (result == current) result += rndUint(2) * 2 - 1; //force some change 145 145 } 146 146 else … … 238 238 if (Neuro::getClass(i)->genactive) 239 239 active.push_back(Neuro::getClass(i)); 240 if (active.size() == 0) return NULL; else return active[r andomN(active.size())];240 if (active.size() == 0) return NULL; else return active[rndUint(active.size())]; 241 241 } 242 242 … … 247 247 if (Neuro::getClass(i)->genactive && Neuro::getClass(i)->getPreferredOutput() != 0) 248 248 active.push_back(Neuro::getClass(i)); 249 if (active.size() == 0) return NULL; else return active[r andomN(active.size())];249 if (active.size() == 0) return NULL; else return active[rndUint(active.size())]; 250 250 } 251 251 … … 256 256 if (Neuro::getClass(i)->genactive && Neuro::getClass(i)->getPreferredInputs() != 0) 257 257 active.push_back(Neuro::getClass(i)); 258 if (active.size() == 0) return NULL; else return active[r andomN(active.size())];258 if (active.size() == 0) return NULL; else return active[rndUint(active.size())]; 259 259 } 260 260 … … 265 265 if (Neuro::getClass(i)->genactive && Neuro::getClass(i)->getPreferredOutput() != 0 && Neuro::getClass(i)->getPreferredInputs() == 0) 266 266 active.push_back(Neuro::getClass(i)); 267 if (active.size() == 0) return NULL; else return active[r andomN(active.size())];267 if (active.size() == 0) return NULL; else return active[rndUint(active.size())]; 268 268 } 269 269 … … 274 274 if (NClist[i]->getPreferredOutput() != 0) //this NeuroClass provides output 275 275 allowed.push_back(i); 276 if (allowed.size() == 0) return -1; else return allowed[r andomN(allowed.size())];276 if (allowed.size() == 0) return -1; else return allowed[rndUint(allowed.size())]; 277 277 } 278 278 … … 283 283 if (NClist[i]->getPreferredInputs() != 0) //this NeuroClass wants one input connection or more 284 284 allowed.push_back(i); 285 if (allowed.size() == 0) return -1; else return allowed[r andomN(allowed.size())];285 if (allowed.size() == 0) return -1; else return allowed[rndUint(allowed.size())]; 286 286 } 287 287 … … 291 291 for (size_t i = 0; i < strlen(choices); i++) if (!strchrn0(excluded, choices[i])) allowed_count++; 292 292 if (allowed_count == 0) return -1; //no char is allowed 293 int rnd_index = r andomN(allowed_count) + 1;293 int rnd_index = rndUint(allowed_count) + 1; 294 294 allowed_count = 0; 295 295 for (size_t i = 0; i < strlen(choices); i++) -
cpp/frams/model/model.cpp
r815 r896 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 … … 83 83 updateRefno(); 84 84 if (using_checkpoints) 85 for (vector<Model *>::const_iterator it = mod.checkpoints.begin(); it != mod.checkpoints.end(); it++)86 { 87 Model *m = *it;88 Model *n = new Model(*m, m->autobuildmaps, false, true);89 checkpoints.push_back(n);85 for (vector<Model *>::const_iterator it = mod.checkpoints.begin(); it != mod.checkpoints.end(); it++) 86 { 87 Model *m = *it; 88 Model *n = new Model(*m, m->autobuildmaps, false, true); 89 checkpoints.push_back(n); 90 90 } 91 91 } … … 152 152 void Model::clear() 153 153 { 154 FOREACH(Part *, p, parts)154 FOREACH(Part *, p, parts) 155 155 delete p; 156 FOREACH(Joint *, j, joints)156 FOREACH(Joint *, j, joints) 157 157 delete j; 158 FOREACH(Neuro *, n, neurons)158 FOREACH(Neuro *, n, neurons) 159 159 delete n; 160 160 parts.clear(); joints.clear(); neurons.clear(); … … 164 164 geno = Geno(); 165 165 f0geno = Geno(); 166 for (vector<Model *>::iterator it = checkpoints.begin(); it != checkpoints.end(); it++)166 for (vector<Model *>::iterator it = checkpoints.begin(); it != checkpoints.end(); it++) 167 167 delete *it; 168 168 checkpoints.clear(); … … 195 195 void Model::removeNeuros(SList &nlist) 196 196 { 197 FOREACH(Neuro *, nu, nlist)197 FOREACH(Neuro *, nu, nlist) 198 198 { 199 199 int i = findNeuro(nu); … … 209 209 SList jlist; 210 210 findJoints(jlist, p); 211 FOREACH(Joint *, j, jlist)211 FOREACH(Joint *, j, jlist) 212 212 { 213 213 int i = findJoint(j); … … 240 240 void Model::removeNeuro(int neuroindex, bool removereferences) 241 241 { 242 Neuro *thisN = getNeuro(neuroindex);242 Neuro *thisN = getNeuro(neuroindex); 243 243 244 244 if (removereferences) 245 245 { 246 Neuro *n;246 Neuro *n; 247 247 // remove all references to thisN 248 for (int i = 0; n = (Neuro *)neurons(i); i++)248 for (int i = 0; n = (Neuro *)neurons(i); i++) 249 249 { 250 250 Neuro *inp; … … 252 252 if (inp == thisN) 253 253 { 254 n->removeInput(j);255 j--;254 n->removeInput(j); 255 j--; 256 256 } 257 257 } … … 262 262 } 263 263 264 MultiMap &Model::getMap()264 MultiMap &Model::getMap() 265 265 { 266 266 if (!map) map = new MultiMap(); … … 277 277 } 278 278 279 void Model::makeGenToGenMap(MultiMap & result, const MultiMap& gen1tomodel, const MultiMap&gen2tomodel)279 void Model::makeGenToGenMap(MultiMap &result, const MultiMap &gen1tomodel, const MultiMap &gen2tomodel) 280 280 { 281 281 result.clear(); … … 285 285 } 286 286 287 void Model::getCurrentToF0Map(MultiMap &result)287 void Model::getCurrentToF0Map(MultiMap &result) 288 288 { 289 289 result.clear(); 290 290 if (!map) return; 291 const MultiMap &f0m = getF0Map();291 const MultiMap &f0m = getF0Map(); 292 292 makeGenToGenMap(result, *map, f0m); 293 293 } … … 312 312 } 313 313 314 Model::ItemType Model::itemTypeFromLinePrefix(const char *line)315 { 316 struct PrefixAndItem { const char *prefix; ItemType type; };314 Model::ItemType Model::itemTypeFromLinePrefix(const char *line) 315 { 316 struct PrefixAndItem { const char *prefix; ItemType type; }; 317 317 static const PrefixAndItem types[] = { { "m:", ModelType }, { "p:", PartType }, { "j:", JointType }, { "n:", NeuronType }, { "c:", NeuronConnectionType }, { F0_CHECKPOINT_LINE, CheckpointType }, { NULL } }; 318 318 for (const PrefixAndItem *t = types; t->prefix != NULL; t++) 319 319 { 320 const char *in = line;321 const char *pattern = t->prefix;320 const char *in = line; 321 const char *pattern = t->prefix; 322 322 for (; *in == *pattern; in++, pattern++) 323 323 if (*pattern == ':') … … 355 355 for (; f0txt.getNextToken(pos, line, '\n'); lnum++) 356 356 { 357 const char *line_ptr = line.c_str();357 const char *line_ptr = line.c_str(); 358 358 for (; *line_ptr; line_ptr++) 359 359 if (!strchr(" \r\t", *line_ptr)) break; … … 361 361 if (!*line_ptr) continue; 362 362 363 const char *colon = strchr(line_ptr, ':');363 const char *colon = strchr(line_ptr, ':'); 364 364 ItemType type = UnknownType; 365 365 SString excluding_prefix; … … 414 414 } 415 415 416 const MultiMap &Model::getF0Map()416 const MultiMap &Model::getF0Map() 417 417 { 418 418 if (!f0map) … … 472 472 } 473 473 474 for (i = 0; p = (Part *)parts(i); i++)474 for (i = 0; p = (Part *)parts(i); i++) 475 475 { 476 476 partparam.select(p); … … 481 481 map->add(len, gen.len() - 1, partToMap(i)); 482 482 } 483 for (i = 0; j = (Joint *)joints(i); i++)483 for (i = 0; j = (Joint *)joints(i); i++) 484 484 { 485 485 jointparam.select(j); … … 491 491 map->add(len, gen.len() - 1, jointToMap(i)); 492 492 } 493 for (i = 0; n = (Neuro *)neurons(i); i++)493 for (i = 0; n = (Neuro *)neurons(i); i++) 494 494 { 495 495 neuroparam.select(n); … … 502 502 for (a = 0; a < neurons.size(); a++) 503 503 { // inputs 504 n = (Neuro *)neurons(a);504 n = (Neuro *)neurons(a); 505 505 // if ((n->getInputCount()==1)&&(n->getInput(0).refno <= n->refno)) 506 506 // continue; // already done with Neuro::conn_refno … … 510 510 double w; 511 511 NeuroConn nc; 512 Neuro *n2 = n->getInput(b, w);512 Neuro *n2 = n->getInput(b, w); 513 513 // if (((n2.parentcount==1)&&(n2.parent)&&(n2.parent->refno < n2.refno)) ^ 514 514 // (n2.neuro_refno>=0)) … … 533 533 } 534 534 535 for (vector<Model *>::const_iterator it = checkpoints.begin(); it != checkpoints.end(); it++)535 for (vector<Model *>::const_iterator it = checkpoints.begin(); it != checkpoints.end(); it++) 536 536 { 537 537 Geno g = (*it)->getF0Geno(); … … 562 562 } 563 563 564 Model *Model::getCheckpoint(int i)564 Model *Model::getCheckpoint(int i) 565 565 { 566 566 return checkpoints[i]; … … 575 575 } 576 576 577 void Model::setGeno(const Geno &newgeno)577 void Model::setGeno(const Geno &newgeno) 578 578 { 579 579 geno = newgeno; … … 586 586 delMap(); 587 587 delF0Map(); 588 for (i = 0; p = (Part *)parts(i); i++)588 for (i = 0; p = (Part *)parts(i); i++) 589 589 p->clearMapping(); 590 for (i = 0; j = (Joint *)joints(i); i++)590 for (i = 0; j = (Joint *)joints(i); i++) 591 591 j->clearMapping(); 592 for (i = 0; n = (Neuro *)neurons(i); i++)592 for (i = 0; n = (Neuro *)neurons(i); i++) 593 593 n->clearMapping(); 594 594 } … … 607 607 Part *p; Joint *j; Neuro *n; 608 608 int i; 609 for (i = 0; p = (Part *)parts(i); i++)609 for (i = 0; p = (Part *)parts(i); i++) 610 610 if (p->getMapping()) 611 611 map->add(*p->getMapping(), partToMap(i)); 612 for (i = 0; j = (Joint *)joints(i); i++)612 for (i = 0; j = (Joint *)joints(i); i++) 613 613 if (j->getMapping()) 614 614 map->add(*j->getMapping(), jointToMap(i)); 615 for (i = 0; n = (Neuro *)neurons(i); i++)615 for (i = 0; n = (Neuro *)neurons(i); i++) 616 616 if (n->getMapping()) 617 617 map->add(*n->getMapping(), neuroToMap(i)); … … 629 629 } 630 630 631 Pt3D Model::whereDelta(const Part & start, const Pt3D& rot, const Pt3D&delta)631 Pt3D Model::whereDelta(const Part &start, const Pt3D &rot, const Pt3D &delta) 632 632 { 633 633 Orient roto; … … 641 641 } 642 642 643 int Model::addFromString(ItemType item_type, const SString &singleline, const MultiRange *srcrange)643 int Model::addFromString(ItemType item_type, const SString &singleline, const MultiRange *srcrange) 644 644 { 645 645 return addFromString(item_type, singleline, 0, srcrange); 646 646 } 647 647 648 int Model::addFromString(ItemType item_type, const SString &singleline, int line_num, const MultiRange *srcrange)648 int Model::addFromString(ItemType item_type, const SString &singleline, int line_num, const MultiRange *srcrange) 649 649 { 650 650 SString error_message; … … 654 654 if (error_message.len() == 0) // generic error when no detailed message is available 655 655 error_message = "Invalid f0 code"; 656 if (line_num >0)656 if (line_num > 0) 657 657 error_message += SString::sprintf(", line #%d", line_num); 658 658 error_message += nameForErrors(); … … 662 662 } 663 663 664 int Model::addFromStringNoLog(ItemType item_type, const SString &line, SString & error_message, const MultiRange*srcrange)664 int Model::addFromStringNoLog(ItemType item_type, const SString &line, SString &error_message, const MultiRange *srcrange) 665 665 { 666 666 error_message = SString::empty(); … … 831 831 SString Model::nameForErrors() const 832 832 { 833 if (geno.getName().len() >0)833 if (geno.getName().len() > 0) 834 834 return SString::sprintf(" in '%s'", geno.getName().c_str()); 835 835 return SString::empty(); … … 850 850 else 851 851 { 852 Pt3D bbmin = ((Part *)parts(0))->p, bbmax = bbmin;852 Pt3D bbmin = ((Part *)parts(0))->p, bbmax = bbmin; 853 853 for (i = 0; i < parts.size(); i++) 854 854 { 855 p = (Part *)parts(i);855 p = (Part *)parts(i); 856 856 p->owner = this; 857 857 if (checklevel > 0) … … 894 894 for (i = 0; i < joints.size(); i++) 895 895 { 896 j = (Joint *)joints(i);896 j = (Joint *)joints(i); 897 897 // VALIDMINMAX are managed manually when adding joint properties in f0-def! 898 898 // (could be made dynamic but not really worth the effort) … … 979 979 for (i = 0; i < neurons.size(); i++) 980 980 { 981 n = (Neuro *)neurons(i);981 n = (Neuro *)neurons(i); 982 982 n->part_refno = (n->part) ? n->part->refno : -1; 983 983 n->joint_refno = (n->joint) ? n->joint->refno : -1; … … 991 991 for (i = 0; i < parts.size(); i++) 992 992 { 993 p = (Part *)parts(i);993 p = (Part *)parts(i); 994 994 if (p->mass <= 0.001) 995 995 p->mass = 1.0; … … 1003 1003 for (i = 0; i < joints.size(); i++) 1004 1004 { 1005 j = (Joint *)joints(i);1006 if (j->part1->flags &LINKFLAG)1005 j = (Joint *)joints(i); 1006 if (j->part1->flags & LINKFLAG) 1007 1007 { 1008 if (!(j->part2->flags &LINKFLAG))1008 if (!(j->part2->flags & LINKFLAG)) 1009 1009 { 1010 1010 change = 1; … … 1013 1013 } 1014 1014 else 1015 if (j->part2->flags &LINKFLAG)1015 if (j->part2->flags & LINKFLAG) 1016 1016 { 1017 if (!(j->part1->flags&LINKFLAG))1018 {1019 change = 1;1020 j->part1->flags |= LINKFLAG;1021 }1017 if (!(j->part1->flags & LINKFLAG)) 1018 { 1019 change = 1; 1020 j->part1->flags |= LINKFLAG; 1021 } 1022 1022 } 1023 1023 } … … 1025 1025 for (i = 0; i < parts.size(); i++) 1026 1026 { 1027 p = (Part *)parts(i);1028 if (!(p->flags &LINKFLAG))1027 p = (Part *)parts(i); 1028 if (!(p->flags & LINKFLAG)) 1029 1029 { 1030 1030 logPrintf("Model", "internalCheck", LOG_ERROR, "Not all parts connected (eg. Part #0 and Part #%d)%s", i, nameForErrors().c_str()); … … 1037 1037 for (i = 0; i < joints.size(); i++) 1038 1038 { 1039 j = (Joint *)joints(i);1039 j = (Joint *)joints(i); 1040 1040 if (j->p1_refno == j->p2_refno) 1041 1041 { … … 1046 1046 for (k = i + 1; k < joints.size(); k++) 1047 1047 { 1048 Joint * j2 = (Joint*)joints(k);1048 Joint *j2 = (Joint *)joints(k); 1049 1049 if (((j->p1_refno == j2->p1_refno) && (j->p2_refno == j2->p2_refno)) 1050 1050 || ((j->p1_refno == j2->p2_refno) && (j->p2_refno == j2->p1_refno))) … … 1073 1073 } 1074 1074 1075 const Geno &Model::getGeno() const1075 const Geno &Model::getGeno() const 1076 1076 { 1077 1077 return geno; … … 1106 1106 } 1107 1107 1108 Part *Model::getPart(int i) const1109 { 1110 return ((Part *)parts(i));1108 Part *Model::getPart(int i) const 1109 { 1110 return ((Part *)parts(i)); 1111 1111 } 1112 1112 … … 1116 1116 } 1117 1117 1118 Joint *Model::getJoint(int i) const1119 { 1120 return ((Joint *)joints(i));1121 } 1122 1123 int Model::findJoints(SList & result, const Part*part)1118 Joint *Model::getJoint(int i) const 1119 { 1120 return ((Joint *)joints(i)); 1121 } 1122 1123 int Model::findJoints(SList &result, const Part *part) 1124 1124 { 1125 1125 Joint *j; 1126 1126 int n0 = result.size(); 1127 1127 if (part) 1128 for (int i = 0; j = (Joint *)joints(i); i++)1129 if ((j->part1 == part) || (j->part2 == part)) result += (void *)j;1128 for (int i = 0; j = (Joint *)joints(i); i++) 1129 if ((j->part1 == part) || (j->part2 == part)) result += (void *)j; 1130 1130 return result.size() - n0; 1131 1131 } 1132 1132 1133 int Model::findNeuro(Neuro *n)1133 int Model::findNeuro(Neuro *n) 1134 1134 { 1135 1135 return neurons.find(n); 1136 1136 } 1137 1137 1138 int Model::findPart(Part *p)1138 int Model::findPart(Part *p) 1139 1139 { 1140 1140 return parts.find(p); 1141 1141 } 1142 1142 1143 int Model::findJoint(Joint *j)1143 int Model::findJoint(Joint *j) 1144 1144 { 1145 1145 return joints.find(j); … … 1148 1148 int Model::findJoint(Part *p1, Part *p2) 1149 1149 { 1150 Joint *j;1150 Joint *j; 1151 1151 for (int i = 0; j = getJoint(i); i++) 1152 1152 if ((j->part1 == p1) && (j->part2 == p2)) return i; … … 1161 1161 } 1162 1162 1163 Neuro *Model::getNeuro(int i) const1164 { 1165 return (Neuro *)neurons(i);1163 Neuro *Model::getNeuro(int i) const 1164 { 1165 return (Neuro *)neurons(i); 1166 1166 } 1167 1167 … … 1174 1174 } 1175 1175 1176 int Model::findNeuros(SList &result,1177 const char * classname, const Part* part, const Joint*joint)1176 int Model::findNeuros(SList &result, 1177 const char *classname, const Part *part, const Joint *joint) 1178 1178 { 1179 1179 Neuro *nu; 1180 1180 SString cn(classname); 1181 1181 int n0 = result.size(); 1182 for (int i = 0; nu = (Neuro *)neurons(i); i++)1182 for (int i = 0; nu = (Neuro *)neurons(i); i++) 1183 1183 { 1184 1184 if (part) … … 1188 1188 if (classname) 1189 1189 if (nu->getClassName() != cn) continue; 1190 result += (void *)nu;1190 result += (void *)nu; 1191 1191 } 1192 1192 return result.size() - n0; … … 1202 1202 { 1203 1203 Part *p = getPart(i); 1204 p->p.x += (rnd 01 - 0.5)*amount;1205 p->p.y += (rnd 01 - 0.5)*amount;1206 p->p.z += (rnd 01 - 0.5)*amount;1204 p->p.x += (rndDouble(1) - 0.5) * amount; 1205 p->p.y += (rndDouble(1) - 0.5) * amount; 1206 p->p.z += (rndDouble(1) - 0.5) * amount; 1207 1207 } 1208 1208 for (i = 0; i < joints.size(); i++) … … 1215 1215 } 1216 1216 1217 void Model::move(const Pt3D &shift)1218 { 1219 FOREACH(Part *, p, parts)1217 void Model::move(const Pt3D &shift) 1218 { 1219 FOREACH(Part *, p, parts) 1220 1220 p->p += shift; 1221 1221 } 1222 1222 1223 void Model::rotate(const Orient &rotation)1224 { 1225 FOREACH(Part *, p, parts)1223 void Model::rotate(const Orient &rotation) 1224 { 1225 FOREACH(Part *, p, parts) 1226 1226 { 1227 1227 p->p = rotation.transform(p->p); … … 1230 1230 } 1231 1231 1232 void Model::buildUsingSolidShapeTypes(const Model &src_ballandstick_shapes, Part::Shape use_shape, double thickness)1232 void Model::buildUsingSolidShapeTypes(const Model &src_ballandstick_shapes, Part::Shape use_shape, double thickness) 1233 1233 { 1234 1234 for (int i = 0; i < src_ballandstick_shapes.getJointCount(); i++) … … 1247 1247 for (int i = 0; i < src_ballandstick_shapes.getPartCount(); i++) 1248 1248 { 1249 Part *op = src_ballandstick_shapes.getPart(i);1250 Part *p = addNewPart(Part::SHAPE_ELLIPSOID); //always using spherical shape regardless of the 'use_shape' parameter - 'use shape' is meant for sticks!1251 p->p = op->p;1252 p->rot = op->rot;1253 p->scale.x = p->scale.y = p->scale.z = thickness;1249 Part *op = src_ballandstick_shapes.getPart(i); 1250 Part *p = addNewPart(Part::SHAPE_ELLIPSOID); //always using spherical shape regardless of the 'use_shape' parameter - 'use shape' is meant for sticks! 1251 p->p = op->p; 1252 p->rot = op->rot; 1253 p->scale.x = p->scale.y = p->scale.z = thickness; 1254 1254 } 1255 1255 for (int i = 0; i < src_ballandstick_shapes.getPartCount(); i++) … … 1275 1275 } 1276 1276 1277 SolidsShapeTypeModel::SolidsShapeTypeModel(Model &m, Part::Shape use_shape, double thickness)1277 SolidsShapeTypeModel::SolidsShapeTypeModel(Model &m, Part::Shape use_shape, double thickness) 1278 1278 { 1279 1279 using_model = converted_model = NULL; … … 1334 1334 class MaxNeuro : public Neuro { public: MaxNeuro() { Param par(f0_neuro_paramtab, this); par.setMax(); } }; 1335 1335 1336 Part &Model::getMinPart() { static MinPart part; return part; }1337 Part &Model::getMaxPart() { static MaxPart part; return part; }1338 Part &Model::getDefPart() { static Part part; return part; }1339 Joint &Model::getMinJoint() { static MinJoint joint; return joint; }1340 Joint &Model::getMaxJoint() { static MaxJoint joint; return joint; }1341 Joint &Model::getDefJoint() { static Joint joint; return joint; }1342 Neuro &Model::getMinNeuro() { static MinNeuro neuro; return neuro; }1343 Neuro &Model::getMaxNeuro() { static MaxNeuro neuro; return neuro; }1344 Neuro &Model::getDefNeuro() { static Neuro neuro; return neuro; }1336 Part &Model::getMinPart() { static MinPart part; return part; } 1337 Part &Model::getMaxPart() { static MaxPart part; return part; } 1338 Part &Model::getDefPart() { static Part part; return part; } 1339 Joint &Model::getMinJoint() { static MinJoint joint; return joint; } 1340 Joint &Model::getMaxJoint() { static MaxJoint joint; return joint; } 1341 Joint &Model::getDefJoint() { static Joint joint; return joint; } 1342 Neuro &Model::getMinNeuro() { static MinNeuro neuro; return neuro; } 1343 Neuro &Model::getMaxNeuro() { static MaxNeuro neuro; return neuro; } 1344 Neuro &Model::getDefNeuro() { static Neuro neuro; return neuro; } -
cpp/frams/model/model.h
r815 r896 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 … … 77 77 SList parts, joints, neurons; 78 78 char partmappingchanged; 79 vector<Model *> checkpoints;79 vector<Model *> checkpoints; 80 80 81 81 void internalCopy(const Model &mod); … … 141 141 142 142 int getCheckpointCount(); 143 Model *getCheckpoint(int i);143 Model *getCheckpoint(int i); 144 144 145 145 /// The bounding box size. Valid if the model is valid. Read only. … … 201 201 202 202 /// change source genotype 203 void setGeno(const Geno &newgeno);203 void setGeno(const Geno &newgeno); 204 204 205 205 /** @return f0 genotype - generated from current model state … … 241 241 @see convmap 242 242 */ 243 void getCurrentToF0Map(MultiMap &m);243 void getCurrentToF0Map(MultiMap &m); 244 244 245 245 void setValidationLevel(int level) … … 250 250 /// calculate location of the new part connected to the existing one 251 251 /// using delta option 252 Pt3D whereDelta(const Part & start, const Pt3D& rot, const Pt3D&delta);252 Pt3D whereDelta(const Part &start, const Pt3D &rot, const Pt3D &delta); 253 253 254 254 /// create the whole model from scratch, using current genotype … … 256 256 257 257 /// setGeno(newgeno); rebuild(); 258 void rebuild(const Geno &newgeno, bool buildmaps) { setGeno(newgeno); rebuild(buildmaps); }258 void rebuild(const Geno &newgeno, bool buildmaps) { setGeno(newgeno); rebuild(buildmaps); } 259 259 260 260 /// reuse current model object but discard all model data … … 262 262 263 263 enum ItemType { UnknownType, ModelType, PartType, JointType, NeuronType, NeuronConnectionType, CheckpointType }; 264 static ItemType itemTypeFromLinePrefix(const char *line);264 static ItemType itemTypeFromLinePrefix(const char *line); 265 265 /** Execute single line of <B>f0</B> genotype. 266 266 Return value is non-negative reference number of the created item, … … 270 270 @param srcrange source genotype range which will be mapped to this element 271 271 */ 272 int addFromString(ItemType item_type, const SString &singleline, int line_num, const MultiRange *srcrange = NULL);272 int addFromString(ItemType item_type, const SString &singleline, int line_num, const MultiRange *srcrange = NULL); 273 273 /** Execute single line of <B>f0</B> genotype - compatiblity variant */ 274 int addFromString(ItemType item_type, const SString &singleline, const MultiRange *srcrange = NULL);274 int addFromString(ItemType item_type, const SString &singleline, const MultiRange *srcrange = NULL); 275 275 /** Execute single line of <B>f0</B> genotype - low level variant, used by Model::build(), error messages returned as string instead of calling logger */ 276 int addFromStringNoLog(ItemType item_type, const SString &singleline, SString & error_message, const MultiRange*srcrange = 0);276 int addFromStringNoLog(ItemType item_type, const SString &singleline, SString &error_message, const MultiRange *srcrange = 0); 277 277 278 278 /// separate build stages (for future use) … … 357 357 358 358 /// @return part index or -1 if not found in the model 359 int findPart(Part *p);359 int findPart(Part *p); 360 360 /// @return joint index or -1 if not found in the model 361 int findJoint(Joint *j);361 int findJoint(Joint *j); 362 362 /// @return neuro index or -1 if not found in the model 363 int findNeuro(Neuro *nu);363 int findNeuro(Neuro *nu); 364 364 /// @return joint index or -1 if not found in the model 365 365 int findJoint(Part *p1, Part *p2); … … 368 368 @param result objects will be appended here 369 369 @return number of objects found */ 370 int findNeuros(SList & result, const char* classname = 0, const Part* part = 0, const Joint*joint = 0);370 int findNeuros(SList &result, const char *classname = 0, const Part *part = 0, const Joint *joint = 0); 371 371 372 372 /** search for joints connected to the part 373 373 @param result objects will be appended here 374 374 @return number of objects found */ 375 int findJoints(SList & result, const Part*part = 0);375 int findJoints(SList &result, const Part *part = 0); 376 376 377 377 void disturb(double amount); 378 void move(const Pt3D &shift);378 void move(const Pt3D &shift); 379 379 /// rotate around the origin (move-rotate-move to rotate around arbitrary point) 380 void rotate(const Orient &rotation);380 void rotate(const Orient &rotation); 381 381 /// rotate around the origin (move-rotate-move to rotate around arbitrary point) 382 void rotate(const Pt3D &angles) { Orient o = Orient_1; o.rotate(angles); rotate(o); }382 void rotate(const Pt3D &angles) { Orient o = Orient_1; o.rotate(angles); rotate(o); } 383 383 384 384 /// build this model using solid shape types, based on the provided ball-and-stick model. See also shapeconvert.cpp. 385 void buildUsingSolidShapeTypes(const Model &src_ballandstick_shapes, Part::Shape use_shape = Part::SHAPE_CYLINDER, double thickness = 0.2);385 void buildUsingSolidShapeTypes(const Model &src_ballandstick_shapes, Part::Shape use_shape = Part::SHAPE_CYLINDER, double thickness = 0.2); 386 386 387 387 protected: … … 403 403 static int mapToNeuro(int i); 404 404 405 static void makeGenToGenMap(MultiMap & result, const MultiMap& gen1tomodel, const MultiMap&gen2tomodel);405 static void makeGenToGenMap(MultiMap &result, const MultiMap &gen1tomodel, const MultiMap &gen2tomodel); 406 406 407 407 /////////////////////////// 408 408 409 static Part &getMinPart();410 static Part &getMaxPart();411 static Part &getDefPart();412 static Joint &getMinJoint();413 static Joint &getMaxJoint();414 static Joint &getDefJoint();415 static Neuro &getMinNeuro();416 static Neuro &getMaxNeuro();417 static Neuro &getDefNeuro();409 static Part &getMinPart(); 410 static Part &getMaxPart(); 411 static Part &getDefPart(); 412 static Joint &getMinJoint(); 413 static Joint &getMaxJoint(); 414 static Joint &getDefJoint(); 415 static Neuro &getMinNeuro(); 416 static Neuro &getMaxNeuro(); 417 static Neuro &getDefNeuro(); 418 418 }; 419 419 … … 436 436 Model *converted_model; 437 437 Model *using_model; 438 SolidsShapeTypeModel(Model &m, Part::Shape use_shape = Part::SHAPE_CYLINDER, double thickness = 0.2);439 operator Model &() { return *using_model; }440 Model &getModel() { return *using_model; }438 SolidsShapeTypeModel(Model &m, Part::Shape use_shape = Part::SHAPE_CYLINDER, double thickness = 0.2); 439 operator Model &() { return *using_model; } 440 Model &getModel() { return *using_model; } 441 441 ~SolidsShapeTypeModel() { if (converted_model) delete converted_model; } 442 442 }; -
cpp/frams/neuro/impl/neuroimpl-simple.h
r791 r896 77 77 public: 78 78 NeuroImpl* makeNew() { return new NI_Random(); }; 79 void go() { setState(rnd 01*2.0- 1.0); }79 void go() { setState(rndDouble(2) - 1.0); } 80 80 }; 81 81 -
cpp/frams/neuro/neuroimpl.cpp
r732 r896 85 85 for (i = 0; n = mod.getNeuro(i); i++) 86 86 { 87 n->state += (rnd 01- 0.5)*config.randominit;87 n->state += (rndDouble(1) - 0.5)*config.randominit; 88 88 ni = (NeuroImpl*)n->userdata[mytags_id]; 89 89 if (!ni) continue; -
cpp/frams/util/rndutil.cpp
r424 r896 21 21 double CustomRnd(double *tab) 22 22 { 23 double *range = tab + 1 + 2 * r andomN((int)(0.5 + tab[0]));24 return range[0] + rnd 0N(range[1] - range[0]);23 double *range = tab + 1 + 2 * rndUint((int)(0.5 + tab[0])); 24 return range[0] + rndDouble(range[1] - range[0]); 25 25 } 26 26 27 27 double RandomGener::Uni(double begin, double end) 28 28 { 29 return begin + rnd 01*(end - begin);29 return begin + rndDouble(end - begin); 30 30 } 31 31 … … 35 35 double v1, v2, s; 36 36 do { 37 v1 = 2 * rnd01- 1; //-1..138 v2 = 2 * rnd01- 1; //-1..137 v1 = rndDouble(2) - 1; //-1..1 38 v2 = rndDouble(2) - 1; //-1..1 39 39 s = v1*v1 + v2*v2; 40 40 } while (s >= 1);
Note: See TracChangeset
for help on using the changeset viewer.