PaGMO  1.1.5
nspso.h
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 #ifndef PAGMO_ALGORITHM_NSPSO_H
26 #define PAGMO_ALGORITHM_NSPSO_H
27 
28 #include "../config.h"
29 #include "../serialization.h"
30 #include "base.h"
31 
32 namespace pagmo { namespace algorithm {
33 
35 
51 class __PAGMO_VISIBLE nspso: public base
52 {
53 public:
56  CROWDING_DISTANCE=0,
57  NICHE_COUNT=1,
58  MAXMIN=2
59  };
60  nspso(int gen=100, double minW = 0.4, double maxW = 1.0, double C1 = 2.0, double C2 = 2.0,
61  double CHI = 1.0, double v_coeff = 0.5, int leader_selection_range = 10, diversity_mechanism_type = CROWDING_DISTANCE);
62 
63  base_ptr clone() const;
64  void evolve(population &) const;
65  std::string get_name() const;
66 
67 protected:
68  std::string human_readable_extra() const;
69 
70 private:
71  struct one_dim_fit_comp {
72  one_dim_fit_comp(const std::vector<fitness_vector> &fit, fitness_vector::size_type dim):m_fit(fit),m_dim(dim){};
73  bool operator()(const population::size_type& idx1, const population::size_type& idx2) const
74  {
75  return m_fit[idx1][m_dim] < m_fit[idx2][m_dim];
76  }
77  const std::vector<fitness_vector>& m_fit;
78  fitness_vector::size_type m_dim;
79  };
80 
81  struct crowding_pareto_comp{
82  crowding_pareto_comp(const std::vector<population::size_type> &pareto_rank, const std::vector<double> &crowding_d):m_pareto_rank(pareto_rank),m_crowding_d(crowding_d){};
83  bool operator()(const population::size_type& idx1, const population::size_type& idx2) const
84  {
85  if (m_pareto_rank[idx1] == m_pareto_rank[idx2]) {
86  return (m_crowding_d[idx1] > m_crowding_d[idx2]);
87  }
88  else {
89  return (m_pareto_rank[idx1] < m_pareto_rank[idx2]);
90  }
91  }
92  const std::vector<population::size_type> &m_pareto_rank;
93  const std::vector<double> &m_crowding_d;
94  };
95 
96  struct nspso_individual {
97  decision_vector cur_x;
98  decision_vector best_x;
99  decision_vector cur_v;
100  fitness_vector cur_f;
101  fitness_vector best_f;
102  constraint_vector cur_c;
103  constraint_vector best_c;
104  };
105 
106 
107  double minfit(unsigned int, unsigned int, const std::vector<fitness_vector> &) const;
108  void compute_maxmin(std::vector<double> &, const std::vector<fitness_vector> &) const;
109  void compute_niche_count(std::vector<int> &, const std::vector<std::vector<double> > &, double) const;
110  double euclidian_distance(const std::vector<double> &, const std::vector<double> &) const;
111  std::vector<std::vector<population::size_type> > compute_domination_list(const pagmo::problem::base &,
112  const std::vector<fitness_vector> &,
113  const std::vector<constraint_vector> &) const;
114  std::vector<population::size_type> compute_domination_count(const std::vector<std::vector<population::size_type> > &) const;
115  std::vector<population::size_type> compute_pareto_rank(const std::vector<std::vector<population::size_type> > &) const;
116  std::vector<std::vector<population::size_type> > compute_pareto_fronts(const std::vector<population::size_type> &) const;
117  std::vector<std::vector<population::size_type> > compute_pareto_fronts(const pagmo::problem::base &,
118  const std::vector<fitness_vector> &,
119  const std::vector<constraint_vector> &) const;
120  std::vector<double> compute_crowding_d(const std::vector<fitness_vector> &, const std::vector<std::vector<population::size_type> > &) const;
121  fitness_vector compute_ideal(const std::vector<fitness_vector> &, const std::vector<population::size_type> &) const;
122  fitness_vector compute_nadir(const std::vector<fitness_vector> &, const std::vector<population::size_type> &) const;
123 
124  friend class boost::serialization::access;
125  template <class Archive>
126  void serialize(Archive &ar, const unsigned int)
127  {
128  ar & boost::serialization::base_object<base>(*this);
129  ar & const_cast<int &>(m_gen);
130  ar & const_cast<double &>(m_minW);
131  ar & const_cast<double &>(m_maxW);
132  ar & const_cast<double &>(m_C1);
133  ar & const_cast<double &>(m_C2);
134  ar & const_cast<double &>(m_CHI);
135  ar & const_cast<double &>(m_v_coeff);
136  ar & const_cast<int &>(m_leader_selection_range);
137  ar & const_cast<diversity_mechanism_type &>(m_diversity_mechanism);
138 
139  }
140  //Number of generations
141  const int m_gen;
142  const double m_minW;
143  const double m_maxW;
144  const double m_C1;
145  const double m_C2;
146  const double m_CHI;
147  const double m_v_coeff;
148  const int m_leader_selection_range;
149  const diversity_mechanism_type m_diversity_mechanism;
150 
151 };
152 
153 }} //namespaces
154 
155 BOOST_CLASS_EXPORT_KEY(pagmo::algorithm::nspso)
156 
157 #endif // PAGMO_ALGORITHM_NSPSO_H
boost::shared_ptr< base > base_ptr
Alias for shared pointer to base algorithm.
Root PaGMO namespace.
std::vector< double > decision_vector
Decision vector type.
Definition: types.h:40
Base algorithm class.
Base problem class.
Definition: problem/base.h:148
Population class.
Definition: population.h:70
std::vector< double > fitness_vector
Fitness vector type.
Definition: types.h:42
diversity_mechanism_type
Mechanism used to asses diversity.
Definition: nspso.h:55
std::vector< double > constraint_vector
Constraint vector type.
Definition: types.h:44
container_type::size_type size_type
Population size type.
Definition: population.h:192
Non-dominated Sorting Particle Swarm Optimizer (NSPSO)
Definition: nspso.h:51