#include "Settings.h" #include "../population/Population.h" #include "../individual/Phenotype.h" #include "../individual/genome/strategies/GenotypeToPhenotypeStrategy.h" #include #include #include #include #include #include "KolchShindyalov.h" void KolchShindyalov::test01(){ std::ofstream statFile("statFile.txt"); std::string stat; std::cout << "Kolch" << std::endl; // Инициализация int maxGenerations = Settings::Iterations; long initPopSize = Settings::InitPopSize; float ratioBetweenPops = Settings::InitRatioBetweenPops; long int maxIndivids = Settings::KMaxParameter; Position3D position(0, 0, 0, 1000, 1000, 1000); Region region(position, maxIndivids); qsrand(0); int RANGE = 1000; int PRECISION = 10; float gValue; std::vector individs; // Стохастическое создание популяции for(int i = 0; i < initPopSize; i++){ // Геном std::vector fGenome; std::vector mGenome; std::vector chroms; for(int j = 0; j < 2; j++){ //float gValue // Одна хромосома с шестью генами RANGE = 10; gValue = -(float)(qrand()%(RANGE*PRECISION+1))/PRECISION; Gene geneF1(Gene::Continious, "C1", gValue); gValue = -(float)(rand()%(RANGE*PRECISION+1))/PRECISION; Gene geneF2(Gene::Continious, "C2", gValue); PRECISION=1; RANGE = 2; gValue = (rand()%(RANGE*PRECISION + 1)) / (float) RANGE / PRECISION; Gene geneF3(Gene::Continious, "C3", gValue); gValue = (rand()%(RANGE*PRECISION + 1)) / (float) RANGE / PRECISION; Gene geneF4(Gene::Continious, "C4", gValue); gValue = (rand()%(RANGE*PRECISION + 1)) / (float) RANGE / PRECISION; Gene geneF5(Gene::Continious, "C5", gValue); gValue = (rand()%(RANGE*PRECISION + 1)) / (float) RANGE / PRECISION; Gene geneF6(Gene::Continious, "E", gValue); gValue = rand()%2; Gene geneF7(Gene::Discrete,"Feedback", gValue); Chromosome chromF("Chrom 1"); // папа / мама chromF.insertGeneToEnd(geneF1); chromF.insertGeneToEnd(geneF2); chromF.insertGeneToEnd(geneF3); chromF.insertGeneToEnd(geneF4); chromF.insertGeneToEnd(geneF5); chromF.insertGeneToEnd(geneF6); chromF.insertGeneToEnd(geneF7); chroms.push_back(chromF); } // (END) for(int i = 0; i < 2; i++) fGenome.push_back(chroms.at(0)); mGenome.push_back(chroms.at(1)); Genotype* genotype = new Genotype(fGenome, mGenome); // (END) Геном // Фенотип Trait trait1(Trait::Continious, "X", 10.0f); Trait trait2(Trait::Continious, "Xopt", 10.0f); Trait trait3(Trait::Continious, "sigmaX", 3.0f); Phenotype* phenotype = new Phenotype(trait1); phenotype->addTrait(trait2); phenotype->addTrait(trait3); // (END) Фенотип Individual* newInd = new Individual(genotype, phenotype, 0, Individual::hermaphrodite, 0); newInd->setGenToPhenStrategy(GenotypeToPhenotypeStrategies::getInstance("kolchan_shindyal_gen_to_phen")); newInd->setPhenToFitnessStrategy(PhenotypeToFitnessStrategy::getInstance("kolch_shindyal_phen_to_fit")); individs.push_back(newInd); } // (END) for(int i = 0; i < size; i++) AsexualPopulation population(individs); population.setBreedingStrategy(PopulationBreedingStrategy::getInstance("kolchan_shindyal_breeding")); population.setRegion(®ion); // (END) Создание популяции // Итерационный цикл for(int i = 0; i < maxGenerations; i++){ // Размножить population.breedAll(); //--- Статистика --- stat = population.getSatistics(); statFile<