PaGMO  1.1.5
pso.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_PSO_H
26 #define PAGMO_ALGORITHM_PSO_H
27 
28 #include "../config.h"
29 #include "../serialization.h"
30 #include "base.h"
31 
32 
33 namespace pagmo { namespace algorithm {
34 
36 
75 class __PAGMO_VISIBLE pso: public base
76 {
77 public:
78  pso(int gen=1, double omega = 0.7298, double eta1 = 2.05, double eta2 = 2.05, double vcoeff = 0.5, int variant = 5, int neighb_type = 2, int neighb_param = 4 );
79  base_ptr clone() const;
80  void evolve(population &) const;
81  decision_vector particle__get_best_neighbor( population::size_type pidx, std::vector< std::vector<int> > &neighb, const std::vector<decision_vector> &lbX, const std::vector<fitness_vector> &lbfit, const problem::base &prob ) const;
82  void initialize_topology__gbest( const population &pop, decision_vector &gbX, fitness_vector &gbfit, std::vector< std::vector<int> > &neighb ) const;
83  void initialize_topology__lbest( std::vector< std::vector<int> > &neighb ) const;
84  void initialize_topology__von( std::vector< std::vector<int> > &neighb ) const;
85  void initialize_topology__adaptive_random( std::vector< std::vector<int> > &neighb ) const;
86  std::string get_name() const;
87 protected:
88  std::string human_readable_extra() const;
89 private:
90  friend class boost::serialization::access;
91  template <class Archive>
92  void serialize(Archive &ar, const unsigned int)
93  {
94  ar & boost::serialization::base_object<base>(*this);
95  ar & const_cast<int &>(m_gen);
96  ar & const_cast<double &>(m_omega);
97  ar & const_cast<double &>(m_eta1);
98  ar & const_cast<double &>(m_eta2);
99  ar & const_cast<double &>(m_vcoeff);
100  ar & const_cast<int &>(m_variant);
101  ar & const_cast<int &>(m_neighb_type);
102  ar & const_cast<int &>(m_neighb_param);
103  }
104  // Number of generations
105  const int m_gen;
106  // Particle Inertia weight, or alternatively the constriction coefficient
107  const double m_omega;
108  // magnitude of the force, applied to the particle's velocity, in the direction of its previous best position
109  const double m_eta1;
110  // magnitude of the force, applied to the particle's velocity, in the direction of the best position in its neighborhood
111  const double m_eta2;
112  // Velocity coefficient: velocity values will range in [ - var_range * m_vcoeff, var_range * m_vcoeff ]
113  const double m_vcoeff;
114  // Velocity update formula
115  const int m_variant;
116  // Swarm topology
117  const int m_neighb_type;
118  // parameterization of the swarm topology
119  const int m_neighb_param;
120 };
121 
122 }} //namespaces
123 
124 BOOST_CLASS_EXPORT_KEY(pagmo::algorithm::pso)
125 
126 #endif // PSO_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
Particle Swarm optimization.
Definition: pso.h:75
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
container_type::size_type size_type
Population size type.
Definition: population.h:192