Commit 60fdcb6c authored by Frédéric Krüger's avatar Frédéric Krüger

Ajout d'une fonction custom pour le strndup pour MAC

parent ca98311c
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -3,7 +3,7 @@
#include <clex.h>
#line 67 "EaseaLex.l"
#line 153 "EaseaLex.l"
// forward references
class CEASEAParser;
......@@ -60,7 +60,7 @@ protected:
virtual int yyaction(int action);
public:
#line 82 "EaseaLex.l"
#line 168 "EaseaLex.l"
protected:
CSymbolTable *pSymbolTable; // the symbol table
......
......@@ -19,6 +19,92 @@ Centre de Math�matiques Appliqu�es
#else
#include <unistd.h>
#endif
#ifdef __APPLE__
/* Mac OS X don't have strndup even if _GNU_SOURCE is defined */
char *strndup (const char *s, size_t n){
size_t len = strlen (s);
char *ret;
if (len <= n)
return strdup (s);
ret = (char *)malloc(n + 1);
strncpy(ret, s, n);
ret[n] = '\0';
return ret;
}
ssize_t getline (char **lineptr, size_t *n, FILE *fp){
ssize_t result;
size_t cur_len = 0;
if (lineptr == NULL || n == NULL || fp == NULL){
errno = EINVAL;
return -1;
}
if (*lineptr == NULL || *n == 0){
*n = 120;
*lineptr = (char *) malloc (*n);
if (*lineptr == NULL){
result = -1;
goto end;
}
}
for (;;){
int i;
i = getc (fp);
if (i == EOF){
result = -1;
break;
}
/* Make enough space for len+1 (for final NUL) bytes. */
if (cur_len + 1 >= *n){
size_t needed_max = SSIZE_MAX < SIZE_MAX ? (size_t) SSIZE_MAX + 1 : SIZE_MAX;
size_t needed = 2 * *n + 1; /* Be generous. */
char *new_lineptr;
if (needed_max < needed)
needed = needed_max;
if (cur_len + 1 >= needed){
result = -1;
goto end;
}
new_lineptr = (char *) realloc (*lineptr, needed);
if (new_lineptr == NULL){
result = -1;
goto end;
}
*lineptr = new_lineptr;
*n = needed;
}
(*lineptr)[cur_len] = i;
cur_len++;
if (i == '\n')
break;
}
(*lineptr)[cur_len] = '\0';
result = cur_len ? (ssize_t) cur_len : result;
end:
return result;
}
#endif
/* getline implementation is copied from glibc. */
#ifndef SIZE_MAX
# define SIZE_MAX ((size_t) -1)
#endif
#ifndef SSIZE_MAX
# define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2))
#endif
#include "debug.h"
#include <iostream>
#include <sstream>
......
......@@ -81,9 +81,9 @@ endif
EaseaParse.o: EaseaParse.cpp EaseaLex.cpp
$(CPPC) $(CPPFLAGS) $< -o $@ -c 2>/dev/null
$(CPPC) $(CPPFLAGS) $< -o $@ -c #2>/dev/null
EaseaLex.o: EaseaLex.cpp
$(CPPC) $(CPPFLAGS) $< -o $@ -c 2>/dev/null
$(CPPC) $(CPPFLAGS) $< -o $@ -c #2>/dev/null
%.o:%.cpp
......
/*_________________________________________________________
Test functions
log normal adaptive mutation
Selection operator: Tournament
__________________________________________________________*/
\User declarations :
#define SIZE 16
#define X_MIN -1.
#define X_MAX 1.
#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
float pMutPerGene=0.3;
\end
\User functions:
//fitness function
#include <math.h>
__host__ __device__ inline float sphere(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]);
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)random(0.,1.) * 2.0 - 1.0;
v2 = (float)random(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
\Before everything else function:
//cout<<"Before everything else function called "<<endl;
\end
\After everything else function:
//cout << "After everything else function called" << endl;
\end
\At the beginning of each generation function:
//cout << "At the beginning of each generation function called" << endl;
\end
\At the end of each generation function:
//cout << "At the end of each generation function called" << endl;
\end
\At each generation before reduce function:
//cout << "At each generation before replacement function called" << endl;
\end
\User classes :
GenomeClass {
float x[SIZE];
float sigma[SIZE]; // auto-adaptative mutation parameter
}
\end
\GenomeClass::display:
/* for( size_t i=0 ; i<SIZE ; i++){ */
/* // cout << Genome.x[i] << ":" << Genome.sigma[i] << "|"; */
/* printf("%.02f:%.02f|",Genome.x[i],Genome.sigma[i]); */
/* } */
\end
\GenomeClass::initialiser : // "initializer" is also accepted
for(int i=0; i<SIZE; i++ ) {
Genome.x[i] = (float)random(X_MIN,X_MAX);
Genome.sigma[i]=(float)random(0.,0.5);
}
\end
\GenomeClass::crossover :
for (int i=0; i<SIZE; i++)
{
float alpha = (float)random(0.,1.); // barycentric crossover
child.x[i] = alpha*parent1.x[i] + (1.-alpha)*parent2.x[i];
}
\end
\GenomeClass::mutator : // Must return the number of mutations
int NbMut=0;
float pond = 1./sqrt((float)SIZE);
for (int i=0; i<SIZE; i++)
if (tossCoin(pMutPerGene)){
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)gauss();
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= sphere(Genome.x, SIZE);
return Score;
\end
\User Makefile options:
CPPFLAGS+=
\end
\Default run parameters : // Please let the parameters appear in this order
Number of generations : 100 // NB_GEN
Time limit: 60 // In seconds, 0 to deactivate
Population size : 3840 //POP_SIZE
Offspring size : 3840 // 40%
Mutation probability : 1 // MUT_PROB
Crossover probability : 1 // XOVER_PROB
Evaluator goal : maximise // Maximise
Selection operator: Tournament 2.0
Surviving parents: 100%//percentage or absolute
Surviving offspring: 100%
Reduce parents operator: Tournament 2
Reduce offspring operator: Tournament 2
Final reduce operator: Tournament 2
Elitism: Strong //Weak or Strong
Elite: 1
Print stats:true //Default: 1
Generate csv stats file:true
Generate gnuplot script:false
Generate R script:false
Plot stats:false //Default: 0
Remote island model: false
IP file: ip.txt //File containing all the remote island's IP
Save population: false
Start from file:false
\end
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