1 /* Copyright 2017-2021 PaGMO development team
2 
3 This file is part of the PaGMO library.
4 
5 The PaGMO library is free software; you can redistribute it and/or modify
6 it under the terms of either:
7 
8   * the GNU Lesser General Public License as published by the Free
9     Software Foundation; either version 3 of the License, or (at your
10     option) any later version.
11 
12 or
13 
14   * the GNU General Public License as published by the Free Software
15     Foundation; either version 3 of the License, or (at your option) any
16     later version.
17 
18 or both in parallel, as here.
19 
20 The PaGMO library is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
23 for more details.
24 
25 You should have received copies of the GNU General Public License and the
26 GNU Lesser General Public License along with the PaGMO library.  If not,
27 see https://www.gnu.org/licenses/. */
28 
29 /*
30   CEC14 Test Function Suite for Single Objective Optimization
31   Jane Jing Liang (email: liangjing@zzu.edu.cn; liangjing@pmail.ntu.edu.cn)
32 */
33 
34 #ifndef PAGMO_PROBLEMS_CEC2014_HPP
35 #define PAGMO_PROBLEMS_CEC2014_HPP
36 
37 #include <string>
38 #include <utility>
39 #include <vector>
40 
41 #include <pagmo/detail/visibility.hpp>
42 #include <pagmo/problem.hpp>
43 #include <pagmo/s11n.hpp>
44 #include <pagmo/types.hpp>
45 
46 namespace pagmo
47 {
48 /// The CEC 2014 problems: Real-Parameter Single Objective Optimization Competition
49 /**
50  * \verbatim embed:rst:leading-asterisk
51  *
52  * .. versionadded:: 2.8
53  *
54  * The 30 problems of the competition on real-parameter single objective optimization problems that
55  * was organized for the 2014 IEEE Congress on Evolutionary Computation.
56  *
57  * .. note::
58  *
59  *    The code for these UDAs is adapted from the original C code distributed during the competition and
60  *    linked below.
61  *
62  * .. note::
63  *
64  *    All problems are box-bounded, continuous, single objective problems.
65  *
66  * .. seealso:
67  *
68  *    http://www.ntu.edu.sg/home/EPNSugan/index_files/CEC2014/CEC2014.htm
69  *    http://web.mysites.ntu.edu.sg/epnsugan/PublicSite/Shared%20Documents/CEC-2014/cec14-c-code.zip
70  *
71  * \endverbatim
72  */
73 class PAGMO_DLL_PUBLIC cec2014
74 {
75 
76 public:
77     /// Constructor
78     /**
79      * Will construct one of the 30 CEC2014 problems
80      *
81      * @param prob_id The problem id. One of [1,2,...,30]
82      * @param dim problem dimension. One of [2,10,20,30,50,100]
83      *
84      * @throws invalid_argument if \p prob_id is not in [1,30] or if \p dim is not one of
85      * [2,10,20,30,50,100]
86      */
87     cec2014(unsigned prob_id = 1u, unsigned dim = 2u);
88 
89     // Box-bounds
90     std::pair<vector_double, vector_double> get_bounds() const;
91 
92     // Fitness computation
93     vector_double fitness(const vector_double &) const;
94 
95     // Problem name
96     std::string get_name() const;
97 
98     /// Returns the origin shift
99     /**
100      * This method will return the origin shift.
101      *
102      * @return The origin shift.
103      */
get_origin_shift() const104     const vector_double &get_origin_shift() const
105     {
106         return m_origin_shift;
107     }
108 
109 private:
110     // Object serialization
111     friend class boost::serialization::access;
112     template <typename Archive>
113     void serialize(Archive &, unsigned);
114 
115     /* Sphere */
116     PAGMO_DLL_LOCAL void sphere_func(const double *x, double *f, const unsigned nx, const double *Os, const double *Mr,
117                                      int s_flag, int r_flag) const;
118     /* Ellipsoidal */
119     PAGMO_DLL_LOCAL void ellips_func(const double *x, double *f, const unsigned nx, const double *Os, const double *Mr,
120                                      int s_flag, int r_flag) const;
121     /* Bent_Cigar */
122     PAGMO_DLL_LOCAL void bent_cigar_func(const double *x, double *f, const unsigned nx, const double *Os,
123                                          const double *Mr, int s_flag, int r_flag) const;
124     /* Discus */
125     PAGMO_DLL_LOCAL void discus_func(const double *x, double *f, const unsigned nx, const double *Os, const double *Mr,
126                                      int s_flag, int r_flag) const;
127     /* Different Powers */
128     PAGMO_DLL_LOCAL void dif_powers_func(const double *x, double *f, const unsigned nx, const double *Os,
129                                          const double *Mr, int s_flag, int r_flag) const;
130     /* Rosenbrock's */
131     PAGMO_DLL_LOCAL void rosenbrock_func(const double *x, double *f, const unsigned nx, const double *Os,
132                                          const double *Mr, int s_flag, int r_flag) const;
133     /* Schwefel's 1.2  */
134     PAGMO_DLL_LOCAL void schaffer_F7_func(const double *x, double *f, const unsigned nx, const double *Os,
135                                           const double *Mr, int s_flag, int r_flag) const;
136     /* Ackley's  */
137     PAGMO_DLL_LOCAL void ackley_func(const double *x, double *f, const unsigned nx, const double *Os, const double *Mr,
138                                      int s_flag, int r_flag) const;
139     /* Weierstrass's  */
140     PAGMO_DLL_LOCAL void weierstrass_func(const double *x, double *f, const unsigned nx, const double *Os,
141                                           const double *Mr, int s_flag, int r_flag) const;
142     /* Griewank's  */
143     PAGMO_DLL_LOCAL void griewank_func(const double *x, double *f, const unsigned nx, const double *Os,
144                                        const double *Mr, int s_flag, int r_flag) const;
145     /* Rastrigin's  */
146     PAGMO_DLL_LOCAL void rastrigin_func(const double *x, double *f, const unsigned nx, const double *Os,
147                                         const double *Mr, int s_flag, int r_flag) const;
148     /* Noncontinuous Rastrigin's  */
149     PAGMO_DLL_LOCAL void step_rastrigin_func(const double *x, double *f, const unsigned nx, const double *Os,
150                                              const double *Mr, int s_flag, int r_flag) const;
151     /* Schwefel's  */
152     PAGMO_DLL_LOCAL void schwefel_func(const double *x, double *f, const unsigned nx, const double *Os,
153                                        const double *Mr, int s_flag, int r_flag) const;
154     /* Katsuura  */
155     PAGMO_DLL_LOCAL void katsuura_func(const double *x, double *f, const unsigned nx, const double *Os,
156                                        const double *Mr, int s_flag, int r_flag) const;
157     /* Lunacek Bi_rastrigin Function */
158     PAGMO_DLL_LOCAL void bi_rastrigin_func(const double *x, double *f, const unsigned nx, const double *Os,
159                                            const double *Mr, int s_flag, int r_flag) const;
160     /* Griewank-Rosenbrock  */
161     PAGMO_DLL_LOCAL void grie_rosen_func(const double *x, double *f, const unsigned nx, const double *Os,
162                                          const double *Mr, int s_flag, int r_flag) const;
163     /* Expanded Scaffer??s F6  */
164     PAGMO_DLL_LOCAL void escaffer6_func(const double *x, double *f, const unsigned nx, const double *Os,
165                                         const double *Mr, int s_flag, int r_flag) const;
166     /* HappyCat, provdided by Hans-Georg Beyer (HGB) */
167     /* original global optimum: [-1,-1,...,-1] */
168     PAGMO_DLL_LOCAL void happycat_func(const double *x, double *f, const unsigned nx, const double *Os,
169                                        const double *Mr, int s_flag, int r_flag) const;
170     /* HGBat, provdided by Hans-Georg Beyer (HGB)*/
171     /* original global optimum: [-1,-1,...,-1] */
172     PAGMO_DLL_LOCAL void hgbat_func(const double *x, double *f, const unsigned nx, const double *Os, const double *Mr,
173                                     int s_flag, int r_flag) const;
174     /* Hybrid Function 1 */
175     PAGMO_DLL_LOCAL void hf01(const double *x, double *f, const unsigned nx, const double *Os, const double *Mr,
176                               const int *S, int s_flag, int r_flag) const;
177     /* Hybrid Function 2 */
178     PAGMO_DLL_LOCAL void hf02(const double *x, double *f, const unsigned nx, const double *Os, const double *Mr,
179                               const int *S, int s_flag, int r_flag) const;
180     /* Hybrid Function 3 */
181     PAGMO_DLL_LOCAL void hf03(const double *x, double *f, const unsigned nx, const double *Os, const double *Mr,
182                               const int *S, int s_flag, int r_flag) const;
183     /* Hybrid Function 4 */
184     PAGMO_DLL_LOCAL void hf04(const double *x, double *f, const unsigned nx, const double *Os, const double *Mr,
185                               const int *S, int s_flag, int r_flag) const;
186     /* Hybrid Function 5 */
187     PAGMO_DLL_LOCAL void hf05(const double *x, double *f, const unsigned nx, const double *Os, const double *Mr,
188                               const int *S, int s_flag, int r_flag) const;
189     /* Hybrid Function 6 */
190     PAGMO_DLL_LOCAL void hf06(const double *x, double *f, const unsigned nx, const double *Os, const double *Mr,
191                               const int *S, int s_flag, int r_flag) const;
192     /* Composition Function 1 */
193     PAGMO_DLL_LOCAL void cf01(const double *x, double *f, const unsigned nx, const double *Os, const double *Mr,
194                               int r_flag) const;
195     /* Composition Function 2 */
196     PAGMO_DLL_LOCAL void cf02(const double *x, double *f, const unsigned nx, const double *Os, const double *Mr,
197                               int r_flag) const;
198     /* Composition Function 3 */
199     PAGMO_DLL_LOCAL void cf03(const double *x, double *f, const unsigned nx, const double *Os, const double *Mr,
200                               int r_flag) const;
201     /* Composition Function 4 */
202     PAGMO_DLL_LOCAL void cf04(const double *x, double *f, const unsigned nx, const double *Os, const double *Mr,
203                               int r_flag) const;
204     /* Composition Function 4 */
205     PAGMO_DLL_LOCAL void cf05(const double *x, double *f, const unsigned nx, const double *Os, const double *Mr,
206                               int r_flag) const;
207     /* Composition Function 6 */
208     PAGMO_DLL_LOCAL void cf06(const double *x, double *f, const unsigned nx, const double *Os, const double *Mr,
209                               int r_flag) const;
210     /* Composition Function 7 */
211     PAGMO_DLL_LOCAL void cf07(const double *x, double *f, const unsigned nx, const double *Os, const double *Mr,
212                               const int *SS, int r_flag) const;
213     /* Composition Function 8 */
214     PAGMO_DLL_LOCAL void cf08(const double *x, double *f, const unsigned nx, const double *Os, const double *Mr,
215                               const int *SS, int r_flag) const;
216     PAGMO_DLL_LOCAL void shiftfunc(const double *x, double *xshift, const unsigned nx, const double *Os) const;
217     PAGMO_DLL_LOCAL void rotatefunc(const double *x, double *xrot, const unsigned nx, const double *Mr) const;
218     /* shift and rotate */
219     PAGMO_DLL_LOCAL void sr_func(const double *x, double *sr_x, const unsigned nx, const double *Os, const double *Mr,
220                                  double sh_rate, int s_flag, int r_flag) const;
221     PAGMO_DLL_LOCAL void asyfunc(const double *x, double *xasy, const unsigned nx, double beta) const;
222     PAGMO_DLL_LOCAL void oszfunc(const double *x, double *xosz, const unsigned nx) const;
223     PAGMO_DLL_LOCAL void cf_cal(const double *x, double *f, const unsigned nx, const double *Os, double *delta,
224                                 double *bias, double *fit, int cf_num) const;
225 
226     // problem data
227     vector_double m_origin_shift;
228     vector_double m_rotation_matrix;
229     std::vector<int> m_shuffle;
230 
231     // auxiliary vectors
232     mutable vector_double m_z;
233     mutable vector_double m_y;
234 
235     // problem id
236     unsigned func_num;
237 };
238 
239 } // namespace pagmo
240 
241 PAGMO_S11N_PROBLEM_EXPORT_KEY(pagmo::cec2014)
242 
243 #endif
244