PGROUTING  2.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
eucledianDmatrix.h
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 
3 FILE: eucledianDmatrix.h
4 
5 Copyright (c) 2015 pgRouting developers
6 Mail: project@pgrouting.org
7 
8 ------
9 
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14 
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 
24  ********************************************************************PGR-GNU*/
25 
26 #ifndef SRC_TSP_SRC_EUCLEDIANDMATRIX_H_
27 #define SRC_TSP_SRC_EUCLEDIANDMATRIX_H_
28 #pragma once
29 
30 #include <iostream>
31 #include <vector>
32 
33 #include "../../common/src/pgr_types.h"
34 
35 namespace pgrouting {
36 namespace tsp {
37 
38 class Tour; // for tourCost
39 
41  public:
42  eucledianDmatrix() = default;
43  explicit eucledianDmatrix(
44  const std::vector< Coordinate_t > &data_coordinates);
45 
46  bool has_no_infinity() const;
47  bool obeys_triangle_inequality() const;
48  bool is_symmetric() const;
49 
57  void set(size_t i, size_t j, double dist) {
58  row = i; column = j; special_distance = dist;}
59 
66  bool has_id(int64_t id) const;
67 
73  size_t get_index(int64_t id) const;
74 
80  int64_t get_id(size_t idx) const;
81 
86  size_t size() const {return ids.size();}
87 
93  double tourCost(const Tour &tour) const;
94 
101  const std::vector<double> get_row(size_t idx) const;
102 
103  double comparable_distance(size_t i, size_t j) const;
104  double distance(size_t i, size_t j) const;
105 
106  friend std::ostream& operator<<(
107  std::ostream &log,
108  const eucledianDmatrix &matrix);
109 
110  protected:
111  void set_ids();
112  std::vector<int64_t> ids;
113 
114  private:
115  std::vector < Coordinate_t > coordinates;
116  size_t row;
117  size_t column;
119 };
120 
121 } // namespace tsp
122 } // namespace pgrouting
123 
124 #endif // SRC_TSP_SRC_EUCLEDIANDMATRIX_H_
int64_t get_id(size_t idx) const
idx -> original id
double comparable_distance(size_t i, size_t j) const
double tourCost(const Tour &tour) const
tour evaluation
const std::vector< double > get_row(size_t idx) const
returns a row of distances
std::vector< Coordinate_t > coordinates
friend std::ostream & operator<<(std::ostream &log, const eucledianDmatrix &matrix)
size_t get_index(int64_t id) const
original id -> idx
void set(size_t i, size_t j, double dist)
sets a special value for the distance(i,j)
bool has_id(int64_t id) const
original id -> true
double distance(size_t i, size_t j) const