PaGMO  1.1.5
pso_generational_racing.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_RACING_H
26 #define PAGMO_ALGORITHM_PSO_GENERATIONAL_RACING_H
27 
28 #include "../config.h"
29 #include "../serialization.h"
30 #include "base.h"
31 #include "../util/race_pop.h"
32 #include <limits>
33 
34 namespace pagmo { namespace algorithm {
35 
37 
43 class __PAGMO_VISIBLE pso_generational_racing: public base
44 {
45 public:
46  pso_generational_racing(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, unsigned int nr_eval_per_x = 5, unsigned int max_fevals = std::numeric_limits<unsigned int>::max());
47  base_ptr clone() const;
48  void evolve(population &) const;
49  std::string get_name() const;
50 protected:
51  std::string human_readable_extra() const;
52 private:
53  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;
54  void initialize_topology__gbest( const population &pop, decision_vector &gbX, fitness_vector &gbfit, std::vector< std::vector<int> > &neighb ) const;
55  void initialize_topology__lbest( std::vector< std::vector<int> > &neighb ) const;
56  void initialize_topology__von( std::vector< std::vector<int> > &neighb ) const;
57  void initialize_topology__adaptive_random( std::vector< std::vector<int> > &neighb ) const;
58 
59  // Handles the averaging of stochastic fitness
60  void particle__average_fitness(const problem::base &, fitness_vector &, const decision_vector &) const;
61  //void particle__average_fitness_set_best(const problem::base &, std::vector<fitness_vector &, const decision_vector &) const;
62  void particle__average_fitness_set_best(const problem::base &base, std::vector<fitness_vector> &F, population::size_type& best_idx, fitness_vector& best_fit, const std::vector<decision_vector> &X) const;
63 
64  // Helper routines for racing related features
65  decision_vector particle__racing_get_best_neighbor( population::size_type pidx, std::vector< std::vector<int> > &neighb, const std::vector<decision_vector> &lbX, util::racing::race_pop& ) const;
66  void racing__construct_race_environment( util::racing::race_pop & race_structure, const problem::base& prob, const std::vector<decision_vector> &x_list1, const std::vector<decision_vector> &x_list2 ) const;
67  std::pair<population::size_type, unsigned int> racing__race_for_winner( util::racing::race_pop &race_structure, int idx1, int idx2, unsigned int max_fevals) const;
68 
69 private:
70  friend class boost::serialization::access;
71  template <class Archive>
72  void serialize(Archive &ar, const unsigned int)
73  {
74  ar & boost::serialization::base_object<base>(*this);
75  ar & const_cast<int &>(m_gen);
76  ar & const_cast<double &>(m_omega);
77  ar & const_cast<double &>(m_eta1);
78  ar & const_cast<double &>(m_eta2);
79  ar & const_cast<double &>(m_vcoeff);
80  ar & const_cast<int &>(m_variant);
81  ar & const_cast<int &>(m_neighb_type);
82  ar & const_cast<int &>(m_neighb_param);
83  ar & m_fevals;
84  ar & const_cast<unsigned int&>(m_max_fevals);
85  }
86  // Number of generations
87  const int m_gen;
88  // Particle Inertia weight, or alternatively the constriction coefficient
89  const double m_omega;
90  // magnitude of the force, applied to the particle's velocity, in the direction of its previous best position
91  const double m_eta1;
92  // magnitude of the force, applied to the particle's velocity, in the direction of the best position in its neighborhood
93  const double m_eta2;
94  // Velocity coefficient: velocity values will range in [ - var_range * m_vcoeff, var_range * m_vcoeff ]
95  const double m_vcoeff;
96  // Velocity update formula
97  const int m_variant;
98  // Swarm topology
99  const int m_neighb_type;
100  // parameterization of the swarm topology
101  const int m_neighb_param;
102  // Parameter controlling how many times a stochastic objective function
103  // will be called for averaging
104  const unsigned int m_nr_eval_per_x;
105  // Incurred objective function evaluation
106  mutable unsigned int m_fevals;
107  // Maximum allowable fevals before algo terminates
108  const unsigned int m_max_fevals;
109 };
110 
111 }} //namespaces
112 
113 BOOST_CLASS_EXPORT_KEY(pagmo::algorithm::pso_generational_racing)
114 
115 #endif // PAGMO_ALGORITHM_PSO_GENERATIONAL_RACING_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 with racing.
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
Racing mechanism for a population.
Definition: race_pop.h:60