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 #ifndef PAGMO_PROBLEMS_ZDT_HPP
30 #define PAGMO_PROBLEMS_ZDT_HPP
31 
32 #include <string>
33 #include <utility>
34 
35 #include <pagmo/detail/visibility.hpp>
36 #include <pagmo/population.hpp>
37 #include <pagmo/problem.hpp>
38 #include <pagmo/types.hpp>
39 
40 namespace pagmo
41 {
42 
43 /// ZDT problem test suite
44 /**
45  *
46  * This widespread test suite was conceived for two-objective problems and takes its name from its
47  * authors Zitzler, Deb and Thiele.
48  *
49  * In their paper the authors propose a set of 6 different scalable problems all originating from a
50  * well thought combination of functions allowing, by construction, to measure the distance of
51  * any point to the Pareto front while creating interesting problems. They also suggest some
52  * dimensions for instantiating the problems, namely \f$m = [30, 30, 30, 10, 11, 10]\f$.
53  *
54  * \verbatim embed:rst:leading-asterisk
55  * .. note::
56  *
57  *    The ZDT5 problem is an integer problem, its fitness is computed rounding all the chromosome values,
58  *    so that [1,0,1] or [0.97, 0.23, 0.57] will have the same fitness. Integer relaxation techniques are
59  *    thus not appropriate fot this type of fitness.
60  *
61  * .. seealso::
62  *
63  *    Zitzler, Eckart, Kalyanmoy Deb, and Lothar Thiele. "Comparison of multiobjective evolutionary algorithms:
64  *    Empirical results." Evolutionary computation 8.2 (2000): 173-195. doi: 10.1.1.30.5848
65  *
66  * \endverbatim
67  *
68  * ZDT1:
69  *
70  * This is a box-constrained continuous \f$n\f$-dimensional (\f$n\f$>1) multi-objecive problem.
71  * \f[
72  * \begin{array}{l}
73  *  g\left(x\right) = 1 + 9 \left(\sum_{i=2}^{n} x_i \right) / \left( n-1 \right) \\
74  *  F_1 \left(x\right) = x_1 \\
75  *  F_2 \left(x\right) = g(x) \left[ 1 - \sqrt{x_1 / g(x)} \right]  x \in \left[ 0,1 \right].
76  * \end{array}
77  * \f]
78  *
79  * ZDT2:
80  *
81  * This is a box-constrained continuous \f$n\f$-dimension multi-objecive problem.
82  * \f[
83  * \begin{array}{l}
84  *      g\left(x\right) = 1 + 9 \left(\sum_{i=2}^{n} x_i \right) / \left( n-1 \right) \\
85  *      F_1 \left(x\right) = x_1 \\
86  *      F_2 \left(x\right) = g(x) \left[ 1 - \left(x_1 / g(x)\right)^2 \right]  x \in \left[ 0,1 \right].
87  * \end{array}
88  * \f]
89  *
90  * ZDT3:
91  *
92  * This is a box-constrained continuous \f$n\f$-dimension multi-objecive problem.
93  * \f[
94  * \begin{array}{l}
95  *      g\left(x\right) = 1 + 9 \left(\sum_{i=2}^{n} x_i \right) / \left( n-1 \right) \\
96  *      F_1 \left(x\right) = x_1 \\
97  *      F_2 \left(x\right) = g(x) \left[ 1 - \sqrt{x_1 / g(x)} - x_1/g(x) \sin(10 \pi x_1) \right]  x \in \left[ 0,1
98  * \right].
99  * \end{array}
100  * \f]
101  *
102  * ZDT4:
103  *
104  * This is a box-constrained continuous \f$n\f$-dimension multi-objecive problem.
105  * \f[
106  * \begin{array}{l}
107  *      g\left(x\right) = 91 + \sum_{i=2}^{n} \left[x_i^2 - 10 \cos \left(4\pi x_i \right) \right] \\
108  *      F_1 \left(x\right) = x_1 \\
109  *      F_2 \left(x\right) = g(x) \left[ 1 - \sqrt{x_1 / g(x)} \right]  x_1 \in [0,1], x_i \in \left[ -5,5 \right] i=2,
110  * \cdots, 10.
111  * \end{array}
112  * \f]
113  *
114  * ZDT5
115  *
116  * This is a box-constrained integer \f$n\f$-dimension multi-objecive problem. The chromosome is
117  * a bitstring so that \f$x_i \in \left\{0,1\right\}\f$. Refer to the original paper for the formal definition.
118  *
119  * ZDT6
120  *
121  * This is a box-constrained continuous \f$n\f$--dimension multi-objecive problem.
122  * \f[
123  * \begin{array}{l}
124  *      g\left(x\right) = 1 + 9 \left[\left(\sum_{i=2}^{n} x_i \right) / \left( n-1 \right)\right]^{0.25} \\
125  *      F_1 \left(x\right) = 1 - \exp(-4 x_1) \sin^6(6 \pi \ x_1) \\
126  *      F_2 \left(x\right) = g(x) \left[ 1 - (f_1(x) / g(x))^2  \right]  x \in \left[ 0,1 \right].
127  * \end{array}
128  * \f]
129  */
130 
131 class PAGMO_DLL_PUBLIC zdt
132 {
133 public:
134     /** Constructor
135      *
136      * Will construct one problem from the ZDT test-suite.
137      *
138      * @param prob_id problem number. Must be in [1, .., 6]
139      * @param param problem parameter, representing the problem dimension
140      * except for ZDT5 where it represents the number of binary strings
141      *
142      * @throws std::invalid_argument if \p id is not in [1,..,6]
143      * @throws std::invalid_argument if \p param is not at least 2.
144      */
145     zdt(unsigned prob_id = 1u, unsigned param = 30u);
146     // Fitness computation
147     vector_double fitness(const vector_double &) const;
148     /// Number of objectives
149     /**
150      * It returns the number of objectives.
151      *
152      * @return the number of objectives
153      */
get_nobj() const154     vector_double::size_type get_nobj() const
155     {
156         return 2u;
157     }
158 
159     // Box-bounds
160     std::pair<vector_double, vector_double> get_bounds() const;
161 
162     // Integer dimension
163     vector_double::size_type get_nix() const;
164 
165     // Problem name
166     std::string get_name() const;
167 
168     // Distance from the Pareto front (of a population)
169     double p_distance(const population &) const;
170     /// Distance from the Pareto front
171     /**
172      * Convergence metric for a given decision_vector (0 = on the optimal front)
173      *
174      * Introduced by Martens and Izzo, this metric is able
175      * to measure "a distance" of any point from the pareto front of any ZDT
176      * problem analytically without the need to precompute the front.
177      *
178      * @param x input decision vector
179      * @return the p_distance
180      *
181      * See: Märtens, Marcus, and Dario Izzo. "The asynchronous island model
182      * and NSGA-II: study of a new migration operator and its performance."
183      * Proceedings of the 15th annual conference on Genetic and evolutionary computation. ACM, 2013.
184      */
185     double p_distance(const vector_double &) const;
186 
187 private:
188     // Object serialization
189     friend class boost::serialization::access;
190     template <typename Archive>
191     void serialize(Archive &, unsigned);
192 
193     PAGMO_DLL_LOCAL vector_double zdt1_fitness(const vector_double &) const;
194     PAGMO_DLL_LOCAL vector_double zdt2_fitness(const vector_double &) const;
195     PAGMO_DLL_LOCAL vector_double zdt3_fitness(const vector_double &) const;
196     PAGMO_DLL_LOCAL vector_double zdt4_fitness(const vector_double &) const;
197     PAGMO_DLL_LOCAL vector_double zdt5_fitness(const vector_double &) const;
198     PAGMO_DLL_LOCAL vector_double zdt6_fitness(const vector_double &) const;
199     PAGMO_DLL_LOCAL double zdt123_p_distance(const vector_double &) const;
200     PAGMO_DLL_LOCAL double zdt4_p_distance(const vector_double &) const;
201     PAGMO_DLL_LOCAL double zdt5_p_distance(const vector_double &) const;
202     PAGMO_DLL_LOCAL double zdt6_p_distance(const vector_double &) const;
203 
204     // Problem dimensions
205     unsigned m_prob_id;
206     unsigned m_param;
207 };
208 } // namespace pagmo
209 
210 PAGMO_S11N_PROBLEM_EXPORT_KEY(pagmo::zdt)
211 
212 #endif
213