164 lines
5.7 KiB
C++
164 lines
5.7 KiB
C++
#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++)
|
||
}
|