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_MINLP_RASTRIGIN_HPP
30 #define PAGMO_PROBLEMS_MINLP_RASTRIGIN_HPP
31 
32 #include <string>
33 #include <utility>
34 #include <vector>
35 
36 #include <pagmo/detail/visibility.hpp>
37 #include <pagmo/problem.hpp>
38 #include <pagmo/s11n.hpp>
39 #include <pagmo/types.hpp>
40 
41 namespace pagmo
42 {
43 
44 /// A MINLP version of the Rastrigin problem
45 /**
46  *
47  * \image html rastrigin.png "Two-dimensional Rastrigin function." width=3cm
48  *
49  * This is a scalable, box-constrained, mixed integer nonlinear programmng (MINLP) problem.
50  * The objective function is the generalised n-dimensional Rastrigin function:
51  * \f[
52  * 	F\left(x_1,\ldots,x_n\right) = 10 \cdot n + \sum_{i=1}^n x_i^2 - 10\cdot\cos\left( 2\pi \cdot x_i \right)
53  * \f]
54  *
55  * where we constraint the last \f$m\f$ components of the decision vector to be integers. The variables are
56  * box bounded as follows: \f$\quad x_i \in [-5.12,5.12], \forall i = 1 .. n-m\f$, \f$\quad x_i \in [-10,-5], \forall
57  * i = m+1 .. n\f$
58  *
59  * Gradients (dense) are also provided (also for the integer part) as:
60  * \f[
61  * 	G_i\left(x_1,\ldots,x_n\right) = 2 x_i + 10 \cdot 2\pi \cdot\sin\left( 2\pi \cdot x_i \right)
62  * \f]
63  * And Hessians (sparse as only the diagonal is non-zero) are:
64  * \f[
65  * 	H_{ii}\left(x_1,\ldots,x_n\right) = 2 + 10 \cdot 4\pi^2 \cdot\cos\left( 2\pi \cdot x_i \right)
66  * \f]
67  */
68 struct PAGMO_DLL_PUBLIC minlp_rastrigin {
69     /// Constructor from continuous and integer dimension
70     /**
71      * Constructs a MINLP Rastrigin problem.
72      *
73      * @param dim_c the problem continuous dimension.
74      * @param dim_i the problem continuous dimension.
75      *
76      * @throw std::invalid_argument if \p dim_c+ \p dim_i is < 1
77      */
78     minlp_rastrigin(unsigned dim_c = 1u, unsigned dim_i = 1u);
79 
80     // Fitness computation
81     vector_double fitness(const vector_double &) const;
82 
83     // Box-bounds
84     /**
85      * It returns the box-bounds for this UDP.
86      *
87      * @return the lower and upper bounds for each of the decision vector components
88      */
89     std::pair<vector_double, vector_double> get_bounds() const;
90 
91     /// Integer dimension
92     /**
93      * It returns the integer dimension of the problem.
94      *
95      * @return the integer dimension of the problem.
96      */
get_nixpagmo::minlp_rastrigin97     vector_double::size_type get_nix() const
98     {
99         return m_dim_i;
100     }
101 
102     // Gradients
103     vector_double gradient(const vector_double &) const;
104 
105     // Hessians
106     std::vector<vector_double> hessians(const vector_double &) const;
107 
108     // Hessians sparsity (only the diagonal elements are non zero)
109     std::vector<sparsity_pattern> hessians_sparsity() const;
110 
111     /// Problem name
112     /**
113      * @return a string containing the problem name
114      */
get_namepagmo::minlp_rastrigin115     std::string get_name() const
116     {
117         return "MINLP Rastrigin Function";
118     }
119 
120     // Extra info
121     std::string get_extra_info() const;
122 
123 private:
124     // Object serialization
125     friend class boost::serialization::access;
126     template <typename Archive>
127     void serialize(Archive &, unsigned);
128 
129     // Problem dimensions
130     unsigned m_dim_c;
131     unsigned m_dim_i;
132 };
133 
134 } // namespace pagmo
135 
136 PAGMO_S11N_PROBLEM_EXPORT_KEY(pagmo::minlp_rastrigin)
137 
138 #endif
139