vrpRouting  0.3
base_matrix.h
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 
3 FILE: matrix.h
4 
5 Copyright (c) 2015 pgRouting developers
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 
28 #ifndef INCLUDE_CPP_COMMON_BASE_MATRIX_H_
29 #define INCLUDE_CPP_COMMON_BASE_MATRIX_H_
30 #pragma once
31 
32 #include <iosfwd>
33 #include <vector>
34 #include <map>
35 #include <utility>
36 #include <cstdint>
37 
38 #include "c_types/typedefs.h"
40 
41 #include "structures/generic/matrix.h"
42 
44 
45 namespace vrprouting {
46 namespace base {
47 
48 
61 class Base_Matrix {
62  public:
64  Base_Matrix() = default;
67  Base_Matrix(Vroom_matrix_t *, size_t, const Identifiers<Id> &, double);
68  explicit Base_Matrix(const std::map<std::pair<Coordinate, Coordinate>, Id> &, Multiplier);
69 
74  bool has_no_infinity() const;
75 
76  vroom::Matrix<vroom::Duration> get_vroom_duration_matrix() const;
77  vroom::Matrix<vroom::Cost> get_vroom_cost_matrix() const;
78 
80  bool obeys_triangle_inequality() const;
81  size_t fix_triangle_inequality(size_t depth = 0);
82 
84  bool empty() const {return m_ids.empty();}
85 
90  size_t size() const {return m_ids.size();}
91 
93  bool is_symmetric() const;
94 
97  TInterval at(Idx i, Idx j) const {return m_time_matrix[i][j];}
98 
99 
101  friend std::ostream& operator<<(
102  std::ostream &log,
103  const Base_Matrix &matrix);
104 
106  bool has_id(Id) const;
107 
109  Idx get_index(Id) const;
110 
112  Id get_original_id(Idx) const;
113 
114  private:
116  void set_ids(const std::vector<Matrix_cell_t> &);
117 
120  std::vector<Id> m_ids;
121 
126  std::vector<std::vector<TInterval>> m_time_matrix;
127 
132  std::vector<std::vector<TravelCost>> m_cost_matrix;
133 };
134 
135 } // namespace base
136 } // namespace vrprouting
137 
138 #endif // INCLUDE_CPP_COMMON_BASE_MATRIX_H_
vrprouting::base::Base_Matrix::get_original_id
Id get_original_id(Idx) const
original id -> idx
Definition: base_matrix.cpp:202
vrprouting::base::Base_Matrix::Base_Matrix
Base_Matrix()=default
Constructs an emtpy matrix.
vrprouting::base::Base_Matrix::get_index
Idx get_index(Id) const
original id -> idx
Definition: base_matrix.cpp:161
vrprouting::base::Base_Matrix::m_cost_matrix
std::vector< std::vector< TravelCost > > m_cost_matrix
the cost matrix for vroom
Definition: base_matrix.h:132
vrprouting::base::Base_Matrix::empty
bool empty() const
is the matrix empty?
Definition: base_matrix.h:84
vrprouting::base::Base_Matrix::set_ids
void set_ids(const std::vector< Matrix_cell_t > &)
Traverses the matrix information to set the ids of the nodes.
Definition: base_matrix.cpp:85
vrprouting::base::Base_Matrix::get_vroom_duration_matrix
vroom::Matrix< vroom::Duration > get_vroom_duration_matrix() const
Get VROOM duration matrix from vrprouting Base Matrix.
Definition: base_matrix.cpp:404
vrprouting::base::Base_Matrix::operator<<
friend std::ostream & operator<<(std::ostream &log, const Base_Matrix &matrix)
print matrix (row per cell)
Definition: base_matrix.cpp:567
Id
int64_t Id
Definition: typedefs.h:78
vrprouting::base::Base_Matrix::size
size_t size() const
|idx|
Definition: base_matrix.h:90
typedefs.h
vrprouting::base::Base_Matrix::has_no_infinity
bool has_no_infinity() const
does the matrix values not given by the user?
Definition: base_matrix.cpp:459
vrprouting::base::Base_Matrix::m_ids
std::vector< Id > m_ids
DATA.
Definition: base_matrix.h:120
vrprouting::base::Base_Matrix::fix_triangle_inequality
size_t fix_triangle_inequality(size_t depth=0)
Fix Triangle Inequality Theorem.
Definition: base_matrix.cpp:508
Vroom_matrix_t
Matrix's attributes.
Definition: vroom_matrix_t.h:46
Idx
uint64_t Idx
Definition: typedefs.h:79
Matrix_cell_t
traveling costs
Definition: matrix_cell_t.h:41
vrprouting::base::Base_Matrix::m_time_matrix
std::vector< std::vector< TInterval > > m_time_matrix
the actual time matrix
Definition: base_matrix.h:126
vrprouting::base::Base_Matrix
N x N matrix.
Definition: base_matrix.h:61
vrprouting::base::Base_Matrix::has_id
bool has_id(Id) const
has identifier
Definition: base_matrix.cpp:126
TInterval
int64_t TInterval
Definition: typedefs.h:72
Multiplier
double Multiplier
Definition: typedefs.h:77
vrprouting::base::Base_Matrix::at
TInterval at(Idx i, Idx j) const
Definition: base_matrix.h:97
vrprouting::base::Base_Matrix::is_symmetric
bool is_symmetric() const
is the matrix symetric?
Definition: base_matrix.cpp:524
vrprouting::base::Base_Matrix::get_vroom_cost_matrix
vroom::Matrix< vroom::Cost > get_vroom_cost_matrix() const
Get VROOM cost matrix from vrprouting Base Matrix.
Definition: base_matrix.cpp:421
identifiers.hpp
Identifiers
Definition: identifiers.hpp:51
vrprouting::base::Base_Matrix::obeys_triangle_inequality
bool obeys_triangle_inequality() const
does the matrix obeys the triangle inequality?
Definition: base_matrix.cpp:487
vrprouting
Definition: base_matrix.cpp:46