Commit 1da585d6 authored by kruger's avatar kruger

Modifications necessaires pour la version Windows

parent 4660d658
......@@ -26,7 +26,7 @@ Centre de Math
bool genomeSizeValidity=false;
int lineCounter = 0;
// local functions
// local functions
char* selectorDetermination(int nMINIMISE, char* sSELECTOR){
char selectorName[50];
......@@ -75,7 +75,7 @@ Centre de Math
%start COPY_EO_INITIALISER
%start COPY COPY_INITIALISER COPY_CROSSOVER COPY_MUTATOR COPY_EVALUATOR COPY_FINALIZATION_FUNCTION
%start COPY_DISPLAY COPY_USER_FUNCTION COPY_USER_GENERATION PARAMETERS_ANALYSIS GET_PARAMETERS
%start COPY_USER_FUNCTIONS COPY_GENERATION_FUNCTION_BEFORE_REPLACEMENT GET_METHODS COPY_MAKEFILE_OPTION COPY_BOUND_CHECKING_FUNCTION COPY_BEG_GENERATION_FUNCTION COPY_END_GENERATION_FUNCTION COPY_INSTEAD_EVAL
%start COPY_USER_FUNCTIONS COPY_GENERATION_FUNCTION_BEFORE_REPLACEMENT GET_METHODS COPY_MAKEFILE_OPTION COPY_BOUND_CHECKING_FUNCTION COPY_BEG_GENERATION_FUNCTION COPY_END_GENERATION_FUNCTION
// lexical analyser name and class definition
%name CEASEALexer {
......@@ -187,15 +187,6 @@ exponent ([Ee][+-]?[0-9]+)
}
<TEMPLATE_ANALYSIS>"\\INSTEAD_EVAL_FUNCTION" {
//DEBUG_PRT_PRT("insert beg");
yyreset();
yyin = fpGenomeFile;
if (bVERBOSE) printf ("Evaluation population in a single function!!.\n");
BEGIN COPY_INSTEAD_EVAL;
}
<TEMPLATE_ANALYSIS>"\\INSERT_END_GENERATION_FUNCTION" {
//DEBUG_PRT_PRT("insert end");
if (bVERBOSE) printf ("Inserting at the end of each generation function.\n");
......@@ -506,7 +497,7 @@ exponent ([Ee][+-]?[0-9]+)
if (bVERBOSE) printf ("Inserting user functions.\n");
yyreset();
yyin = fpGenomeFile;
lineCounter=2; // switch to .ez file and analyser
lineCounter=1; // switch to .ez file and analyser
BEGIN COPY_USER_FUNCTIONS;
}
<TEMPLATE_ANALYSIS>"\\INSERT_EO_INITIALISER" {
......@@ -540,13 +531,11 @@ exponent ([Ee][+-]?[0-9]+)
<TEMPLATE_ANALYSIS>"\\INSERT_MUTATOR" {
yyreset();
yyin = fpGenomeFile; // switch to .ez file and analyser
lineCounter=1;
BEGIN COPY_MUTATOR;
}
<TEMPLATE_ANALYSIS>"\\INSERT_EVALUATOR" {
yyreset();
yyin = fpGenomeFile; // switch to .ez file and analyser
lineCounter=1;
BEGIN COPY_EVALUATOR;
}
......@@ -554,7 +543,6 @@ exponent ([Ee][+-]?[0-9]+)
yyreset();
yyin = fpGenomeFile; // switch to .ez file and analyser
bWithinCUDA_Evaluator = 1;
lineCounter=1;
BEGIN COPY_EVALUATOR;
}
......@@ -972,29 +960,6 @@ if(OPERATING_SYSTEM=WINDOWS)
}
}
<COPY_INSTEAD_EVAL>"\\Instead"[ \t\n]+"evaluation"[ \t\n]+"function:" {
//DEBUG_PRT_PRT("at each beg");
if( (TARGET==CUDA || TARGET==STD)){
fprintf (fpOutputFile,"{\n");
bFunction=1;
BEGIN COPY_USER_GENERATION;
}
}
<COPY_INSTEAD_EVAL>.|\n {}
<COPY_INSTEAD_EVAL><<EOF>> {
bBeginGenerationFunction=0; // No Generation function was found in the .ez file
if (bVERBOSE) printf("*** No Instead evaluation step function was found. ***\n");
fprintf(fpOutputFile,"\n// No Instead evaluation step function.\n");
rewind(fpGenomeFile);
yyin = fpTemplateFile;
BEGIN TEMPLATE_ANALYSIS;
bNotFinishedYet=1;
}
<COPY_BEG_GENERATION_FUNCTION><<EOF>> {
bBeginGenerationFunction=0; // No Generation function was found in the .ez file
if (bVERBOSE) printf("*** No beginning generation function was found. ***\n");
......@@ -1336,23 +1301,16 @@ if(OPERATING_SYSTEM=WINDOWS)
<COPY_CROSSOVER>\n {lineCounter++;}
<COPY_MUTATOR>"\\GenomeClass::mutator"[ \t\n]*":" {
bWithinMutator=1;
if( bLINE_NUM_EZ_FILE )
fprintf(fpOutputFile,"#line %d \"%s.ez\"\n",lineCounter, sRAW_PROJECT_NAME);
BEGIN COPY_USER_FUNCTION;
return USER_MUTATOR;
}
<COPY_MUTATOR>. {}
<COPY_MUTATOR>\n {lineCounter++;}
<COPY_MUTATOR>.|\n {}
<COPY_EVALUATOR>"\\GenomeClass::evaluator"[ \t\n]*":" {
BEGIN COPY_USER_FUNCTION;
bWithinEvaluator=1;
if( bLINE_NUM_EZ_FILE )
fprintf(fpOutputFile,"#line %d \"%s.ez\"\n",lineCounter, sRAW_PROJECT_NAME);
return USER_EVALUATOR;
}
<COPY_EVALUATOR>. {}
<COPY_EVALUATOR>\n {lineCounter++;}
<COPY_EVALUATOR>.|\n {}
//****************************************
// Basic copy to .cpp file with major changes
......@@ -1682,7 +1640,7 @@ if(OPERATING_SYSTEM=WINDOWS)
<GET_PARAMETERS>"Print"[ \t\n]+"stats"[ \t\n]*":"[\t\n]* {if (bVERBOSE) printf("\tPrint Stats...\n");return PRINT_STATS;}
<GET_PARAMETERS>"Plot"[ \t\n]+"stats"[ \t\n]*":"[\t\n]* {if (bVERBOSE) printf("\tPlot Stats with gnuplot...\n");return PLOT_STATS;}
<GET_PARAMETERS>"Generate"[ \t\n]+"cvs"[ \t\n]+"stats"[ \t\n]+"file"[ \t\n]*":"[ \t\n]* {if (bVERBOSE) printf("\tPrint Stats to cvs File...\n");return GENERATE_CVS_FILE;}
<GET_PARAMETERS>"Generate"[ \t\n]+"csv"[ \t\n]+"stats"[ \t\n]+"file"[ \t\n]*":"[ \t\n]* {if (bVERBOSE) printf("\tPrint Stats to cvs File...\n");return GENERATE_CVS_FILE;}
<GET_PARAMETERS>"Generate"[ \t\n]+"gnuplot"[ \t\n]+"script"[ \t\n]*":"[ \t\n]* {if (bVERBOSE) printf("\tGenerate Gnuplot Script...\n");return GENERATE_GNUPLOT_SCRIPT;}
<GET_PARAMETERS>"Generate"[ \t\n]+"R"[ \t\n]+"script"[ \t\n]*":"[ \t\n]* {if (bVERBOSE) printf("\tGenerate R Script...\n");return GENERATE_R_SCRIPT;}
......
#ifdef WIN32
#pragma comment(lib, "WinMM.lib")
#endif
/*
* CEvolutionaryAlgorithm.cpp
*
......@@ -15,8 +13,8 @@
#endif
#ifdef WIN32
#include <windows.h>
#endif
#include <time.h>
#endif
#include <math.h>
#include <string>
#include "include/CIndividual.h"
......@@ -31,9 +29,6 @@ extern CEvolutionaryAlgorithm* EA;
void EASEABeginningGenerationFunction(CEvolutionaryAlgorithm* evolutionaryAlgorithm);
void EASEAEndGenerationFunction(CEvolutionaryAlgorithm* evolutionaryAlgorithm);
void EASEAGenerationFunctionBeforeReplacement(CEvolutionaryAlgorithm* evolutionaryAlgorithm);
extern void evale_pop_chunk(CIndividual** pop, int popSize);
extern bool INSTEAD_EVAL_STEP;
/**
* @DEPRECATED the next contructor has to be used instead of this one.
*/
......@@ -115,19 +110,19 @@ void CEvolutionaryAlgorithm::runEvolutionaryLoop(){
std::cout << "Parent's population initializing "<< std::endl;
this->initializeParentPopulation();
if(!INSTEAD_EVAL_STEP)
this->population->evaluateParentPopulation();
else
evale_pop_chunk(population->parents, population->parentPopulationSize);
this->population->evaluateParentPopulation();
this->population->currentEvaluationNb += this->params->parentPopulationSize;
if(this->params->printInitialPopulation){
std::cout << *population << std::endl;
}
#ifdef WIN32
clock_t begin(clock());
#else
struct timeval begin;
gettimeofday(&begin,NULL);
#endif
//Initialize elitPopulation
if(params->elitSize)
......@@ -138,10 +133,9 @@ void CEvolutionaryAlgorithm::runEvolutionaryLoop(){
EASEABeginningGenerationFunction(this);
population->produceOffspringPopulation();
if(!INSTEAD_EVAL_STEP)
population->evaluateOffspringPopulation();
else
evale_pop_chunk(population->offsprings, population->offspringPopulationSize);
population->evaluateOffspringPopulation();
population->currentEvaluationNb += this->params->offspringPopulationSize;
EASEAGenerationFunctionBeforeReplacement(this);
......@@ -168,9 +162,8 @@ void CEvolutionaryAlgorithm::runEvolutionaryLoop(){
population->reduceTotalPopulation(elitistPopulation);
population->sortParentPopulation();
showPopulationStats(begin);
bBest = population->Best;
EASEAEndGenerationFunction(this);
currentGeneration += 1;
......@@ -198,7 +191,12 @@ void CEvolutionaryAlgorithm::runEvolutionaryLoop(){
}
#ifdef WIN32
void CEvolutionaryAlgorithm::showPopulationStats(clock_t beginTime){
#else
void CEvolutionaryAlgorithm::showPopulationStats(struct timeval beginTime){
#endif
float currentAverageFitness=0.0;
float currentSTDEV=0.0;
......@@ -223,27 +221,44 @@ void CEvolutionaryAlgorithm::showPopulationStats(struct timeval beginTime){
currentSTDEV/=population->parentPopulationSize;
currentSTDEV=sqrt(currentSTDEV);
#ifdef WIN32
clock_t end(clock());
double duration;
duration = (double)(end-beginTime)/CLOCKS_PER_SEC;
#else
struct timeval end, res;
gettimeofday(&end,0);
timersub(&end,&beginTime,&res);
#endif
//Affichage
if(params->printStats){
if(currentGeneration==0)
printf("GEN\tTIME\t\tEVAL\tBEST\t\tAVG\t\tSTDEV\n\n");
#ifdef WIN32
printf("%lu\t%2.6f\t%lu\t%.15e\t%.15e\t%.15e\n",currentGeneration,duration,population->currentEvaluationNb,population->Best->getFitness(),currentAverageFitness,currentSTDEV);
#else
printf("%lu\t%ld.%06ld\t%lu\t%.15e\t%.15e\t%.15e\n",currentGeneration,res.tv_sec,res.tv_usec,population->currentEvaluationNb,population->Best->getFitness(),currentAverageFitness,currentSTDEV);
#endif
//printf("%lu\t%ld.%06ld\t%lu\t%f\t%f\t%f\n",currentGeneration,res.tv_sec,res.tv_usec,population->currentEvaluationNb,population->Best->getFitness(),currentAverageFitness,currentSTDEV);
}
if((this->params->plotStats && this->gnuplot->valid) || this->params->generateGnuplotScript){
FILE *f;
string fichier (params->outputFilename);
fichier.append(".dat");
f = fopen(fichier.c_str(),"a"); //ajouter .dat
f = fopen(params->outputFilename,"a"); //ajouter .dat
if(f!=NULL){
if(currentGeneration==0)
fprintf(f,"#GEN\tTIME\t\tEVAL\tBEST\t\tAVG\t\tSTDEV\n\n");
#ifdef WIN32
fprintf(f,"%lu\t%2.6f\t%lu\t%.15e\t%.15e\t%.15e\n",currentGeneration,duration,population->currentEvaluationNb,population->Best->getFitness(),currentAverageFitness,currentSTDEV);
#else
fprintf(f,"%lu\t%ld.%06ld\t%lu\t%.15e\t%.15e\t%.15e\n",currentGeneration,res.tv_sec,res.tv_usec,population->currentEvaluationNb,population->Best->getFitness(),currentAverageFitness,currentSTDEV);
#endif
fclose(f);
}
}
......@@ -255,7 +270,13 @@ void CEvolutionaryAlgorithm::showPopulationStats(struct timeval beginTime){
if(f!=NULL){
if(currentGeneration==0)
fprintf(f,"GEN,TIME,EVAL,BEST,AVG,STDEV\n");
#ifdef WIN32
fprintf(f,"%lu,%2.6f,%lu,%.15e,%.15e,%.15e\n",currentGeneration,duration,population->currentEvaluationNb,population->Best->getFitness(),currentAverageFitness,currentSTDEV);
#else
fprintf(f,"%lu,%ld.%06ld,%lu,%.15e,%.15e,%.15e\n",currentGeneration,res.tv_sec,res.tv_usec,population->currentEvaluationNb,population->Best->getFitness(),currentAverageFitness,currentSTDEV);
#endif
fclose(f);
}
}
......@@ -263,7 +284,7 @@ void CEvolutionaryAlgorithm::showPopulationStats(struct timeval beginTime){
#ifdef __linux__
if(this->params->plotStats && this->gnuplot->valid){
if(currentGeneration==0)
fprintf(this->gnuplot->fWrit,"plot \'%s.dat\' using 3:4 t \'Best Fitness\' w lines, \'%s.dat\' using 3:5 t \'Average\' w lines, \'%s.dat\' using 3:6 t \'StdDev\' w lines\n", params->outputFilename,params->outputFilename,params->outputFilename);
fprintf(this->gnuplot->fWrit,"plot \'%s\' using 3:4 t \'Best Fitness\' w lines, \'%s\' using 3:5 t \'Average\' w lines, \'%s\' using 3:6 t \'StdDev\' w lines\n", params->outputFilename,params->outputFilename,params->outputFilename);
else
fprintf(this->gnuplot->fWrit,"replot\n");
fflush(this->gnuplot->fWrit);
......@@ -271,7 +292,7 @@ void CEvolutionaryAlgorithm::showPopulationStats(struct timeval beginTime){
#endif
params->timeCriterion->setElapsedTime(res.tv_sec);
params->timeCriterion->setElapsedTime(duration);
}
void CEvolutionaryAlgorithm::outputGraph(){
......@@ -326,27 +347,3 @@ bool CEvolutionaryAlgorithm::allCriteria(){
}
return false;
}
#ifdef WIN32
int gettimeofday
(struct timeval* tp, void* tzp) {
DWORD t;
t = timeGetTime();
tp->tv_sec = t / 1000;
tp->tv_usec = t % 1000;
/* 0 indicates success. */
return 0;
}
void timersub( const timeval * tvp, const timeval * uvp, timeval* vvp )
{
vvp->tv_sec = tvp->tv_sec - uvp->tv_sec;
vvp->tv_usec = tvp->tv_usec - uvp->tv_usec;
if( vvp->tv_usec < 0 )
{
--vvp->tv_sec;
vvp->tv_usec += 1000000;
}
}
#endif
......@@ -4,8 +4,7 @@
* Created on: 22 juin 2009
* Author: maitre
*/
#include <boost/program_options.hpp>
#include "boost/program_options.hpp"
#include <iostream>
namespace po = boost::program_options;
......@@ -137,7 +136,7 @@ void parseArguments(const char* parametersFileName, int ac, char** av,
("inputfile",po::value<string>(),"Set an input file for the initial population (default : none)")
("printStats",po::value<int>(),"Print the Stats (default : 1)")
("plotStats",po::value<int>(),"Plot the Stats with gnuplot (default : 0)")
("generateCSV",po::value<int>(),"Print the Stats to a CSV File (Filename: ProjectName.csv) (default : 0)")
("generateCSVFile",po::value<int>(),"Print the Stats to a CSV File (Filename: ProjectName.dat) (default : 0)")
("generateGnuplotScript",po::value<int>(),"Generates a Gnuplot script to plat the Stats (Filename: ProjectName.plot) (default : 0)")
("generateRScript",po::value<int>(),"Generates a R script to plat the Stats (Filename: ProjectName.r) (default : 0)")
// ("printStatsFile",po::value<int>(),"Print the Stats to a File (Filename: ProjectName.dat) (default : 0)")
......
......@@ -8,7 +8,6 @@
#include "include/CStoppingCriterion.h"
#include <iostream>
#include <signal.h>
#include "include/global.h"
#include "include/CEvolutionaryAlgorithm.h"
/* ****************************************
......@@ -93,19 +92,3 @@ void signal_handler(int sig){
}
/* ****************************************
Goal stopping criterion class
****************************************/
CGoalCriterion::CGoalCriterion( double goal, bool minimize ){
this->goal = goal;
this->minimize = minimize;
}
bool CGoalCriterion::reached(){
if( minimize ){
//printf("bf : %f\n",bBest->fitness);
return bBest->fitness <= goal;
}
else
return bBest->fitness >= goal;
}
......@@ -9,6 +9,7 @@
#define CEVOLUTIONARYALGORITHM_H_
#include <stdlib.h>
#include <string>
#include <time.h>
#include "CEvolutionaryAlgorithm.h"
#include "CSelectionOperator.h"
#include "CPopulation.h"
......@@ -46,7 +47,11 @@ public:
size_t reduceParents;
size_t reduceOffsprings;
#ifdef WIN32
void showPopulationStats(clock_t beginTime);
#else
void showPopulationStats(struct timeval beginTime);
#endif
void generateGnuplotScript();
void generateRScript();
......@@ -61,9 +66,4 @@ public:
std::string* inputfile;
};
#ifdef WIN32
int gettimeofday(struct timeval* tp, void* tzp);
void timersub( const timeval * tvp, const timeval * uvp, timeval* vvp );
#endif
#endif /* CEVOLUTIONARYALGORITHM_H_ */
......@@ -58,19 +58,6 @@ class CTimeCriterion : public CStoppingCriterion {
void setElapsedTime(size_t elapsedTime);
};
/* ****************************************
Goal stopping criterion class
****************************************/
class CGoalCriterion : public CStoppingCriterion {
private:
double goal;
bool minimize;
public:
virtual bool reached();
CGoalCriterion( double goal, bool minimize );
};
/* ****************************************
ControlCStopingCriterion class
****************************************/
......
......@@ -14,7 +14,7 @@
//#define true 1;
//#define false 0;
class CIndividual;
class CRandomGenerator;
extern CIndividual** pPopulation;
extern CIndividual* bBest;
extern float* pEZ_MUT_PROB;
......
......@@ -287,7 +287,7 @@ void ParametersImpl::setDefaultParameters(int argc, char** argv){
this->printInitialPopulation = setVariable("printInitialPopulation",0);
this->printFinalPopulation = setVariable("printFinalPopulation",0);
this->outputFilename = (char*)"EASEA";
this->outputFilename = (char*)"EASEA.dat";
this->plotOutputFilename = (char*)"EASEA.png";
}
......
......@@ -81,7 +81,7 @@ int main(int argc, char** argv){
using namespace std;
#include "EASEAIndividual.hpp"
bool INSTEAD_EVAL_STEP = false;
CRandomGenerator* globalRandomGenerator;
extern CEvolutionaryAlgorithm* EA;
......@@ -99,11 +99,6 @@ extern CEvolutionaryAlgorithm* EA;
\INSERT_BOUND_CHECKING
void evale_pop_chunk(CIndividual** population, int popSize){
printf("evalPopChunk\n");
\INSTEAD_EVAL_FUNCTION
}
void EASEAInit(int argc, char** argv){
\INSERT_INIT_FCT_CALL
}
......
Markdown is supported
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