PGROUTING  2.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Dmatrix.h
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 
3 FILE: Dmatrix.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_DMATRIX_H_
27 #define SRC_TSP_SRC_DMATRIX_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 
40 class Dmatrix {
41  public:
42  Dmatrix() = default;
43  explicit Dmatrix(const std::vector < Matrix_cell_t > &data_costs);
44 
45  bool has_no_infinity() const;
46  bool obeys_triangle_inequality() const;
47  bool is_symmetric() const;
48 
56  void set(size_t i, size_t j, double dist) {
57  costs[i][j] = costs[j][i] = dist;}
58 
64  bool has_id(int64_t id) const;
65 
71  size_t get_index(int64_t id) const;
72 
78  int64_t get_id(size_t idx) const;
79 
84  size_t size() const {return ids.size();}
85 
91  double tourCost(const Tour &tour) const;
92 
98  const std::vector<double>& get_row(size_t idx) const {
99  return costs[idx];}
100 
101  double comparable_distance(size_t i, size_t j) const {
102  return distance(i, j);}
103 
104  double distance(size_t i, size_t j) const {
105  return costs[i][j];}
106 
107  friend std::ostream& operator<<(
108  std::ostream &log,
109  const Dmatrix &matrix);
110 
111  protected:
112  void set_ids(const std::vector<matrix_cell> &data_costs);
113  std::vector<int64_t> ids;
114 
115  private:
116  typedef std::vector < std::vector < double > > Costs;
118  std::vector< double >& operator[] (size_t i) {return costs[i];}
119  const std::vector< double >& operator[] (size_t i) const {return costs[i];}
120 };
121 
122 } // namespace tsp
123 } // namespace pgrouting
124 
125 #endif // SRC_TSP_SRC_DMATRIX_H_
std::vector< std::vector< double > > Costs
Definition: Dmatrix.h:116
bool is_symmetric() const
Definition: Dmatrix.cpp:147
bool obeys_triangle_inequality() const
Definition: Dmatrix.cpp:128
size_t size() const
|idx|
Definition: Dmatrix.h:84
void set_ids(const std::vector< matrix_cell > &data_costs)
Definition: Dmatrix.cpp:63
std::vector< int64_t > ids
Definition: Dmatrix.h:113
std::vector< double > & operator[](size_t i)
Definition: Dmatrix.h:118
const std::vector< double > & get_row(size_t idx) const
returns a row of distances
Definition: Dmatrix.h:98
int64_t get_id(size_t idx) const
idx -> original id
Definition: Dmatrix.cpp:91
bool has_no_infinity() const
Definition: Dmatrix.cpp:116
double tourCost(const Tour &tour) const
tour evaluation
Definition: Dmatrix.cpp:43
bool has_id(int64_t id) const
original id -> true
Definition: Dmatrix.cpp:78
size_t get_index(int64_t id) const
original id -> idx
Definition: Dmatrix.cpp:85
double comparable_distance(size_t i, size_t j) const
Definition: Dmatrix.h:101
void set(size_t i, size_t j, double dist)
sets a special value for the distance(i,j)
Definition: Dmatrix.h:56
double distance(size_t i, size_t j) const
Definition: Dmatrix.h:104
friend std::ostream & operator<<(std::ostream &log, const Dmatrix &matrix)
Definition: Dmatrix.cpp:167