PaGMO  1.1.5
base_tsp.h
1 /*****************************************************************************
2  * Copyright (C) 2004-2014 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_TSP_H
26 #define PAGMO_PROBLEM_BASE_TSP_H
27 
28 #include <vector>
29 
30 #include "./base.h"
31 #include "../serialization.h"
32 #include "../population.h"
33 
34 namespace pagmo { namespace problem {
35 
37 
64 class __PAGMO_VISIBLE base_tsp: public base
65 {
66  public:
69  RANDOMKEYS = 0,
70  FULL = 1,
71  CITIES = 2
72  };
73 
74  base_tsp(int n_cities, int nc, int nic, encoding_type = CITIES);
75 
78  encoding_type get_encoding() const;
79  decision_vector::size_type get_n_cities() const;
81 
84  pagmo::decision_vector full2cities(const pagmo::decision_vector &) const;
85  pagmo::decision_vector cities2full(const pagmo::decision_vector &) const;
86  pagmo::decision_vector randomkeys2cities(const pagmo::decision_vector &) const;
87  pagmo::decision_vector cities2randomkeys(const pagmo::decision_vector &, const pagmo::decision_vector &) const;
89 
90  // Pure virtual method returning the distance between cities
91  virtual double distance(decision_vector::size_type, decision_vector::size_type) const = 0;
92 
93  private:
94  friend class boost::serialization::access;
95  template <class Archive>
96  void serialize(Archive &ar, const unsigned int)
97  {
98  ar & boost::serialization::base_object<base>(*this);
99  ar & const_cast<encoding_type &>(m_encoding);
100  ar & const_cast<pagmo::decision_vector::size_type &>(m_n_cities);
101  }
102 
103  private:
104  const encoding_type m_encoding;
105  const pagmo::decision_vector::size_type m_n_cities;
106 };
107 
108 }} //namespaces
109 
110 BOOST_SERIALIZATION_ASSUME_ABSTRACT(pagmo::problem::base_tsp)
111 
112 #endif //PAGMO_PROBLEM_BASE_TSP_H
Root PaGMO namespace.
std::vector< double > decision_vector
Decision vector type.
Definition: types.h:40
Base problem class.
Definition: problem/base.h:148
encoding_type
Mechanism used to encode the sequence of vertices to be visited.
Definition: base_tsp.h:68
Base TSP (Travelling Salesman Problem).
Definition: base_tsp.h:64