Commit 9a480ab6 authored by Frederic Kruger's avatar Frederic Kruger

Bound checking function

parent 0fd78b8f
This diff is collapsed.
......@@ -1636,7 +1636,8 @@ if(OPERATING_SYSTEM=WINDOWS)
<COPY_BOUND_CHECKING_FUNCTION>"\\Bound"[ \t\n]+"checking"[ \t\n]*":" {
if(TARGET==CUDA || TARGET==STD){
fprintf (fpOutputFile,"void EASEABoundChecking(EvolutionaryAlgorithm* evolutionaryAlgorithm){\n");
//fprintf (fpOutputFile,"void EASEABoundChecking(EvolutionaryAlgorithm* evolutionaryAlgorithm){\n");
fprintf (fpOutputFile,"{\n");
}
bFunction=1; bBoundCheckingFunction=1;
BEGIN COPY_USER_GENERATION;
......
......@@ -73,7 +73,9 @@ float gauss()
\end
\After everything else function:
//cout << "After everything else function called" << endl;
ofstream SaveFile("save.csv", ios::app);
SaveFile << bBest->fitness << ";" << endl;
SaveFile.close();
\end
\At the beginning of each generation function:
......@@ -146,8 +148,8 @@ CPPFLAGS+=
\end
\Default run parameters : // Please let the parameters appear in this order
Number of generations : 9999999 // NB_GEN
Time limit: 60 // In seconds, 0 to deactivate
Number of generations : 100000 // NB_GEN
Time limit: 0 // In seconds, 0 to deactivate
Population size : 3840 //POP_SIZE
Offspring size : 3840 // 40%
Mutation probability : 1 // MUT_PROB
......@@ -170,6 +172,7 @@ CPPFLAGS+=
Remote island model: false
IP file: ip.txt //File containing all the remote island's IP
Migration probability : 0.8
Save population: false
Start from file:false
......
......@@ -376,8 +376,16 @@ void CEvolutionaryAlgorithm::showPopulationStats(struct timeval beginTime){
}
#endif
double elapsedTime = res.tv_sec + 0.0;
double micSec = res.tv_usec + 0.0;
params->timeCriterion->setElapsedTime(res.tv_sec);
while(micSec>1){
micSec /= 10.;
}
elapsedTime += micSec + 0.0;
params->timeCriterion->setElapsedTime(elapsedTime);
}
//REMOTE ISLAND MODEL FUNCTIONS
......@@ -416,19 +424,20 @@ void CEvolutionaryAlgorithm::initializeClients(){
void CEvolutionaryAlgorithm::sendIndividual(){
//Sending an individual every n generations
if(globalRandomGenerator->random(0.0,1.0)<=params->migrationProbability){
//if((this->currentGeneration+this->myClientNumber)%3==0 && this->currentGeneration!=0){
//cout << "I'm going to send an Individual now" << endl;
//this->population->selectionOperator->initialize(this->population->parents, 7, this->population->actualParentPopulationSize);
this->population->selectionOperator->initialize(this->population->parents, params->selectionPressure, 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
int client = globalRandomGenerator->getRandomIntMax(this->numberOfClients);
//for(int client=0; client<this->numberOfClients; client++){
cout << "Going to send and individual to client " << client << endl;
cout << "His IP is " << this->Clients[client]->getIP() << endl;
//cout << "Sending individual " << index << " to client " << client << " now" << endl;
//cout << this->population->parents[index]->serialize() << endl;
this->Clients[client]->CComUDP_client_send((char*)bBest->serialize().c_str());
}
}
......@@ -437,16 +446,16 @@ void CEvolutionaryAlgorithm::receiveIndividuals(){
if(this->treatedIndividuals<(unsigned)this->server->nb_data){
//cout << "number of received individuals :" << this->server->nb_data << endl;
//cout << "number of treated individuals :" << this->treatedIndividuals << endl;
CSelectionOperator *antiTournament = getSelectionOperator("Tournament",!this->params->minimizing, globalRandomGenerator);
//Treating all the individuals before continuing
while(this->treatedIndividuals < (unsigned)this->server->nb_data){
//selecting the individual to erase
//CSelectionOperator *antiTournament = getSelectionOperator("Tournament",!this->params->minimizing, globalRandomGenerator);
//antiTournament->initialize(this->population->parents, 7, this->population->actualParentPopulationSize);
//unsigned index = antiTournament->selectNext(this->population->actualParentPopulationSize);
antiTournament->initialize(this->population->parents, 7, 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);
//size_t index = this->population->getWorstIndividualIndex(this->population->parents);
//cout << "old individual fitness :" << this->population->parents[index]->fitness << endl;
//cout << "old Individual :" << this->population->parents[index]->serialize() << endl;
......
......@@ -336,6 +336,8 @@ void CPopulation::produceOffspringPopulation(){
child->mutate(pMutationPerGene);
}
child->boundChecking();
offsprings[actualOffspringPopulationSize++] = child;
}
delete[](ps);
......
......@@ -40,7 +40,7 @@ unsigned* CGenerationalCriterion::getGenerationalLimit(){
****************************************/
CTimeCriterion::CTimeCriterion(unsigned timeLimit){
this->timeLimit = timeLimit;
this->elapsedTime = 0;
this->elapsedTime = 0.0;
}
bool CTimeCriterion::reached(){
......@@ -58,10 +58,14 @@ bool CTimeCriterion::reached(){
else return false;
}
void CTimeCriterion::setElapsedTime(unsigned elapsedTime){
void CTimeCriterion::setElapsedTime(double elapsedTime){
this->elapsedTime = elapsedTime;
}
double CTimeCriterion::getElapsedTime(){
return this->elapsedTime;
}
/* ****************************************
CtrlCStopingCriterion class
****************************************/
......
......@@ -29,6 +29,8 @@ public:
virtual std::string serialize() = 0;
virtual void deserialize(std::string EASEA_Line) = 0;
virtual void boundChecking() = 0;
static unsigned getCrossoverArrity(){ return 2; }
float getFitness(){ return this->fitness; }
......
......@@ -51,11 +51,12 @@ class CGenerationalCriterion : public CStoppingCriterion {
class CTimeCriterion : public CStoppingCriterion {
private:
unsigned timeLimit;
unsigned elapsedTime;
double elapsedTime;
public:
virtual bool reached();
CTimeCriterion(unsigned timeLimit);
void setElapsedTime(unsigned elapsedTime);
void setElapsedTime(double elapsedTime);
double getElapsedTime();
};
/* ****************************************
......
......@@ -103,8 +103,6 @@ extern CEvolutionaryAlgorithm* EA;
\INSERT_INITIALISATION_FUNCTION
\INSERT_FINALIZATION_FUNCTION
\INSERT_BOUND_CHECKING
void evale_pop_chunk(CIndividual** population, int popSize){
\INSTEAD_EVAL_FUNCTION
}
......@@ -184,6 +182,10 @@ float IndividualImpl::evaluate(){
}
}
void IndividualImpl::boundChecking(){
\INSERT_BOUND_CHECKING
}
string IndividualImpl::serialize(){
ostringstream AESAE_Line(ios_base::app);
\GENOME_SERIAL
......@@ -414,6 +416,9 @@ public:
CIndividual* clone();
unsigned mutate(float pMutationPerGene);
void boundChecking();
string serialize();
void deserialize(string AESAE_Line);
......
......@@ -132,8 +132,6 @@ void cudaPreliminaryProcess(size_t populationSize, dim3* dimBlock, dim3* dimGrid
\INSERT_INITIALISATION_FUNCTION
\INSERT_FINALIZATION_FUNCTION
\INSERT_BOUND_CHECKING
void evale_pop_chunk(CIndividual** population, int popSize){
\INSTEAD_EVAL_FUNCTION
}
......@@ -215,6 +213,10 @@ float IndividualImpl::evaluate(){
}
}
void IndividualImpl::boundChecking(){
\INSERT_BOUND_CHECKING
}
IndividualImpl::IndividualImpl(const IndividualImpl& genome){
......@@ -546,6 +548,9 @@ public:
CIndividual* clone();
size_t mutate(float pMutationPerGene);
void boundChecking();
void copyToCudaBuffer(void* buffer, size_t id);
friend std::ostream& operator << (std::ostream& O, const IndividualImpl& B) ;
......
......@@ -235,8 +235,6 @@ void InitialiseGPUs(){
\INSERT_INITIALISATION_FUNCTION
\INSERT_FINALIZATION_FUNCTION
\INSERT_BOUND_CHECKING
void evale_pop_chunk(CIndividual** population, int popSize){
\INSTEAD_EVAL_FUNCTION
}
......@@ -294,6 +292,11 @@ float IndividualImpl::evaluate(){
}
}
void IndividualImpl::boundChecking(){
\INSERT_BOUND_CHECKING
}
string IndividualImpl::serialize(){
ostringstream AESAE_Line(ios_base::app);
\GENOME_SERIAL
......@@ -612,6 +615,9 @@ public:
CIndividual* clone();
unsigned mutate(float pMutationPerGene);
void boundChecking();
string serialize();
void deserialize(string AESAE_Line);
void copyToCudaBuffer(void* buffer, unsigned id);
......
......@@ -559,7 +559,9 @@ float IndividualImpl::evaluate(){
\INSERT_INITIALISATION_FUNCTION
\INSERT_FINALIZATION_FUNCTION
\INSERT_BOUND_CHECKING
void IndividualImpl::boundChecking(){
\INSERT_BOUND_CHECKING
}
string IndividualImpl::serialize(){
ostringstream AESAE_Line(ios_base::app);
......@@ -934,6 +936,9 @@ public:
CIndividual* clone();
unsigned mutate(float pMutationPerGene);
void boundChecking();
string serialize();
void deserialize(string AESAE_Line);
......
......@@ -138,8 +138,6 @@ void cudaPreliminaryProcess(unsigned populationSize, dim3* dimBlock, dim3* dimGr
\INSERT_INITIALISATION_FUNCTION
\INSERT_FINALIZATION_FUNCTION
\INSERT_BOUND_CHECKING
void evale_pop_chunk(CIndividual** population, int popSize){
\INSTEAD_EVAL_FUNCTION
}
......@@ -195,6 +193,10 @@ float IndividualImpl::evaluate(){
}
}
void IndividualImpl::boundChecking(){
\INSERT_BOUND_CHECKING
}
string IndividualImpl::serialize(){
ostringstream AESAE_Line(ios_base::app);
\GENOME_SERIAL
......@@ -698,6 +700,9 @@ public:
CIndividual* clone();
unsigned mutate(float pMutationPerGene);
void boundChecking();
string serialize();
void deserialize(string AESAE_Line);
void copyToCudaBuffer(void* buffer, unsigned id);
......
......@@ -99,7 +99,6 @@ extern CEvolutionaryAlgorithm* EA;
\INSERT_INITIALISATION_FUNCTION
\INSERT_FINALIZATION_FUNCTION
\INSERT_BOUND_CHECKING
void evale_pop_chunk(CIndividual** population, int popSize){
\INSTEAD_EVAL_FUNCTION
......@@ -150,6 +149,10 @@ float IndividualImpl::evaluate(){
}
}
void IndividualImpl::boundChecking(){
\INSERT_BOUND_CHECKING
}
string IndividualImpl::serialize(){
ostringstream AESAE_Line(ios_base::app);
\GENOME_SERIAL
......@@ -404,6 +407,9 @@ public:
CIndividual* clone();
unsigned mutate(float pMutationPerGene);
void boundChecking();
string serialize();
void deserialize(string AESAE_Line);
......
......@@ -99,8 +99,6 @@ extern CEvolutionaryAlgorithm* EA;
\INSERT_INITIALISATION_FUNCTION
\INSERT_FINALIZATION_FUNCTION
\INSERT_BOUND_CHECKING
void evale_pop_chunk(CIndividual** population, int popSize){
\INSTEAD_EVAL_FUNCTION
}
......@@ -146,6 +144,10 @@ float IndividualImpl::evaluate(){
\INSERT_EVALUATOR
}
void IndividualImpl::boundChecking(){
\INSERT_BOUND_CHECKING
}
string IndividualImpl::serialize(){
ostringstream AESAE_Line(ios_base::app);
\GENOME_SERIAL
......@@ -437,6 +439,9 @@ public:
CIndividual* clone();
unsigned mutate(float pMutationPerGene);
void boundChecking();
string serialize();
void deserialize(string AESAE_Line);
......
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