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
a5be0722
Commit
a5be0722
authored
Oct 18, 2010
by
Frederic Kruger
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of git@atia.u-strasbg.fr:easea
parents
876ad2d7
bff12e4a
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
84 additions
and
81 deletions
+84
-81
Easea.h
Easea.h
+1
-1
EaseaLex.cpp
EaseaLex.cpp
+1
-1
EaseaLex.l
EaseaLex.l
+1
-1
EaseaSym.cpp
EaseaSym.cpp
+7
-7
Makefile
Makefile
+3
-0
libeasea/CEvolutionaryAlgorithm.cpp
libeasea/CEvolutionaryAlgorithm.cpp
+8
-8
libeasea/CPopulation.cpp
libeasea/CPopulation.cpp
+35
-35
libeasea/include/CEvolutionaryAlgorithm.h
libeasea/include/CEvolutionaryAlgorithm.h
+8
-8
libeasea/include/CPopulation.h
libeasea/include/CPopulation.h
+20
-20
No files found.
Easea.h
View file @
a5be0722
...
...
@@ -63,4 +63,4 @@ extern float fMIGRATION_PROBABILITY;
extern
unsigned
iMAX_INIT_TREE_D
,
iMIN_INIT_TREE_D
,
iMAX_TREE_D
,
iNB_GPU
,
iPRG_BUF_SIZE
,
iMAX_TREE_DEPTH
,
iNO_FITNESS_CASES
;
// Prototypes
extern
int
mystricmp
(
c
har
*
,
char
*
);
extern
int
mystricmp
(
c
onst
char
*
,
const
char
*
);
EaseaLex.cpp
View file @
a5be0722
...
...
@@ -4357,7 +4357,7 @@ inline char mytolower(char c) {
return ((c>=65)&&(c<=90)) ? c+=32:c;
}
inline int mystricmp(c
har *string1,
char *string2){
inline int mystricmp(c
onst char *string1, const
char *string2){
int i;
for (i=0; string1[i]&&string2[i];i++){
if (mytolower(string1[i])<mytolower(string2[i])) return -(i+1);
...
...
EaseaLex.l
View file @
a5be0722
...
...
@@ -2209,7 +2209,7 @@ inline char mytolower(char c) {
return ((c>=65)&&(c<=90)) ? c+=32:c;
}
inline int mystricmp(c
har *string1,
char *string2){
inline int mystricmp(c
onst char *string1, const
char *string2){
int i;
for (i=0; string1[i]&&string2[i];i++){
if (mytolower(string1[i])<mytolower(string2[i])) return -(i+1);
...
...
EaseaSym.cpp
View file @
a5be0722
...
...
@@ -149,7 +149,7 @@ void CSymbol::print(FILE *fp){
if
(
pSym
->
Object
->
ObjectType
==
oPointer
)
fprintf
(
fp
,
" %s=NULL;
\n
"
,
pSym
->
Object
->
sName
);
if
(
pSym
->
Object
->
ObjectType
==
oArrayPointer
){
fprintf
(
fp
,
" for(int EASEA_Ndx=0; EASEA_Ndx<%d; EASEA_Ndx++)
\n
"
,
pSym
->
Object
->
nSize
/
sizeof
(
char
*
));
fprintf
(
fp
,
" for(int EASEA_Ndx=0; EASEA_Ndx<%d; EASEA_Ndx++)
\n
"
,
(
int
)(
pSym
->
Object
->
nSize
/
sizeof
(
char
*
)
));
fprintf
(
fp
,
" %s[EASEA_Ndx]=NULL;
\n
"
,
pSym
->
Object
->
sName
);
}
}
...
...
@@ -168,7 +168,7 @@ void CSymbol::print(FILE *fp){
fprintf
(
fp
,
" %s=(EASEA_Var.%s ? new %s(*(EASEA_Var.%s)) : NULL);
\n
"
,
pSym
->
Object
->
sName
,
pSym
->
Object
->
sName
,
pSym
->
Object
->
pType
->
sName
,
pSym
->
Object
->
sName
);
}
if
(
pSym
->
Object
->
ObjectType
==
oArrayPointer
){
fprintf
(
fp
,
" for(int EASEA_Ndx=0; EASEA_Ndx<%d; EASEA_Ndx++)
\n
"
,
pSym
->
Object
->
nSize
/
sizeof
(
char
*
));
fprintf
(
fp
,
" for(int EASEA_Ndx=0; EASEA_Ndx<%d; EASEA_Ndx++)
\n
"
,
(
int
)(
pSym
->
Object
->
nSize
/
sizeof
(
char
*
)
));
fprintf
(
fp
,
" if( EASEA_Var.%s[EASEA_Ndx] ) %s[EASEA_Ndx] = new %s(*(EASEA_Var.%s[EASEA_Ndx]));
\n
"
,
pSym
->
Object
->
sName
,
pSym
->
Object
->
sName
,
pSym
->
Object
->
pType
->
sName
,
pSym
->
Object
->
sName
);
fprintf
(
fp
,
" else %s[EASEA_Ndx] = NULL;
\n
"
,
pSym
->
Object
->
sName
);
}
...
...
@@ -181,7 +181,7 @@ void CSymbol::print(FILE *fp){
if
(
pSym
->
Object
->
ObjectType
==
oPointer
)
fprintf
(
fp
,
" if (%s) delete %s;
\n
%s=NULL;
\n
"
,
pSym
->
Object
->
sName
,
pSym
->
Object
->
sName
,
pSym
->
Object
->
sName
);
if
(
pSym
->
Object
->
ObjectType
==
oArrayPointer
){
fprintf
(
fp
,
" for(int EASEA_Ndx=0; EASEA_Ndx<%d; EASEA_Ndx++)
\n
"
,
pSym
->
Object
->
nSize
/
sizeof
(
char
*
));
fprintf
(
fp
,
" for(int EASEA_Ndx=0; EASEA_Ndx<%d; EASEA_Ndx++)
\n
"
,
(
int
)(
pSym
->
Object
->
nSize
/
sizeof
(
char
*
)
));
fprintf
(
fp
,
" if( %s[EASEA_Ndx] ) delete %s[EASEA_Ndx];
\n
"
,
pSym
->
Object
->
sName
,
pSym
->
Object
->
sName
);
}
}
...
...
@@ -249,7 +249,7 @@ void CSymbol::print(FILE *fp){
fprintf
(
fp
,
" %s[EASEA_Ndx] = EASEA_Var.%s[EASEA_Ndx];}
\n
"
,
pSym
->
Object
->
sName
,
pSym
->
Object
->
sName
);
}
if
(
pSym
->
Object
->
ObjectType
==
oArrayPointer
){
fprintf
(
fp
,
" for(int EASEA_Ndx=0; EASEA_Ndx<%d; EASEA_Ndx++)
\n
"
,
pSym
->
Object
->
nSize
/
sizeof
(
char
*
));
fprintf
(
fp
,
" for(int EASEA_Ndx=0; EASEA_Ndx<%d; EASEA_Ndx++)
\n
"
,
(
int
)(
pSym
->
Object
->
nSize
/
sizeof
(
char
*
)
));
fprintf
(
fp
,
" if(EASEA_Var.%s[EASEA_Ndx]) %s[EASEA_Ndx] = new %s(*(EASEA_Var.%s[EASEA_Ndx]));
\n
"
,
pSym
->
Object
->
sName
,
pSym
->
Object
->
sName
,
pSym
->
Object
->
pType
->
sName
,
pSym
->
Object
->
sName
);
}
if
(
pSym
->
Object
->
ObjectType
==
oPointer
){
...
...
@@ -270,7 +270,7 @@ void CSymbol::print(FILE *fp){
fprintf
(
fp
,
" if (%s[EASEA_Ndx]!=EASEA_Var.%s[EASEA_Ndx]) return false;}
\n
"
,
pSym
->
Object
->
sName
,
pSym
->
Object
->
sName
);
}
if
(
pSym
->
Object
->
ObjectType
==
oArrayPointer
){
fprintf
(
fp
,
" {for(int EASEA_Ndx=0; EASEA_Ndx<%d; EASEA_Ndx++)
\n
"
,
pSym
->
Object
->
nSize
/
sizeof
(
char
*
));
fprintf
(
fp
,
" {for(int EASEA_Ndx=0; EASEA_Ndx<%d; EASEA_Ndx++)
\n
"
,
(
int
)(
pSym
->
Object
->
nSize
/
sizeof
(
char
*
)
));
fprintf
(
fp
,
" if (%s[EASEA_Ndx]!=EASEA_Var.%s[EASEA_Ndx]) return false;}
\n
"
,
pSym
->
Object
->
sName
,
pSym
->
Object
->
sName
);
}
if
(
pSym
->
Object
->
ObjectType
==
oPointer
){
...
...
@@ -295,7 +295,7 @@ void CSymbol::print(FILE *fp){
}
if
(
pSym
->
Object
->
ObjectType
==
oArrayPointer
){
fprintf
(
fp
,
" {os <<
\"
Array %s :
\"
;
\n
"
,
pSym
->
Object
->
sName
);
fprintf
(
fp
,
" for(int EASEA_Ndx=0; EASEA_Ndx<%d; EASEA_Ndx++)
\n
"
,
pSym
->
Object
->
nSize
/
sizeof
(
char
*
));
fprintf
(
fp
,
" for(int EASEA_Ndx=0; EASEA_Ndx<%d; EASEA_Ndx++)
\n
"
,
(
int
)(
pSym
->
Object
->
nSize
/
sizeof
(
char
*
)
));
fprintf
(
fp
,
" if( EASEA_Var.%s[EASEA_Ndx] ) os <<
\"
[
\"
<< EASEA_Ndx <<
\"
]:
\"
<< *(EASEA_Var.%s[EASEA_Ndx]) <<
\"\\
t
\"
;}
\n
os <<
\"\\
n
\"
;
\n
"
,
pSym
->
Object
->
sName
,
pSym
->
Object
->
sName
);
}
if
(
pSym
->
Object
->
ObjectType
==
oPointer
)
...
...
@@ -334,7 +334,7 @@ void CSymbol::print(FILE *fp){
if
((
pSym
->
Object
->
ObjectType
==
oArray
))
fprintf
(
fp
,
" %s %s[%d];
\n
"
,
pSym
->
Object
->
pType
->
sName
,
pSym
->
Object
->
sName
,
pSym
->
Object
->
nSize
/
pSym
->
Object
->
pType
->
nSize
);
if
((
pSym
->
Object
->
ObjectType
==
oArrayPointer
))
fprintf
(
fp
,
" %s* %s[%d];
\n
"
,
pSym
->
Object
->
pType
->
sName
,
pSym
->
Object
->
sName
,
pSym
->
Object
->
nSize
/
sizeof
(
char
*
));
fprintf
(
fp
,
" %s* %s[%d];
\n
"
,
pSym
->
Object
->
pType
->
sName
,
pSym
->
Object
->
sName
,
(
int
)(
pSym
->
Object
->
nSize
/
sizeof
(
char
*
)
));
}
...
...
Makefile
View file @
a5be0722
...
...
@@ -82,6 +82,9 @@ endif
EaseaParse.o
:
EaseaParse.cpp EaseaLex.cpp
$(CPPC)
$(CPPFLAGS)
$<
-o
$@
-c
2>/dev/null
EaseaLex.o
:
EaseaLex.cpp
$(CPPC)
$(CPPFLAGS)
$<
-o
$@
-c
2>/dev/null
%.o
:
%.cpp
$(CPPC)
$(CPPFLAGS)
-c
-o
$@
$<
...
...
libeasea/CEvolutionaryAlgorithm.cpp
View file @
a5be0722
...
...
@@ -44,8 +44,8 @@ extern bool INSTEAD_EVAL_STEP;
/**
* @DEPRECATED the next contructor has to be used instead of this one.
*/
/*CEvolutionaryAlgorithm::CEvolutionaryAlgorithm(
size_t
parentPopulationSize,
size_t
offspringPopulationSize,
/*CEvolutionaryAlgorithm::CEvolutionaryAlgorithm(
unsigned
parentPopulationSize,
unsigned
offspringPopulationSize,
float selectionPressure, float replacementPressure, float parentReductionPressure, float offspringReductionPressure,
CSelectionOperator* selectionOperator, CSelectionOperator* replacementOperator,
CSelectionOperator* parentReductionOperator, CSelectionOperator* offspringReductionOperator,
...
...
@@ -287,7 +287,7 @@ void CEvolutionaryAlgorithm::showPopulationStats(struct timeval beginTime){
//Calcul de la moyenne et de l'ecart type
population
->
Best
=
population
->
parents
[
0
];
for
(
size_t
i
=
0
;
i
<
population
->
parentPopulationSize
;
i
++
){
for
(
unsigned
i
=
0
;
i
<
population
->
parentPopulationSize
;
i
++
){
currentAverageFitness
+=
population
->
parents
[
i
]
->
getFitness
();
// here we are looking for the smaller individual's fitness if we are minimizing
...
...
@@ -299,7 +299,7 @@ void CEvolutionaryAlgorithm::showPopulationStats(struct timeval beginTime){
currentAverageFitness
/=
population
->
parentPopulationSize
;
for
(
size_t
i
=
0
;
i
<
population
->
parentPopulationSize
;
i
++
){
for
(
unsigned
i
=
0
;
i
<
population
->
parentPopulationSize
;
i
++
){
currentSTDEV
+=
(
population
->
parents
[
i
]
->
getFitness
()
-
currentAverageFitness
)
*
(
population
->
parents
[
i
]
->
getFitness
()
-
currentAverageFitness
);
}
currentSTDEV
/=
population
->
parentPopulationSize
;
...
...
@@ -334,7 +334,7 @@ void CEvolutionaryAlgorithm::showPopulationStats(struct timeval beginTime){
f
=
fopen
(
fichier
.
c_str
(),
"a"
);
//ajouter .csv
if
(
f
!=
NULL
){
if
(
currentGeneration
==
0
)
fprintf
(
f
,
"#GEN
\t
TIME
\t\t
EVAL
\t
BEST
\t\t
AVG
\t\t
STDEV
\n\n
"
);
fprintf
(
f
,
"#GEN
\t
TIME
\t\t
EVAL
\t
BEST
\t\t
AVG
\t\t
STDEV
\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
...
...
@@ -412,7 +412,7 @@ void CEvolutionaryAlgorithm::sendIndividual(){
if
(
globalRandomGenerator
->
random
(
0.0
,
1.0
)
<=
params
->
migrationProbability
){
//cout << "I'm going to send an Individual now" << endl;
//this->population->selectionOperator->initialize(this->population->parents, 7, this->population->actualParentPopulationSize);
//
size_t
index = this->population->selectionOperator->selectNext(this->population->actualParentPopulationSize);
//
unsigned
index = this->population->selectionOperator->selectNext(this->population->actualParentPopulationSize);
//cout << "Going to send individual " << index << " with fitness " << this->population->parents[index]->fitness << endl;
//selecting a client randomly
...
...
@@ -437,7 +437,7 @@ void CEvolutionaryAlgorithm::receiveIndividuals(){
//selecting the individual to erase
//CSelectionOperator *antiTournament = getSelectionOperator("Tournament",!this->params->minimizing, globalRandomGenerator);
//antiTournament->initialize(this->population->parents, 7, this->population->actualParentPopulationSize);
//size_t
index = antiTournament->selectNext(this->population->actualParentPopulationSize);
unsigned
index
=
antiTournament
->
selectNext
(
this
->
population
->
actualParentPopulationSize
);
//We're selecting the worst element to replace
size_t
index
=
this
->
population
->
getWorstIndividualIndex
(
this
->
population
->
parents
);
...
...
@@ -498,7 +498,7 @@ void CEvolutionaryAlgorithm::generateRScript(){
bool
CEvolutionaryAlgorithm
::
allCriteria
(){
for
(
size_t
i
=
0
;
i
<
stoppingCriteria
.
size
();
i
++
){
for
(
unsigned
i
=
0
;
i
<
stoppingCriteria
.
size
();
i
++
){
if
(
stoppingCriteria
.
at
(
i
)
->
reached
()
){
std
::
cout
<<
"Stopping criterion reached"
<<
std
::
endl
;
return
true
;
...
...
libeasea/CPopulation.cpp
View file @
a5be0722
...
...
@@ -35,7 +35,7 @@ extern CIndividual* bBest;
CPopulation
::
CPopulation
(){
}
CPopulation
::
CPopulation
(
size_t
parentPopulationSize
,
size_t
offspringPopulationSize
,
CPopulation
::
CPopulation
(
unsigned
parentPopulationSize
,
unsigned
offspringPopulationSize
,
float
pCrossover
,
float
pMutation
,
float
pMutationPerGene
,
CRandomGenerator
*
rg
,
Parameters
*
params
){
...
...
@@ -63,14 +63,14 @@ CPopulation::CPopulation(size_t parentPopulationSize, size_t offspringPopulation
}
void
CPopulation
::
syncInVector
(){
for
(
size_t
i
=
0
;
i
<
actualParentPopulationSize
;
i
++
){
for
(
unsigned
i
=
0
;
i
<
actualParentPopulationSize
;
i
++
){
parents
[
i
]
=
pop_vect
.
at
(
i
);
}
}
void
CPopulation
::
syncOutVector
(){
pop_vect
.
clear
();
for
(
size_t
i
=
0
;
i
<
actualParentPopulationSize
;
i
++
){
for
(
unsigned
i
=
0
;
i
<
actualParentPopulationSize
;
i
++
){
pop_vect
.
push_back
(
parents
[
i
]);
}
#ifndef WIN32
...
...
@@ -79,8 +79,8 @@ void CPopulation::syncOutVector(){
}
CPopulation
::~
CPopulation
(){
for
(
size_t
i
=
0
;
i
<
actualOffspringPopulationSize
;
i
++
)
delete
(
offsprings
[
i
]);
for
(
size_t
i
=
0
;
i
<
actualParentPopulationSize
;
i
++
)
delete
(
parents
[
i
]);
for
(
unsigned
i
=
0
;
i
<
actualOffspringPopulationSize
;
i
++
)
delete
(
offsprings
[
i
]);
for
(
unsigned
i
=
0
;
i
<
actualParentPopulationSize
;
i
++
)
delete
(
parents
[
i
]);
delete
[](
this
->
parents
);
delete
[](
this
->
offsprings
);
...
...
@@ -107,12 +107,12 @@ void CPopulation::initPopulation(CSelectionOperator* selectionOperator,
void
CPopulation
::
evaluatePopulation
(
CIndividual
**
population
,
size_t
populationSize
){
for
(
size_t
i
=
0
;
i
<
populationSize
;
i
++
)
void
CPopulation
::
evaluatePopulation
(
CIndividual
**
population
,
unsigned
populationSize
){
for
(
unsigned
i
=
0
;
i
<
populationSize
;
i
++
)
population
[
i
]
->
evaluate
();
}
void
CPopulation
::
optimisePopulation
(
CIndividual
**
population
,
size_t
populationSize
){
void
CPopulation
::
optimisePopulation
(
CIndividual
**
population
,
unsigned
populationSize
){
}
void
CPopulation
::
evaluateParentPopulation
(){
...
...
@@ -141,17 +141,17 @@ void CPopulation::optimiseOffspringPopulation(){
*/
void
CPopulation
::
reducePopulation
(
CIndividual
**
population
,
size_t
populationSize
,
CIndividual
**
reducedPopulation
,
size_t
obSize
,
void
CPopulation
::
reducePopulation
(
CIndividual
**
population
,
unsigned
populationSize
,
CIndividual
**
reducedPopulation
,
unsigned
obSize
,
CSelectionOperator
*
replacementOperator
){
replacementOperator
->
initialize
(
population
,
replacementPressure
,
populationSize
);
for
(
size_t
i
=
0
;
i
<
obSize
;
i
++
){
for
(
unsigned
i
=
0
;
i
<
obSize
;
i
++
){
// select an CIndividual and add it to the reduced population
size_t
selectedIndex
=
replacementOperator
->
selectNext
(
populationSize
-
i
);
unsigned
selectedIndex
=
replacementOperator
->
selectNext
(
populationSize
-
i
);
// std::cout << "Selected " << selectedIndex << "/" << populationSize
// << " replaced by : " << populationSize-(i+1)<< std::endl;
reducedPopulation
[
i
]
=
population
[
selectedIndex
];
...
...
@@ -166,7 +166,7 @@ void CPopulation::reducePopulation(CIndividual** population, size_t populationSi
}
CIndividual
**
CPopulation
::
reduceParentPopulation
(
size_t
obSize
){
CIndividual
**
CPopulation
::
reduceParentPopulation
(
unsigned
obSize
){
CIndividual
**
nextGeneration
;
if
(
obSize
==
0
){
nextGeneration
=
new
CIndividual
*
[
1
];
...
...
@@ -178,7 +178,7 @@ CIndividual** CPopulation::reduceParentPopulation(size_t obSize){
CPopulation
::
parentReductionOperator
);
// free no longer needed CIndividuals
for
(
size_t
i
=
0
;
i
<
actualParentPopulationSize
-
obSize
;
i
++
)
for
(
unsigned
i
=
0
;
i
<
actualParentPopulationSize
-
obSize
;
i
++
)
delete
(
parents
[
i
]);
delete
[](
parents
);
...
...
@@ -191,7 +191,7 @@ CIndividual** CPopulation::reduceParentPopulation(size_t obSize){
CIndividual
**
CPopulation
::
reduceOffspringPopulation
(
size_t
obSize
){
CIndividual
**
CPopulation
::
reduceOffspringPopulation
(
unsigned
obSize
){
// this array has offspringPopulationSize because it will be used as offspring population in
// the next generation
CIndividual
**
nextGeneration
=
new
CIndividual
*
[
offspringPopulationSize
];
...
...
@@ -201,7 +201,7 @@ CIndividual** CPopulation::reduceOffspringPopulation(size_t obSize){
//printf("POPULATION SIZE %d\n",actualOffspringPopulationSize-obSize);
// free no longer needed CIndividuals
for
(
size_t
i
=
0
;
i
<
actualOffspringPopulationSize
-
obSize
;
i
++
)
for
(
unsigned
i
=
0
;
i
<
actualOffspringPopulationSize
-
obSize
;
i
++
)
delete
(
offsprings
[
i
]);
delete
[](
offsprings
);
//printf("DANS LA FONCTION DE REMPLACEMENT\n");
...
...
@@ -230,11 +230,11 @@ static int CIndividualRCompare(const void* p1, const void* p2){
}
void
CPopulation
::
sortPopulation
(
CIndividual
**
population
,
size_t
populationSize
){
void
CPopulation
::
sortPopulation
(
CIndividual
**
population
,
unsigned
populationSize
){
qsort
(
population
,
populationSize
,
sizeof
(
CIndividual
*
),
CIndividualCompare
);
}
void
CPopulation
::
sortRPopulation
(
CIndividual
**
population
,
size_t
populationSize
){
void
CPopulation
::
sortRPopulation
(
CIndividual
**
population
,
unsigned
populationSize
){
qsort
(
population
,
populationSize
,
sizeof
(
CIndividual
*
),
CIndividualRCompare
);
}
...
...
@@ -275,7 +275,7 @@ void CPopulation::reduceTotalPopulation(CIndividual** elitPop){
if
(
params
->
elitSize
)
memcpy
(
nextGeneration
,
elitPop
,
sizeof
(
CIndividual
*
)
*
params
->
elitSize
);
size_t
actualGlobalSize
=
actualParentPopulationSize
+
actualOffspringPopulationSize
;
unsigned
actualGlobalSize
=
actualParentPopulationSize
+
actualOffspringPopulationSize
;
CIndividual
**
globalPopulation
=
new
CIndividual
*
[
actualGlobalSize
]();
...
...
@@ -312,19 +312,19 @@ void CPopulation::reduceTotalPopulation(CIndividual** elitPop){
void
CPopulation
::
produceOffspringPopulation
(){
size_t
crossoverArrity
=
CIndividual
::
getCrossoverArrity
();
unsigned
crossoverArrity
=
CIndividual
::
getCrossoverArrity
();
CIndividual
*
p1
;
CIndividual
**
ps
=
new
CIndividual
*
[
crossoverArrity
]();
CIndividual
*
child
;
selectionOperator
->
initialize
(
parents
,
selectionPressure
,
actualParentPopulationSize
);
for
(
size_t
i
=
0
;
i
<
offspringPopulationSize
;
i
++
){
size_t
index
=
selectionOperator
->
selectNext
(
parentPopulationSize
);
for
(
unsigned
i
=
0
;
i
<
offspringPopulationSize
;
i
++
){
unsigned
index
=
selectionOperator
->
selectNext
(
parentPopulationSize
);
p1
=
parents
[
index
];
if
(
rg
->
tossCoin
(
pCrossover
)
){
for
(
size_t
j
=
0
;
j
<
crossoverArrity
-
1
;
j
++
){
for
(
unsigned
j
=
0
;
j
<
crossoverArrity
-
1
;
j
++
){
index
=
selectionOperator
->
selectNext
(
parentPopulationSize
);
ps
[
j
]
=
parents
[
index
];
}
...
...
@@ -354,22 +354,22 @@ void CPopulation::produceOffspringPopulation(){
@ARG outPopulationSize the size of the output population
*/
void
CPopulation
::
strongElitism
(
size_t
elitismSize
,
CIndividual
**
population
,
size_t
populationSize
,
CIndividual
**
outPopulation
,
size_t
outPopulationSize
){
void
CPopulation
::
strongElitism
(
unsigned
elitismSize
,
CIndividual
**
population
,
unsigned
populationSize
,
CIndividual
**
outPopulation
,
unsigned
outPopulationSize
){
float
bestFitness
=
population
[
0
]
->
getFitness
();
size_t
bestCIndividual
=
0
;
unsigned
bestCIndividual
=
0
;
#ifndef WIN32
if
(
elitismSize
>=
5
)
DEBUG_PRT
(
"Warning, elitism has O(n) complexity, elitismSize is maybe too big (%d)"
,
elitismSize
);
#endif
//printf("MINIMIZING ? %d\n",params->minimizing);
for
(
size_t
i
=
0
;
i
<
elitismSize
;
i
++
){
for
(
unsigned
i
=
0
;
i
<
elitismSize
;
i
++
){
//bestFitness = replacementOperator->getExtremum();
bestFitness
=
population
[
0
]
->
getFitness
();
bestCIndividual
=
0
;
for
(
size_t
j
=
0
;
j
<
populationSize
-
i
;
j
++
){
for
(
unsigned
j
=
0
;
j
<
populationSize
-
i
;
j
++
){
if
(
(
params
->
minimizing
&&
bestFitness
>
population
[
j
]
->
getFitness
()
)
||
(
!
params
->
minimizing
&&
bestFitness
<
population
[
j
]
->
getFitness
()
)){
...
...
@@ -383,7 +383,7 @@ void CPopulation::strongElitism(size_t elitismSize, CIndividual** population, si
}
}
void
CPopulation
::
weakElitism
(
size_t
elitismSize
,
CIndividual
**
parentsPopulation
,
CIndividual
**
offspringPopulation
,
size_t
*
parentPopSize
,
size_t
*
offPopSize
,
CIndividual
**
outPopulation
,
size_t
outPopulationSize
){
void
CPopulation
::
weakElitism
(
unsigned
elitismSize
,
CIndividual
**
parentsPopulation
,
CIndividual
**
offspringPopulation
,
unsigned
*
parentPopSize
,
unsigned
*
offPopSize
,
CIndividual
**
outPopulation
,
unsigned
outPopulationSize
){
float
bestParentFitness
=
parentsPopulation
[
0
]
->
getFitness
();
float
bestOffspringFitness
=
offspringPopulation
[
0
]
->
getFitness
();
...
...
@@ -445,7 +445,7 @@ void CPopulation::weakElitism(size_t elitismSize, CIndividual** parentsPopulatio
}
void
CPopulation
::
addIndividualParentPopulation
(
CIndividual
*
indiv
,
size_t
id
){
void
CPopulation
::
addIndividualParentPopulation
(
CIndividual
*
indiv
,
unsigned
id
){
parents
[
id
]
=
indiv
;
}
void
CPopulation
::
addIndividualParentPopulation
(
CIndividual
*
indiv
){
...
...
@@ -455,11 +455,11 @@ void CPopulation::addIndividualParentPopulation(CIndividual* indiv){
std
::
ostream
&
operator
<<
(
std
::
ostream
&
O
,
const
CPopulation
&
B
)
{
size_t
offspringPopulationSize
=
B
.
offspringPopulationSize
;
size_t
realOffspringPopulationSize
=
B
.
actualOffspringPopulationSize
;
unsigned
offspringPopulationSize
=
B
.
offspringPopulationSize
;
unsigned
realOffspringPopulationSize
=
B
.
actualOffspringPopulationSize
;
size_t
parentPopulationSize
=
B
.
parentPopulationSize
;
size_t
realParentPopulationSize
=
B
.
actualParentPopulationSize
;
unsigned
parentPopulationSize
=
B
.
parentPopulationSize
;
unsigned
realParentPopulationSize
=
B
.
actualParentPopulationSize
;
O
<<
"CPopulation : "
<<
std
::
endl
;
...
...
@@ -468,7 +468,7 @@ std::ostream& operator << (std::ostream& O, const CPopulation& B)
O
<<
"
\t
Offspring size : "
<<
realOffspringPopulationSize
<<
"/"
<<
offspringPopulationSize
<<
std
::
endl
;
for
(
size_t
i
=
0
;
i
<
realParentPopulationSize
;
i
++
){
for
(
unsigned
i
=
0
;
i
<
realParentPopulationSize
;
i
++
){
B
.
parents
[
i
]
->
printOn
(
O
);
O
<<
"
\n
"
;
...
...
libeasea/include/CEvolutionaryAlgorithm.h
View file @
a5be0722
...
...
@@ -36,22 +36,22 @@ public:
CEvolutionaryAlgorithm
(
Parameters
*
params
);
virtual
void
initializeParentPopulation
()
=
0
;
size_t
*
getCurrentGenerationPtr
(){
return
&
currentGeneration
;}
unsigned
*
getCurrentGenerationPtr
(){
return
&
currentGeneration
;}
void
addStoppingCriterion
(
CStoppingCriterion
*
sc
);
void
runEvolutionaryLoop
();
bool
allCriteria
();
CPopulation
*
getPopulation
(){
return
population
;}
size_t
getCurrentGeneration
()
{
return
currentGeneration
;}
unsigned
getCurrentGeneration
()
{
return
currentGeneration
;}
public:
size_t
currentGeneration
;
unsigned
currentGeneration
;
CPopulation
*
population
;
size_t
reduceParents
;
size_t
reduceOffsprings
;
unsigned
reduceParents
;
unsigned
reduceOffsprings
;
//methods and variables for remote island model
size_t
treatedIndividuals
;
size_t
numberOfClients
;
size_t
myClientNumber
;
unsigned
treatedIndividuals
;
unsigned
numberOfClients
;
unsigned
myClientNumber
;
CComUDPServer
*
server
;
CComUDPClient
**
Clients
;
void
initializeClients
();
...
...
libeasea/include/CPopulation.h
View file @
a5be0722
...
...
@@ -39,18 +39,18 @@ public:
CIndividual
**
parents
;
CIndividual
**
offsprings
;
size_t
parentPopulationSize
;
size_t
offspringPopulationSize
;
unsigned
parentPopulationSize
;
unsigned
offspringPopulationSize
;
size_t
actualParentPopulationSize
;
size_t
actualOffspringPopulationSize
;
unsigned
actualParentPopulationSize
;
unsigned
actualOffspringPopulationSize
;
static
CSelectionOperator
*
selectionOperator
;
static
CSelectionOperator
*
replacementOperator
;
static
CSelectionOperator
*
parentReductionOperator
;
static
CSelectionOperator
*
offspringReductionOperator
;
size_t
currentEvaluationNb
;
unsigned
currentEvaluationNb
;
CRandomGenerator
*
rg
;
std
::
vector
<
CIndividual
*>
pop_vect
;
...
...
@@ -58,27 +58,27 @@ public:
public:
CPopulation
();
CPopulation
(
size_t
parentPopulationSize
,
size_t
offspringPopulationSize
,
CPopulation
(
unsigned
parentPopulationSize
,
unsigned
offspringPopulationSize
,
float
pCrossover
,
float
pMutation
,
float
pMutationPerGene
,
CRandomGenerator
*
rg
,
Parameters
*
params
);
virtual
~
CPopulation
();
//virtual void initializeParentPopulation() = 0;
void
addIndividualParentPopulation
(
CIndividual
*
indiv
,
size_t
id
);
void
addIndividualParentPopulation
(
CIndividual
*
indiv
,
unsigned
id
);
void
addIndividualParentPopulation
(
CIndividual
*
indiv
);
void
evaluatePopulation
(
CIndividual
**
population
,
size_t
populationSize
);
virtual
void
optimisePopulation
(
CIndividual
**
population
,
size_t
populationSize
);
void
evaluatePopulation
(
CIndividual
**
population
,
unsigned
populationSize
);
virtual
void
optimisePopulation
(
CIndividual
**
population
,
unsigned
populationSize
);
virtual
void
evaluateParentPopulation
();
virtual
void
optimiseParentPopulation
();
void
strongElitism
(
size_t
elitismSize
,
CIndividual
**
population
,
size_t
populationSize
,
CIndividual
**
outPopulation
,
size_t
outPopulationSize
);
void
weakElitism
(
size_t
elitismSize
,
CIndividual
**
parentsPopulation
,
CIndividual
**
offspringPopulation
,
size_t
*
parentPopSize
,
size_t
*
offPopSize
,
CIndividual
**
outPopulation
,
size_t
outPopulationSize
);
void
strongElitism
(
unsigned
elitismSize
,
CIndividual
**
population
,
unsigned
populationSize
,
CIndividual
**
outPopulation
,
unsigned
outPopulationSize
);
void
weakElitism
(
unsigned
elitismSize
,
CIndividual
**
parentsPopulation
,
CIndividual
**
offspringPopulation
,
unsigned
*
parentPopSize
,
unsigned
*
offPopSize
,
CIndividual
**
outPopulation
,
unsigned
outPopulationSize
);
virtual
void
evaluateOffspringPopulation
();
virtual
void
optimiseOffspringPopulation
();
CIndividual
**
reducePopulations
(
CIndividual
**
population
,
size_t
populationSize
,
CIndividual
**
reducedPopulation
,
size_t
obSize
);
CIndividual
**
reduceParentPopulation
(
size_t
obSize
);
CIndividual
**
reduceOffspringPopulation
(
size_t
obSize
);
CIndividual
**
reducePopulations
(
CIndividual
**
population
,
unsigned
populationSize
,
CIndividual
**
reducedPopulation
,
unsigned
obSize
);
CIndividual
**
reduceParentPopulation
(
unsigned
obSize
);
CIndividual
**
reduceOffspringPopulation
(
unsigned
obSize
);
void
reduceTotalPopulation
(
CIndividual
**
elitPop
);
void
evolve
();
...
...
@@ -94,9 +94,9 @@ public:
float
selectionPressure
,
float
replacementPressure
,
float
parentReductionPressure
,
float
offspringReductionPressure
);
static
void
sortPopulation
(
CIndividual
**
population
,
size_t
populationSize
);
static
void
sortPopulation
(
CIndividual
**
population
,
unsigned
populationSize
);
static
void
sortRPopulation
(
CIndividual
**
population
,
size_t
populationSize
);
static
void
sortRPopulation
(
CIndividual
**
population
,
unsigned
populationSize
);
void
serializePopulation
();
int
getWorstIndividualIndex
(
CIndividual
**
population
);
...
...
@@ -108,13 +108,13 @@ public:
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
O
,
const
CPopulation
&
B
);
void
setParentPopulation
(
CIndividual
**
population
,
size_t
actualParentPopulationSize
){
void
setParentPopulation
(
CIndividual
**
population
,
unsigned
actualParentPopulationSize
){
this
->
parents
=
population
;
this
->
actualParentPopulationSize
=
actualParentPopulationSize
;
}
static
void
reducePopulation
(
CIndividual
**
population
,
size_t
populationSize
,
CIndividual
**
reducedPopulation
,
size_t
obSize
,
static
void
reducePopulation
(
CIndividual
**
population
,
unsigned
populationSize
,
CIndividual
**
reducedPopulation
,
unsigned
obSize
,
CSelectionOperator
*
replacementOperator
);
void
syncOutVector
();
void
syncInVector
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment