Commit eb546cbc authored by moh_lo's avatar moh_lo

Almost ready version

with working weierstrass algorithm
parent eb43e1e1
......@@ -25,7 +25,7 @@ class CSymbolTable;
%start COPY_EO_INITIALISER
%start COPY COPY_INITIALISER COPY_CROSSOVER COPY_MUTATOR COPY_EVALUATOR
%start COPY_DISPLAY COPY_USER_FUNCTION COPY_USER_GENERATION PARAMETERS_ANALYSIS GET_PARAMETERS
%start COPY_USER_FUNCTIONS COPY_GENERATION_FUNCTION
%start COPY_USER_FUNCTIONS COPY_GENERATION_FUNCTION COPY_USER_FUNCTIONS_PROTO
// lexical analyser name and class definition
%name CEASEALexer {
......@@ -78,7 +78,8 @@ YYSTYPE& yylval = *(YYSTYPE*)yyparserptr->yylvalptr;
char sFileName[1000];
strcpy(sFileName, sRAW_PROJECT_NAME);
switch (TARGET) {
case DREAM : strcat(sFileName,".java"); break;
case DREAM : strcat(sFileName,".java"); break;
case GPU : strcat(sFileName,".cu"); break;
default : strcat(sFileName,".cpp");
}
fpOutputFile=fopen(sFileName,"w");
......@@ -118,6 +119,12 @@ YYSTYPE& yylval = *(YYSTYPE*)yyparserptr->yylvalptr;
yyin = fpGenomeFile; // switch to .ez file and analyser
BEGIN ANALYSE_USER_CLASSES;
}
<TEMPLATE_ANALYSIS>"\\ANALYSE_ENV" {
if (bVERBOSE) printf ("Analysing evironement variables.\n");
}
<TEMPLATE_ANALYSIS>"\\INSERT_USER_CLASSES" {
if (bVERBOSE) printf ("Inserting User classes.\n");
if (TARGET!=DREAM) fprintf (fpOutputFile,"// User classes\n");
......@@ -127,6 +134,31 @@ YYSTYPE& yylval = *(YYSTYPE*)yyparserptr->yylvalptr;
if ((pSym->Object->pType->ObjectType==oUserClass)&&(!pSym->Object->pType->bAlreadyPrinted))
pSym->Object->pType->printClasses(fpOutputFile);
}
<TEMPLATE_ANALYSIS>"\\INSERT_USER_CLASSES_HDR" {
if (bVERBOSE) printf ("Inserting User header classes.\n");
if (TARGET!=DREAM) fprintf (fpOutputFile,"// User classes header\n");
CListItem<CSymbol*> *pSym;
pGENOME->pSymbolList->reset();
while (pSym=pGENOME->pSymbolList->walkToNextItem())
if ((pSym->Object->pType->ObjectType==oUserClass)&&(!pSym->Object->pType->bAlreadyPrinted))
pSym->Object->pType->printClassesHdr(fpOutputFile);
}
<TEMPLATE_ANALYSIS>"\\INSERT_USER_CLASSES_CODE" {
if (bVERBOSE) printf ("Inserting User code classes.\n");
if (TARGET!=DREAM) fprintf (fpOutputFile,"// User classes Code\n");
CListItem<CSymbol*> *pSym;
pGENOME->pSymbolList->reset();
reInitAlreadyPtedBit(pGENOME->pSymbolList);
pGENOME->bAlreadyPrinted = false;
pGENOME->pSymbolList->reset();
while (pSym=pGENOME->pSymbolList->walkToNextItem())
if ((pSym->Object->pType->ObjectType==oUserClass)&&(!pSym->Object->pType->bAlreadyPrinted)){
pSym->Object->pType->printClassesCode(fpOutputFile);
}
}
<TEMPLATE_ANALYSIS>"\\GENOME_CTOR" {
CListItem<CSymbol*> *pSym;
if (bVERBOSE) printf ("Inserting default genome constructor.\n");
......@@ -245,6 +277,10 @@ YYSTYPE& yylval = *(YYSTYPE*)yyparserptr->yylvalptr;
else fprintf(fpOutputFile," if (%s) delete %s;\n %s=NULL;\n",pSym->Object->sName,pSym->Object->sName,pSym->Object->sName);
}
}
<TEMPLATE_ANALYSIS>"\\ENV_SHM" {
fprintf(stdout,"here takes place the environement variables analysis\n");
}
<TEMPLATE_ANALYSIS>"\\EQUAL" {
CListItem<CSymbol*> *pSym;
if (bVERBOSE) printf ("Creating default diversity test.\n");
......@@ -374,6 +410,15 @@ YYSTYPE& yylval = *(YYSTYPE*)yyparserptr->yylvalptr;
yyin = fpGenomeFile; // switch to .ez file and analyser
BEGIN COPY_USER_FUNCTIONS;
}
<TEMPLATE_ANALYSIS>"\\INSERT_USER_FUNCTIONS_PROTO" {
if (bVERBOSE) printf ("Inserting user functions prototype.\n");
yyreset();
yyin = fpGenomeFile; // switch to .ez file and analyser
BEGIN COPY_USER_FUNCTIONS_PROTO;
}
<TEMPLATE_ANALYSIS>"\\INSERT_EO_INITIALISER" {
yyreset();
bWithinEO_Function=1;
......@@ -405,6 +450,10 @@ YYSTYPE& yylval = *(YYSTYPE*)yyparserptr->yylvalptr;
}
<TEMPLATE_ANALYSIS>"\\INSERT_EVALUATOR" {
yyreset();
if( TARGET == GPU ){
bWithinGPU_Function = true;
//bWithinGPUEval = true;
}
yyin = fpGenomeFile; // switch to .ez file and analyser
BEGIN COPY_EVALUATOR;
}
......@@ -421,7 +470,12 @@ YYSTYPE& yylval = *(YYSTYPE*)yyparserptr->yylvalptr;
}
<TEMPLATE_ANALYSIS>"\\SELECTOR" {fprintf(fpOutputFile,"%s",sSELECTOR);}
//<TEMPLATE_ANALYSIS>"\\GEN_SELECTOR" {fprintf(fpOutputFile,"%s(%s,%d)",sGEN_SELECTOR);}
<TEMPLATE_ANALYSIS>"\\SELECT_PRM" {fprintf(fpOutputFile,"%s",sSELECT_PRM);}
<TEMPLATE_ANALYSIS>"\\SELECT_PRM" {
if(bVERBOSE){
fprintf(stdout,"SELECT_PRM : %s",sSELECT_PRM);
}
fprintf(fpOutputFile,"%s",sSELECT_PRM);
}
<TEMPLATE_ANALYSIS>"\\POP_SIZE" {fprintf(fpOutputFile,"%d",nPOP_SIZE);}
<TEMPLATE_ANALYSIS>"\\OFF_SIZE" {fprintf(fpOutputFile,"%d",nOFF_SIZE);}
<TEMPLATE_ANALYSIS>"\\ELITE_SIZE" {fprintf(fpOutputFile,"%d",nELITE);}
......@@ -446,10 +500,14 @@ YYSTYPE& yylval = *(YYSTYPE*)yyparserptr->yylvalptr;
<TEMPLATE_ANALYSIS>"\\STEADYSTATE" {if ((fREPL_PERC==0)||(!strcmp(sREPLACEMENT,"Incremental"))||(!strcmp(sREPLACEMENT,"Simple")))
fprintf(fpOutputFile,"// undefined ");}
<TEMPLATE_ANALYSIS>"\\COMMENT" {if (mystricmp(sREPLACEMENT,"SSGA")) fprintf(fpOutputFile,"//");}
<TEMPLATE_ANALYSIS>"\\MINIMAXI" {switch (TARGET) { case GALIB : fprintf(fpOutputFile,"%d",nMINIMISE? -1:1); break;
case EO : fprintf(fpOutputFile,"%s",nMINIMISE? "eoMinimizingFitness" : "eoMaximizingFitness"); break;
case DREAM : fprintf(fpOutputFile,"%s",nMINIMISE? "false" : "true"); break;
} }
<TEMPLATE_ANALYSIS>"\\MINIMAXI" {
switch (TARGET) {
case GALIB : fprintf(fpOutputFile,"%d",nMINIMISE? -1:1); break;
case EO : fprintf(fpOutputFile,"%s",nMINIMISE? "eoMinimizingFitness" : "eoMaximizingFitness"); break;
case DREAM : fprintf(fpOutputFile,"%s",nMINIMISE? "false" : "true"); break;
case GPU : fprintf(fpOutputFile,"%s",nMINIMISE? "false" : "true"); break;
}
}
<TEMPLATE_ANALYSIS>"\\ELITIST_REPLACE_NAME" {if (TARGET==EO) {if (bELITISM) fprintf(fpOutputFile,"standardR");
else fprintf(fpOutputFile,"r");}}
<TEMPLATE_ANALYSIS>"\\ELITISM" {switch (TARGET) { case GALIB : if (!mystricmp(sREPLACEMENT,"simple"))
......@@ -516,6 +574,15 @@ YYSTYPE& yylval = *(YYSTYPE*)yyparserptr->yylvalptr;
if (bVERBOSE) printf("Creating %s...\n",sFileName);
}
<TEMPLATE_ANALYSIS>"\\START_USER_FUN_C_TPL" {
char sFileName[1000];
fclose(fpOutputFile);
strcpy(sFileName, sRAW_PROJECT_NAME);
strcat(sFileName,"UserFunc.cpp");
fpOutputFile=fopen(sFileName,"w");
if (bVERBOSE) printf("Creating %s...\n",sFileName);
}
<TEMPLATE_ANALYSIS>"\\START_EO_GENOME_H_TPL" {
char sFileName[1000];
......@@ -713,6 +780,7 @@ YYSTYPE& yylval = *(YYSTYPE*)yyparserptr->yylvalptr;
fprintf (fpOutputFile,"// User functions\n\n");
BEGIN COPY;
}
<COPY_USER_FUNCTIONS><<EOF>> {
if (bVERBOSE) printf("*** No user functions were found. ***\n");
fprintf(fpOutputFile,"\n// No user functions.\n");
......@@ -720,9 +788,28 @@ YYSTYPE& yylval = *(YYSTYPE*)yyparserptr->yylvalptr;
yyin = fpTemplateFile;
BEGIN TEMPLATE_ANALYSIS;
bNotFinishedYet=1;
}
}
<COPY_USER_FUNCTIONS>.|\n {}
<COPY_USER_FUNCTIONS_PROTO>"\\User"[ \t\n]+"functions"[ \t\n]+"proto"[ \t\n]*":" {
fprintf (fpOutputFile,"// User functions proto\n\n");
BEGIN COPY;
}
<COPY_USER_FUNCTIONS_PROTO><<EOF>> {
if (bVERBOSE) printf("*** No user functions were found. ***\n");
fprintf(fpOutputFile,"\n// No user functions.\n");
rewind(fpGenomeFile);
yyin = fpTemplateFile;
BEGIN TEMPLATE_ANALYSIS;
bNotFinishedYet=1;
}
<COPY_USER_FUNCTIONS_PROTO>.|\n {}
<COPY_INITIALISATION_FUNCTION>"\\Initialisation"[ \t\n]+"function"[ \t\n]*":" {
if (TARGET==DREAM)
fprintf (fpOutputFile,"// Evaluator Constructor\n\n public %sEvaluator(){",sPROJECT_NAME);
......@@ -763,6 +850,11 @@ YYSTYPE& yylval = *(YYSTYPE*)yyparserptr->yylvalptr;
BEGIN GENOME_ANALYSIS; return CLASSES;}
<ANALYSE_USER_CLASSES>.|\n {}
<ANALYSE_ENV>"\\User"[ \t\n]+"evaluator"[ \t\n]+"env"[ \t\n]*:{
BEGIN GENOME_ANALYSIS; return CLASSES;}
<ANALYSE_ENV>.|\n {}
//****************************************
// Basic copy to cpp file with minor changes
//****************************************
......@@ -936,6 +1028,7 @@ YYSTYPE& yylval = *(YYSTYPE*)yyparserptr->yylvalptr;
<COPY_CROSSOVER>.|\n {}
<COPY_MUTATOR>"\\GenomeClass::mutator"[ \t\n]*":" {
bWithinMutator=1;
if(TARGET == GPU) bWithinGPU_Function = true;
BEGIN COPY_USER_FUNCTION;
return USER_MUTATOR;
}
......@@ -1117,14 +1210,15 @@ YYSTYPE& yylval = *(YYSTYPE*)yyparserptr->yylvalptr;
<COPY_USER_FUNCTION>^[ \t]*\/\*[^\*]*\*\/[ \t]*\n {fprintf(fpOutputFile,yytext);} /* blah blah with nothing before the comment */
<COPY_USER_FUNCTION>"GenomeClass" {if (TARGET==EO) fprintf(fpOutputFile, "GenotypeT");
else fprintf(fpOutputFile,"Genome.");
}
else fprintf(fpOutputFile,"Genome.");
}
<COPY_USER_FUNCTION>"Genome" {
if (bWithinDisplayFunction && TARGET!=GPU) fprintf(fpOutputFile,"(*this)");
else if ((TARGET==EO)&&(bWithinInitialiser)) fprintf(fpOutputFile, "(*genome)");
else if ((TARGET==EO)&&(bWithinMutator)) fprintf(fpOutputFile, "_genotype");
else if (TARGET==GPU && bWithinGPUEval) fprintf(fpOutputFile,"(*genome)");
else fprintf(fpOutputFile,"genome");
else if (TARGET==GPU && bWithinEvaluator) fprintf(fpOutputFile,"(*genome)");
else fprintf(fpOutputFile,"genome");
} // local genome name
<COPY_USER_FUNCTION>"\"" {(bDoubleQuotes ? bDoubleQuotes=0:bDoubleQuotes=1); fprintf(fpOutputFile,"\"");}
<COPY_USER_FUNCTION>"\\\"" {fprintf(fpOutputFile,"\\\"");}
......
This diff is collapsed.
This diff is collapsed.
......@@ -35,6 +35,7 @@ public:
CListItem<T> *pNext; // pointer to the next object in the list
};
/////////////////////////////////////////////////////////////////////////////
// Linked List
......@@ -55,7 +56,7 @@ public :
CListItem<T> *walkToNextItem();
CListItem<T> *remove(T *p);
};
void reInitAlreadyPtedBit(CLList<CSymbol *> *pSymbolList);
/////////////////////////////////////////////////////////////////////////////
// Symbol
......@@ -83,7 +84,11 @@ public:
// Operations
public:
void print(FILE *f);
void printHdr(FILE *fp);
void printCode(FILE* fp);
void printClasses(FILE *f);
void printClassesHdr(FILE* f);
void printClassesCode(FILE* f);
void printAllSymbols(FILE *f, char *, EObjectType, CListItem<CSymbol *> *pSym);
};
......
/*_________________________________________________________
Test functions
log normal adaptive mutation
Selection operator: Tournament
__________________________________________________________*/
\User declarations :
#define SIZE 501
#define X_MIN -1.
#define X_MAX 1.
#define ITER 50
#define Abs(x) ((x) < 0 ? -(x) : (x))
#define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y))
#define SIGMA 1. /* mutation parameter */
#define PI 3.141592654
#include <math.h>
float pMutPerGene=1.;
int mutationOccured = 0;
#define N 10
float (*Fitness)(float *, int); // pointeur sur la fonction de fitness designee dans argv[1]
float Sphere(float *, int);
float AckleyPath(float *, int);
float Easom(float *, int);
float Griewangk(float *, int);
float Rastrigin(float *, int);
float Rosenbrock(float *, int);
float Schwefel(float *, int);
float Weierstrass(float *, int);
\end
\User functions proto:
float gauss();
\end
\User functions:
//fitness function
inline float Sphere(float x[SIZE], int n) {// Ex-DeJong function 1
float ret = 0;
for (int i = 0;i<n; i++) ret += x[ i ] * x[ i ];
return ret;
}
/* __host__ __device__ inline float AckleyPath(float x[SIZE], int n) */
/* { */
/* //Parameters */
/* float a = 20.; */
/* float b = 0.2; */
/* float c = 2*PI; */
/* float Scale = 32.768; // pour matcher avec les limites [-1,1] */
/* //Function computation */
/* float sum_x2 = 0.0; */
/* float sum_cos_cx = 0.0; */
/* for (int i=0; i<n; i++) { */
/* sum_x2 += Scale*Scale*x[i]*x[i]; */
/* sum_cos_cx += cos(c*Scale*x[i]); */
/* } */
/* float res = -a * exp( -b * sqrt( 1/(float)n * sum_x2) ) - exp( 1/(float)n * sum_cos_cx ) + a + exp(1); */
/* return res; */
/* } */
/* __host__ __device__ inline float Easom(float x[SIZE], int n) */
/* { */
/* float res = 1.; */
/* //function computation */
/* for (int i=0; i<n; i++) */
/* res *= cos(100.*x[i])*exp(-(100.*x[i]-PI)*(100.*x[i]-PI)); */
/* return (1.-res); // pour avoir un minimum a 0. */
/* } */
/* __host__ __device__ inline float Griewangk(float x[SIZE], int n) */
/* { */
/* float res, sum = 0., prod =1.; */
/* float Scale = 600.; // pour matcher avec les limites [-1,1] */
/* for (int i=1; i<=n; i++) { */
/* prod *= cos( Scale*x[i]/sqrt( (float)i ) ); */
/* sum += (Scale*Scale*x[i]*x[i]/4000.); */
/* } */
/* res = sum - prod + 1.; */
/* return res; */
/* } */
__host__ __device__ inline float Rastrigin(float x[SIZE], int n)
{
float res = 0.;
float Scale = 5.12; // pour matcher avec les limites [-1,1]
for (int i = 0;i<n; i++)
res += ((Scale*Scale*x[i]*x[i])-10*cos( 2*PI*Scale*x[i]));
return (10.*N + res);
}
/* inline float Rosenbrock(float x[SIZE], int n) */
/* { */
/* float res = 0.; */
/* float Scale = 2.048; // pour matcher avec les limites [-1,1] */
/* for (int i = 0;i<n; i++) */
/* res += 100.*((Scale*x[i+1] - Scale*Scale*x[i]*x[i])*(Scale*x[i+1] */
/* - Scale*Scale*x[i]*x[i]))+(1-Scale*x[i])*(1-Scale*x[i]); */
/* return (res); */
/* } */
__host__ __device__ inline float Schwefel(float x[SIZE], int n)
{
float res = 0.;
float Scale = 500.; // pour matcher avec les limites [-1,1]
for (int i = 0;i<N; i++)
res += (-Scale*x[i]*sin(sqrt(Abs(Scale*x[i]))));
return ((float)n*418.9829 + res);
}
__device__ __host__ inline float Weierstrass(float x[SIZE], int n) // Weierstrass multimidmensionnel h = 0.25
{
float res = 0.;
float val[SIZE];
float b=2.;
float h = 0.25;
for (int i = 0;i<N; i++) {
val[i] = 0.;
for (int k=0;k<ITER;k++)
val[i] += pow(b,-(float)k*h) * sin(pow(b,(float)k)*x[i]);
res += Abs(val[i]);
}
return (res);
}
float gauss()
/* Generates a normally distributed random value with variance 1 and 0 mean.
Algorithm based on "gasdev" from Numerical recipes' pg. 203. */
{
int iset = 0;
float gset = 0.0;
float v1 = 0.0, v2 = 0.0, r = 0.0;
float factor = 0.0;
if (iset) {
iset = 0;
return gset;
}
else {
do {
v1 = (float)fRandomLoc(0.,1.) * 2.0 - 1.0;
v2 = (float)fRandomLoc(0.,1.) * 2.0 - 1.0;
r = v1 * v1 + v2 * v2;
}
while (r > 1.0);
factor = sqrt (-2.0 * log (r) / r);
gset = v1 * factor;
iset = 1;
return (v2 * factor);
} }
\end
\Initialisation function:
cout<<"N: "<<N<<endl;
\end
\User classes :
GenomeClass {
float x[SIZE];
float sigma[SIZE]; // auto-adaptative mutation parameter
}
\end
\GenomeClass::initialiser : // "initializer" is also accepted
for(int i=0; i<N; i++ ) {
Genome.x[i] = (float)fRandomLoc(X_MIN,X_MAX);
Genome.sigma[i]=(float)fRandomLoc(0.,0.5);
}
\end
\GenomeClass::crossover :
for (int i=0; i<N; i++)
{
float alpha = (float)randomLoc(0.,1.); // barycentric crossover
if (&child1) child1->Genome.x[i] = alpha*parent1->Genome.x[i] + (1.-alpha)*parent2->Genome.x[i];
//if (&child2) child2->Genome.x[i] = alpha*parent2->Genome.x[i] + (1.-alpha)*parent1->Genome.x[i];
}
\end
\GenomeClass::mutator : // Must return the number of mutations
int NbMut=0;
float pond = 1./sqrt((float)N);
for (int i=0; i<N; i++)
if (tossCoin(pMutPerGene)){
mutationOccured++;
NbMut++;
Genome.sigma[i] = Genome.sigma[i] * exp(SIGMA*pond*(float)gauss());
Genome.sigma[i] = MIN(0.5,Genome.sigma[0]);
Genome.sigma[i] = MAX(0.,Genome.sigma[0]);
Genome.x[i] += Genome.sigma[i]*(float)fRandomLoc(0,1);
Genome.x[i] = MIN(X_MAX,Genome.x[i]); // pour eviter les depassements
Genome.x[i] = MAX(X_MIN,Genome.x[i]);
}
return NbMut;
\end
\GenomeClass::evaluator : // Returns the score
float Score= 0.0;
Score= Weierstrass(Genome.x,N);
return Score;
\end
\Default run parameters : // Please let the parameters appear in this order
Number of generations : 100 // NB_GEN
Mutation probability : 1 // MUT_PROB
Crossover probability : 1 // XOVER_PROB
Population size : 10 // POP_SIZE
Genitors selector: Tournament 2
Final reduce: Tournament 2
// Selection operator : Tournament // RouletteWheel, Deterministic, Ranking, Random
Offspring size : 80% // 40%
//Replacement strategy : Plus // Comma, SteadyState, Generational
// Discarding operator : Worst // Best, Tournament, Parent, Random
Evaluator goal : Minimise // Maximise
Elitism : On // Off
\end
#define FITNESS_TYPE float
#define BOOLEAN_EA char
#define true 1
#define false 0
/* #ifdef DEBUG_KRNL */
/* #define CDC( lastError, errorMsg, fun ) \ */
/* fun ; \ */
/* cout <<__FILE__<< " : "<<__LINE__<<" "<<errorMsg<<" : "<<endl; \ */
/* cout << "\t" <<(cudaGetErrorString(lastError=cudaGetLastError())) \ */
/* << endl; \ */
/* if( lastError != cudaSuccess )exit(-1) */
/* #else */
/* #define CDC( lastError, errorMsg, fun ) \ */
/* fun */
/* #endif */
#ifdef DEBUG_KRNL
#define CDC( lastError, errorMsg, fun ) \
fun ; \
if((lastError=cudaGetLastError())!=cudaSuccess ){ \
cout <<__FILE__<< " : "<<__LINE__<<" "<<errorMsg<<" : "<<endl; \
cout << "\t" <<(cudaGetErrorString(lastError)) \
<< endl; \
exit(-1); \
}
#else
#define CDC( lastError, errorMsg, fun ) \
fun
#endif
#ifndef OUTPUT_EA_H
#define OUTPUT_EA_H
#define TMP_BUF_LENGTH 512
#define TIMING
#include "timing.h"
#include <libxml/tree.h>
#include "basetype.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
DECLARE_TIME(gpu);
DECLARE_TIME(cpu);
DECLARE_TIME(init);
DECLARE_TIME(krnl);
DECLARE_TIME(memCpy1);
DECLARE_TIME(memCpy2);
DECLARE_TIME(alloc);
BOOLEAN_EA cmp;
BOOLEAN_EA repartition;
size_t popSize;
size_t nbBlock,nbThreadPB,nbThreadLB,memSize,sharedMemSize;
size_t fakeIteration;
}OutputEa;
xmlNodePtr outputEaToXmlNode(OutputEa* tt);
xmlChar* timevalToXmlChar(struct timeval* ts);
void outputTss(const char* filename);
void addTs(OutputEa* ts);
void initTss(const char* args);
void attachSignal();
#ifdef __cplusplus
}
#endif
#endif
#include <time.h> //gettimeofday
#include <sys/time.h>
#include <stdio.h>
#ifndef TIMING_H
#define TIMING_H
#ifdef TIMING
#define DECLARE_TIME(t) \
struct timeval t##_beg, t##_end, t##_res
#define TIME_ST(t) \
gettimeofday(&t##_beg,NULL)
#define TIME_END(t) \
gettimeofday(&t##_end,NULL)
#define SHOW_TIME(t) \
timersub(&t##_end,&t##_beg,&t##_res); \
printf("%s : %d.%06d\n",#t,t##_res.tv_sec,t##_res.tv_usec)
#define SHOW_SIMPLE_TIME(t) \
printf("%s : %d.%06d\n",#t,t.tv_sec,t.tv_usec)
#define COMPUTE_TIME(t) \
timersub(&t##_end,&t##_beg,&t##_res)
#else
#define DECLARE_TIME(t)
#define TIME_ST(t)
#define TIME_END(t)
#define SHOW_TIME(t)
#define SHOW_SIMPLE_TIME(t)
#endif
#endif
#include <stdlib.h>
#include <stdio.h>
#include "tool.h"
#include <math.h>
int tossCoin(double p){
if( rand() < p*RAND_MAX)
return 1;
else
return 0;
}
int getRandomIntMax(int max){
double r = rand();
r = r / RAND_MAX;
r = r * max;
return r;
}
int randomLoc(int min, int max){
return min+getRandomIntMax(max-min);
}
float getRandomFloatMax(float max){
float r = rand();
r = r / RAND_MAX;
r = r * max;
return r;
}
float fRandomLoc(float min,float max){
return min+getRandomFloatMax(max-min);
}
size_t
partieEntiereSup(float E){
int fl = floor(E);
if( fl == E )
return E;
else