Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
easea
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Arnaud Kress
easea
Commits
6a088d6d
Commit
6a088d6d
authored
Mar 25, 2009
by
maitre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Easea EO/Galib independant template
0.9bu rc-1
parent
eb546cbc
Changes
25
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
25 changed files
with
2913 additions
and
2924 deletions
+2913
-2924
Easea.h
Easea.h
+1
-1
EaseaLex.l
EaseaLex.l
+1021
-934
EaseaParse.y
EaseaParse.y
+455
-454
EaseaSym.cpp
EaseaSym.cpp
+146
-378
EaseaSym.h
EaseaSym.h
+5
-7
exemples/cuda_bench/Generic_T_ad.ez
exemples/cuda_bench/Generic_T_ad.ez
+0
-230
exemples/cuda_bench/tool/basetype.h
exemples/cuda_bench/tool/basetype.h
+0
-4
exemples/cuda_bench/tool/debug.h
exemples/cuda_bench/tool/debug.h
+0
-29
exemples/cuda_bench/tool/outputea.h
exemples/cuda_bench/tool/outputea.h
+0
-50
exemples/cuda_bench/tool/timing.h
exemples/cuda_bench/tool/timing.h
+0
-32
exemples/cuda_bench/tool/tool.c
exemples/cuda_bench/tool/tool.c
+0
-46
exemples/cuda_bench/tool/tool.h
exemples/cuda_bench/tool/tool.h
+0
-17
exemples/cuda_onemax/onemax_cuda.ez
exemples/cuda_onemax/onemax_cuda.ez
+0
-112
exemples/cuda_onemax/tool/basetype.h
exemples/cuda_onemax/tool/basetype.h
+0
-4
exemples/cuda_onemax/tool/debug.h
exemples/cuda_onemax/tool/debug.h
+0
-12
exemples/cuda_onemax/tool/outputea.h
exemples/cuda_onemax/tool/outputea.h
+0
-50
exemples/cuda_onemax/tool/timing.h
exemples/cuda_onemax/tool/timing.h
+0
-32
exemples/cuda_onemax/tool/tool.c
exemples/cuda_onemax/tool/tool.c
+0
-35
exemples/cuda_onemax/tool/tool.h
exemples/cuda_onemax/tool/tool.h
+0
-16
exemples/myonemax.ez
exemples/myonemax.ez
+0
-55
exemples/onemax.ez
exemples/onemax.ez
+0
-82
makefile
makefile
+32
-25
tpl/CUDA.tpl
tpl/CUDA.tpl
+1075
-0
tpl/EO.tpl
tpl/EO.tpl
+16
-2
tpl/GPU.tpl
tpl/GPU.tpl
+162
-317
No files found.
Easea.h
View file @
6a088d6d
...
...
@@ -21,7 +21,7 @@ Centre de Math
#define GALIB 1
#define EO 2
#define DREAM 3
#define
GPU
4
#define
CUDA
4
#define UNIX 1
#define WINDOWS 2
#define UNKNOWN_OS 3
...
...
EaseaLex.l
View file @
6a088d6d
This diff is collapsed.
Click to expand it.
EaseaParse.y
View file @
6a088d6d
This diff is collapsed.
Click to expand it.
EaseaSym.cpp
View file @
6a088d6d
This diff is collapsed.
Click to expand it.
EaseaSym.h
View file @
6a088d6d
...
...
@@ -35,7 +35,6 @@ public:
CListItem
<
T
>
*
pNext
;
// pointer to the next object in the list
};
/////////////////////////////////////////////////////////////////////////////
// Linked List
...
...
@@ -56,7 +55,7 @@ public :
CListItem
<
T
>
*
walkToNextItem
();
CListItem
<
T
>
*
remove
(
T
*
p
);
};
void
reInitAlreadyPtedBit
(
CLList
<
CSymbol
*>
*
pSymbolList
);
/////////////////////////////////////////////////////////////////////////////
// Symbol
...
...
@@ -80,16 +79,15 @@ public:
CSymbol
*
pClass
;
// pointer to the variable class in which it is defined.
CLList
<
CSymbol
*>
*
pSymbolList
;
// pointer on a list of class members (if the symbol is a class)
// pointer on the class (if the symbol is a variable)
// 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
);
void
printUserClasses
(
FILE
*
fp
);
void
printUC
(
FILE
*
fp
);
};
/////////////////////////////////////////////////////////////////////////////
...
...
exemples/cuda_bench/Generic_T_ad.ez
deleted
100644 → 0
View file @
eb546cbc
/*_________________________________________________________
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
exemples/cuda_bench/tool/basetype.h
deleted
100644 → 0
View file @
eb546cbc
#define FITNESS_TYPE float
#define BOOLEAN_EA char
#define true 1
#define false 0
exemples/cuda_bench/tool/debug.h
deleted
100644 → 0
View file @
eb546cbc
/* #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
exemples/cuda_bench/tool/outputea.h
deleted
100644 → 0
View file @
eb546cbc
#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
exemples/cuda_bench/tool/timing.h
deleted
100644 → 0
View file @
eb546cbc
#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
exemples/cuda_bench/tool/tool.c
deleted
100644 → 0
View file @
eb546cbc
#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
return
floor
(
E
)
+
1
;
}
exemples/cuda_bench/tool/tool.h
deleted
100644 → 0
View file @
eb546cbc
#ifndef TOOL_H
#define TOOL_H
#ifdef __cpluplus
extern
"C"
{
#endif
int
tossCoin
(
double
p
);
int
getRandomIntMax
(
int
max
);
int
randomLoc
(
int
min
,
int
max
);
size_t
partieEntiereSup
(
float
E
);
float
fRandomLoc
(
float
min
,
float
max
);
#ifdef __cpluplus
}
#endif
#endif
exemples/cuda_onemax/onemax_cuda.ez
deleted
100644 → 0
View file @
eb546cbc
/*_________________________________________________________
This file was automatically created by GUIDE v0.1c
User: collet
Date: Fri Apr 04 23:41:34 CEST 2003
File name: /home/collet/progs/onemax/onemax.ez
Target library: EO
Operating System: Linux
_________________________________________________________*/
\User declarations:
#define SIZE 16
static float pMutPerGene=0.1;
static inline void swap(bool& a, bool& b)
{bool c=a; a=b; b=c;}
\end
\User functions:
/* void swap(bool* a, bool* b){ */
/* bool tmp = *a; */
/* *a = *b; */
/* *b = tmp; */
/* } */
\end
\Initialisation function:
\end
\User classes:
GenomeClass {bool x[SIZE]; }
\end
\GenomeClass::display:
for( int i=0 ; i<SIZE;i++) cout << (Genome.x[i]? "1 ":"0 ");
\end
\GenomeClass::initialiser:
for (int i=0;i<SIZE;i++) Genome.x[i]=tossCoin(.5);
\end
\GenomeClass::crossover:
int CrossoverPosition=randomLoc(0,SIZE);
for(int i=0;i<CrossoverPosition+1;i++)
swap(child1->Genome.x[i],child2->Genome.x[i]);
\end
\GenomeClass::mutator:
int NbMut=0;
for (int i=0;i<SIZE;i++)
if (tossCoin(pMutPerGene)){
NbMut++;
Genome.x[i]=Genome.x[i]?0:1;
}
return NbMut;
\end
\GenomeClass::evaluator:
float Score=0;
for (int i=0; i<SIZE;i++)
Score+=(Genome.x[i]?1.:0.);
for( size_t i=0; i<SIZE ; i++ )
printf("%d ",(Genome.x[i]==1?1:0));
printf("\n");
return Score;
\end
\At each new generation:
\end
\Default run parameters:
// Variation operators:
Operators are called: Sequentially
Mutation probability: 0.05
Crossover probability: 1
// Evolution Engine:
Evaluator goal: Maximise
Number of generations: 5
Evolutionary engine: Generational
Population size: 10
Elite: 1
Fertility: 10
Genitors selector: Tournament 2
Selected genitors: 10
Offspring size: 10
Reduce parents: Tournament 2
Surviving parents: 0
Reduce offspring: Tournament 2
Surviving offspring: 10
Final reduce: Tournament 5
Elitism: Strong
// Island model:
Number of islands: 5
Emigration policy: Move
Migrants selector: Tournament 2
Migrants destination: Neighbours
Migration frequency: 0.2
Number of emigrants: 3
Immigration replacement: Tournament 2
Immigration policy: Add
\end
exemples/cuda_onemax/tool/basetype.h
deleted
100644 → 0
View file @
eb546cbc
#define FITNESS_TYPE float
#define BOOLEAN_EA char
#define true 1
#define false 0
exemples/cuda_onemax/tool/debug.h
deleted
100644 → 0
View file @
eb546cbc
#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
exemples/cuda_onemax/tool/outputea.h
deleted
100644 → 0
View file @
eb546cbc
#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
;