#include "Processor.h" #include "Settings.h" #include "../population/Population.h" #include "../individual/Phenotype.h" #include "../individual/genome/strategies/GenotypeToPhenotypeStrategy.h" #include #include #include void Processor::test(/*int initPSize, int steps*/){ std::ofstream statFile("statFile.txt"); std::string stat; // Инициализация int maxGenerations = Settings::Iterations; int initPopSize = Settings::InitPopSize; AsexualPopulation population(initPopSize); population.setBreedingStrategy(PopulationBreedingStrategy::getInstance(Settings::BreedingStrategy)); // Итерационный цикл for(int i = 0; i < maxGenerations; i++){ // Покушать (пока ничего делать не надо) // Испытать эффект среды population.calculateFitnessAll(); // Размножить population.breedAll(); // Мутации population.mutationAll(); // Миграция (пока нет) // Смоделировать отбор (случайная смертность и т.д.) population.selectionAll(); //--- Статистика --- stat = population.getSatistics(); statFile< position(0, 0, 0, 1000, 1000, 1000); Region region(position, maxIndivids); AsexualPopulation population(initPopSize); population.setBreedingStrategy(PopulationBreedingStrategy::getInstance(Settings::BreedingStrategy)); population.setRegion(®ion); // Итерационный цикл for(int i = 0; i < maxGenerations; i++){ // Покушать (пока ничего делать не надо) // Испытать эффект среды population.calculateFitnessAll(); // Размножить population.breedAll(); // Мутации population.mutationAll(); // Миграция (пока нет) // Смоделировать отбор (случайная смертность и т.д.) population.selectionAll(); //--- Статистика --- stat = population.getSatistics(); statFile< position(0, 0, 0, 1000, 1000, 1000); Region region(position, maxIndivids); srand(0); int RANGE = 1000; int PRECISION = 10; float gValue; std::vector individs; // Стохастическое создание популяции for(int i = 0; i < maxIndivids/2; i++){ // Геном std::vector fGenome; std::vector mGenome; std::vector chroms; for(int j = 0; j < 2; j++){ // Одна хромосома с шестью генами RANGE = 10; gValue = (float)(rand()%(RANGE*PRECISION+1))/PRECISION; Gene geneF1(Gene::Continious, "A coadaptive", gValue); gValue = (float)(rand()%(RANGE*PRECISION+1))/PRECISION; Gene geneF2(Gene::Continious, "B coadaptive", gValue); RANGE = 2; gValue = (rand()%(RANGE + 1)) / (float) RANGE; Gene geneF3(Gene::Continious, "C disease", gValue); gValue = (rand()%(RANGE + 1)) / (float) RANGE; Gene geneF4(Gene::Continious, "D disease", gValue); gValue = (rand()%(RANGE + 1)) / (float) RANGE; Gene geneF5(Gene::Continious, "E disease", gValue); gValue = (rand()%(RANGE + 1)) / (float) RANGE; Gene geneF6(Gene::Continious, "F disease", gValue); Chromosome chromF("Chrom 1"); // папа / мама chromF.insertGeneToEnd(geneF1); chromF.insertGeneToEnd(geneF2); chromF.insertGeneToEnd(geneF3); chromF.insertGeneToEnd(geneF4); chromF.insertGeneToEnd(geneF5); chromF.insertGeneToEnd(geneF6); 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, "coadaptive", 0.0f); Trait trait2(Trait::Continious, "disease", 0.0f); Phenotype* phenotype = new Phenotype(trait1); phenotype->addTrait(trait2); // (END) Фенотип // Пул субстратов InnerSubstratesPool* subPool = 0; // (END) Пул субстратов Individual* newInd = new Individual(genotype, phenotype, subPool, Individual::hermaphrodite, 0); newInd->setGenToPhenStrategy(GenotypeToPhenotypeStrategies::getInstance("inoutbreeding")); individs.push_back(newInd); } // (END) for(int i = 0; i < size; i++) AsexualPopulation population(individs); population.setBreedingStrategy(PopulationBreedingStrategy::getInstance("inoutbreeding")); population.setRegion(®ion); // (END) Создание популяции // Итерационный цикл for(int i = 0; i < maxGenerations; i++){ // Размножить population.breedAll(); //--- Статистика --- stat = population.getSatistics(); statFile< position(0, 0, 0, 1000, 1000, 1000); Region region(position, maxIndivids); srand(0); int RANGE = 1000; int PRECISION = 10; float gValue; std::vector individs; // Стохастическое создание популяции - часть 1 for(int i = 0; i < initPopSize*ratioBetweenPops; i++){ // Геном std::vector fGenome; std::vector mGenome; std::vector chroms; for(int j = 0; j < 2; j++){ // Одна хромосома с шестью генами RANGE = 10; gValue = (float)(rand()%(RANGE*PRECISION+1))/PRECISION; Gene geneF1(Gene::Continious, "A coadaptive", gValue); gValue = (float)(rand()%(RANGE*PRECISION+1))/PRECISION; Gene geneF2(Gene::Continious, "B coadaptive", gValue); RANGE = 2; gValue = (rand()%(RANGE*PRECISION + 1)) / (float) RANGE / PRECISION; Gene geneF3(Gene::Continious, "C disease", gValue); gValue = (rand()%(RANGE*PRECISION + 1)) / (float) RANGE / PRECISION; Gene geneF4(Gene::Continious, "D disease", gValue); gValue = (rand()%(RANGE*PRECISION + 1)) / (float) RANGE / PRECISION; Gene geneF5(Gene::Continious, "E disease", gValue); gValue = (rand()%(RANGE*PRECISION + 1)) / (float) RANGE / PRECISION; Gene geneF6(Gene::Continious, "F disease", gValue); Chromosome chromF("Chrom 1"); // папа / мама chromF.insertGeneToEnd(geneF1); chromF.insertGeneToEnd(geneF2); chromF.insertGeneToEnd(geneF3); chromF.insertGeneToEnd(geneF4); chromF.insertGeneToEnd(geneF5); chromF.insertGeneToEnd(geneF6); 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, "coadaptive", 0.0f); Trait trait2(Trait::Continious, "disease", 0.0f); Phenotype* phenotype = new Phenotype(trait1); phenotype->addTrait(trait2); // (END) Фенотип Individual* newInd = new Individual(genotype, phenotype, 0, Individual::hermaphrodite, 0); newInd->setGenToPhenStrategy(GenotypeToPhenotypeStrategies::getInstance("inoutbreeding")); individs.push_back(newInd); } // (END) for(int i = 0; i < size; i++) // Стохастическое создание популяции - часть 2 for(int i = 0; i < initPopSize; i++){ // Геном std::vector fGenome; std::vector mGenome; std::vector chroms; for(int j = 0; j < 2; j++){ // Одна хромосома с шестью генами RANGE = 10; gValue = -(float)(rand()%(RANGE*PRECISION+1))/PRECISION; Gene geneF1(Gene::Continious, "A coadaptive", gValue); gValue = -(float)(rand()%(RANGE*PRECISION+1))/PRECISION; Gene geneF2(Gene::Continious, "B coadaptive", gValue); PRECISION=1; RANGE = 2; gValue = (rand()%(RANGE*PRECISION + 1)) / (float) RANGE / PRECISION; Gene geneF3(Gene::Continious, "C disease", gValue); gValue = (rand()%(RANGE*PRECISION + 1)) / (float) RANGE / PRECISION; Gene geneF4(Gene::Continious, "D disease", gValue); gValue = (rand()%(RANGE*PRECISION + 1)) / (float) RANGE / PRECISION; Gene geneF5(Gene::Continious, "E disease", gValue); gValue = (rand()%(RANGE*PRECISION + 1)) / (float) RANGE / PRECISION; Gene geneF6(Gene::Continious, "F disease", gValue); Chromosome chromF("Chrom 1"); // папа / мама chromF.insertGeneToEnd(geneF1); chromF.insertGeneToEnd(geneF2); chromF.insertGeneToEnd(geneF3); chromF.insertGeneToEnd(geneF4); chromF.insertGeneToEnd(geneF5); chromF.insertGeneToEnd(geneF6); 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, "coadaptive", 0.0f); Trait trait2(Trait::Continious, "disease", 0.0f); Phenotype* phenotype = new Phenotype(trait1); phenotype->addTrait(trait2); // (END) Фенотип Individual* newInd = new Individual(genotype, phenotype, 0, Individual::hermaphrodite, 0); newInd->setGenToPhenStrategy(GenotypeToPhenotypeStrategies::getInstance("inoutbreeding")); individs.push_back(newInd); } // (END) for(int i = 0; i < size; i++) AsexualPopulation population(individs); population.setBreedingStrategy(PopulationBreedingStrategy::getInstance("inoutbreeding")); population.setRegion(®ion); // (END) Создание популяции // Итерационный цикл for(int i = 0; i < maxGenerations; i++){ // Размножить population.breedAll(); //--- Статистика --- stat = population.getSatistics(); statFile<