From a0fd39f04307e9f729af0c2cab057350d94426df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20PASINI?= <kevin.pasini@ensiie.fr> Date: Wed, 19 Oct 2016 00:45:02 +0200 Subject: [PATCH] Update combination.cpp --- src/ibea/combination.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/ibea/combination.cpp b/src/ibea/combination.cpp index 70da707..499963c 100644 --- a/src/ibea/combination.cpp +++ b/src/ibea/combination.cpp @@ -1,7 +1,6 @@ #include <utility> #include <cstdlib> #include <iostream> -#include <cstdio> #include "../coco/coco.h" #include "population.h" #include "combination.h" @@ -9,6 +8,8 @@ void simple_combination(Population & pop_in, Population & pop_out, + const double *lower_bounds, + const double *upper_bounds, int parent1, int parent2, const double eta, @@ -22,14 +23,25 @@ void simple_combination(Population & pop_in, if (u <= 0.5){ beta = pow(2*u,1/(1+eta)); - } else { - beta = pow(1/(2*u),1/(1+eta)); - + beta = pow(1/(2*(1-u)),1/(1+eta)); } double child1 = 0.5*((1+beta)*pop_in.getIndiv(parent1,j) + (1-beta)*pop_in.getIndiv(parent2,j)); double child2 = 0.5*((1-beta)*pop_in.getIndiv(parent1,j) + (1+beta)*pop_in.getIndiv(parent2,j)); + + if (child1 > upper_bounds[j]){ + child1 = upper_bounds[j]; + } + if (child1 < lower_bounds[j]){ + child1 = lower_bounds[j]; + } + if (child2 > upper_bounds[j]){ + child2 = upper_bounds[j]; + } + if (child2 < lower_bounds[j]){ + child2 = lower_bounds[j]; + } pop_out.setIndiv(parent1,j,child1); pop_out.setIndiv(parent2,j,child2); } @@ -38,6 +50,8 @@ void simple_combination(Population & pop_in, /* Recombinaison prédéfini */ void combinate(Population & pop_in, Population & pop_out, + const double *lower_bounds, + const double *upper_bounds, double eta, double p_combination, coco_random_state_t *random_generator) @@ -47,8 +61,9 @@ void combinate(Population & pop_in, u = coco_random_uniform(random_generator); for (int i=0; i<floor(size/2.0); i++){ if (u <= p_combination){ - simple_combination(pop_in,pop_out,i,size-i-1, eta, random_generator); + simple_combination(pop_in,pop_out,lower_bounds,upper_bounds,i,size-i-1, eta, random_generator); } } pop_out.setCurrenSize(size); } + -- GitLab