PaGMO  1.1.5
cec2009.cpp
1 /*****************************************************************************
2  * Copyright (C) 2004-2015 The PaGMO development team, *
3  * Advanced Concepts Team (ACT), European Space Agency (ESA) *
4  * *
5  * https://github.com/esa/pagmo *
6  * *
7  * act@esa.int *
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  * This program is distributed in the hope that it will be useful, *
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17  * GNU General Public License for more details. *
18  * *
19  * You should have received a copy of the GNU General Public License *
20  * along with this program; if not, write to the *
21  * Free Software Foundation, Inc., *
22  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
23  *****************************************************************************/
24 
25 #include <boost/math/constants/constants.hpp>
26 #include <boost/lexical_cast.hpp>
27 #include <cmath>
28 #include <string>
29 #include <iostream>
30 #include <fstream>
31 #include <vector>
32 #include <iterator>
33 
34 #include "../exceptions.h"
35 #include "../types.h"
36 #include "base.h"
37 #include "cec2009.h"
38 
39 #define MYSIGN(x) ((x)>0?1.0:-1.0)
40 
41 namespace pagmo { namespace problem {
42 
43 static const double PI = boost::math::constants::pi<double>();
44 
46 
58 cec2009::cec2009(unsigned int fun_id, size_type prob_dim, bool is_constrained):
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)
62 {
63  configure_bounds();
64 }
65 
68 {
69  return base_ptr(new cec2009(*this));
70 }
71 
72 std::string cec2009::get_name() const
73 {
74  std::string retval("CEC2009 - ");
75  if(!m_is_constrained){
76  retval.append("UF");
77  }
78  else{
79  retval.append("CF");
80  }
81  retval.append(boost::lexical_cast<std::string>(m_problem_number));
82  return retval;
83 }
84 
86 fitness_vector::size_type cec2009::cec2009_fitness_dimension(int problem_id)
87 {
88  // UF/CF 1-7 2-objective, UF/CF8-10 3-objective
89  if(problem_id >= 1 && problem_id <= 7){
90  return 2;
91  }
92  else if(problem_id >= 8 && problem_id <= 10){
93  return 3;
94  }
95  else{
96  pagmo_throw(value_error, "Error: CEC2009 unexpected problem id when determining fitness dimension.");
97  }
98 }
99 
101 constraint_vector::size_type cec2009::cec2009_ic_dimension(int problem_id)
102 {
103  // Note: Only come here if you are CF!
104  // Only CF6 & CF7 have two inequality constraints, the rest has 1.
105  // All the problems have no equality constraints.
106  if(problem_id == 6 || problem_id == 7){
107  return 2;
108  }
109  else if(problem_id >= 1 && problem_id <= 10){
110  return 1;
111  }
112  else{
113  pagmo_throw(value_error, "Error: CEC2009 unexpected problem id when determining inequality constraints\' dimension.");
114  }
115 }
116 
118 void cec2009::configure_bounds(){
119 
120  size_type nx = get_dimension();
121  std::vector<double> lb(nx, 0), ub(nx, 0);
122 
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){
125  // [0,1] x [-1,1]^{n-1}
126  lb[0] = 0.0;
127  ub[0] = 1.0;
128  for(unsigned int i = 1; i < nx; i++){
129  lb[i] = -1.0;
130  ub[i] = 1.0;
131  }
132  }
133  else if(m_problem_number == 3){
134  // [0,1]^{n}
135  for(unsigned int i = 0; i < nx; i++){
136  lb[i] = 0.0;
137  ub[i] = 1.0;
138  }
139  }
140  else if(m_problem_number == 4){
141  // [0,1] x [-2,2]^{n-1}
142  lb[0] = 0.0;
143  ub[0] = 1.0;
144  for(unsigned int i = 1; i < nx; i++){
145  lb[i] = -2.0;
146  ub[i] = 2.0;
147  }
148  }
149  else if(m_problem_number == 8 || m_problem_number == 9 || m_problem_number == 10){
150  // [0,1]^{2} x [-2,2]^{n-2}
151  lb[0] = 0.0;
152  ub[0] = 1.0;
153  lb[1] = 0.0;
154  ub[1] = 1.0;
155  for(unsigned int i = 2; i < nx; i++){
156  lb[i] = -2.0;
157  ub[i] = 2.0;
158  }
159  }
160  else{
161  pagmo_throw(value_error, "Error: CEC2009 unexpected problem id when setting bounds.");
162  }
163  }
164  else{ // For CF
165  if(m_problem_number == 2){
166  // [0,1] x [-1,1]^{n-1}
167  lb[0] = 0.0;
168  ub[0] = 1.0;
169  for(unsigned int i = 1; i < nx; i++){
170  lb[i] = -1.0;
171  ub[i] = 1.0;
172  }
173  }
174  else if(m_problem_number == 1){
175  // [0,1]^{n}
176  for(unsigned int i = 0; i < nx; i++){
177  lb[i] = 0.0;
178  ub[i] = 1.0;
179  }
180  }
181  else if(m_problem_number == 3 || m_problem_number == 4 || m_problem_number == 5 || m_problem_number == 6 || m_problem_number == 7){
182  // [0,1] x [-2,2]^{n-1}
183  lb[0] = 0.0;
184  ub[0] = 1.0;
185  for(unsigned int i = 1; i < nx; i++){
186  lb[i] = -2.0;
187  ub[i] = 2.0;
188  }
189  }
190  else if(m_problem_number == 8){
191  // [0,1]^{2} x [-4,4]^{n-2}
192  lb[0] = 0.0;
193  ub[0] = 1.0;
194  lb[1] = 0.0;
195  ub[1] = 1.0;
196  for(unsigned int i = 2; i < nx; i++){
197  lb[i] = -4.0;
198  ub[i] = 4.0;
199  }
200  }
201  else if(m_problem_number == 9 || m_problem_number == 10){
202  // [0,1]^{2} x [-2,2]^{n-2}
203  lb[0] = 0.0;
204  ub[0] = 1.0;
205  lb[1] = 0.0;
206  ub[1] = 1.0;
207  for(unsigned int i = 2; i < nx; i++){
208  lb[i] = -2.0;
209  ub[i] = 2.0;
210  }
211  }
212  else{
213  pagmo_throw(value_error, "Error: CEC2009 unexpected problem id when setting bounds.");
214  }
215  }
216  set_bounds(lb, ub);
217 }
218 
221 {
222  size_type nx = get_dimension();
223  if(!m_is_constrained){
224  switch(m_problem_number)
225  {
226  case 1:
227  UF1(&x[0], &f[0], nx);
228  break;
229  case 2:
230  UF2(&x[0], &f[0], nx);
231  break;
232  case 3:
233  UF3(&x[0], &f[0], nx);
234  break;
235  case 4:
236  UF4(&x[0], &f[0], nx);
237  break;
238  case 5:
239  UF5(&x[0], &f[0], nx);
240  break;
241  case 6:
242  UF6(&x[0], &f[0], nx);
243  break;
244  case 7:
245  UF7(&x[0], &f[0], nx);
246  break;
247  case 8:
248  UF8(&x[0], &f[0], nx);
249  break;
250  case 9:
251  UF9(&x[0], &f[0], nx);
252  break;
253  case 10:
254  UF10(&x[0], &f[0], nx);
255  break;
256  default:
257  pagmo_throw(value_error, "Error: CEC2009 unexpected problem id when computing fitness values.");
258  }
259  }
260  else{
261  switch(m_problem_number)
262  {
263  // NULL means do not compute the constraint values.
264  case 1:
265  CF1(&x[0], &f[0], NULL, nx);
266  break;
267  case 2:
268  CF2(&x[0], &f[0], NULL, nx);
269  break;
270  case 3:
271  CF3(&x[0], &f[0], NULL, nx);
272  break;
273  case 4:
274  CF4(&x[0], &f[0], NULL, nx);
275  break;
276  case 5:
277  CF5(&x[0], &f[0], NULL, nx);
278  break;
279  case 6:
280  CF6(&x[0], &f[0], NULL, nx);
281  break;
282  case 7:
283  CF7(&x[0], &f[0], NULL, nx);
284  break;
285  case 8:
286  CF8(&x[0], &f[0], NULL, nx);
287  break;
288  case 9:
289  CF9(&x[0], &f[0], NULL, nx);
290  break;
291  case 10:
292  CF10(&x[0], &f[0], NULL, nx);
293  break;
294  default:
295  pagmo_throw(value_error, "Error: CEC2009 unexpected problem id when computing fitness values.");
296  }
297  }
298 }
299 
302 {
303  size_type nx = get_dimension();
304  if(!m_is_constrained){
305  // TODO: Now just ignore; need to force c to zeros or throw?
306  return;
307  }
308  // Allocation of f is done here as constraints computation requires the values of the objectives...
309  // But here the process is forced to be de-coupled, hence recomputation of f is required.
310  decision_vector f(nx);
311  switch(m_problem_number)
312  {
313  case 1:
314  CF1(&x[0], &f[0], &c[0], nx);
315  break;
316  case 2:
317  CF2(&x[0], &f[0], &c[0], nx);
318  break;
319  case 3:
320  CF3(&x[0], &f[0], &c[0], nx);
321  break;
322  case 4:
323  CF4(&x[0], &f[0], &c[0], nx);
324  break;
325  case 5:
326  CF5(&x[0], &f[0], &c[0], nx);
327  break;
328  case 6:
329  CF6(&x[0], &f[0], &c[0], nx);
330  break;
331  case 7:
332  CF7(&x[0], &f[0], &c[0], nx);
333  break;
334  case 8:
335  CF8(&x[0], &f[0], &c[0], nx);
336  break;
337  case 9:
338  CF9(&x[0], &f[0], &c[0], nx);
339  break;
340  case 10:
341  CF10(&x[0], &f[0], &c[0], nx);
342  break;
343  default:
344  pagmo_throw(value_error, "Error: CEC2009 unexpected problem id when computing constraint values.");
345  }
346 }
347 
348 // Below is slightly adapted from the problem code provided by the CEC2009
349 // competition organizing committee, e.g. changing the format of the
350 // constraint to g(x) <= 0.
351 
352 /****************************************************************************/
353 // unconstraint test instances
354 /****************************************************************************/
355 void cec2009::UF1(const double *x, double *f, const unsigned int nx) const
356 {
357  unsigned int j, count1, count2;
358  double sum1, sum2, yj;
359 
360  sum1 = sum2 = 0.0;
361  count1 = count2 = 0;
362  for(j = 2; j <= nx; j++)
363  {
364  yj = x[j-1] - sin(6.0*PI*x[0] + j*PI/nx);
365  yj = yj * yj;
366  if(j % 2 == 0)
367  {
368  sum2 += yj;
369  count2++;
370  }
371  else
372  {
373  sum1 += yj;
374  count1++;
375  }
376  }
377  f[0] = x[0] + 2.0 * sum1 / (double)count1;
378  f[1] = 1.0 - sqrt(x[0]) + 2.0 * sum2 / (double)count2;
379 }
380 
381 void cec2009::UF2(const double *x, double *f, const unsigned int nx) const
382 {
383  unsigned int j, count1, count2;
384  double sum1, sum2, yj;
385 
386  sum1 = sum2 = 0.0;
387  count1 = count2 = 0;
388  for(j = 2; j <= nx; j++)
389  {
390  if(j % 2 == 0) {
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);
392  sum2 += yj*yj;
393  count2++;
394  }
395  else
396  {
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);
398  sum1 += yj*yj;
399  count1++;
400  }
401  }
402  f[0] = x[0] + 2.0 * sum1 / (double)count1;
403  f[1] = 1.0 - sqrt(x[0]) + 2.0 * sum2 / (double)count2;
404 }
405 
406 void cec2009::UF3(const double *x, double *f, const unsigned int nx) const
407 {
408  unsigned int j, count1, count2;
409  double sum1, sum2, prod1, prod2, yj, pj;
410 
411  sum1 = sum2 = 0.0;
412  count1 = count2 = 0;
413  prod1 = prod2 = 1.0;
414  for(j = 2; j <= nx; j++)
415  {
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));
418  if (j % 2 == 0)
419  {
420  sum2 += yj*yj;
421  prod2 *= pj;
422  count2++;
423  }
424  else
425  {
426  sum1 += yj*yj;
427  prod1 *= pj;
428  count1++;
429  }
430  }
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;
432 }
433 
434 void cec2009::UF4(const double *x, double *f, const unsigned int nx) const
435 {
436  unsigned int j, count1, count2;
437  double sum1, sum2, yj, hj;
438 
439  sum1 = sum2 = 0.0;
440  count1 = count2 = 0;
441  for(j = 2; j <= nx; j++)
442  {
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)));
445  if (j % 2 == 0)
446  {
447  sum2 += hj;
448  count2++;
449  }
450  else
451  {
452  sum1 += hj;
453  count1++;
454  }
455  }
456  f[0] = x[0] + 2.0*sum1 / (double)count1;
457  f[1] = 1.0 - x[0]*x[0] + 2.0*sum2 / (double)count2;
458 }
459 
460 void cec2009::UF5(const double *x, double *f, const unsigned int nx) const
461 {
462  unsigned int j, count1, count2;
463  double sum1, sum2, yj, hj, N, E;
464 
465  sum1 = sum2 = 0.0;
466  count1 = count2 = 0;
467  N = 10.0; E = 0.1;
468  for(j = 2; j <= nx; j++)
469  {
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;
472  if (j % 2 == 0)
473  {
474  sum2 += hj;
475  count2++;
476  }
477  else
478  {
479  sum1 += hj;
480  count1++;
481  }
482  }
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;
486 }
487 
488 void cec2009::UF6(const double *x, double *f, const unsigned int nx) const
489 {
490  unsigned int j, count1, count2;
491  double sum1, sum2, prod1, prod2, yj, hj, pj, N, E;
492  N = 2.0; E = 0.1;
493 
494  sum1 = sum2 = 0.0;
495  count1 = count2 = 0;
496  prod1 = prod2 = 1.0;
497  for(j = 2; j <= nx; j++)
498  {
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));
501  if (j % 2 == 0)
502  {
503  sum2 += yj*yj;
504  prod2 *= pj;
505  count2++;
506  }
507  else
508  {
509  sum1 += yj*yj;
510  prod1 *= pj;
511  count1++;
512  }
513  }
514 
515  hj = 2.0*(0.5/N + E)*sin(2.0*N*PI*x[0]);
516  if(hj<0.0) hj = 0.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;
519 }
520 
521 void cec2009::UF7(const double *x, double *f, const unsigned int nx) const
522 {
523  unsigned int j, count1, count2;
524  double sum1, sum2, yj;
525 
526  sum1 = sum2 = 0.0;
527  count1 = count2 = 0;
528  for(j = 2; j <= nx; j++)
529  {
530  yj = x[j-1] - sin(6.0*PI*x[0]+j*PI/nx);
531  if (j % 2 == 0)
532  {
533  sum2 += yj*yj;
534  count2++;
535  }
536  else
537  {
538  sum1 += yj*yj;
539  count1++;
540  }
541  }
542  yj = pow(x[0],0.2);
543  f[0] = yj + 2.0*sum1 / (double)count1;
544  f[1] = 1.0 - yj + 2.0*sum2 / (double)count2;
545 }
546 
547 void cec2009::UF8(const double *x, double *f, const unsigned int nx) const
548 {
549  unsigned int j, count1, count2, count3;
550  double sum1, sum2, sum3, yj;
551 
552  sum1 = sum2 = sum3 = 0.0;
553  count1 = count2 = count3 = 0;
554  for(j = 3; j <= nx; j++)
555  {
556  yj = x[j-1] - 2.0*x[1]*sin(2.0*PI*x[0]+j*PI/nx);
557  if(j % 3 == 1)
558  {
559  sum1 += yj*yj;
560  count1++;
561  }
562  else if(j % 3 == 2)
563  {
564  sum2 += yj*yj;
565  count2++;
566  }
567  else
568  {
569  sum3 += yj*yj;
570  count3++;
571  }
572  }
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;
576 }
577 
578 void cec2009::UF9(const double *x, double *f, const unsigned int nx) const
579 {
580  unsigned int j, count1, count2, count3;
581  double sum1, sum2, sum3, yj, E;
582 
583  E = 0.1;
584  sum1 = sum2 = sum3 = 0.0;
585  count1 = count2 = count3 = 0;
586  for(j = 3; j <= nx; j++)
587  {
588  yj = x[j-1] - 2.0*x[1]*sin(2.0*PI*x[0]+j*PI/nx);
589  if(j % 3 == 1)
590  {
591  sum1 += yj*yj;
592  count1++;
593  }
594  else if(j % 3 == 2)
595  {
596  sum2 += yj*yj;
597  count2++;
598  }
599  else
600  {
601  sum3 += yj*yj;
602  count3++;
603  }
604  }
605  yj = (1.0+E)*(1.0-4.0*(2.0*x[0]-1.0)*(2.0*x[0]-1.0));
606  if(yj<0.0) yj = 0.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;
610 }
611 
612 void cec2009::UF10(const double *x, double *f, const unsigned int nx) const
613 {
614  unsigned int j, count1, count2, count3;
615  double sum1, sum2, sum3, yj, hj;
616 
617  sum1 = sum2 = sum3 = 0.0;
618  count1 = count2 = count3 = 0;
619  for(j = 3; j <= nx; j++)
620  {
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;
623  if(j % 3 == 1)
624  {
625  sum1 += hj;
626  count1++;
627  }
628  else if(j % 3 == 2)
629  {
630  sum2 += hj;
631  count2++;
632  }
633  else
634  {
635  sum3 += hj;
636  count3++;
637  }
638  }
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;
642 }
643 
644 /****************************************************************************/
645 // constraint test instances
646 /****************************************************************************/
647 void cec2009::CF1(const double *x, double *f, double *c, const unsigned int nx) const
648 {
649  unsigned int j, count1, count2;
650  double sum1, sum2, yj, N, a;
651  N = 10.0; a = 1.0;
652 
653  sum1 = sum2 = 0.0;
654  count1 = count2 = 0;
655  for(j = 2; j <= nx; j++)
656  {
657  yj = x[j-1]-pow(x[0],0.5*(1.0+3.0*(j-2.0)/(nx-2.0)));
658  if (j % 2 == 1)
659  {
660  sum1 += yj*yj;
661  count1++;
662  }
663  else
664  {
665  sum2 += yj*yj;
666  count2++;
667  }
668  }
669  f[0] = x[0] + 2.0*sum1 / (double)count1;
670  f[1] = 1.0 - x[0] + 2.0*sum2 / (double)count2;
671 
672  if(c != NULL){
673  c[0] = f[1] + f[0] - a*fabs(sin(N*PI*(f[0]-f[1]+1.0))) - 1.0;
674  c[0] = -c[0]; //convert to g(x) <= 0 form
675  }
676 }
677 
678 void cec2009::CF2(const double *x, double *f, double *c, const unsigned int nx) const
679 {
680  unsigned int j, count1, count2;
681  double sum1, sum2, yj, N, a, t;
682  N = 2.0; a = 1.0;
683 
684  sum1 = sum2 = 0.0;
685  count1 = count2 = 0;
686  for(j = 2; j <= nx; j++)
687  {
688  if (j % 2 == 1)
689  {
690  yj = x[j-1] - sin(6.0*PI*x[0] + j*PI/nx);
691  sum1 += yj*yj;
692  count1++;
693  }
694  else
695  {
696  yj = x[j-1] - cos(6.0*PI*x[0] + j*PI/nx);
697  sum2 += yj*yj;
698  count2++;
699  }
700  }
701  f[0] = x[0] + 2.0*sum1 / (double)count1;
702  f[1] = 1.0 - sqrt(x[0]) + 2.0*sum2 / (double)count2;
703 
704  if(c != NULL){
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)));
707  c[0] = -c[0]; //convert to g(x) <= 0 form
708  }
709 }
710 
711 void cec2009::CF3(const double *x, double *f, double *c, const unsigned int nx) const
712 {
713  unsigned int j, count1, count2;
714  double sum1, sum2, prod1, prod2, yj, pj, N, a;
715  N = 2.0; a = 1.0;
716 
717  sum1 = sum2 = 0.0;
718  count1 = count2 = 0;
719  prod1 = prod2 = 1.0;
720  for(j = 2; j <= nx; j++)
721  {
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));
724  if (j % 2 == 0)
725  {
726  sum2 += yj*yj;
727  prod2 *= pj;
728  count2++;
729  }
730  else
731  {
732  sum1 += yj*yj;
733  prod1 *= pj;
734  count1++;
735  }
736  }
737 
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;
740 
741  if(c != NULL){
742  c[0] = f[1] + f[0]*f[0] - a*sin(N*PI*(f[0]*f[0]-f[1]+1.0)) - 1.0;
743  c[0] = -c[0]; //convert to g(x) <= 0 form
744  }
745 }
746 
747 void cec2009::CF4(const double *x, double *f, double *c, const unsigned int nx) const
748 {
749  unsigned int j;
750  double sum1, sum2, yj, t;
751 
752  sum1 = sum2 = 0.0;
753  for(j = 2; j <= nx; j++)
754  {
755  yj = x[j-1] - sin(6.0*PI*x[0] + j*PI/nx);
756  if (j % 2 == 1)
757  {
758  sum1 += yj*yj;
759  }
760  else
761  {
762  if (j==2)
763  sum2 += yj < 1.5-0.75*sqrt(2.0) ? fabs(yj) : (0.125+(yj-1)*(yj-1));
764  else
765  sum2 += yj*yj;
766  }
767  }
768  f[0] = x[0] + sum1;
769  f[1] = 1.0 - x[0] + sum2;
770 
771  if(c != NULL){
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)));
774  c[0] = -c[0]; //convert to g(x) <= 0 form
775  }
776 }
777 
778 void cec2009::CF5(const double *x, double *f, double *c, const unsigned int nx) const
779 {
780  unsigned int j;
781  double sum1, sum2, yj;
782 
783  sum1 = sum2 = 0.0;
784  for(j = 2; j <= nx; j++)
785  {
786  if (j % 2 == 1)
787  {
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;
790  }
791  else
792  {
793  yj = x[j-1] - 0.8*x[0]*sin(6.0*PI*x[0] + j*PI/nx);
794  if (j==2)
795  sum2 += yj < 1.5-0.75*sqrt(2.0) ? fabs(yj) : (0.125+(yj-1)*(yj-1));
796  else
797  sum2 += 2.0*yj*yj - cos(4.0*PI*yj) + 1.0;
798  }
799  }
800  f[0] = x[0] + sum1;
801  f[1] = 1.0 - x[0] + sum2;
802 
803  if(c != NULL){
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;
805  c[0] = -c[0]; //convert to g(x) <= 0 form
806  }
807 }
808 
809 void cec2009::CF6(const double *x, double *f, double *c, const unsigned int nx) const
810 {
811  unsigned int j;
812  double sum1, sum2, yj;
813 
814  sum1 = sum2 = 0.0;
815  for(j = 2; j <= nx; j++)
816  {
817  if (j % 2 == 1)
818  {
819  yj = x[j-1] - 0.8*x[0]*cos(6.0*PI*x[0] + j*PI/nx);
820  sum1 += yj*yj;
821  }
822  else
823  {
824  yj = x[j-1] - 0.8*x[0]*sin(6.0*PI*x[0] + j*PI/nx);
825  sum2 += yj*yj;
826  }
827  }
828  f[0] = x[0] + sum1;
829  f[1] = (1.0 - x[0])*(1.0 - x[0]) + sum2;
830 
831  if(c != NULL){
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])));
834  //convert to g(x) <= 0 form
835  c[0] = -c[0];
836  c[1] = -c[1];
837  }
838 }
839 
840 void cec2009::CF7(const double *x, double *f, double *c, const unsigned int nx) const
841 {
842  unsigned int j;
843  double sum1, sum2, yj;
844 
845  sum1 = sum2 = 0.0;
846  for(j = 2; j <= nx; j++)
847  {
848  if (j % 2 == 1)
849  {
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;
852  }
853  else
854  {
855  yj = x[j-1] - sin(6.0*PI*x[0] + j*PI/nx);
856  if (j==2 || j==4)
857  sum2 += yj*yj;
858  else
859  sum2 += 2.0*yj*yj-cos(4.0*PI*yj)+1.0;
860  }
861  }
862  f[0] = x[0] + sum1;
863  f[1] = (1.0 - x[0])*(1.0 - x[0]) + sum2;
864 
865  if(c != NULL){
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])));
868  //convert to g(x) <= 0 form
869  c[0] = -c[0];
870  c[1] = -c[1];
871  }
872 }
873 
874 void cec2009::CF8(const double *x, double *f, double *c, const unsigned int nx) const
875 {
876  unsigned int j, count1, count2, count3;
877  double sum1, sum2, sum3, yj, N, a;
878  N = 2.0; a = 4.0;
879 
880  sum1 = sum2 = sum3 = 0.0;
881  count1 = count2 = count3 = 0;
882  for(j = 3; j <= nx; j++)
883  {
884  yj = x[j-1] - 2.0*x[1]*sin(2.0*PI*x[0]+j*PI/nx);
885  if(j % 3 == 1)
886  {
887  sum1 += yj*yj;
888  count1++;
889  }
890  else if(j % 3 == 2)
891  {
892  sum2 += yj*yj;
893  count2++;
894  }
895  else
896  {
897  sum3 += yj*yj;
898  count3++;
899  }
900  }
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;
904 
905  if(c != NULL){
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;
907  c[0] = -c[0]; //convert to g(x) <= 0 form
908  }
909 }
910 
911 void cec2009::CF9(const double *x, double *f, double *c, const unsigned int nx) const
912 {
913  unsigned int j, count1, count2, count3;
914  double sum1, sum2, sum3, yj, N, a;
915  N = 2.0; a = 3.0;
916 
917  sum1 = sum2 = sum3 = 0.0;
918  count1 = count2 = count3 = 0;
919  for(j = 3; j <= nx; j++)
920  {
921  yj = x[j-1] - 2.0*x[1]*sin(2.0*PI*x[0]+j*PI/nx);
922  if(j % 3 == 1)
923  {
924  sum1 += yj*yj;
925  count1++;
926  }
927  else if(j % 3 == 2)
928  {
929  sum2 += yj*yj;
930  count2++;
931  }
932  else
933  {
934  sum3 += yj*yj;
935  count3++;
936  }
937  }
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;
941 
942  if(c != NULL){
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;
944  c[0] = -c[0]; //convert to g(x) <= 0 form
945  }
946 }
947 
948 void cec2009::CF10(const double *x, double *f, double *c, const unsigned int nx) const
949 {
950  unsigned int j, count1, count2, count3;
951  double sum1, sum2, sum3, yj, hj, N, a;
952  N = 2.0; a = 1.0;
953 
954  sum1 = sum2 = sum3 = 0.0;
955  count1 = count2 = count3 = 0;
956  for(j = 3; j <= nx; j++)
957  {
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;
960  if(j % 3 == 1)
961  {
962  sum1 += hj;
963  count1++;
964  }
965  else if(j % 3 == 2)
966  {
967  sum2 += hj;
968  count2++;
969  }
970  else
971  {
972  sum3 += hj;
973  count3++;
974  }
975  }
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;
979 
980  if(c != NULL){
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;
982  c[0] = -c[0]; //convert to g(x) <= 0 form
983  }
984 }
985 
986 }} //namespaces
987 
988 #undef MYSIGN
989 
990 BOOST_CLASS_EXPORT_IMPLEMENT(pagmo::problem::cec2009)
Root PaGMO namespace.
boost::shared_ptr< base > base_ptr
Alias for shared pointer to base problem.
Definition: problem/base.h:62
std::vector< double > decision_vector
Decision vector type.
Definition: types.h:40
Base problem class.
Definition: problem/base.h:148
size_type get_dimension() const
Return global dimension.
cec2009(unsigned int=1, problem::base::size_type=30, bool=false)
Constructor.
Definition: cec2009.cpp:58
void objfun_impl(fitness_vector &, const decision_vector &) const
Implementation of the objective function.
Definition: cec2009.cpp:220
std::vector< double > fitness_vector
Fitness vector type.
Definition: types.h:42
base_ptr clone() const
Clone method.
Definition: cec2009.cpp:67
std::vector< double > constraint_vector
Constraint vector type.
Definition: types.h:44
void compute_constraints_impl(constraint_vector &, const decision_vector &) const
Implementation of the constraint computation.
Definition: cec2009.cpp:301
std::string get_name() const
Get problem's name.
Definition: cec2009.cpp:72
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.
Definition: problem/base.h:160