PaGMO  1.1.5
pso_generational.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_GENERATIONAL_H
26 #define PAGMO_ALGORITHM_PSO_GENERATIONAL_H
27 
28 #include "../config.h"
29 #include "../serialization.h"
30 #include "base.h"
31 
32 
33 namespace pagmo { namespace algorithm {
34 
36 
52 class __PAGMO_VISIBLE pso_generational: public base
53 {
54 public:
55  pso_generational(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 );
56  base_ptr clone() const;
57  void evolve(population &) const;
58  std::string get_name() const;
59 protected:
60  std::string human_readable_extra() const;
61 private:
62  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;
63  void initialize_topology__gbest( const population &pop, decision_vector &gbX, fitness_vector &gbfit, std::vector< std::vector<int> > &neighb ) const;
64  void initialize_topology__lbest( std::vector< std::vector<int> > &neighb ) const;
65  void initialize_topology__von( std::vector< std::vector<int> > &neighb ) const;
66  void initialize_topology__adaptive_random( std::vector< std::vector<int> > &neighb ) const;
67 private:
68  friend class boost::serialization::access;
69  template <class Archive>
70  void serialize(Archive &ar, const unsigned int)
71  {
72  ar & boost::serialization::base_object<base>(*this);
73  ar & const_cast<int &>(m_gen);
74  ar & const_cast<double &>(m_omega);
75  ar & const_cast<double &>(m_eta1);
76  ar & const_cast<double &>(m_eta2);
77  ar & const_cast<double &>(m_vcoeff);
78  ar & const_cast<int &>(m_variant);
79  ar & const_cast<int &>(m_neighb_type);
80  ar & const_cast<int &>(m_neighb_param);
81  }
82  // Number of generations
83  const int m_gen;
84  // Particle Inertia weight, or alternatively the constriction coefficient
85  const double m_omega;
86  // magnitude of the force, applied to the particle's velocity, in the direction of its previous best position
87  const double m_eta1;
88  // magnitude of the force, applied to the particle's velocity, in the direction of the best position in its neighborhood
89  const double m_eta2;
90  // Velocity coefficient: velocity values will range in [ - var_range * m_vcoeff, var_range * m_vcoeff ]
91  const double m_vcoeff;
92  // Velocity update formula
93  const int m_variant;
94  // Swarm topology
95  const int m_neighb_type;
96  // parameterization of the swarm topology
97  const int m_neighb_param;
98 };
99 
100 }} //namespaces
101 
102 BOOST_CLASS_EXPORT_KEY(pagmo::algorithm::pso_generational)
103 
104 #endif // PAGMO_ALGORITHM_PSO_GENERATIONAL_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 generational.
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