PaGMO  1.1.5
sga.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_SGA_H
26 #define PAGMO_ALGORITHM_SGA_H
27 
28 #include "../config.h"
29 #include "../problem/base.h"
30 #include "../serialization.h"
31 #include "base.h"
32 
33 namespace pagmo { namespace algorithm {
34 
36 
53 class __PAGMO_VISIBLE sga: public base
54 {
55 public:
57  struct selection {
59  enum type {BEST20 = 0,ROULETTE = 1};
60  };
62  struct mutation {
64  enum type {GAUSSIAN = 0, RANDOM = 1};
66 
72  mutation(mutation::type t, double width) : m_type(t),m_width(width) {}
76  double m_width;
77  private:
78  friend class boost::serialization::access;
79  template <class Archive>
80  void serialize(Archive &ar, const unsigned int)
81  {
82  ar & m_type;
83  ar & m_width;
84  }
85  };
86 
88  struct crossover {
90  enum type {BINOMIAL = 0, EXPONENTIAL = 1};
91  };
92  sga(int gen = 1, const double &cr = .95, const double &m = .02, int elitism = 1,
93  mutation::type mut = mutation::GAUSSIAN, double width = 0.1,
94  selection::type sel = selection::ROULETTE,
95  crossover::type cro = crossover::EXPONENTIAL);
96  base_ptr clone() const;
97  void evolve(population &) const;
98  std::string get_name() const;
99 protected:
100  std::string human_readable_extra() const;
101 private:
102  friend class boost::serialization::access;
103  template <class Archive>
104  void serialize(Archive &ar, const unsigned int)
105  {
106  ar & boost::serialization::base_object<base>(*this);
107  ar & const_cast<int &>(m_gen);
108  ar & const_cast<double &>(m_cr);
109  ar & const_cast<double &>(m_m);
110  ar & const_cast<int &>(m_elitism);
111  ar & const_cast<mutation &>(m_mut);
112  ar & const_cast<selection::type &>(m_sel);
113  ar & const_cast<crossover::type &>(m_cro);
114  }
115  //Number of generations
116  const int m_gen;
117  //Crossover rate
118  const double m_cr;
119  //Mutation rate
120  const double m_m;
121 
122  //Elitism (number of generations after which to reinsert the best)
123  const int m_elitism;
124  //Mutation
125  const mutation m_mut;
126  //Selection_type
127  const selection::type m_sel;
128  //Crossover_type
129  const crossover::type m_cro;
130 };
131 
132 }} //namespaces
133 
134 BOOST_CLASS_EXPORT_KEY(pagmo::algorithm::sga)
135 
136 #endif // PAGMO_ALGORITHM_SGA_H
boost::shared_ptr< base > base_ptr
Alias for shared pointer to base algorithm.
Root PaGMO namespace.
type
Selection type, best 20% or roulette.
Definition: sga.h:59
Selection info.
Definition: sga.h:57
Base algorithm class.
type
Crossover type, binomial or exponential.
Definition: sga.h:90
Population class.
Definition: population.h:70
double m_width
Mutation width.
Definition: sga.h:76
Crossover operator info.
Definition: sga.h:88
type
Mutation type, gaussian or random.
Definition: sga.h:64
The Simple Genetic Algorithm (SGA)
Definition: sga.h:53
type m_type
Mutation type.
Definition: sga.h:74
Mutation operator info.
Definition: sga.h:62
mutation(mutation::type t, double width)
Constructor.
Definition: sga.h:72