#include "Dmatrix.h"
|
std::vector< int64_t > | ids |
|
|
typedef std::vector< std::vector< double > > | Costs |
|
|
std::vector< double > & | operator[] (size_t i) |
|
const std::vector< double > & | operator[] (size_t i) const |
|
Definition at line 43 of file Dmatrix.h.
◆ Costs
◆ Dmatrix() [1/3]
pgrouting::tsp::Dmatrix::Dmatrix |
( |
| ) |
|
|
default |
◆ Dmatrix() [2/3]
pgrouting::tsp::Dmatrix::Dmatrix |
( |
const std::vector< Matrix_cell_t > & |
data_costs | ) |
|
|
explicit |
◆ Dmatrix() [3/3]
pgrouting::tsp::Dmatrix::Dmatrix |
( |
const std::map< std::pair< double, double >, int64_t > & |
euclidean_data | ) |
|
|
explicit |
Definition at line 136 of file Dmatrix.cpp.
137 ids.reserve(euclidean_data.size());
138 for (
const auto &e: euclidean_data) {
139 ids.push_back(e.second);
145 (std::numeric_limits<double>::max)()));
147 for (
const auto &from : euclidean_data) {
148 for (
const auto &to : euclidean_data) {
152 costs[to_id][from_id] =
costs[from_id][to_id];
156 for (
size_t i = 0; i <
costs.size(); ++i) {
References costs, pgrouting::tsp::get_distance(), get_index(), and ids.
◆ comparable_distance()
double pgrouting::tsp::Dmatrix::comparable_distance |
( |
size_t |
i, |
|
|
size_t |
j |
|
) |
| const |
|
inline |
◆ distance() [1/2]
double pgrouting::tsp::Dmatrix::distance |
( |
int64_t |
i, |
|
|
int64_t |
j |
|
) |
| const |
|
inline |
◆ distance() [2/2]
double pgrouting::tsp::Dmatrix::distance |
( |
size_t |
i, |
|
|
size_t |
j |
|
) |
| const |
|
inline |
◆ empty()
bool pgrouting::tsp::Dmatrix::empty |
( |
| ) |
const |
|
inline |
◆ get_id()
int64_t pgrouting::tsp::Dmatrix::get_id |
( |
size_t |
idx | ) |
const |
idx -> original id
- Parameters
-
[in] | idx | - index (i-th coordinate) |
- Returns
- the original id corresponding to idx
Definition at line 101 of file Dmatrix.cpp.
References ids.
Referenced by do_pgr_tsp().
◆ get_index()
size_t pgrouting::tsp::Dmatrix::get_index |
( |
int64_t |
id | ) |
const |
◆ get_row()
const std::vector<double>& pgrouting::tsp::Dmatrix::get_row |
( |
size_t |
idx | ) |
const |
|
inline |
returns a row of distances
- Parameters
-
- Returns
- distances from idx to all other coordinates
Definition at line 102 of file Dmatrix.h.
References costs.
◆ has_id()
bool pgrouting::tsp::Dmatrix::has_id |
( |
int64_t |
id | ) |
const |
◆ has_no_infinity()
bool pgrouting::tsp::Dmatrix::has_no_infinity |
( |
| ) |
const |
Definition at line 162 of file Dmatrix.cpp.
163 for (
const auto &row :
costs) {
164 for (
const auto &val : row) {
165 if (val == (std::numeric_limits<double>::infinity)())
return false;
166 if (val == (std::numeric_limits<double>::max)())
return false;
References costs.
Referenced by do_pgr_pickDeliver(), and do_pgr_tsp().
◆ is_symmetric()
bool pgrouting::tsp::Dmatrix::is_symmetric |
( |
| ) |
const |
Definition at line 193 of file Dmatrix.cpp.
194 for (
size_t i = 0; i <
costs.size(); ++i) {
195 for (
size_t j = 0; j <
costs.size(); ++j) {
196 if (0.000001 < std::fabs(
costs[i][j] -
costs[j][i])) {
197 std::ostringstream log;
200 <<
"costs[i][j] \t" <<
costs[i][j]
201 <<
"costs[j][i] \t" <<
costs[j][i]
References costs, and pgassertwm.
Referenced by do_pgr_tsp().
◆ obeys_triangle_inequality()
bool pgrouting::tsp::Dmatrix::obeys_triangle_inequality |
( |
| ) |
const |
Triangle Inequality Theorem.
The sum of the lengths of any two sides of a triangle is greater than the length of the third side. NOTE: can also be equal for streets costs[i][k] != inf costs[i][k] <= costs[i][j] + costs[j][k]
Definition at line 181 of file Dmatrix.cpp.
182 for (
size_t i = 0; i <
costs.size(); ++i) {
183 for (
size_t j = 0; j <
costs.size(); ++j) {
184 for (
size_t k = 0; k <
costs.size(); ++k) {
References costs.
◆ operator[]() [1/2]
std::vector< double >& pgrouting::tsp::Dmatrix::operator[] |
( |
size_t |
i | ) |
|
|
inlineprivate |
◆ operator[]() [2/2]
const std::vector< double >& pgrouting::tsp::Dmatrix::operator[] |
( |
size_t |
i | ) |
const |
|
inlineprivate |
◆ set()
void pgrouting::tsp::Dmatrix::set |
( |
size_t |
i, |
|
|
size_t |
j, |
|
|
double |
dist |
|
) |
| |
|
inline |
sets a special value for the distance(i,j)
- Parameters
-
[in] | i | - index in matrix |
[in] | j | - index in matrix |
[in] | dist | - distance from i to j & from j to i |
Definition at line 60 of file Dmatrix.h.
References costs.
Referenced by do_pgr_tsp().
◆ set_ids()
void pgrouting::tsp::Dmatrix::set_ids |
( |
const std::vector< matrix_cell > & |
data_costs | ) |
|
|
protected |
Definition at line 64 of file Dmatrix.cpp.
65 ids.reserve(data_costs.size() * 2);
66 for (
const auto &cost : data_costs) {
67 ids.push_back(cost.from_vid);
68 ids.push_back(cost.to_vid);
70 std::sort(
ids.begin(),
ids.end());
71 ids.erase(std::unique(
ids.begin(),
ids.end()),
ids.end());
References ids.
Referenced by Dmatrix().
◆ size()
size_t pgrouting::tsp::Dmatrix::size |
( |
| ) |
const |
|
inline |
◆ tourCost()
double pgrouting::tsp::Dmatrix::tourCost |
( |
const Tour & |
tour | ) |
const |
tour evaluation
- Parameters
-
- Returns
- total cost of traversing the tour
Definition at line 44 of file Dmatrix.cpp.
46 if (tour.cities.empty())
return total_cost;
48 auto prev_id = tour.cities.front();
49 for (
const auto &
id : tour.cities) {
50 if (
id == tour.cities.front())
continue;
54 total_cost +=
costs[prev_id][id];
57 total_cost +=
costs[prev_id][tour.cities.front()];
References pgrouting::tsp::Tour::cities, costs, distance(), and pgassert.
Referenced by do_pgr_tsp().
◆ operator<<
std::ostream& operator<< |
( |
std::ostream & |
log, |
|
|
const Dmatrix & |
matrix |
|
) |
| |
|
friend |
Definition at line 216 of file Dmatrix.cpp.
217 for (
const auto id : matrix.ids) {
222 for (
const auto &row : matrix.costs) {
224 for (
const auto cost : row) {
225 log <<
"Internal(" << i <<
"," << j <<
")"
226 <<
"\tUsers(" << matrix.ids[i] <<
"," << matrix.ids[j] <<
")"
229 <<
"\t(" << matrix.get_index(matrix.ids[i])
230 <<
"," << matrix.get_index(matrix.ids[j]) <<
")"
231 <<
"\t = " << matrix.costs[i][j]
232 <<
"\t = " << matrix.costs[j][i]
234 << (matrix.costs[i][j] ==
235 (std::numeric_limits<double>::infinity)())
237 << (matrix.costs[j][i] ==
238 (std::numeric_limits<double>::infinity)())
246 for (
size_t i = 0; i < matrix.costs.size(); ++i) {
247 for (
size_t j = 0; j < matrix.costs.size(); ++j) {
248 for (
size_t k = 0; k < matrix.costs.size(); ++k) {
249 log << matrix.costs[i][k] <<
" <= ("
250 << matrix.costs[i][j] <<
" + " << matrix.costs[j][k] <<
")"
251 << (matrix.costs[i][k]
252 <= (matrix.costs[i][j] + matrix.costs[j][k]))
◆ costs
Costs pgrouting::tsp::Dmatrix::costs |
|
private |
◆ ids
std::vector<int64_t> pgrouting::tsp::Dmatrix::ids |
|
protected |
The documentation for this class was generated from the following files: