Ignore:
Timestamp:
11/30/19 01:30:22 (4 years ago)
Author:
Maciej Komosinski
Message:

Replaced #defined macros for popular random-related operations with functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/f4/f4_oper.cpp

    r779 r896  
    158158                        // "X>" or "N>"
    159159                        f4_node *n5 = NULL;
    160                         double pr = rnd01;
     160                        double pr = rndDouble(1);
    161161                        pr -= 0.5;
    162162                        if (pr < 0) n5 = new f4_node('X', n2, n2->pos);
     
    204204                        n1->parent = n2;
    205205                        // now with 50% chance swap children
    206                         if (randomN(2) == 0)
     206                        if (rndUint(2) == 0)
    207207                        {
    208208                                n3 = n2->child;
     
    275275                        // choose a simple node from ADD_SIMPLE_CODES
    276276                        n1->parent->removeChild(n1);
    277                         //f4_node *n2 = new f4_node(ADD_SIMPLE_CODES[randomN(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);
    278278                        int modifierid = GenoOperators::getRandomChar(all_modifiers, excluded_modifiers.c_str());
    279279                        f4_node *n2 = new f4_node(all_modifiers[modifierid], n1->parent, n1->parent->pos);
     
    333333                                n2->removeChild(n1);
    334334                                // n1 has two children. pick one randomly 50-50, destroy other
    335                                 if (randomN(2) == 0)
     335                                if (rndUint(2) == 0)
    336336                                {
    337337                                        n1->child->parent = n2;
     
    429429
    430430        // 35% chance one of *GTS
    431         prob1 = rnd01;
     431        prob1 = rndDouble(1);
    432432        prob1 -= 0.35f;
    433433        if (prob1 < 0)
     
    468468        case 0: // change type
    469469                // 80% for link, 20% for random sensor
    470                 if (rnd01 < 0.2f)
     470                if (rndDouble(1) < 0.2f)
    471471                {
    472472                        cl = GenoOperators::getRandomNeuroClassWithOutputAndNoInputs();
     
    497497void Geno_f4::nparNodeMakeRandom(f4_node *nn) const
    498498{
    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);
    501501        if (param > 2) param = 2;
    502502        nn->l1 = sign;
     
    512512        // change count
    513513        count = nn->i1;
    514         prob1 = rnd01;
     514        prob1 = rndDouble(1);
    515515        if (prob1 < 0.5f) count++;
    516516        else count--;
     
    699699        // decide amounts of crossover, 0.25-0.75
    700700        // adam: seems 0.1-0.9 -- MacKo
    701         chg1 = 0.1f + 0.8f*rnd01;
    702         chg2 = 0.1f + 0.8f*rnd01;
     701        chg1 = 0.1 + rndDouble(0.8);
     702        chg2 = 0.1 + rndDouble(0.8);
    703703
    704704        copy1 = root1.duplicate();
Note: See TracChangeset for help on using the changeset viewer.