74 lines
2.5 KiB
C++
74 lines
2.5 KiB
C++
#include "ChromosomeRearrangementStrategy.h"
|
|
#include <cstdlib>
|
|
#include <ctime>
|
|
|
|
HaploidGenotype ChromosomeRearrangementStrategy::buildRecombinantGenotype(const Genotype* parentGenotype){
|
|
std::vector<Chromosome> chromosomes;
|
|
const std::vector<Chromosome>* fGenome = &parentGenotype->fatherGenome.chromosomes;
|
|
const std::vector<Chromosome>* mGenome = &parentGenotype->motherGenome.chromosomes;
|
|
|
|
//srand((unsigned int)time(NULL));
|
|
for (unsigned int i = 0; i < fGenome->size(); i++){
|
|
int flag = rand() % 2;
|
|
const std::vector<Gene>* first;
|
|
const std::vector<Gene>* second;
|
|
if(flag == 0){
|
|
first = &fGenome->at(i).genes;
|
|
second= &mGenome->at(i).genes;
|
|
}
|
|
else{
|
|
first = &mGenome->at(i).genes;
|
|
second= &fGenome->at(i).genes;
|
|
}
|
|
Chromosome childChromosome(fGenome->at(i).name, *first);
|
|
// Äëÿ êàæäîé õðîìîñîìû âûáèðàåì ñâîþ "òî÷êó ïåðåãèáà"
|
|
int bound = rand() % first->size();
|
|
for(unsigned int j = bound; j < first->size(); j++){
|
|
childChromosome.genes.at(j) = second->at(j);
|
|
}
|
|
chromosomes.push_back(childChromosome);
|
|
|
|
}
|
|
// Òóò òàêæå ìîæíî ó÷åñòü, ÷òî ìîãóò áûòü íåãîìîëîãè÷íûå õðîìîñîìû (íàïð. Õ è Ó),
|
|
// êîòîðûå áóäóò íàñëåäîâàòüñÿ, îïðåäåëÿÿ ïîë îñîáè ïî ãåíîìó
|
|
|
|
return HaploidGenotype(chromosomes);
|
|
}
|
|
|
|
HaploidGenotype ChromosomeRearrangementStrategy::
|
|
buildRecombinantGenotype(const HaploidGenotype& fatherGenome, const HaploidGenotype& motherGenome){
|
|
std::vector<Chromosome> chromosomes;
|
|
const std::vector<Chromosome> fGenome = fatherGenome.chromosomes;
|
|
const std::vector<Chromosome> mGenome = motherGenome.chromosomes;
|
|
|
|
//srand((unsigned int)time(NULL));
|
|
for (unsigned int i = 0; i < fGenome.size(); i++){
|
|
int flag = rand() % 2;
|
|
std::vector<Gene> first;
|
|
std::vector<Gene> second;
|
|
if(flag == 0){
|
|
first = fGenome.at(i).genes;
|
|
second= mGenome.at(i).genes;
|
|
}
|
|
else{
|
|
first = mGenome.at(i).genes;
|
|
second= fGenome.at(i).genes;
|
|
}
|
|
Chromosome childChromosome(fGenome.at(i).name, first);
|
|
// Äëÿ êàæäîé õðîìîñîìû âûáèðàåì ñâîþ "òî÷êó ïåðåãèáà"
|
|
int bound = rand() % first.size();
|
|
for(unsigned int j = bound; j < first.size(); j++){
|
|
childChromosome.genes.at(j) = second.at(j);
|
|
}
|
|
chromosomes.push_back(childChromosome);
|
|
|
|
}
|
|
// Òóò òàêæå ìîæíî ó÷åñòü, ÷òî ìîãóò áûòü íåãîìîëîãè÷íûå õðîìîñîìû (íàïð. Õ è Ó),
|
|
// êîòîðûå áóäóò íàñëåäîâàòüñÿ, îïðåäåëÿÿ ïîë îñîáè ïî ãåíîìó
|
|
|
|
return HaploidGenotype(chromosomes);
|
|
}
|
|
|
|
ChromosomeRearrangementStrategy* RecombinationStrategies::getInstance(std::string _name){
|
|
return new ChromosomeRearrangementStrategy();
|
|
} |