PaGMO  1.1.5
cec2013.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 
35 #include "../exceptions.h"
36 #include "../types.h"
37 #include "cec2013.h"
38 
39 #define INF 1.0e99
40 #define EPS 1.0e-14
41 #define E 2.7182818284590452353602874713526625
42 
43 namespace pagmo { namespace problem {
44 
46 
58 cec2013::cec2013(unsigned int fun_id, problem::base::size_type d, const std::string& dir):base(d),m_problem_number(fun_id), m_y(d), m_z(d)
59 {
60  if (!(d==2||d==5||d==10||d==20||d==30||d==40||d==50||d==60||d==70||d==80||d==90||d==100))
61  {
62  pagmo_throw(value_error, "Error: CEC2013 Test functions are only defined for dimensions 2,5,10,20,30,40,50,60,70,80,90,100.");
63  }
64 
65  // We create the full file name for the rotation matrix
66  std::string data_file_name(dir);
67  data_file_name.append("M_D");
68  data_file_name.append(boost::lexical_cast<std::string>(d));
69  data_file_name.append(".txt");
70  // And we read all datas into m_rotation_matrix
71  {
72  std::ifstream data_file(data_file_name.c_str());
73  if (!data_file.is_open()) {
74  pagmo_throw(io_error, std::string("Error: file not found. I was looking for (") + data_file_name.c_str() + ")");
75  }
76  std::istream_iterator<double> start(data_file), end;
77  m_rotation_matrix = std::vector<double>(start,end);
78  data_file.close();
79  }
80 
81  // We create the full file name for the shift vector
82  data_file_name = dir;
83  data_file_name.append("shift_data.txt");
84  // And we read all data into m_origin_shift
85  {
86  std::ifstream data_file(data_file_name.c_str());
87  if (!data_file.is_open()) {
88  pagmo_throw(io_error, std::string("Error: file not found. I was looking for ").append(data_file_name.c_str()));
89  }
90  std::istream_iterator<double> start(data_file), end;
91  m_origin_shift = std::vector<double>(start,end);
92  data_file.close();
93  }
94  // Set bounds. All CEC2013 problems have the same bounds
95  set_bounds(-100,100);
96 }
97 
100 {
101  return base_ptr(new cec2013(*this));
102 }
103 
106 {
107  size_type nx = get_dimension();
108  switch(m_problem_number)
109  {
110  case 1:
111  sphere_func(&x[0],&f[0],nx,&m_origin_shift[0],&m_rotation_matrix[0],0);
112  f[0]+=-1400.0;
113  break;
114  case 2:
115  ellips_func(&x[0],&f[0],nx,&m_origin_shift[0],&m_rotation_matrix[0],1);
116  f[0]+=-1300.0;
117  break;
118  case 3:
119  bent_cigar_func(&x[0],&f[0],nx,&m_origin_shift[0],&m_rotation_matrix[0],1);
120  f[0]+=-1200.0;
121  break;
122  case 4:
123  discus_func(&x[0],&f[0],nx,&m_origin_shift[0],&m_rotation_matrix[0],1);
124  f[0]+=-1100.0;
125  break;
126  case 5:
127  dif_powers_func(&x[0],&f[0],nx,&m_origin_shift[0],&m_rotation_matrix[0],0);
128  f[0]+=-1000.0;
129  break;
130  case 6:
131  rosenbrock_func(&x[0],&f[0],nx,&m_origin_shift[0],&m_rotation_matrix[0],1);
132  f[0]+=-900.0;
133  break;
134  case 7:
135  schaffer_F7_func(&x[0],&f[0],nx,&m_origin_shift[0],&m_rotation_matrix[0],1);
136  f[0]+=-800.0;
137  break;
138  case 8:
139  ackley_func(&x[0],&f[0],nx,&m_origin_shift[0],&m_rotation_matrix[0],1);
140  f[0]+=-700.0;
141  break;
142  case 9:
143  weierstrass_func(&x[0],&f[0],nx,&m_origin_shift[0],&m_rotation_matrix[0],1);
144  f[0]+=-600.0;
145  break;
146  case 10:
147  griewank_func(&x[0],&f[0],nx,&m_origin_shift[0],&m_rotation_matrix[0],1);
148  f[0]+=-500.0;
149  break;
150  case 11:
151  rastrigin_func(&x[0],&f[0],nx,&m_origin_shift[0],&m_rotation_matrix[0],0);
152  f[0]+=-400.0;
153  break;
154  case 12:
155  rastrigin_func(&x[0],&f[0],nx,&m_origin_shift[0],&m_rotation_matrix[0],1);
156  f[0]+=-300.0;
157  break;
158  case 13:
159  step_rastrigin_func(&x[0],&f[0],nx,&m_origin_shift[0],&m_rotation_matrix[0],1);
160  f[0]+=-200.0;
161  break;
162  case 14:
163  schwefel_func(&x[0],&f[0],nx,&m_origin_shift[0],&m_rotation_matrix[0],0);
164  f[0]+=-100.0;
165  break;
166  case 15:
167  schwefel_func(&x[0],&f[0],nx,&m_origin_shift[0],&m_rotation_matrix[0],1);
168  f[0]+=100.0;
169  break;
170  case 16:
171  katsuura_func(&x[0],&f[0],nx,&m_origin_shift[0],&m_rotation_matrix[0],1);
172  f[0]+=200.0;
173  break;
174  case 17:
175  bi_rastrigin_func(&x[0],&f[0],nx,&m_origin_shift[0],&m_rotation_matrix[0],0);
176  f[0]+=300.0;
177  break;
178  case 18:
179  bi_rastrigin_func(&x[0],&f[0],nx,&m_origin_shift[0],&m_rotation_matrix[0],1);
180  f[0]+=400.0;
181  break;
182  case 19:
183  grie_rosen_func(&x[0],&f[0],nx,&m_origin_shift[0],&m_rotation_matrix[0],1);
184  f[0]+=500.0;
185  break;
186  case 20:
187  escaffer6_func(&x[0],&f[0],nx,&m_origin_shift[0],&m_rotation_matrix[0],1);
188  f[0]+=600.0;
189  break;
190  case 21:
191  cf01(&x[0],&f[0],nx,&m_origin_shift[0],&m_rotation_matrix[0],1);
192  f[0]+=700.0;
193  break;
194  case 22:
195  cf02(&x[0],&f[0],nx,&m_origin_shift[0],&m_rotation_matrix[0],0);
196  f[0]+=800.0;
197  break;
198  case 23:
199  cf03(&x[0],&f[0],nx,&m_origin_shift[0],&m_rotation_matrix[0],1);
200  f[0]+=900.0;
201  break;
202  case 24:
203  cf04(&x[0],&f[0],nx,&m_origin_shift[0],&m_rotation_matrix[0],1);
204  f[0]+=1000.0;
205  break;
206  case 25:
207  cf05(&x[0],&f[0],nx,&m_origin_shift[0],&m_rotation_matrix[0],1);
208  f[0]+=1100.0;
209  break;
210  case 26:
211  cf06(&x[0],&f[0],nx,&m_origin_shift[0],&m_rotation_matrix[0],1);
212  f[0]+=1200.0;
213  break;
214  case 27:
215  cf07(&x[0],&f[0],nx,&m_origin_shift[0],&m_rotation_matrix[0],1);
216  f[0]+=1300.0;
217  break;
218  case 28:
219  cf08(&x[0],&f[0],nx,&m_origin_shift[0],&m_rotation_matrix[0],1);
220  f[0]+=1400.0;
221  break;
222  default:
223  pagmo_throw(value_error, "Error: There are only 28 test functions in this test suite!");
224  break;
225  }
226 
227 }
228 
229 std::string cec2013::get_name() const
230 {
231  std::string retval("CEC2013 - f");
232  retval.append(boost::lexical_cast<std::string>(m_problem_number));
233  switch(m_problem_number)
234  {
235  case 1:
236  retval.append("(sphere_func)");
237  break;
238  case 2:
239  retval.append("(ellips_func)");
240  break;
241  case 3:
242  retval.append("(bent_cigar_func)");
243  break;
244  case 4:
245  retval.append("(discus_func)");
246  break;
247  case 5:
248  retval.append("(dif_powers_func_non_rotated)");
249  break;
250  case 6:
251  retval.append("(rosenbrock_func)");
252  break;
253  case 7:
254  retval.append("(schaffer_F7_func)");
255  break;
256  case 8:
257  retval.append("(ackley_func)");
258  break;
259  case 9:
260  retval.append("(weierstrass_func)");
261  break;
262  case 10:
263  retval.append("(griewank_func)");
264  break;
265  case 11:
266  retval.append("(rastrigin_func_non_rotated)");
267  break;
268  case 12:
269  retval.append("(rastrigin_func)");
270  break;
271  case 13:
272  retval.append("(step_rastrigin_func)");
273  break;
274  case 14:
275  retval.append("(schwefel_func_non_rotated)");
276  break;
277  case 15:
278  retval.append("(schwefel_func)");
279  break;
280  case 16:
281  retval.append("(katsuura_func)");
282  break;
283  case 17:
284  retval.append("(bi_rastrigin_func_non_rotated)");
285  break;
286  case 18:
287  retval.append("(bi_rastrigin_func)");
288  break;
289  case 19:
290  retval.append("(grie_rosen_func)");
291  break;
292  case 20:
293  retval.append("(escaffer6_func)");
294  break;
295  case 21:
296  retval.append("(cf01)");
297  break;
298  case 22:
299  retval.append("(cf02)");
300  break;
301  case 23:
302  retval.append("(cf03)");
303  break;
304  case 24:
305  retval.append("(cf04)");
306  break;
307  case 25:
308  retval.append("(cf05)");
309  break;
310  case 26:
311  retval.append("(cf06)");
312  break;
313  case 27:
314  retval.append("(cf07)");
315  break;
316  case 28:
317  retval.append("(cf08)");
318  break;
319  default:
320  pagmo_throw(value_error, "Error: There are only 28 test functions in this test suite!");
321  break;
322  }
323  return retval;
324 
325 }
326 
327 void cec2013::sphere_func (const double *x, double *f, int nx, const double *Os,const double *Mr,int r_flag) const /* Sphere */
328 {
329  shiftfunc(x, &m_y[0], nx, Os);
330  if (r_flag==1)
331  rotatefunc(&m_y[0], &m_z[0], nx, Mr);
332  else
333  for (int i=0; i<nx; i++)
334  m_z[i]=m_y[i];
335  f[0] = 0.0;
336  for (int i=0; i<nx; i++)
337  {
338  f[0] += m_z[i]*m_z[i];
339  }
340 }
341 
342 void cec2013::ellips_func (const double *x, double *f, int nx, const double *Os,const double *Mr,int r_flag) const /* Ellipsoidal */
343 {
344  int i;
345  shiftfunc(x, &m_y[0], nx, Os);
346  if (r_flag==1)
347  rotatefunc(&m_y[0], &m_z[0], nx, Mr);
348  else
349  for (i=0; i<nx; i++)
350  m_z[i]=m_y[i];
351  oszfunc (&m_z[0], &m_y[0], nx);
352  f[0] = 0.0;
353  for (i=0; i<nx; i++)
354  {
355  f[0] += pow(10.0,6.0*i/(nx-1))*m_y[i]*m_y[i];
356  }
357 }
358 
359 void cec2013::bent_cigar_func (const double *x, double *f, int nx, const double *Os,const double *Mr,int r_flag) const /* Bent_Cigar */
360 {
361  int i;
362  double beta=0.5;
363  shiftfunc(x, &m_y[0], nx, Os);
364  if (r_flag==1)
365  rotatefunc(&m_y[0], &m_z[0], nx, Mr);
366  else
367  for (i=0; i<nx; i++)
368  m_z[i]=m_y[i];
369  asyfunc (&m_z[0], &m_y[0], nx,beta);
370  if (r_flag==1)
371  rotatefunc(&m_y[0], &m_z[0], nx, &Mr[nx*nx]);
372  else
373  for (i=0; i<nx; i++)
374  m_z[i]=m_y[i];
375 
376  f[0] = m_z[0]*m_z[0];
377  for (i=1; i<nx; i++)
378  {
379  f[0] += pow(10.0,6.0)*m_z[i]*m_z[i];
380  }
381 }
382 
383 void cec2013::discus_func (const double *x, double *f, int nx, const double *Os,const double *Mr,int r_flag) const /* Discus */
384 {
385  int i;
386  shiftfunc(x, &m_y[0], nx, Os);
387  if (r_flag==1)
388  rotatefunc(&m_y[0], &m_z[0], nx, Mr);
389  else
390  for (i=0; i<nx; i++)
391  m_z[i]=m_y[i];
392  oszfunc (&m_z[0], &m_y[0], nx);
393 
394  f[0] = pow(10.0,6.0)*m_y[0]*m_y[0];
395  for (i=1; i<nx; i++)
396  {
397  f[0] += m_y[i]*m_y[i];
398  }
399 }
400 
401 void cec2013::dif_powers_func (const double *x, double *f, int nx, const double *Os,const double *Mr,int r_flag) const /* Different Powers */
402 {
403  int i;
404  shiftfunc(x, &m_y[0], nx, Os);
405  if (r_flag==1)
406  rotatefunc(&m_y[0], &m_z[0], nx, Mr);
407  else
408  for (i=0; i<nx; i++)
409  m_z[i]=m_y[i];
410  f[0] = 0.0;
411  for (i=0; i<nx; i++)
412  {
413  f[0] += pow(fabs(m_z[i]),2+4*i/(nx-1));
414  }
415  f[0]=pow(f[0],0.5);
416 }
417 
418 void cec2013::rosenbrock_func (const double *x, double *f, int nx, const double *Os,const double *Mr,int r_flag) const /* Rosenbrock's */
419 {
420  int i;
421  double tmp1,tmp2;
422  shiftfunc(x, &m_y[0], nx, Os);//shift
423  for (i=0; i<nx; i++)//shrink to the orginal search range
424  {
425  m_y[i]=m_y[i]*2.048/100;
426  }
427  if (r_flag==1)
428  rotatefunc(&m_y[0], &m_z[0], nx, Mr);//rotate
429  else
430  for (i=0; i<nx; i++)
431  m_z[i]=m_y[i];
432  for (i=0; i<nx; i++)//shift to orgin
433  {
434  m_z[i]=m_z[i]+1;
435  }
436 
437  f[0] = 0.0;
438  for (i=0; i<nx-1; i++)
439  {
440  tmp1=m_z[i]*m_z[i]-m_z[i+1];
441  tmp2=m_z[i]-1.0;
442  f[0] += 100.0*tmp1*tmp1 +tmp2*tmp2;
443  }
444 }
445 
446 void cec2013::schaffer_F7_func (const double *x, double *f, int nx, const double *Os,const double *Mr,int r_flag) const /* Schwefel's 1.2 */
447 {
448  int i;
449  double tmp;
450  shiftfunc(x, &m_y[0], nx, Os);
451  if (r_flag==1)
452  rotatefunc(&m_y[0], &m_z[0], nx, Mr);
453  else
454  for (i=0; i<nx; i++)
455  m_z[i]=m_y[i];
456  asyfunc (&m_z[0], &m_y[0], nx, 0.5);
457  for (i=0; i<nx; i++)
458  m_z[i] = m_y[i]*pow(10.0,1.0*i/(nx-1)/2.0);
459  if (r_flag==1)
460  rotatefunc(&m_z[0], &m_y[0], nx, &Mr[nx*nx]);
461  else
462  for (i=0; i<nx; i++)
463  m_y[i]=m_z[i];
464 
465  for (i=0; i<nx-1; i++)
466  m_z[i]=pow(m_y[i]*m_y[i]+m_y[i+1]*m_y[i+1],0.5);
467  f[0] = 0.0;
468  for (i=0; i<nx-1; i++)
469  {
470  tmp=sin(50.0*pow(m_z[i],0.2));
471  f[0] += pow(m_z[i],0.5)+pow(m_z[i],0.5)*tmp*tmp ;
472  }
473  f[0] = f[0]*f[0]/(nx-1)/(nx-1);
474 }
475 
476 void cec2013::ackley_func (const double *x, double *f, int nx, const double *Os,const double *Mr,int r_flag) const /* Ackley's */
477 {
478  int i;
479  double sum1, sum2;
480 
481  shiftfunc(x, &m_y[0], nx, Os);
482  if (r_flag==1)
483  rotatefunc(&m_y[0], &m_z[0], nx, Mr);
484  else
485  for (i=0; i<nx; i++)
486  m_z[i]=m_y[i];
487 
488  asyfunc (&m_z[0], &m_y[0], nx, 0.5);
489  for (i=0; i<nx; i++)
490  m_z[i] = m_y[i]*pow(10.0,1.0*i/(nx-1)/2.0);
491  if (r_flag==1)
492  rotatefunc(&m_z[0], &m_y[0], nx, &Mr[nx*nx]);
493  else
494  for (i=0; i<nx; i++)
495  m_y[i]=m_z[i];
496 
497  sum1 = 0.0;
498  sum2 = 0.0;
499  for (i=0; i<nx; i++)
500  {
501  sum1 += m_y[i]*m_y[i];
502  sum2 += cos(2.0*boost::math::constants::pi<double>()*m_y[i]);
503  }
504  sum1 = -0.2*sqrt(sum1/nx);
505  sum2 /= nx;
506  f[0] = E - 20.0*exp(sum1) - exp(sum2) +20.0;
507 }
508 
509 void cec2013::weierstrass_func (const double *x, double *f, int nx, const double *Os,const double *Mr,int r_flag) const /* Weierstrass's */
510 {
511  int i,j,k_max;
512  double sum=0,sum2=0, a, b;
513 
514  shiftfunc(x, &m_y[0], nx, Os);
515  for (i=0; i<nx; i++)//shrink to the orginal search range
516  {
517  m_y[i]=m_y[i]*0.5/100;
518  }
519  if (r_flag==1)
520  rotatefunc(&m_y[0], &m_z[0], nx, Mr);
521  else
522  for (i=0; i<nx; i++)
523  m_z[i]=m_y[i];
524 
525  asyfunc (&m_z[0], &m_y[0], nx, 0.5);
526  for (i=0; i<nx; i++)
527  m_z[i] = m_y[i]*pow(10.0,1.0*i/(nx-1)/2.0);
528  if (r_flag==1)
529  rotatefunc(&m_z[0], &m_y[0], nx, &Mr[nx*nx]);
530  else
531  for (i=0; i<nx; i++)
532  m_y[i]=m_z[i];
533 
534  a = 0.5;
535  b = 3.0;
536  k_max = 20;
537  f[0] = 0.0;
538  for (i=0; i<nx; i++)
539  {
540  sum = 0.0;
541  sum2 = 0.0;
542  for (j=0; j<=k_max; j++)
543  {
544  sum += pow(a,j)*cos(2.0*boost::math::constants::pi<double>()*pow(b,j)*(m_y[i]+0.5));
545  sum2 += pow(a,j)*cos(2.0*boost::math::constants::pi<double>()*pow(b,j)*0.5);
546  }
547  f[0] += sum;
548  }
549  f[0] -= nx*sum2;
550 }
551 
552 void cec2013::griewank_func (const double *x, double *f, int nx, const double *Os,const double *Mr,int r_flag) const /* Griewank's */
553 {
554  int i;
555  double s, p;
556 
557  shiftfunc(x, &m_y[0], nx, Os);
558  for (i=0; i<nx; i++)//shrink to the orginal search range
559  {
560  m_y[i]=m_y[i]*600.0/100.0;
561  }
562  if (r_flag==1)
563  rotatefunc(&m_y[0], &m_z[0], nx, Mr);
564  else
565  for (i=0; i<nx; i++)
566  m_z[i]=m_y[i];
567 
568  for (i=0; i<nx; i++)
569  m_z[i] = m_z[i]*pow(100.0,1.0*i/(nx-1)/2.0);
570 
571 
572  s = 0.0;
573  p = 1.0;
574  for (i=0; i<nx; i++)
575  {
576  s += m_z[i]*m_z[i];
577  p *= cos(m_z[i]/sqrt(1.0+i));
578  }
579  f[0] = 1.0 + s/4000.0 - p;
580 }
581 
582 void cec2013::rastrigin_func (const double *x, double *f, int nx, const double *Os,const double *Mr,int r_flag) const /* Rastrigin's */
583 {
584  int i;
585  double alpha=10.0,beta=0.2;
586  shiftfunc(x, &m_y[0], nx, Os);
587  for (i=0; i<nx; i++)//shrink to the orginal search range
588  {
589  m_y[i]=m_y[i]*5.12/100;
590  }
591 
592  if (r_flag==1)
593  rotatefunc(&m_y[0], &m_z[0], nx, Mr);
594  else
595  for (i=0; i<nx; i++)
596  m_z[i]=m_y[i];
597 
598  oszfunc (&m_z[0], &m_y[0], nx);
599  asyfunc (&m_y[0], &m_z[0], nx, beta);
600 
601  if (r_flag==1)
602  rotatefunc(&m_z[0], &m_y[0], nx, &Mr[nx*nx]);
603  else
604  for (i=0; i<nx; i++)
605  m_y[i]=m_z[i];
606 
607  for (i=0; i<nx; i++)
608  {
609  m_y[i]*=pow(alpha,1.0*i/(nx-1)/2);
610  }
611 
612  if (r_flag==1)
613  rotatefunc(&m_y[0], &m_z[0], nx, Mr);
614  else
615  for (i=0; i<nx; i++)
616  m_z[i]=m_y[i];
617 
618  f[0] = 0.0;
619  for (i=0; i<nx; i++)
620  {
621  f[0] += (m_z[i]*m_z[i] - 10.0*cos(2.0*boost::math::constants::pi<double>()*m_z[i]) + 10.0);
622  }
623 }
624 
625 void cec2013::step_rastrigin_func (const double *x, double *f, int nx, const double *Os,const double *Mr,int r_flag) const /* Noncontinuous Rastrigin's */
626 {
627  int i;
628  double alpha=10.0,beta=0.2;
629  shiftfunc(x, &m_y[0], nx, Os);
630  for (i=0; i<nx; i++)//shrink to the orginal search range
631  {
632  m_y[i]=m_y[i]*5.12/100;
633  }
634 
635  if (r_flag==1)
636  rotatefunc(&m_y[0], &m_z[0], nx, Mr);
637  else
638  for (i=0; i<nx; i++)
639  m_z[i]=m_y[i];
640 
641  for (i=0; i<nx; i++)
642  {
643  if (fabs(m_z[i])>0.5)
644  m_z[i]=floor(2*m_z[i]+0.5)/2;
645  }
646 
647  oszfunc (&m_z[0], &m_y[0], nx);
648  asyfunc (&m_y[0], &m_z[0], nx, beta);
649 
650  if (r_flag==1)
651  rotatefunc(&m_z[0], &m_y[0], nx, &Mr[nx*nx]);
652  else
653  for (i=0; i<nx; i++)
654  m_y[i]=m_z[i];
655 
656  for (i=0; i<nx; i++)
657  {
658  m_y[i]*=pow(alpha,1.0*i/(nx-1)/2);
659  }
660 
661  if (r_flag==1)
662  rotatefunc(&m_y[0], &m_z[0], nx, Mr);
663  else
664  for (i=0; i<nx; i++)
665  m_z[i]=m_y[i];
666 
667  f[0] = 0.0;
668  for (i=0; i<nx; i++)
669  {
670  f[0] += (m_z[i]*m_z[i] - 10.0*cos(2.0*boost::math::constants::pi<double>()*m_z[i]) + 10.0);
671  }
672 }
673 
674 void cec2013::schwefel_func (const double *x, double *f, int nx, const double *Os,const double *Mr,int r_flag) const /* Schwefel's */
675 {
676  int i;
677  double tmp;
678  shiftfunc(x, &m_y[0], nx, Os);
679  for (i=0; i<nx; i++)//shrink to the orginal search range
680  {
681  m_y[i]*=1000/100;
682  }
683  if (r_flag==1)
684  rotatefunc(&m_y[0], &m_z[0], nx, Mr);
685  else
686  for (i=0; i<nx; i++)
687  m_z[i]=m_y[i];
688 
689  for (i=0; i<nx; i++)
690  m_y[i] = m_z[i]*pow(10.0,1.0*i/(nx-1)/2.0);
691 
692  for (i=0; i<nx; i++)
693  m_z[i] = m_y[i]+4.209687462275036e+002;
694 
695  f[0]=0;
696  for (i=0; i<nx; i++)
697  {
698  if (m_z[i]>500)
699  {
700  f[0]-=(500.0-fmod(m_z[i],500))*sin(pow(500.0-fmod(m_z[i],500),0.5));
701  tmp=(m_z[i]-500.0)/100;
702  f[0]+= tmp*tmp/nx;
703  }
704  else if (m_z[i]<-500)
705  {
706  f[0]-=(-500.0+fmod(fabs(m_z[i]),500))*sin(pow(500.0-fmod(fabs(m_z[i]),500),0.5));
707  tmp=(m_z[i]+500.0)/100;
708  f[0]+= tmp*tmp/nx;
709  }
710  else
711  f[0]-=m_z[i]*sin(pow(fabs(m_z[i]),0.5));
712  }
713  f[0]=4.189828872724338e+002*nx+f[0];
714 }
715 
716 void cec2013::katsuura_func (const double *x, double *f, int nx, const double *Os,const double *Mr,int r_flag) const /* Katsuura */
717 {
718  int i,j;
719  double temp,tmp1,tmp2,tmp3;
720  tmp3=pow(1.0*nx,1.2);
721  shiftfunc(x, &m_y[0], nx, Os);
722  for (i=0; i<nx; i++)//shrink to the orginal search range
723  {
724  m_y[i]*=5.0/100.0;
725  }
726  if (r_flag==1)
727  rotatefunc(&m_y[0], &m_z[0], nx, Mr);
728  else
729  for (i=0; i<nx; i++)
730  m_z[i]=m_y[i];
731 
732  for (i=0; i<nx; i++)
733  m_z[i] *=pow(100.0,1.0*i/(nx-1)/2.0);
734 
735  if (r_flag==1)
736  rotatefunc(&m_z[0], &m_y[0], nx, &Mr[nx*nx]);
737  else
738  for (i=0; i<nx; i++)
739  m_y[i]=m_z[i];
740 
741  f[0]=1.0;
742  for (i=0; i<nx; i++)
743  {
744  temp=0.0;
745  for (j=1; j<=32; j++)
746  {
747  tmp1=pow(2.0,j);
748  tmp2=tmp1*m_y[i];
749  temp += fabs(tmp2-floor(tmp2+0.5))/tmp1;
750  }
751  f[0] *= pow(1.0+(i+1)*temp,10.0/tmp3);
752  }
753  tmp1=10.0/nx/nx;
754  f[0]=f[0]*tmp1-tmp1;
755 
756 }
757 
758 void cec2013::bi_rastrigin_func (const double *x, double *f, int nx, const double *Os,const double *Mr,int r_flag) const /* Lunacek Bi_rastrigin Function */
759 {
760  int i;
761  double mu0=2.5,d=1.0,s,mu1,tmp,tmp1,tmp2;
762  double *tmpx;
763  tmpx=(double *)malloc(sizeof(double) * nx);
764  s=1.0-1.0/(2.0*pow(nx+20.0,0.5)-8.2);
765  mu1=-pow((mu0*mu0-d)/s,0.5);
766 
767  shiftfunc(x, &m_y[0], nx, Os);
768  for (i=0; i<nx; i++)//shrink to the orginal search range
769  {
770  m_y[i]*=10.0/100.0;
771  }
772 
773  for (i = 0; i < nx; i++)
774  {
775  tmpx[i]=2*m_y[i];
776  if (Os[i] < 0.)
777  tmpx[i] *= -1.;
778  }
779 
780  for (i=0; i<nx; i++)
781  {
782  m_z[i]=tmpx[i];
783  tmpx[i] += mu0;
784  }
785  if (r_flag==1)
786  rotatefunc(&m_z[0], &m_y[0], nx, Mr);
787  else
788  for (i=0; i<nx; i++)
789  m_y[i]=m_z[i];
790 
791  for (i=0; i<nx; i++)
792  m_y[i] *=pow(100.0,1.0*i/(nx-1)/2.0);
793  if (r_flag==1)
794  rotatefunc(&m_y[0], &m_z[0], nx, &Mr[nx*nx]);
795  else
796  for (i=0; i<nx; i++)
797  m_z[i]=m_y[i];
798 
799  tmp1=0.0;tmp2=0.0;
800  for (i=0; i<nx; i++)
801  {
802  tmp = tmpx[i]-mu0;
803  tmp1 += tmp*tmp;
804  tmp = tmpx[i]-mu1;
805  tmp2 += tmp*tmp;
806  }
807  tmp2 *= s;
808  tmp2 += d*nx;
809  tmp=0;
810  for (i=0; i<nx; i++)
811  {
812  tmp+=cos(2.0*boost::math::constants::pi<double>()*m_z[i]);
813  }
814 
815  if(tmp1<tmp2)
816  f[0] = tmp1;
817  else
818  f[0] = tmp2;
819  f[0] += 10.0*(nx-tmp);
820  free(tmpx);
821 }
822 
823 void cec2013::grie_rosen_func (const double *x, double *f, int nx, const double *Os,const double *Mr,int r_flag) const /* Griewank-Rosenbrock */
824 {
825  int i;
826  double temp,tmp1,tmp2;
827 
828  shiftfunc(x, &m_y[0], nx, Os);
829  for (i=0; i<nx; i++)//shrink to the orginal search range
830  {
831  m_y[i]=m_y[i]*5/100;
832  }
833  if (r_flag==1)
834  rotatefunc(&m_y[0], &m_z[0], nx, Mr);
835  else
836  for (i=0; i<nx; i++)
837  m_z[i]=m_y[i];
838 
839  for (i=0; i<nx; i++)//shift to orgin
840  {
841  m_z[i]=m_y[i]+1;
842  }
843 
844  f[0]=0.0;
845  for (i=0; i<nx-1; i++)
846  {
847  tmp1 = m_z[i]*m_z[i]-m_z[i+1];
848  tmp2 = m_z[i]-1.0;
849  temp = 100.0*tmp1*tmp1 + tmp2*tmp2;
850  f[0] += (temp*temp)/4000.0 - cos(temp) + 1.0;
851  }
852  tmp1 = m_z[nx-1]*m_z[nx-1]-m_z[0];
853  tmp2 = m_z[nx-1]-1.0;
854  temp = 100.0*tmp1*tmp1 + tmp2*tmp2;;
855  f[0] += (temp*temp)/4000.0 - cos(temp) + 1.0 ;
856 }
857 
858 void cec2013::escaffer6_func (const double *x, double *f, int nx, const double *Os,const double *Mr,int r_flag) const /* Expanded Scaffer¡¯s F6 */
859 {
860  int i;
861  double temp1, temp2;
862  shiftfunc(x, &m_y[0], nx, Os);
863  if (r_flag==1)
864  rotatefunc(&m_y[0], &m_z[0], nx, Mr);
865  else
866  for (i=0; i<nx; i++)
867  m_z[i]=m_y[i];
868 
869  asyfunc (&m_z[0], &m_y[0], nx, 0.5);
870  if (r_flag==1)
871  rotatefunc(&m_y[0], &m_z[0], nx, &Mr[nx*nx]);
872  else
873  for (i=0; i<nx; i++)
874  m_z[i]=m_y[i];
875 
876  f[0] = 0.0;
877  for (i=0; i<nx-1; i++)
878  {
879  temp1 = sin(sqrt(m_z[i]*m_z[i]+m_z[i+1]*m_z[i+1]));
880  temp1 =temp1*temp1;
881  temp2 = 1.0 + 0.001*(m_z[i]*m_z[i]+m_z[i+1]*m_z[i+1]);
882  f[0] += 0.5 + (temp1-0.5)/(temp2*temp2);
883  }
884  temp1 = sin(sqrt(m_z[nx-1]*m_z[nx-1]+m_z[0]*m_z[0]));
885  temp1 =temp1*temp1;
886  temp2 = 1.0 + 0.001*(m_z[nx-1]*m_z[nx-1]+m_z[0]*m_z[0]);
887  f[0] += 0.5 + (temp1-0.5)/(temp2*temp2);
888 }
889 
890 void cec2013::cf01 (const double *x, double *f, int nx, const double *Os,const double *Mr,int r_flag) const /* Composition Function 1 */
891 {
892  int i,cf_num=5;
893  double fit[5];
894  double delta[5] = {10, 20, 30, 40, 50};
895  double bias[5] = {0, 100, 200, 300, 400};
896 
897  i=0;
898  rosenbrock_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],r_flag);
899  fit[i]=10000*fit[i]/1e+4;
900  i=1;
901  dif_powers_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],r_flag);
902  fit[i]=10000*fit[i]/1e+10;
903  i=2;
904  bent_cigar_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],r_flag);
905  fit[i]=10000*fit[i]/1e+30;
906  i=3;
907  discus_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],r_flag);
908  fit[i]=10000*fit[i]/1e+10;
909  i=4;
910  sphere_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],0);
911  fit[i]=10000*fit[i]/1e+5;
912  cf_cal(x, f, nx, Os, delta,bias,fit,cf_num);
913 }
914 
915 void cec2013::cf02 (const double *x, double *f, int nx, const double *Os,const double *Mr,int r_flag) const /* Composition Function 2 */
916 {
917  int i,cf_num=3;
918  double fit[3];
919  double delta[3] = {20,20,20};
920  double bias[3] = {0, 100, 200};
921  for(i=0;i<cf_num;i++)
922  {
923  schwefel_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],r_flag);
924  }
925  cf_cal(x, f, nx, Os, delta,bias,fit,cf_num);
926 }
927 
928 void cec2013::cf03 (const double *x, double *f, int nx, const double *Os,const double *Mr,int r_flag) const /* Composition Function 3 */
929 {
930  int i,cf_num=3;
931  double fit[3];
932  double delta[3] = {20,20,20};
933  double bias[3] = {0, 100, 200};
934  for(i=0;i<cf_num;i++)
935  {
936  schwefel_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],r_flag);
937  }
938  cf_cal(x, f, nx, Os, delta,bias,fit,cf_num);
939 }
940 
941 void cec2013::cf04 (const double *x, double *f, int nx, const double *Os,const double *Mr,int r_flag) const /* Composition Function 4 */
942 {
943  int i,cf_num=3;
944  double fit[3];
945  double delta[3] = {20,20,20};
946  double bias[3] = {0, 100, 200};
947  i=0;
948  schwefel_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],r_flag);
949  fit[i]=1000*fit[i]/4e+3;
950  i=1;
951  rastrigin_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],r_flag);
952  fit[i]=1000*fit[i]/1e+3;
953  i=2;
954  weierstrass_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],r_flag);
955  fit[i]=1000*fit[i]/400;
956  cf_cal(x, f, nx, Os, delta,bias,fit,cf_num);
957 }
958 
959 void cec2013::cf05 (const double *x, double *f, int nx, const double *Os,const double *Mr,int r_flag) const /* Composition Function 4 */
960 {
961  int i,cf_num=3;
962  double fit[3];
963  double delta[3] = {10,30,50};
964  double bias[3] = {0, 100, 200};
965  i=0;
966  schwefel_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],r_flag);
967  fit[i]=1000*fit[i]/4e+3;
968  i=1;
969  rastrigin_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],r_flag);
970  fit[i]=1000*fit[i]/1e+3;
971  i=2;
972  weierstrass_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],r_flag);
973  fit[i]=1000*fit[i]/400;
974  cf_cal(x, f, nx, Os, delta,bias,fit,cf_num);
975 }
976 
977 void cec2013::cf06 (const double *x, double *f, int nx, const double *Os,const double *Mr,int r_flag) const /* Composition Function 6 */
978 {
979  int i,cf_num=5;
980  double fit[5];
981  double delta[5] = {10,10,10,10,10};
982  double bias[5] = {0, 100, 200, 300, 400};
983  i=0;
984  schwefel_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],r_flag);
985  fit[i]=1000*fit[i]/4e+3;
986  i=1;
987  rastrigin_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],r_flag);
988  fit[i]=1000*fit[i]/1e+3;
989  i=2;
990  ellips_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],r_flag);
991  fit[i]=1000*fit[i]/1e+10;
992  i=3;
993  weierstrass_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],r_flag);
994  fit[i]=1000*fit[i]/400;
995  i=4;
996  griewank_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],r_flag);
997  fit[i]=1000*fit[i]/100;
998  cf_cal(x, f, nx, Os, delta,bias,fit,cf_num);
999 
1000 }
1001 
1002 void cec2013::cf07 (const double *x, double *f, int nx, const double *Os,const double *Mr,int r_flag) const /* Composition Function 7 */
1003 {
1004  int i,cf_num=5;
1005  double fit[5];
1006  double delta[5] = {10,10,10,20,20};
1007  double bias[5] = {0, 100, 200, 300, 400};
1008  i=0;
1009  griewank_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],r_flag);
1010  fit[i]=10000*fit[i]/100;
1011  i=1;
1012  rastrigin_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],r_flag);
1013  fit[i]=10000*fit[i]/1e+3;
1014  i=2;
1015  schwefel_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],r_flag);
1016  fit[i]=10000*fit[i]/4e+3;
1017  i=3;
1018  weierstrass_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],r_flag);
1019  fit[i]=10000*fit[i]/400;
1020  i=4;
1021  sphere_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],0);
1022  fit[i]=10000*fit[i]/1e+5;
1023  cf_cal(x, f, nx, Os, delta,bias,fit,cf_num);
1024 }
1025 
1026 void cec2013::cf08 (const double *x, double *f, int nx, const double *Os,const double *Mr,int r_flag) const /* Composition Function 8 */
1027 {
1028  int i,cf_num=5;
1029  double fit[5];
1030  double delta[5] = {10,20,30,40,50};
1031  double bias[5] = {0, 100, 200, 300, 400};
1032  i=0;
1033  grie_rosen_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],r_flag);
1034  fit[i]=10000*fit[i]/4e+3;
1035  i=1;
1036  schaffer_F7_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],r_flag);
1037  fit[i]=10000*fit[i]/4e+6;
1038  i=2;
1039  schwefel_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],r_flag);
1040  fit[i]=10000*fit[i]/4e+3;
1041  i=3;
1042  escaffer6_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],r_flag);
1043  fit[i]=10000*fit[i]/2e+7;
1044  i=4;
1045  sphere_func(x,&fit[i],nx,&Os[i*nx],&Mr[i*nx*nx],0);
1046  fit[i]=10000*fit[i]/1e+5;
1047  cf_cal(x, f, nx, Os, delta,bias,fit,cf_num);
1048 }
1049 
1050 void cec2013::shiftfunc (const double *x, double *xshift, int nx, const double *Os) const {
1051  int i;
1052  for (i=0; i<nx; i++)
1053  {
1054  xshift[i]=x[i]-Os[i];
1055  }
1056 }
1057 
1058 void cec2013::rotatefunc (const double *x, double *xrot, int nx,const double *Mr) const
1059 {
1060  int i,j;
1061  for (i=0; i<nx; i++)
1062  {
1063  xrot[i]=0;
1064  for (j=0; j<nx; j++)
1065  {
1066  xrot[i]=xrot[i]+x[j]*Mr[i*nx+j];
1067  }
1068  }
1069 }
1070 
1071 void cec2013::asyfunc (const double *x, double *xasy, int nx, double beta) const
1072 {
1073  int i;
1074  for (i=0; i<nx; i++)
1075  {
1076  if (x[i]>0)
1077  xasy[i]=pow(x[i],1.0+beta*i/(nx-1)*pow(x[i],0.5));
1078  }
1079 }
1080 
1081 void cec2013::oszfunc (const double *x, double *xosz, int nx) const
1082 {
1083  int i,sx;
1084  double c1,c2,xx=0;
1085  for (i=0; i<nx; i++)
1086  {
1087  if (i==0||i==nx-1)
1088  {
1089  if (x[i]!=0)
1090  xx=log(fabs(x[i]));
1091  if (x[i]>0)
1092  {
1093  c1=10;
1094  c2=7.9;
1095  }
1096  else
1097  {
1098  c1=5.5;
1099  c2=3.1;
1100  }
1101  if (x[i]>0)
1102  sx=1;
1103  else if (x[i]==0)
1104  sx=0;
1105  else
1106  sx=-1;
1107  xosz[i]=sx*exp(xx+0.049*(sin(c1*xx)+sin(c2*xx)));
1108  }
1109  else
1110  xosz[i]=x[i];
1111  }
1112 }
1113 
1114 void cec2013::cf_cal(const double *x, double *f, int nx, const double *Os,double * delta,double * bias,double * fit, int cf_num) const
1115 {
1116  int i,j;
1117  double *w;
1118  double w_max=0,w_sum=0;
1119  w=(double *)malloc(cf_num * sizeof(double));
1120  for (i=0; i<cf_num; i++)
1121  {
1122  fit[i]+=bias[i];
1123  w[i]=0;
1124  for (j=0; j<nx; j++)
1125  {
1126  w[i]+=pow(x[j]-Os[i*nx+j],2.0);
1127  }
1128  if (w[i]!=0)
1129  w[i]=pow(1.0/w[i],0.5)*exp(-w[i]/2.0/nx/pow(delta[i],2.0));
1130  else
1131  w[i]=INF;
1132  if (w[i]>w_max)
1133  w_max=w[i];
1134  }
1135 
1136  for (i=0; i<cf_num; i++)
1137  {
1138  w_sum=w_sum+w[i];
1139  }
1140  if(w_max==0)
1141  {
1142  for (i=0; i<cf_num; i++)
1143  w[i]=1;
1144  w_sum=cf_num;
1145  }
1146  f[0] = 0.0;
1147  for (i=0; i<cf_num; i++)
1148  {
1149  f[0]=f[0]+w[i]/w_sum*fit[i];
1150  }
1151  free(w);
1152 }
1153 
1154 }} //namespaces
1155 
1156 #undef EPS
1157 #undef E
1158 #undef INF
1159 
1160 BOOST_CLASS_EXPORT_IMPLEMENT(pagmo::problem::cec2013)
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.
std::string get_name() const
Get problem's name.
Definition: cec2013.cpp:229
The CEC 2013 problems: Real-Parameter Single Objective Optimization Competition.
Definition: cec2013.h:54
std::vector< double > fitness_vector
Fitness vector type.
Definition: types.h:42
cec2013(unsigned int=1, problem::base::size_type=30, const std::string &="input_data/")
Constructor.
Definition: cec2013.cpp:58
void objfun_impl(fitness_vector &, const decision_vector &) const
Implementation of the objective function.
Definition: cec2013.cpp:105
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
base_ptr clone() const
Clone method.
Definition: cec2013.cpp:99