PaGMO  1.1.5
base_meta.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_BASE_META_H
26 #define PAGMO_PROBLEM_BASE_META_H
27 
28 #include <string>
29 
30 #include "../serialization.h"
31 #include "ackley.h"
32 #include "../types.h"
33 #include "base.h"
34 
35 namespace pagmo{ namespace problem {
36 
38 
50 class __PAGMO_VISIBLE base_meta : public base
51 {
52  public:
54  base_meta(const base &p = ackley(1), int n=1, int ni=0, int nf=1, int nc=0, int nic=0, const std::vector<double>&c_tol = std::vector<double>()):
55  base(n,ni,nf,nc,nic,c_tol), m_original_problem(p.clone()) {
56  //Setting the bounds according to the original problem
57  set_bounds(m_original_problem->get_lb(),m_original_problem->get_ub());
58  }
60  base_meta(const base_meta &p):base(p), m_original_problem(p.m_original_problem->clone()) {}
61  protected:
62  bool compare_fitness_impl(const fitness_vector &f1, const fitness_vector &f2) const
63  {return m_original_problem->compare_fitness_impl(f1,f2);}
64  //NOTE: It is not possible to use the same trick for the other two virtual compares as they also depend from
65  //the class parameter m_ic_dimension which in m_original_problem may be different than in the meta problem
67  {return m_original_problem->compare_constraints_impl(c1,c2);}
68  bool compare_fc_impl(const fitness_vector &f1, const constraint_vector &c1, const fitness_vector &f2, const constraint_vector &c2) const
69  {return m_original_problem->compare_fc_impl(f1,c1,f2,c2);}
70  private:
71  friend class boost::serialization::access;
72  template <class Archive>
73  void serialize(Archive &ar, const unsigned int)
74  {
75  ar & boost::serialization::base_object<base>(*this);
76  ar & m_original_problem;
77  }
78  protected:
81 };
82 
83 }} //namespaces
84 
85 BOOST_CLASS_EXPORT_KEY(pagmo::problem::base_meta)
86 
87 #endif // PAGMO_PROBLEM_BASE_META_H
Root PaGMO namespace.
boost::shared_ptr< base > base_ptr
Alias for shared pointer to base problem.
Definition: problem/base.h:62
bool compare_fc_impl(const fitness_vector &f1, const constraint_vector &c1, const fitness_vector &f2, const constraint_vector &c2) const
Implementation of simultaneous fitness-constraint comparison.
Definition: base_meta.h:68
Base problem class.
Definition: problem/base.h:148
Meta=problems base class.
Definition: base_meta.h:50
bool compare_constraints_impl(const constraint_vector &c1, const constraint_vector &c2) const
Implementation of constraint vector comparison.
Definition: base_meta.h:66
std::vector< double > fitness_vector
Fitness vector type.
Definition: types.h:42
std::vector< double > constraint_vector
Constraint vector type.
Definition: types.h:44
base_meta(const base &p=ackley(1), int n=1, int ni=0, int nf=1, int nc=0, int nic=0, const std::vector< double > &c_tol=std::vector< double >())
Constructor.
Definition: base_meta.h:54
base_meta(const base_meta &p)
Copy constructor.
Definition: base_meta.h:60
bool compare_fitness_impl(const fitness_vector &f1, const fitness_vector &f2) const
Implementation of fitness vectors comparison.
Definition: base_meta.h:62
The Ackley problem.
Definition: ackley.h:51
base_ptr m_original_problem
Smart pointer to the original problem instance.
Definition: base_meta.h:80