25 #ifndef PAGMO_POPULATION_H
26 #define PAGMO_POPULATION_H
35 #include "problem/base.h"
37 #include "serialization.h"
45 struct population_access;
49 typedef boost::shared_ptr<base>
base_ptr;
73 friend struct population_access;
102 std::ostringstream oss;
103 oss <<
"\tDecision vector:\t\t" << cur_x <<
'\n';
104 oss <<
"\tVelocity vector:\t\t" << cur_v <<
'\n';
105 oss <<
"\tConstraint vector:\t\t" << cur_c <<
'\n';
106 oss <<
"\tFitness vector:\t\t\t" << cur_f <<
'\n';
107 oss <<
"\tBest decision vector:\t\t" << best_x <<
'\n';
108 oss <<
"\tBest constraint vector:\t\t" << best_c <<
'\n';
109 oss <<
"\tBest fitness vector:\t\t" << best_f <<
'\n';
113 friend class boost::serialization::access;
114 template <
class Archive>
115 void save(Archive &ar,
const unsigned int version)
const
125 template <
class Archive>
126 void load(Archive &ar,
const unsigned int version)
136 template <
class Archive>
137 void serialize(Archive &ar,
const unsigned int version)
139 boost::serialization::split_member(ar,*
this,version);
160 std::ostringstream oss;
161 oss <<
"\tDecision vector:\t" << x <<
'\n';
162 oss <<
"\tConstraints vector:\t" << c <<
'\n';
163 oss <<
"\tFitness vector:\t\t" << f <<
'\n';
167 friend class boost::serialization::access;
168 template <
class Archive>
169 void save(Archive &ar,
const unsigned int version)
const
175 template <
class Archive>
176 void load(Archive &ar,
const unsigned int version)
182 template <
class Archive>
183 void serialize(Archive &ar,
const unsigned int version)
185 boost::serialization::split_member(ar,*
this,version);
197 static boost::uint32_t getSeed(){
198 return rng_generator::get<rng_uint32>()();
202 const individual_type &get_individual(
const size_type &)
const;
205 const std::vector<size_type> &get_domination_list(
const size_type &)
const;
206 size_type get_domination_count(
const size_type &)
const;
207 size_type get_pareto_rank(
const size_type &)
const;
208 double get_crowding_d(
const size_type &)
const;
209 void update_pareto_information()
const;
210 size_type n_dominated(
const individual_type &)
const;
211 std::vector<std::vector<size_type> > compute_pareto_fronts()
const;
216 const champion_type &champion()
const;
217 std::string human_readable_terse()
const;
218 std::string human_readable()
const;
219 size_type get_best_idx()
const;
220 std::vector<size_type> get_best_idx(
const size_type & N)
const;
221 size_type get_worst_idx()
const;
225 void erase(
const size_type &);
226 size_type size()
const;
227 const_iterator begin()
const;
228 const_iterator end()
const;
230 void reinit(
const size_type &);
233 double mean_velocity()
const;
239 std::pair<std::vector<population::size_type>,
unsigned int> race(
const size_type n_final,
240 const unsigned int min_trials = 0,
241 const unsigned int max_count = 1000,
243 const std::vector<size_type>& = std::vector<size_type>(),
244 const bool race_best =
true,
245 const bool screen_output =
false)
const;
247 struct crowded_comparison_operator {
248 crowded_comparison_operator(
const population &);
249 bool operator()(
const individual_type &i1,
const individual_type &i2)
const;
250 bool operator()(
const size_type &idx1,
const size_type &idx2)
const;
254 struct trivial_comparison_operator {
255 trivial_comparison_operator(
const population &);
256 bool operator()(
const individual_type &i1,
const individual_type &i2)
const;
257 bool operator()(
const size_type &idx1,
const size_type &idx2)
const;
258 const population &m_pop;
262 void init_velocity(
const size_type &);
263 void update_champion(
const size_type &);
266 void update_crowding_d(std::vector<size_type>)
const;
269 void update_dom(
const size_type &);
273 friend class boost::serialization::access;
274 template <
class Archive>
275 void serialize(Archive &ar,
const unsigned int)
292 container_type m_container;
294 std::vector<std::vector<size_type> > m_dom_list;
296 std::vector<size_type> m_dom_count;
299 champion_type m_champion;
301 mutable std::vector<size_type> m_pareto_rank;
303 mutable std::vector<double> m_crowding_d;
305 mutable rng_double m_drng;
307 mutable rng_uint32 m_urng;
311 __PAGMO_VISIBLE_FUNC std::ostream &
operator<<(std::ostream &,
const population &);
313 __PAGMO_VISIBLE_FUNC std::ostream &
operator<<(std::ostream &,
const population::individual_type &);
315 __PAGMO_VISIBLE_FUNC std::ostream &
operator<<(std::ostream &,
const population::champion_type &);
317 struct __PAGMO_VISIBLE population_access
324 namespace boost {
namespace serialization {
326 template <
class Archive>
327 inline void save_construct_data(Archive &ar,
const pagmo::population *pop,
const unsigned int)
334 template <
class Archive>
335 inline void load_construct_data(Archive &ar,
pagmo::population *pop,
const unsigned int)
341 ::new(pop)
pagmo::population(*prob);
boost::shared_ptr< base > base_ptr
Alias for shared pointer to base algorithm.
boost::shared_ptr< base > base_ptr
Alias for shared pointer to base problem.
std::vector< double > decision_vector
Decision vector type.
fitness_vector cur_f
Current fitness vector.
void custom_vector_double_save(Archive &ar, const std::vector< double > &v, const unsigned int)
Custom save function for the serialization of vector of doubles that handle also inf and NaN...
std::ostream & operator<<(std::ostream &s, const archipelago &a)
Overload stream operator for pagmo::archipelago.
constraint_vector cur_c
Current constraint vector.
Individuals stored in the population.
decision_vector x
Decision vector.
fitness_vector f
Fitness vector.
std::vector< individual_type > container_type
Underlying container type.
virtual base_ptr clone() const =0
Clone method.
std::string human_readable() const
Human-readable representation.
void custom_vector_double_load(Archive &ar, std::vector< double > &v, const unsigned int)
Custom load function for the serialization of vector of doubles that handle also inf and NaN...
fitness_vector best_f
Best fitness vector so far.
std::vector< double > fitness_vector
Fitness vector type.
std::string human_readable() const
Human-readable representation.
std::vector< double > constraint_vector
Constraint vector type.
container_type::const_iterator const_iterator
Const iterator.
decision_vector cur_v
Current velocity vector.
constraint_vector c
Constraint vector.
container_type::size_type size_type
Population size type.
decision_vector cur_x
Current decision vector.
constraint_vector best_c
Best constraint vector so far.
decision_vector best_x
Best decision vector so far.