Init version
This commit is contained in:
125
processor/KolchShindyalov.cpp
Normal file
125
processor/KolchShindyalov.cpp
Normal file
@@ -0,0 +1,125 @@
|
||||
#include "Settings.h"
|
||||
#include "../population/Population.h"
|
||||
#include "../individual/Phenotype.h"
|
||||
#include "../individual/genome/strategies/GenotypeToPhenotypeStrategy.h"
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include "KolchShindyalov.h"
|
||||
|
||||
void KolchShindyalov::test01(){
|
||||
std::ofstream statFile("statFile.txt");
|
||||
std::string stat;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int maxGenerations = Settings::Iterations;
|
||||
long initPopSize = Settings::InitPopSize;
|
||||
float ratioBetweenPops = Settings::InitRatioBetweenPops;
|
||||
long int maxIndivids = Settings::KMaxParameter;
|
||||
|
||||
Position3D<double> position(0, 0, 0, 1000, 1000, 1000);
|
||||
Region region(position, maxIndivids);
|
||||
|
||||
srand(0);
|
||||
int RANGE = 1000;
|
||||
int PRECISION = 10;
|
||||
float gValue;
|
||||
|
||||
std::vector<Individual*> individs;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
for(int i = 0; i < initPopSize; i++){
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
std::vector<Chromosome> fGenome;
|
||||
std::vector<Chromosome> mGenome;
|
||||
|
||||
std::vector<Chromosome> chroms;
|
||||
for(int j = 0; j < 2; j++){
|
||||
//float gValue
|
||||
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
RANGE = 10;
|
||||
gValue = -(float)(rand()%(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"); // <20><><EFBFBD><EFBFBD> / <20><><EFBFBD><EFBFBD>
|
||||
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) <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
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) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
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) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
for(int i = 0; i < maxGenerations; i++){
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
population.breedAll();
|
||||
//--- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ---
|
||||
stat = population.getSatistics();
|
||||
statFile<<stat<<std::endl;
|
||||
|
||||
if(Settings::WRITE_FULL_STATISTICS_TO_FILE){
|
||||
std::stringstream ss;
|
||||
std::stringstream ss2;
|
||||
std::stringstream ss3;
|
||||
ss<<"generation."<<(i)<<".xls";
|
||||
ss2<<"generation."<<(i)<<".txt";
|
||||
ss3<<"gmaxAB."<<(i)<<".txt";
|
||||
std::ofstream genFile(ss.str().c_str());
|
||||
std::ofstream genFile2(ss2.str().c_str());
|
||||
std::ofstream genFile3(ss3.str().c_str());
|
||||
population.putGeneticStatisticsToStream(genFile);
|
||||
population.putGeneticSimpleStatisticsToStream(genFile2);
|
||||
population.putGeneticMaxModuleStatisticsToStream(genFile3);
|
||||
genFile.close();
|
||||
genFile2.close();
|
||||
genFile3.close();
|
||||
}
|
||||
//------------------
|
||||
}
|
||||
statFile.close();
|
||||
}
|
||||
6
processor/KolchShindyalov.h
Normal file
6
processor/KolchShindyalov.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
class KolchShindyalov{
|
||||
public:
|
||||
static void test01(/*int, int*/);
|
||||
};
|
||||
372
processor/Processor.cpp
Normal file
372
processor/Processor.cpp
Normal file
@@ -0,0 +1,372 @@
|
||||
#include "Processor.h"
|
||||
#include "Settings.h"
|
||||
#include "../population/Population.h"
|
||||
#include "../individual/Phenotype.h"
|
||||
#include "../individual/genome/strategies/GenotypeToPhenotypeStrategy.h"
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
void Processor::test(/*int initPSize, int steps*/){
|
||||
std::ofstream statFile("statFile.txt");
|
||||
std::string stat;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int maxGenerations = Settings::Iterations;
|
||||
int initPopSize = Settings::InitPopSize;
|
||||
|
||||
AsexualPopulation population(initPopSize);
|
||||
population.setBreedingStrategy(PopulationBreedingStrategy::getInstance(Settings::BreedingStrategy));
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
for(int i = 0; i < maxGenerations; i++){
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (<28><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD>)
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
population.calculateFitnessAll();
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
population.breedAll();
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
population.mutationAll();
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (<28><><EFBFBD><EFBFBD> <20><><EFBFBD>)
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> (<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20>.<2E>.)
|
||||
population.selectionAll();
|
||||
|
||||
//--- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ---
|
||||
stat = population.getSatistics();
|
||||
statFile<<stat<<std::endl;
|
||||
|
||||
if(Settings::WRITE_FULL_STATISTICS_TO_FILE){
|
||||
std::stringstream ss;
|
||||
ss<<"generation."<<(i)<<".txt";
|
||||
std::ofstream genFile(ss.str().c_str());
|
||||
population.putGeneticStatisticsToStream(genFile);
|
||||
genFile.close();
|
||||
}
|
||||
//------------------
|
||||
}
|
||||
statFile.close();
|
||||
}
|
||||
|
||||
void Processor::test01(/*int initPSize, int steps*/){
|
||||
std::ofstream statFile("statFile.txt");
|
||||
std::string stat;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int maxGenerations = Settings::Iterations;
|
||||
long initPopSize = Settings::InitPopSize;
|
||||
long int maxIndivids = Settings::KMaxParameter;
|
||||
|
||||
Position3D<double> position(0, 0, 0, 1000, 1000, 1000);
|
||||
Region region(position, maxIndivids);
|
||||
|
||||
AsexualPopulation population(initPopSize);
|
||||
population.setBreedingStrategy(PopulationBreedingStrategy::getInstance(Settings::BreedingStrategy));
|
||||
population.setRegion(®ion);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
for(int i = 0; i < maxGenerations; i++){
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (<28><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD>)
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
population.calculateFitnessAll();
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
population.breedAll();
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
population.mutationAll();
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (<28><><EFBFBD><EFBFBD> <20><><EFBFBD>)
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> (<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20>.<2E>.)
|
||||
population.selectionAll();
|
||||
|
||||
//--- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ---
|
||||
stat = population.getSatistics();
|
||||
statFile<<stat<<std::endl;
|
||||
|
||||
if(Settings::WRITE_FULL_STATISTICS_TO_FILE){
|
||||
std::stringstream ss;
|
||||
ss<<"generation."<<(i)<<".txt";
|
||||
std::ofstream genFile(ss.str().c_str());
|
||||
population.putGeneticStatisticsToStream(genFile);
|
||||
genFile.close();
|
||||
}
|
||||
//------------------
|
||||
}
|
||||
statFile.close();
|
||||
}
|
||||
|
||||
///
|
||||
void Processor::testInOutBreeding01(){
|
||||
std::ofstream statFile("statFile.txt");
|
||||
std::string stat;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int maxGenerations = Settings::Iterations;
|
||||
long initPopSize = Settings::InitPopSize;
|
||||
long int maxIndivids = Settings::KMaxParameter;
|
||||
|
||||
Position3D<double> position(0, 0, 0, 1000, 1000, 1000);
|
||||
Region region(position, maxIndivids);
|
||||
|
||||
|
||||
srand(0);
|
||||
int RANGE = 1000;
|
||||
int PRECISION = 10;
|
||||
float gValue;
|
||||
|
||||
std::vector<Individual*> individs;
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
for(int i = 0; i < maxIndivids/2; i++){
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
std::vector<Chromosome> fGenome;
|
||||
std::vector<Chromosome> mGenome;
|
||||
|
||||
std::vector<Chromosome> chroms;
|
||||
for(int j = 0; j < 2; j++){
|
||||
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
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"); // <20><><EFBFBD><EFBFBD> / <20><><EFBFBD><EFBFBD>
|
||||
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) <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
Trait trait1(Trait::Continious, "coadaptive", 0.0f);
|
||||
Trait trait2(Trait::Continious, "disease", 0.0f);
|
||||
Phenotype* phenotype = new Phenotype(trait1);
|
||||
phenotype->addTrait(trait2);
|
||||
// (END) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
// <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
InnerSubstratesPool* subPool = 0;
|
||||
// (END) <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
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) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
for(int i = 0; i < maxGenerations; i++){
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
population.breedAll();
|
||||
//--- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ---
|
||||
stat = population.getSatistics();
|
||||
statFile<<stat<<std::endl;
|
||||
|
||||
if(Settings::WRITE_FULL_STATISTICS_TO_FILE){
|
||||
std::stringstream ss;
|
||||
std::stringstream ss2;
|
||||
ss<<"generation."<<(i)<<".xls";
|
||||
ss2<<"generation."<<(i)<<".txt";
|
||||
std::ofstream genFile(ss.str().c_str());
|
||||
std::ofstream genFile2(ss2.str().c_str());
|
||||
population.putGeneticStatisticsToStream(genFile);
|
||||
population.putGeneticSimpleStatisticsToStream(genFile2);
|
||||
genFile.close();
|
||||
genFile2.close();
|
||||
}
|
||||
//------------------
|
||||
}
|
||||
statFile.close();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
void Processor::testInOutBreeding02(){
|
||||
std::ofstream statFile("statFile.txt");
|
||||
std::string stat;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int maxGenerations = Settings::Iterations;
|
||||
long initPopSize = Settings::InitPopSize;
|
||||
float ratioBetweenPops = Settings::InitRatioBetweenPops;
|
||||
long int maxIndivids = Settings::KMaxParameter;
|
||||
|
||||
Position3D<double> position(0, 0, 0, 1000, 1000, 1000);
|
||||
Region region(position, maxIndivids);
|
||||
|
||||
srand(0);
|
||||
int RANGE = 1000;
|
||||
int PRECISION = 10;
|
||||
float gValue;
|
||||
|
||||
std::vector<Individual*> individs;
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - <20><><EFBFBD><EFBFBD><EFBFBD> 1
|
||||
for(int i = 0; i < initPopSize*ratioBetweenPops; i++){
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
std::vector<Chromosome> fGenome;
|
||||
std::vector<Chromosome> mGenome;
|
||||
|
||||
std::vector<Chromosome> chroms;
|
||||
for(int j = 0; j < 2; j++){
|
||||
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
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"); // <20><><EFBFBD><EFBFBD> / <20><><EFBFBD><EFBFBD>
|
||||
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) <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
Trait trait1(Trait::Continious, "coadaptive", 0.0f);
|
||||
Trait trait2(Trait::Continious, "disease", 0.0f);
|
||||
Phenotype* phenotype = new Phenotype(trait1);
|
||||
phenotype->addTrait(trait2);
|
||||
// (END) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
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++)
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - <20><><EFBFBD><EFBFBD><EFBFBD> 2
|
||||
for(int i = 0; i < initPopSize; i++){
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
std::vector<Chromosome> fGenome;
|
||||
std::vector<Chromosome> mGenome;
|
||||
|
||||
std::vector<Chromosome> chroms;
|
||||
for(int j = 0; j < 2; j++){
|
||||
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
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"); // <20><><EFBFBD><EFBFBD> / <20><><EFBFBD><EFBFBD>
|
||||
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) <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
Trait trait1(Trait::Continious, "coadaptive", 0.0f);
|
||||
Trait trait2(Trait::Continious, "disease", 0.0f);
|
||||
Phenotype* phenotype = new Phenotype(trait1);
|
||||
phenotype->addTrait(trait2);
|
||||
// (END) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
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) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
for(int i = 0; i < maxGenerations; i++){
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
population.breedAll();
|
||||
//--- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ---
|
||||
stat = population.getSatistics();
|
||||
statFile<<stat<<std::endl;
|
||||
|
||||
if(Settings::WRITE_FULL_STATISTICS_TO_FILE){
|
||||
std::stringstream ss;
|
||||
std::stringstream ss2;
|
||||
std::stringstream ss3;
|
||||
ss<<"generation."<<(i)<<".xls";
|
||||
ss2<<"generation."<<(i)<<".txt";
|
||||
ss3<<"gmaxAB."<<(i)<<".txt";
|
||||
std::ofstream genFile(ss.str().c_str());
|
||||
std::ofstream genFile2(ss2.str().c_str());
|
||||
std::ofstream genFile3(ss3.str().c_str());
|
||||
population.putGeneticStatisticsToStream(genFile);
|
||||
population.putGeneticSimpleStatisticsToStream(genFile2);
|
||||
population.putGeneticMaxModuleStatisticsToStream(genFile3);
|
||||
genFile.close();
|
||||
genFile2.close();
|
||||
genFile3.close();
|
||||
}
|
||||
//------------------
|
||||
}
|
||||
statFile.close();
|
||||
}
|
||||
11
processor/Processor.h
Normal file
11
processor/Processor.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
class Processor{
|
||||
|
||||
public:
|
||||
static void test(/*int, int*/);
|
||||
static void test01(/*int, int*/);
|
||||
|
||||
static void testInOutBreeding01();
|
||||
static void testInOutBreeding02();
|
||||
};
|
||||
163
processor/Settings.cpp
Normal file
163
processor/Settings.cpp
Normal file
@@ -0,0 +1,163 @@
|
||||
#include "Settings.h"
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <cstdio>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/tokenizer.hpp>
|
||||
|
||||
#ifdef LINUX
|
||||
#define sscanf_s sscanf
|
||||
#endif
|
||||
|
||||
// Default parameters
|
||||
bool Settings::WRITE_FULL_STATISTICS_TO_FILE = false;
|
||||
|
||||
int Settings::Iterations = 10;
|
||||
long int Settings::InitPopSize = 10;
|
||||
float Settings::InitRatioBetweenPops = 1.f;
|
||||
|
||||
double Settings::BirthRate = 0.01;
|
||||
double Settings::NaturalDeathRate = 0.01;
|
||||
|
||||
long int Settings::KMaxParameter = 10000;
|
||||
|
||||
int Settings::OffspringsMean = 3;
|
||||
float Settings::CoadaptiveThreshold = 0;
|
||||
float Settings::CoadaptiveMinimumP = 0.2f;
|
||||
float Settings::CoadaptiveMaximumTrait = 15.f;
|
||||
|
||||
float Settings::DiseaseThreshold = 1;
|
||||
std::string Settings::CoadaptiveGenesInteraction = "onechromosome";
|
||||
std::string Settings::DiseaseGenesInteraction = "add";
|
||||
|
||||
|
||||
std::string Settings::BreedingStrategy = "default";
|
||||
std::string Settings::GenToPhenStrategy = "default";
|
||||
std::string Settings::PhenToFitStrategy = "default";
|
||||
std::string Settings::RecombinationStrategy = "default";
|
||||
|
||||
double Settings::ProbMtDNARecomb = 0.0;
|
||||
int Settings::PopulationHomoInitSize = 1000;
|
||||
int Settings::PopulationAncientInitSize = 1000;
|
||||
double Settings::migrationPartHomoToAncient = 0.1;
|
||||
double Settings::migrationPartAncientToHomo = 0.1;
|
||||
int Settings::generationsPerMigration = 100;
|
||||
int Settings::locusLength = 60;
|
||||
double Settings::percentDiffLoci = 0.1;
|
||||
int Settings::numLoci = 50;
|
||||
// (END) Default parameters
|
||||
|
||||
void Settings::initScript(std::string fileName){
|
||||
std::vector<std::string> script;
|
||||
std::ifstream file(fileName.c_str());
|
||||
std::string str;
|
||||
|
||||
while(getline(file,str)){
|
||||
if(str.length() > 2)
|
||||
script.push_back(str);
|
||||
}
|
||||
file.close();
|
||||
|
||||
// process Script
|
||||
unsigned int curLine;
|
||||
for(curLine = 0; curLine < script.size(); curLine++){
|
||||
if(script.at(curLine).at(0) == '/' || script.at(curLine).at(0) == '#')
|
||||
continue;
|
||||
|
||||
std::vector<std::string > tokensVector; // Search for tokens
|
||||
boost::split(tokensVector, script.at(curLine), boost::is_any_of("=") );
|
||||
|
||||
std::string instr = tokensVector.at(0);
|
||||
boost::to_lower(instr);
|
||||
boost::trim(instr);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if(instr == "fullstat"){
|
||||
int flag = 0;
|
||||
sscanf_s(tokensVector.at(1).c_str(),"%d", &flag);
|
||||
if(flag != 0)
|
||||
Settings::WRITE_FULL_STATISTICS_TO_FILE = true;
|
||||
}
|
||||
else if(instr == "generations" || instr == "iterations" ){
|
||||
int iter = Settings::Iterations;
|
||||
sscanf_s(tokensVector.at(1).c_str(),"%d", &iter);
|
||||
Settings::Iterations = iter;
|
||||
}
|
||||
else if(instr == "initpopsize" || instr == "init_pop_size" || instr == "popsize" ){
|
||||
long int size = Settings::InitPopSize;
|
||||
sscanf_s(tokensVector.at(1).c_str(),"%ld", &size);
|
||||
Settings::InitPopSize = size;
|
||||
}
|
||||
else if(instr == "initratio" || instr == "init_ratio" || instr == "init_ratio_between_pop_size" ){
|
||||
float size = Settings::InitRatioBetweenPops;
|
||||
sscanf_s(tokensVector.at(1).c_str(),"%f", &size);
|
||||
Settings::InitRatioBetweenPops = size;
|
||||
}
|
||||
else if(instr == "birth" || instr == "birthrate" || instr == "birth_rate" ){
|
||||
double rate = Settings::BirthRate;
|
||||
sscanf_s(tokensVector.at(1).c_str(),"%lg", &rate);
|
||||
Settings::BirthRate = rate;
|
||||
}
|
||||
else if(instr == "death" || instr == "deathrate" || instr == "death_rate" ){
|
||||
double rate = Settings::NaturalDeathRate;
|
||||
sscanf_s(tokensVector.at(1).c_str(),"%lg", &rate);
|
||||
Settings::NaturalDeathRate = rate;
|
||||
}
|
||||
else if(instr == "kmax"){
|
||||
long int kMax = Settings::KMaxParameter;
|
||||
sscanf_s(tokensVector.at(1).c_str(),"%ld", &kMax);
|
||||
Settings::KMaxParameter = kMax;
|
||||
}
|
||||
else if(instr == "offsprings" || instr == "offsprings_mean" ){
|
||||
int offsprings = Settings::OffspringsMean;
|
||||
sscanf_s(tokensVector.at(1).c_str(),"%d", &offsprings);
|
||||
Settings::OffspringsMean = offsprings;
|
||||
}
|
||||
else if(instr == "coadaptivet" || instr == "coadaptive_threshold" ){
|
||||
float coadaptive = Settings::CoadaptiveThreshold;
|
||||
sscanf_s(tokensVector.at(1).c_str(),"%f", &coadaptive);
|
||||
Settings::CoadaptiveThreshold = coadaptive;
|
||||
}
|
||||
else if(instr == "coadaptivemax" || instr == "coadaptive_maximum_trait" ){
|
||||
float coadaptive = Settings::CoadaptiveMaximumTrait;
|
||||
sscanf_s(tokensVector.at(1).c_str(),"%f", &coadaptive);
|
||||
Settings::CoadaptiveMaximumTrait = coadaptive;
|
||||
}
|
||||
else if(instr == "coadaptivemin" || instr == "coadaptive_minimum_p" ){
|
||||
float coadaptive = Settings::CoadaptiveMinimumP;
|
||||
sscanf_s(tokensVector.at(1).c_str(),"%f", &coadaptive);
|
||||
Settings::CoadaptiveMinimumP = coadaptive;
|
||||
}
|
||||
else if(instr == "diseaset" || instr == "disease_threshold" ){
|
||||
float disease = Settings::DiseaseThreshold;
|
||||
sscanf_s(tokensVector.at(1).c_str(),"%f", &disease);
|
||||
Settings::DiseaseThreshold = disease;
|
||||
}
|
||||
else if(instr == "coadaptivegenesinteract" || instr == "cgi"){
|
||||
//long int kMax = Settings::KMaxParameter;
|
||||
//sscanf_s(tokensVector.at(1).c_str(),"%ld", &kMax);
|
||||
std::string cgi = tokensVector.at(1);
|
||||
boost::to_lower(cgi);
|
||||
boost::trim(cgi);
|
||||
Settings::CoadaptiveGenesInteraction = cgi;
|
||||
}
|
||||
else if(instr == "diseasegenesinteract" || instr == "dgi"){
|
||||
//long int kMax = Settings::KMaxParameter;
|
||||
//sscanf_s(tokensVector.at(1).c_str(),"%ld", &kMax);
|
||||
std::string dgi = tokensVector.at(1);
|
||||
boost::to_lower(dgi);
|
||||
boost::trim(dgi);
|
||||
Settings::DiseaseGenesInteraction = dgi;
|
||||
}
|
||||
//*****************************
|
||||
else if(instr == "breedings"){
|
||||
//long int kMax = Settings::KMaxParameter;
|
||||
//sscanf_s(tokensVector.at(1).c_str(),"%ld", &kMax);
|
||||
std::string strategy = tokensVector.at(1);
|
||||
boost::to_lower(strategy);
|
||||
boost::trim(strategy);
|
||||
Settings::BreedingStrategy = strategy;
|
||||
}
|
||||
} // (END) for(curLine = 0; curLine < script.size(); curLine++)
|
||||
}
|
||||
45
processor/Settings.h
Normal file
45
processor/Settings.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
class Settings {
|
||||
public:
|
||||
static bool WRITE_FULL_STATISTICS_TO_FILE;
|
||||
|
||||
static int Iterations;
|
||||
static long int InitPopSize;
|
||||
static float InitRatioBetweenPops;
|
||||
|
||||
// Common breeding strategies parameters
|
||||
static double BirthRate;
|
||||
static double NaturalDeathRate;
|
||||
|
||||
// Verhulst breeding strategy default parameters
|
||||
static long int KMaxParameter; // r*X*(1 - X/KMax)
|
||||
|
||||
// Inbreeding/Outbreeding model parameters
|
||||
static int OffspringsMean;
|
||||
static float CoadaptiveThreshold;
|
||||
static float CoadaptiveMinimumP;
|
||||
static float CoadaptiveMaximumTrait;
|
||||
static float DiseaseThreshold;
|
||||
static std::string CoadaptiveGenesInteraction;
|
||||
static std::string DiseaseGenesInteraction;
|
||||
|
||||
static std::string BreedingStrategy;
|
||||
static std::string GenToPhenStrategy;
|
||||
static std::string PhenToFitStrategy;
|
||||
static std::string RecombinationStrategy;
|
||||
|
||||
static double ProbMtDNARecomb;
|
||||
static int PopulationHomoInitSize;
|
||||
static int PopulationAncientInitSize;
|
||||
static double migrationPartHomoToAncient;
|
||||
static double migrationPartAncientToHomo;
|
||||
static int generationsPerMigration;
|
||||
static int locusLength;
|
||||
static double percentDiffLoci;
|
||||
static int numLoci;
|
||||
|
||||
public:
|
||||
static void initScript(std::string fileName);
|
||||
};
|
||||
Reference in New Issue
Block a user