MOEAD.h
Go to the documentation of this file.
1 //===========================================================================
2 /*!
3  *
4  *
5  * \brief Implements the MOEA/D algorithm.
6  *
7  * \author Bjoern Bugge Grathwohl
8  * \date February 2017
9  *
10  * \par Copyright 1995-2017 Shark Development Team
11  *
12  * <BR><HR>
13  * This file is part of Shark.
14  * <http://shark-ml.org/>
15  *
16  * Shark is free software: you can redistribute it and/or modify
17  * it under the terms of the GNU Lesser General Public License as published
18  * by the Free Software Foundation, either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * Shark is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  * GNU Lesser General Public License for more details.
25  *
26  * You should have received a copy of the GNU Lesser General Public License
27  * along with Shark. If not, see <http://www.gnu.org/licenses/>.
28  *
29  */
30 //===========================================================================
31 
32 #ifndef SHARK_ALGORITHMS_DIRECT_SEARCH_MOEAD
33 #define SHARK_ALGORITHMS_DIRECT_SEARCH_MOEAD
34 
35 #include <shark/Core/DLLSupport.h>
41 
42 namespace shark {
43 
44 /**
45  * \brief Implements the MOEA/D algorithm.
46  *
47  * Implementation of the MOEA/D algorithm from the following paper:
48  * Q. Zhang and H. Li, MOEA/D: a multi-objective evolutionary algorithm based
49  * on decomposition, IEEE Transactions on Evolutionary Computation, vol. 11,
50  * no. 6, pp. 712 - 731, 2007
51  * DOI: 10.1109/TEVC.2007.892759
52  */
53 class MOEAD : public AbstractMultiObjectiveOptimizer<RealVector>
54 {
55 public:
56  SHARK_EXPORT_SYMBOL MOEAD(random::rng_type & rng = random::globalRng);
57 
58  std::string name() const{
59  return "MOEA/D";
60  }
61 
62  double crossoverProbability() const{
63  return m_crossoverProbability;
64  }
65 
67  return m_crossoverProbability;
68  }
69 
70  double nm() const{
71  return m_mutation.m_nm;
72  }
73 
74  double & nm(){
75  return m_mutation.m_nm;
76  }
77 
78  double nc() const{
79  return m_crossover.m_nc;
80  }
81 
82  double & nc(){
83  return m_crossover.m_nc;
84  }
85 
86  std::size_t mu() const{
87  return m_mu;
88  }
89 
90  std::size_t & mu(){
91  return m_mu;
92  }
93 
94  /// \brief The number of points used for initialization of the algorithm.
95  std::size_t numInitPoints() const{
96  return m_mu;
97  }
98 
99  std::size_t neighbourhoodSize() const{
100  return m_neighbourhoodSize;
101  }
102 
103  std::size_t & neighbourhoodSize(){
104  return m_neighbourhoodSize;
105  }
106 
107  template <typename Archive>
108  void serialize(Archive & archive)
109  {
110  archive & BOOST_SERIALIZATION_NVP(m_crossoverProbability);
111  archive & BOOST_SERIALIZATION_NVP(m_mu);
112  archive & BOOST_SERIALIZATION_NVP(m_parents);
113  archive & BOOST_SERIALIZATION_NVP(m_best);
114  archive & BOOST_SERIALIZATION_NVP(m_weights);
115  archive & BOOST_SERIALIZATION_NVP(m_neighbourhoods);
116  archive & BOOST_SERIALIZATION_NVP(m_neighbourhoodSize);
117  archive & BOOST_SERIALIZATION_NVP(m_bestDecomposedValues);
118  archive & BOOST_SERIALIZATION_NVP(m_crossover);
119  archive & BOOST_SERIALIZATION_NVP(m_mutation);
120  archive & BOOST_SERIALIZATION_NVP(m_curParentIndex);
121  }
122 
125  ObjectiveFunctionType const& function,
126  std::vector<SearchPointType> const & initialSearchPoints
127  );
128  SHARK_EXPORT_SYMBOL void step(ObjectiveFunctionType const & function);
129 protected:
132  std::vector<SearchPointType> const & initialSearchPoints,
133  std::vector<ResultType> const & functionValues,
134  RealVector const & lowerBounds,
135  RealVector const & upperBounds,
136  std::size_t const mu,
137  double const nm,
138  double const nc,
139  double const crossover_prob,
140  std::size_t const neighbourhoodSize,
141  std::vector<Preference> const & weightVectorPreferences = std::vector<Preference>()
142  );
143  // Make me an offspring...
144  SHARK_EXPORT_SYMBOL std::vector<IndividualType> generateOffspring() const;
145  SHARK_EXPORT_SYMBOL void updatePopulation(std::vector<IndividualType> const & offspringvec);
146 
147  std::vector<IndividualType> m_parents;
148 
149 private:
150  random::rng_type * mpe_rng;
151  double m_crossoverProbability; ///< Probability of crossover happening.
152  std::size_t m_mu; ///< Size of parent population and the "N" from the paper
153 
154  std::size_t m_curParentIndex;
155 
156  /// \brief Number of neighbours for each candidate to consider.
157  ///
158  /// This is the "T" from the paper.
159  std::size_t m_neighbourhoodSize;
160  RealMatrix m_weights; ///< The weight vectors. These are all the lambdas from the paper
161 
162  /// \brief Row n stores the indices of the T closest weight vectors.
163  ///
164  /// This is the "B" function from the paper.
165  UIntMatrix m_neighbourhoods;
166  RealVector m_bestDecomposedValues; ///< The "z" from the paper.
167 
169  PolynomialMutator m_mutation;
170 };
171 
172 
173 } // namespace shark
174 
175 #endif // SHARK_ALGORITHMS_DIRECT_SEARCH_MOEAD