PaGMO  1.1.5
island.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_ISLAND_H
26 #define PAGMO_ISLAND_H
27 
28 #include <string>
29 
30 #include "base_island.h"
31 #include "config.h"
32 #include "algorithm/base.h"
33 #include "migration/base_r_policy.h"
34 #include "migration/base_s_policy.h"
35 #include "migration/best_s_policy.h"
36 #include "migration/fair_r_policy.h"
37 #include "population.h"
38 #include "problem/base.h"
39 #include "serialization.h"
40 
41 // Forward declarations.
42 namespace pagmo {
43 
44 class island;
45 
46 }
47 
48 namespace boost { namespace serialization {
49 
50 template <class Archive>
51 void save_construct_data(Archive &, const pagmo::island *, const unsigned int);
52 
53 template <class Archive>
54 inline void load_construct_data(Archive &, pagmo::island *, const unsigned int);
55 
56 }}
57 
58 namespace pagmo
59 {
60 
62 
68 class __PAGMO_VISIBLE island: public base_island
69 {
70  public:
71  island(const island &);
72  explicit island(const algorithm::base &, const problem::base &, int = 0,
75  explicit island(const algorithm::base &, const population &,
78  island &operator=(const island &);
79  base_island_ptr clone() const;
80  protected:
85  void perform_evolution(const algorithm::base &, population &) const;
87  public:
90  std::string get_name() const;
92  private:
93  template <class Archive>
94  friend void boost::serialization::save_construct_data(Archive &, const island *, const unsigned int);
95  template <class Archive>
96  friend void boost::serialization::load_construct_data(Archive &, island *, const unsigned int);
97  friend class boost::serialization::access;
98  template <class Archive>
99  void serialize(Archive &ar, const unsigned int)
100  {
101  // Join will be done here already.
102  ar & boost::serialization::base_object<base_island>(*this);
103  }
104 };
105 
106 }
107 
108 namespace boost { namespace serialization {
109 
110 template <class Archive>
111 inline void save_construct_data(Archive &ar, const pagmo::island *isl, const unsigned int)
112 {
113  // Save data required to construct instance.
114  pagmo::algorithm::base_ptr algo = isl->m_algo->clone();
115  pagmo::problem::base_ptr prob = isl->m_pop.problem().clone();
116  ar << algo;
117  ar << prob;
118 }
119 
120 template <class Archive>
121 inline void load_construct_data(Archive &ar, pagmo::island *isl, const unsigned int)
122 {
123  // Retrieve data from archive required to construct new instance.
126  ar >> algo;
127  ar >> prob;
128  // Invoke inplace constructor to initialize instance of the algorithm.
129  ::new(isl)pagmo::island(*algo,*prob);
130 }
131 
132 }} //namespaces
133 
134 BOOST_CLASS_EXPORT_KEY(pagmo::island)
135 
136 #endif
boost::shared_ptr< base > base_ptr
Alias for shared pointer to base algorithm.
Root PaGMO namespace.
boost::shared_ptr< base > base_ptr
Alias for shared pointer to base problem.
Definition: problem/base.h:62
Base class for migration replacement policies.
Definition: base_r_policy.h:57
Base class for migration selection policies.
Definition: base_s_policy.h:54
Base algorithm class.
Local island class.
Definition: island.h:68
Base problem class.
Definition: problem/base.h:148
Population class.
Definition: population.h:70
"Choose best" migration selection policy.
Definition: best_s_policy.h:48
Fair replacement policy.
Definition: fair_r_policy.h:49
virtual base_ptr clone() const =0
Clone method.
algorithm::base_ptr m_algo
Algorithm.
Definition: base_island.h:159
Base island class.
Definition: base_island.h:81
boost::shared_ptr< base_island > base_island_ptr
Alias for the shared pointer to a pagmo::base_island.
Definition: base_island.h:49
population m_pop
Population.
Definition: base_island.h:161