* @return new Chromosome crossed between given two
*/
_Chromosome do_cross(_Chromosome first, _Chromosome second, unsigned int splitPlace) {
- const unsigned int chromosomeSize = first.get().size();
+ const unsigned int chromosomeSize = first.size();
// cout << " ";
// for (unsigned int i = 0; i < chromosomeSize; i++) {
-// cout << first.get()[i].get();
+// cout << first[i].get();
// }
// cout << "\n x ";
// for (unsigned int i = 0; i < chromosomeSize; i++) {
-// cout << second.get()[i].get();
+// cout << second[i].get();
// }
// cout << "\n--------";
// for (unsigned int i = 0; i < chromosomeSize; i++) {
vector<GeneType> crossedChromosome;
for (unsigned int i = 0; i < chromosomeSize; i++) {
if (i < splitPlace) {
- crossedChromosome.push_back(first.get()[i].get());
+ crossedChromosome.push_back(first[i].get());
}
else {
- crossedChromosome.push_back(second.get()[i].get());
+ crossedChromosome.push_back(second[i].get());
}
}
// cout << "\n ";
// for (unsigned int i = 0; i < chromosomeSize; i++) {
-// cout << crossedChromosome[i].get();
+// cout << crossedChromosome[i];
// }
// cout << "\n";
* @return new Generation of Chromosome's after the Crossover
*/
Generation<_Chromosome> cross(Generation<_Chromosome> _generation) {
- const unsigned int generationSize = _generation.get().size();
+ const unsigned int generationSize = _generation.size();
vector<_Chromosome> newGeneration;
for (unsigned int i = 0; i < generationSize; i++) {
CrossoverChanceType random = (rand() + 1 % 10000) / 10000.0;
- _Chromosome chromosome = _generation.get()[i];
+ _Chromosome chromosome = _generation[i];
if (random < this->chance) {
- const unsigned int chromosomeSize = chromosome.get().size();
+ const unsigned int chromosomeSize = chromosome.size();
const unsigned int splitPlace = rand() % chromosomeSize;
unsigned int pairedChromosome = 0;
pairedChromosome = rand() % generationSize;
} while(pairedChromosome == i);
- chromosome = do_cross(chromosome, _generation.get()[pairedChromosome], splitPlace);
+ chromosome = do_cross(chromosome, _generation[pairedChromosome], splitPlace);
}
newGeneration.push_back(chromosome);
}