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