Commit e0611b9c authored by Ogier Maitre's avatar Ogier Maitre
Browse files

Segfault resolved. Correct initialization of the random generator.

parent 3fd5741e
...@@ -17,6 +17,10 @@ CRandomGenerator::CRandomGenerator(unsigned int seed){ ...@@ -17,6 +17,10 @@ CRandomGenerator::CRandomGenerator(unsigned int seed){
//srand(seed); //srand(seed);
} }
CRandomGenerator::~CRandomGenerator(){
delete this->mt_rnd;
}
int CRandomGenerator::randInt(){ int CRandomGenerator::randInt(){
//return rand(); //return rand();
return mt_rnd->randInt(); return mt_rnd->randInt();
......
...@@ -16,6 +16,7 @@ class CRandomGenerator { ...@@ -16,6 +16,7 @@ class CRandomGenerator {
MTRand* mt_rnd; MTRand* mt_rnd;
public: public:
CRandomGenerator(unsigned int seed); CRandomGenerator(unsigned int seed);
~CRandomGenerator();
int randInt(); int randInt();
bool tossCoin(); bool tossCoin();
bool tossCoin(float bias); bool tossCoin(float bias);
......
...@@ -214,6 +214,11 @@ size_t IndividualImpl::mutate( float pMutationPerGene ){ ...@@ -214,6 +214,11 @@ size_t IndividualImpl::mutate( float pMutationPerGene ){
} }
void ParametersImpl::setDefaultParameters(int argc, char** argv){ void ParametersImpl::setDefaultParameters(int argc, char** argv){
seed = setVariable("seed",(int)time(0));
globalRandomGenerator = new CRandomGenerator(seed);
this->randomGenerator = globalRandomGenerator;
this->minimizing = \MINIMAXI; this->minimizing = \MINIMAXI;
this->nbGen = setVariable("nbGen",(int)\NB_GEN); this->nbGen = setVariable("nbGen",(int)\NB_GEN);
...@@ -279,9 +284,6 @@ void ParametersImpl::setDefaultParameters(int argc, char** argv){ ...@@ -279,9 +284,6 @@ void ParametersImpl::setDefaultParameters(int argc, char** argv){
this->optimise = 0; this->optimise = 0;
seed = setVariable("seed",(int)time(0));
globalRandomGenerator = new CRandomGenerator(seed);
this->randomGenerator = globalRandomGenerator;
this->printStats = setVariable("printStats",\PRINT_STATS); this->printStats = setVariable("printStats",\PRINT_STATS);
this->generateCSVFile = setVariable("generateCSVFile",\GENERATE_CSV_FILE); this->generateCSVFile = setVariable("generateCSVFile",\GENERATE_CSV_FILE);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment