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