- Timestamp:
- 01/02/25 02:00:48 (5 days ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/genetics/f9/f9_oper.cpp
r1274 r1330 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-202 1Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2024 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 81 81 } 82 82 83 /// Simple mutation83 ///A simple mutation 84 84 int GenoOper_f9::mutate(char *&gene, float &chg, int &method) 85 85 { … … 123 123 int GenoOper_f9::crossOver(char *&g1, char *&g2, float& chg1, float& chg2) 124 124 { 125 // printf("%s \t %s\n", g1, g2); 125 126 int len1 = (int)strlen(g1), len2 = (int)strlen(g2); 126 int p1 = rndUint(len1); //random cut point for the first genotype 127 int p2 = rndUint(len2); //random cut point for the second genotype 127 double p = rndDouble(1); //random cut point 128 int p1 = 1 + int(p * (len1 - 1)); //...mapped to the first parent, avoiding cuts that would cause a simple swap of the entire genotype. Unavoidable for a single-letter parent 129 int p2 = 1 + int(p * (len2 - 1)); //...mapped to the second parent, as above 128 130 char *child1 = (char*)malloc(p1 + len2 - p2 + 1); 129 131 char *child2 = (char*)malloc(p2 + len1 - p1 + 1); … … 132 134 free(g1); g1 = child1; 133 135 free(g2); g2 = child2; 136 //children non-empty if parents non-empty (valid) 134 137 chg1 = (float)p1 / strlen(child1); 135 138 chg2 = (float)p2 / strlen(child2); 139 // printf("%s \t %s\n", child1, child2); 140 // printf("%g \t %g\n", chg1, chg2); 136 141 return GENOPER_OK; 137 142 }
Note: See TracChangeset
for help on using the changeset viewer.