25 #include <boost/math/constants/constants.hpp>
26 #include <boost/lexical_cast.hpp>
34 #include "../exceptions.h"
39 #define MYSIGN(x) ((x)>0?1.0:-1.0)
41 namespace pagmo {
namespace problem {
43 static const double PI = boost::math::constants::pi<double>();
59 base(prob_dim, 0, cec2009_fitness_dimension(fun_id), is_constrained?cec2009_ic_dimension(fun_id):0, is_constrained?cec2009_ic_dimension(fun_id):0, 0.0),
60 m_problem_number(fun_id),
61 m_is_constrained(is_constrained)
74 std::string retval(
"CEC2009 - ");
75 if(!m_is_constrained){
81 retval.append(boost::lexical_cast<std::string>(m_problem_number));
86 fitness_vector::size_type cec2009::cec2009_fitness_dimension(
int problem_id)
89 if(problem_id >= 1 && problem_id <= 7){
92 else if(problem_id >= 8 && problem_id <= 10){
96 pagmo_throw(value_error,
"Error: CEC2009 unexpected problem id when determining fitness dimension.");
101 constraint_vector::size_type cec2009::cec2009_ic_dimension(
int problem_id)
106 if(problem_id == 6 || problem_id == 7){
109 else if(problem_id >= 1 && problem_id <= 10){
113 pagmo_throw(value_error,
"Error: CEC2009 unexpected problem id when determining inequality constraints\' dimension.");
118 void cec2009::configure_bounds(){
121 std::vector<double> lb(nx, 0), ub(nx, 0);
123 if(!m_is_constrained){
124 if(m_problem_number == 1 || m_problem_number == 2 || m_problem_number == 5 || m_problem_number == 6 || m_problem_number == 7){
128 for(
unsigned int i = 1; i < nx; i++){
133 else if(m_problem_number == 3){
135 for(
unsigned int i = 0; i < nx; i++){
140 else if(m_problem_number == 4){
144 for(
unsigned int i = 1; i < nx; i++){
149 else if(m_problem_number == 8 || m_problem_number == 9 || m_problem_number == 10){
155 for(
unsigned int i = 2; i < nx; i++){
161 pagmo_throw(value_error,
"Error: CEC2009 unexpected problem id when setting bounds.");
165 if(m_problem_number == 2){
169 for(
unsigned int i = 1; i < nx; i++){
174 else if(m_problem_number == 1){
176 for(
unsigned int i = 0; i < nx; i++){
181 else if(m_problem_number == 3 || m_problem_number == 4 || m_problem_number == 5 || m_problem_number == 6 || m_problem_number == 7){
185 for(
unsigned int i = 1; i < nx; i++){
190 else if(m_problem_number == 8){
196 for(
unsigned int i = 2; i < nx; i++){
201 else if(m_problem_number == 9 || m_problem_number == 10){
207 for(
unsigned int i = 2; i < nx; i++){
213 pagmo_throw(value_error,
"Error: CEC2009 unexpected problem id when setting bounds.");
223 if(!m_is_constrained){
224 switch(m_problem_number)
227 UF1(&x[0], &f[0], nx);
230 UF2(&x[0], &f[0], nx);
233 UF3(&x[0], &f[0], nx);
236 UF4(&x[0], &f[0], nx);
239 UF5(&x[0], &f[0], nx);
242 UF6(&x[0], &f[0], nx);
245 UF7(&x[0], &f[0], nx);
248 UF8(&x[0], &f[0], nx);
251 UF9(&x[0], &f[0], nx);
254 UF10(&x[0], &f[0], nx);
257 pagmo_throw(value_error,
"Error: CEC2009 unexpected problem id when computing fitness values.");
261 switch(m_problem_number)
265 CF1(&x[0], &f[0], NULL, nx);
268 CF2(&x[0], &f[0], NULL, nx);
271 CF3(&x[0], &f[0], NULL, nx);
274 CF4(&x[0], &f[0], NULL, nx);
277 CF5(&x[0], &f[0], NULL, nx);
280 CF6(&x[0], &f[0], NULL, nx);
283 CF7(&x[0], &f[0], NULL, nx);
286 CF8(&x[0], &f[0], NULL, nx);
289 CF9(&x[0], &f[0], NULL, nx);
292 CF10(&x[0], &f[0], NULL, nx);
295 pagmo_throw(value_error,
"Error: CEC2009 unexpected problem id when computing fitness values.");
304 if(!m_is_constrained){
311 switch(m_problem_number)
314 CF1(&x[0], &f[0], &c[0], nx);
317 CF2(&x[0], &f[0], &c[0], nx);
320 CF3(&x[0], &f[0], &c[0], nx);
323 CF4(&x[0], &f[0], &c[0], nx);
326 CF5(&x[0], &f[0], &c[0], nx);
329 CF6(&x[0], &f[0], &c[0], nx);
332 CF7(&x[0], &f[0], &c[0], nx);
335 CF8(&x[0], &f[0], &c[0], nx);
338 CF9(&x[0], &f[0], &c[0], nx);
341 CF10(&x[0], &f[0], &c[0], nx);
344 pagmo_throw(value_error,
"Error: CEC2009 unexpected problem id when computing constraint values.");
355 void cec2009::UF1(
const double *x,
double *f,
const unsigned int nx)
const
357 unsigned int j, count1, count2;
358 double sum1, sum2, yj;
362 for(j = 2; j <= nx; j++)
364 yj = x[j-1] - sin(6.0*PI*x[0] + j*PI/nx);
377 f[0] = x[0] + 2.0 * sum1 / (double)count1;
378 f[1] = 1.0 - sqrt(x[0]) + 2.0 * sum2 / (double)count2;
381 void cec2009::UF2(
const double *x,
double *f,
const unsigned int nx)
const
383 unsigned int j, count1, count2;
384 double sum1, sum2, yj;
388 for(j = 2; j <= nx; j++)
391 yj = x[j-1]-0.3*x[0]*(x[0]*cos(24.0*PI*x[0]+4.0*j*PI/nx)+2.0)*sin(6.0*PI*x[0]+j*PI/nx);
397 yj = x[j-1]-0.3*x[0]*(x[0]*cos(24.0*PI*x[0]+4.0*j*PI/nx)+2.0)*cos(6.0*PI*x[0]+j*PI/nx);
402 f[0] = x[0] + 2.0 * sum1 / (double)count1;
403 f[1] = 1.0 - sqrt(x[0]) + 2.0 * sum2 / (double)count2;
406 void cec2009::UF3(
const double *x,
double *f,
const unsigned int nx)
const
408 unsigned int j, count1, count2;
409 double sum1, sum2, prod1, prod2, yj, pj;
414 for(j = 2; j <= nx; j++)
416 yj = x[j-1]-pow(x[0],0.5*(1.0+3.0*(j-2.0)/(nx-2.0)));
417 pj = cos(20.0*yj*PI/sqrt(j+0.0));
431 f[0] = x[0] + 2.0*(4.0*sum1 - 2.0*prod1 + 2.0) / (double)count1; f[1] = 1.0 - sqrt(x[0]) + 2.0*(4.0*sum2 - 2.0*prod2 + 2.0) / (double)count2;
434 void cec2009::UF4(
const double *x,
double *f,
const unsigned int nx)
const
436 unsigned int j, count1, count2;
437 double sum1, sum2, yj, hj;
441 for(j = 2; j <= nx; j++)
443 yj = x[j-1]-sin(6.0*PI*x[0]+j*PI/nx);
444 hj = fabs(yj)/(1.0+exp(2.0*fabs(yj)));
456 f[0] = x[0] + 2.0*sum1 / (double)count1;
457 f[1] = 1.0 - x[0]*x[0] + 2.0*sum2 / (double)count2;
460 void cec2009::UF5(
const double *x,
double *f,
const unsigned int nx)
const
462 unsigned int j, count1, count2;
463 double sum1, sum2, yj, hj, N, E;
468 for(j = 2; j <= nx; j++)
470 yj = x[j-1]-sin(6.0*PI*x[0]+j*PI/nx);
471 hj = 2.0*yj*yj - cos(4.0*PI*yj) + 1.0;
483 hj = (0.5/N + E)*fabs(sin(2.0*N*PI*x[0]));
484 f[0] = x[0] + hj + 2.0*sum1 / (double)count1;
485 f[1] = 1.0 - x[0] + hj + 2.0*sum2 / (double)count2;
488 void cec2009::UF6(
const double *x,
double *f,
const unsigned int nx)
const
490 unsigned int j, count1, count2;
491 double sum1, sum2, prod1, prod2, yj, hj, pj, N, E;
497 for(j = 2; j <= nx; j++)
499 yj = x[j-1]-sin(6.0*PI*x[0]+j*PI/nx);
500 pj = cos(20.0*yj*PI/sqrt(j+0.0));
515 hj = 2.0*(0.5/N + E)*sin(2.0*N*PI*x[0]);
517 f[0] = x[0] + hj + 2.0*(4.0*sum1 - 2.0*prod1 + 2.0) / (double)count1;
518 f[1] = 1.0 - x[0] + hj + 2.0*(4.0*sum2 - 2.0*prod2 + 2.0) / (double)count2;
521 void cec2009::UF7(
const double *x,
double *f,
const unsigned int nx)
const
523 unsigned int j, count1, count2;
524 double sum1, sum2, yj;
528 for(j = 2; j <= nx; j++)
530 yj = x[j-1] - sin(6.0*PI*x[0]+j*PI/nx);
543 f[0] = yj + 2.0*sum1 / (double)count1;
544 f[1] = 1.0 - yj + 2.0*sum2 / (double)count2;
547 void cec2009::UF8(
const double *x,
double *f,
const unsigned int nx)
const
549 unsigned int j, count1, count2, count3;
550 double sum1, sum2, sum3, yj;
552 sum1 = sum2 = sum3 = 0.0;
553 count1 = count2 = count3 = 0;
554 for(j = 3; j <= nx; j++)
556 yj = x[j-1] - 2.0*x[1]*sin(2.0*PI*x[0]+j*PI/nx);
573 f[0] = cos(0.5*PI*x[0])*cos(0.5*PI*x[1]) + 2.0*sum1 / (double)count1;
574 f[1] = cos(0.5*PI*x[0])*sin(0.5*PI*x[1]) + 2.0*sum2 / (double)count2;
575 f[2] = sin(0.5*PI*x[0]) + 2.0*sum3 / (double)count3;
578 void cec2009::UF9(
const double *x,
double *f,
const unsigned int nx)
const
580 unsigned int j, count1, count2, count3;
581 double sum1, sum2, sum3, yj, E;
584 sum1 = sum2 = sum3 = 0.0;
585 count1 = count2 = count3 = 0;
586 for(j = 3; j <= nx; j++)
588 yj = x[j-1] - 2.0*x[1]*sin(2.0*PI*x[0]+j*PI/nx);
605 yj = (1.0+E)*(1.0-4.0*(2.0*x[0]-1.0)*(2.0*x[0]-1.0));
607 f[0] = 0.5*(yj + 2*x[0])*x[1] + 2.0*sum1 / (
double)count1;
608 f[1] = 0.5*(yj - 2*x[0] + 2.0)*x[1] + 2.0*sum2 / (double)count2;
609 f[2] = 1.0 - x[1] + 2.0*sum3 / (double)count3;
612 void cec2009::UF10(
const double *x,
double *f,
const unsigned int nx)
const
614 unsigned int j, count1, count2, count3;
615 double sum1, sum2, sum3, yj, hj;
617 sum1 = sum2 = sum3 = 0.0;
618 count1 = count2 = count3 = 0;
619 for(j = 3; j <= nx; j++)
621 yj = x[j-1] - 2.0*x[1]*sin(2.0*PI*x[0]+j*PI/nx);
622 hj = 4.0*yj*yj - cos(8.0*PI*yj) + 1.0;
639 f[0] = cos(0.5*PI*x[0])*cos(0.5*PI*x[1]) + 2.0*sum1 / (double)count1;
640 f[1] = cos(0.5*PI*x[0])*sin(0.5*PI*x[1]) + 2.0*sum2 / (double)count2;
641 f[2] = sin(0.5*PI*x[0]) + 2.0*sum3 / (double)count3;
647 void cec2009::CF1(
const double *x,
double *f,
double *c,
const unsigned int nx)
const
649 unsigned int j, count1, count2;
650 double sum1, sum2, yj, N, a;
655 for(j = 2; j <= nx; j++)
657 yj = x[j-1]-pow(x[0],0.5*(1.0+3.0*(j-2.0)/(nx-2.0)));
669 f[0] = x[0] + 2.0*sum1 / (double)count1;
670 f[1] = 1.0 - x[0] + 2.0*sum2 / (double)count2;
673 c[0] = f[1] + f[0] - a*fabs(sin(N*PI*(f[0]-f[1]+1.0))) - 1.0;
678 void cec2009::CF2(
const double *x,
double *f,
double *c,
const unsigned int nx)
const
680 unsigned int j, count1, count2;
681 double sum1, sum2, yj, N, a, t;
686 for(j = 2; j <= nx; j++)
690 yj = x[j-1] - sin(6.0*PI*x[0] + j*PI/nx);
696 yj = x[j-1] - cos(6.0*PI*x[0] + j*PI/nx);
701 f[0] = x[0] + 2.0*sum1 / (double)count1;
702 f[1] = 1.0 - sqrt(x[0]) + 2.0*sum2 / (double)count2;
705 t = f[1] + sqrt(f[0]) - a*sin(N*PI*(sqrt(f[0])-f[1]+1.0)) - 1.0;
706 c[0] = MYSIGN(t)*fabs(t)/(1+exp(4.0*fabs(t)));
711 void cec2009::CF3(
const double *x,
double *f,
double *c,
const unsigned int nx)
const
713 unsigned int j, count1, count2;
714 double sum1, sum2, prod1, prod2, yj, pj, N, a;
720 for(j = 2; j <= nx; j++)
722 yj = x[j-1]-sin(6.0*PI*x[0]+j*PI/nx);
723 pj = cos(20.0*yj*PI/sqrt(j+0.0));
738 f[0] = x[0] + 2.0*(4.0*sum1 - 2.0*prod1 + 2.0) / (double)count1;
739 f[1] = 1.0 - x[0]*x[0] + 2.0*(4.0*sum2 - 2.0*prod2 + 2.0) / (double)count2;
742 c[0] = f[1] + f[0]*f[0] - a*sin(N*PI*(f[0]*f[0]-f[1]+1.0)) - 1.0;
747 void cec2009::CF4(
const double *x,
double *f,
double *c,
const unsigned int nx)
const
750 double sum1, sum2, yj, t;
753 for(j = 2; j <= nx; j++)
755 yj = x[j-1] - sin(6.0*PI*x[0] + j*PI/nx);
763 sum2 += yj < 1.5-0.75*sqrt(2.0) ? fabs(yj) : (0.125+(yj-1)*(yj-1));
769 f[1] = 1.0 - x[0] + sum2;
772 t = x[1] - sin(6.0*x[0]*PI+2.0*PI/nx) - 0.5*x[0] + 0.25;
773 c[0] = MYSIGN(t)*fabs(t)/(1+exp(4.0*fabs(t)));
778 void cec2009::CF5(
const double *x,
double *f,
double *c,
const unsigned int nx)
const
781 double sum1, sum2, yj;
784 for(j = 2; j <= nx; j++)
788 yj = x[j-1] - 0.8*x[0]*cos(6.0*PI*x[0] + j*PI/nx);
789 sum1 += 2.0*yj*yj - cos(4.0*PI*yj) + 1.0;
793 yj = x[j-1] - 0.8*x[0]*sin(6.0*PI*x[0] + j*PI/nx);
795 sum2 += yj < 1.5-0.75*sqrt(2.0) ? fabs(yj) : (0.125+(yj-1)*(yj-1));
797 sum2 += 2.0*yj*yj - cos(4.0*PI*yj) + 1.0;
801 f[1] = 1.0 - x[0] + sum2;
804 c[0] = x[1] - 0.8*x[0]*sin(6.0*x[0]*PI+2.0*PI/nx) - 0.5*x[0] + 0.25;
809 void cec2009::CF6(
const double *x,
double *f,
double *c,
const unsigned int nx)
const
812 double sum1, sum2, yj;
815 for(j = 2; j <= nx; j++)
819 yj = x[j-1] - 0.8*x[0]*cos(6.0*PI*x[0] + j*PI/nx);
824 yj = x[j-1] - 0.8*x[0]*sin(6.0*PI*x[0] + j*PI/nx);
829 f[1] = (1.0 - x[0])*(1.0 - x[0]) + sum2;
832 c[0] = x[1]-0.8*x[0]*sin(6.0*x[0]*PI+2.0*PI/nx) - MYSIGN((x[0]-0.5)*(1.0-x[0]))*sqrt(fabs((x[0]-0.5)*(1.0-x[0])));
833 c[1] = x[3]-0.8*x[0]*sin(6.0*x[0]*PI+4.0*PI/nx) - MYSIGN(0.25*sqrt(1-x[0])-0.5*(1.0-x[0]))*sqrt(fabs(0.25*sqrt(1-x[0])-0.5*(1.0-x[0])));
840 void cec2009::CF7(
const double *x,
double *f,
double *c,
const unsigned int nx)
const
843 double sum1, sum2, yj;
846 for(j = 2; j <= nx; j++)
850 yj = x[j-1] - cos(6.0*PI*x[0] + j*PI/nx);
851 sum1 += 2.0*yj*yj-cos(4.0*PI*yj)+1.0;
855 yj = x[j-1] - sin(6.0*PI*x[0] + j*PI/nx);
859 sum2 += 2.0*yj*yj-cos(4.0*PI*yj)+1.0;
863 f[1] = (1.0 - x[0])*(1.0 - x[0]) + sum2;
866 c[0] = x[1]-sin(6.0*x[0]*PI+2.0*PI/nx) - MYSIGN((x[0]-0.5)*(1.0-x[0]))*sqrt(fabs((x[0]-0.5)*(1.0-x[0])));
867 c[1] = x[3]-sin(6.0*x[0]*PI+4.0*PI/nx) - MYSIGN(0.25*sqrt(1-x[0])-0.5*(1.0-x[0]))*sqrt(fabs(0.25*sqrt(1-x[0])-0.5*(1.0-x[0])));
874 void cec2009::CF8(
const double *x,
double *f,
double *c,
const unsigned int nx)
const
876 unsigned int j, count1, count2, count3;
877 double sum1, sum2, sum3, yj, N, a;
880 sum1 = sum2 = sum3 = 0.0;
881 count1 = count2 = count3 = 0;
882 for(j = 3; j <= nx; j++)
884 yj = x[j-1] - 2.0*x[1]*sin(2.0*PI*x[0]+j*PI/nx);
901 f[0] = cos(0.5*PI*x[0])*cos(0.5*PI*x[1]) + 2.0*sum1 / (double)count1;
902 f[1] = cos(0.5*PI*x[0])*sin(0.5*PI*x[1]) + 2.0*sum2 / (double)count2;
903 f[2] = sin(0.5*PI*x[0]) + 2.0*sum3 / (double)count3;
906 c[0] = (f[0]*f[0]+f[1]*f[1])/(1-f[2]*f[2]) - a*fabs(sin(N*PI*((f[0]*f[0]-f[1]*f[1])/(1-f[2]*f[2])+1.0))) - 1.0;
911 void cec2009::CF9(
const double *x,
double *f,
double *c,
const unsigned int nx)
const
913 unsigned int j, count1, count2, count3;
914 double sum1, sum2, sum3, yj, N, a;
917 sum1 = sum2 = sum3 = 0.0;
918 count1 = count2 = count3 = 0;
919 for(j = 3; j <= nx; j++)
921 yj = x[j-1] - 2.0*x[1]*sin(2.0*PI*x[0]+j*PI/nx);
938 f[0] = cos(0.5*PI*x[0])*cos(0.5*PI*x[1]) + 2.0*sum1 / (double)count1;
939 f[1] = cos(0.5*PI*x[0])*sin(0.5*PI*x[1]) + 2.0*sum2 / (double)count2;
940 f[2] = sin(0.5*PI*x[0]) + 2.0*sum3 / (double)count3;
943 c[0] = (f[0]*f[0]+f[1]*f[1])/(1-f[2]*f[2]) - a*sin(N*PI*((f[0]*f[0]-f[1]*f[1])/(1-f[2]*f[2])+1.0)) - 1.0;
948 void cec2009::CF10(
const double *x,
double *f,
double *c,
const unsigned int nx)
const
950 unsigned int j, count1, count2, count3;
951 double sum1, sum2, sum3, yj, hj, N, a;
954 sum1 = sum2 = sum3 = 0.0;
955 count1 = count2 = count3 = 0;
956 for(j = 3; j <= nx; j++)
958 yj = x[j-1] - 2.0*x[1]*sin(2.0*PI*x[0]+j*PI/nx);
959 hj = 4.0*yj*yj - cos(8.0*PI*yj) + 1.0;
976 f[0] = cos(0.5*PI*x[0])*cos(0.5*PI*x[1]) + 2.0*sum1 / (double)count1;
977 f[1] = cos(0.5*PI*x[0])*sin(0.5*PI*x[1]) + 2.0*sum2 / (double)count2;
978 f[2] = sin(0.5*PI*x[0]) + 2.0*sum3 / (double)count3;
981 c[0] = (f[0]*f[0]+f[1]*f[1])/(1-f[2]*f[2]) - a*sin(N*PI*((f[0]*f[0]-f[1]*f[1])/(1-f[2]*f[2])+1.0)) - 1.0;
boost::shared_ptr< base > base_ptr
Alias for shared pointer to base problem.
std::vector< double > decision_vector
Decision vector type.
size_type get_dimension() const
Return global dimension.
cec2009(unsigned int=1, problem::base::size_type=30, bool=false)
Constructor.
void objfun_impl(fitness_vector &, const decision_vector &) const
Implementation of the objective function.
std::vector< double > fitness_vector
Fitness vector type.
base_ptr clone() const
Clone method.
std::vector< double > constraint_vector
Constraint vector type.
void compute_constraints_impl(constraint_vector &, const decision_vector &) const
Implementation of the constraint computation.
std::string get_name() const
Get problem's name.
void set_bounds(const decision_vector &, const decision_vector &)
Bounds setter from pagmo::decision_vector.
decision_vector::size_type size_type
Problem's size type: the same as pagmo::decision_vector's size type.