PaGMO  1.1.5
problem/cstrs_co_evolution.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_PROBLEM_CSTRS_CO_EVOLUTION_H
26 #define PAGMO_PROBLEM_CSTRS_CO_EVOLUTION_H
27 
28 #include <string>
29 #include <boost/functional/hash.hpp>
30 #include <boost/serialization/map.hpp>
31 
32 #include "../serialization.h"
33 #include "../types.h"
34 #include "cec2006.h"
35 #include "base.h"
36 #include "base_meta.h"
37 #include "../algorithm/cstrs_co_evolution.h"
38 
41 
42 namespace pagmo{ namespace problem {
43 
45 
57 class __PAGMO_VISIBLE cstrs_co_evolution : public base_meta
58 {
59 public:
60  //constructors
61  cstrs_co_evolution(const base & = cec2006(4), const algorithm::cstrs_co_evolution::method_type = algorithm::cstrs_co_evolution::SIMPLE);
62  cstrs_co_evolution(const base &, const population&, const algorithm::cstrs_co_evolution::method_type = algorithm::cstrs_co_evolution::SIMPLE);
63 
64  base_ptr clone() const;
65  std::string get_name() const;
66 
67  void set_penalty_coeff(const std::vector<double> &);
68  int get_penalty_coeff_size();
69 
70 protected:
71  std::string human_readable_extra() const;
72  void objfun_impl(fitness_vector &, const decision_vector &) const;
73 
74 private:
75  void compute_penalty(std::vector<double> &, std::vector<int> &, const constraint_vector &) const;
76 
77 private:
78  friend class boost::serialization::access;
79  template <class Archive>
80  void serialize(Archive &ar, const unsigned int)
81  {
82  ar & boost::serialization::base_object<base>(*this);
83  ar & m_penalty_coeff;
84  ar & const_cast<algorithm::cstrs_co_evolution::method_type &>(m_method);
85  ar & m_map_fitness;
86  ar & m_map_constraint;
87  }
88 
89  std::vector<double> m_penalty_coeff;
90 
92 
93  //caches for fitness and constraints values to not recompute them
94  std::map<std::size_t, fitness_vector> m_map_fitness;
95  std::map<std::size_t, constraint_vector> m_map_constraint;
96 
97  // no need to serialize the hasher (and impossible)
98  boost::hash< std::vector<double> > m_decision_vector_hash;
99 };
100 
101 
102 //The cstrs_co_evolution_penalty cannot inherit from base_meta as the problem dimesnion changes
103 // and the constructor of base_meta uses set_bounds using the original problem dimension ....
104 class __PAGMO_VISIBLE cstrs_co_evolution_penalty : public base
105 {
106 public:
107 
108  //constructors
109  cstrs_co_evolution_penalty(const base & = cec2006(4), int dimension = 2, int size = 30);
110 
111  //copy constructor
112  cstrs_co_evolution_penalty(const cstrs_co_evolution_penalty &);
113  base_ptr clone() const;
114  std::string get_name() const;
115 
116  void update_penalty_coeff(population::size_type &, const decision_vector &, const population &);
117 
118 protected:
119  std::string human_readable_extra() const;
120  void objfun_impl(fitness_vector &, const decision_vector &) const;
121  bool compare_fitness_impl(const fitness_vector &, const fitness_vector &) const;
122 
123 private:
124  void compute_penalty(double &, int &, const decision_vector &) const;
125 
126 private:
127  friend class boost::serialization::access;
128  template <class Archive>
129  void serialize(Archive &ar, const unsigned int)
130  {
131  ar & boost::serialization::base_object<base>(*this);
132  ar & m_original_problem;
133  ar & m_pop_2_x_vector;
134  ar & m_feasible_count_vector;
135  ar & m_feasible_fitness_sum_vector;
136  ar & m_max_feasible_fitness;
137  ar & m_total_sum_viol;
138  ar & m_total_num_viol;
139  }
140  base_ptr m_original_problem;
141 
142  std::vector<decision_vector> m_pop_2_x_vector;
143 
144  // penalty coefficients
145  std::vector<int> m_feasible_count_vector;
146  std::vector<double> m_feasible_fitness_sum_vector;
147  double m_max_feasible_fitness;
148 
149  // penalty for infeasible
150  std::vector<double> m_total_sum_viol;
151  std::vector<int> m_total_num_viol;
152 };
153 }} //namespaces
154 
156 
157 BOOST_CLASS_EXPORT_KEY(pagmo::problem::cstrs_co_evolution)
158 BOOST_CLASS_EXPORT_KEY(pagmo::problem::cstrs_co_evolution_penalty)
159 
160 #endif // PAGMO_PROBLEM_cstrs_co_evolution_H
Root PaGMO namespace.
boost::shared_ptr< base > base_ptr
Alias for shared pointer to base problem.
Definition: problem/base.h:62
std::vector< double > decision_vector
Decision vector type.
Definition: types.h:40
std::vector< double > fitness_vector
Fitness vector type.
Definition: types.h:42
std::vector< double > constraint_vector
Constraint vector type.
Definition: types.h:44
container_type::size_type size_type
Population size type.
Definition: population.h:192