Changeset 896 for cpp/frams/genetics
- Timestamp:
- 11/30/19 01:30:22 (5 years ago)
- Location:
- cpp/frams/genetics
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
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++)
Note: See TracChangeset
for help on using the changeset viewer.