handle trips with identical coordinates

This commit is contained in:
Moritz Kobitzsch 2016-10-17 13:24:42 +02:00 committed by Huyen Chau Nguyen
parent 8ed6bb8a1b
commit 46c936b48e
2 changed files with 23 additions and 4 deletions

View File

@ -108,4 +108,17 @@ Feature: Basic trip planning
| waypoints | trips |
| 1,2 | |
Scenario: Testbot - Repeated Coordinate
Given the node map
"""
a b
"""
And the ways
| nodes |
| ab |
When I plan a trip I should get
| waypoints | trips |
| a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a | |

View File

@ -168,9 +168,11 @@ std::vector<NodeID> FarthestInsertionTrip(const NodeIDIterator &start,
if (static_cast<std::size_t>(component_size) == number_of_locations)
{
// find the pair of location with the biggest distance and make the pair the initial start
// trip
const auto index = std::distance(
std::begin(dist_table), std::max_element(std::begin(dist_table), std::end(dist_table)));
// trip. Skipping over the very first element (0,0), we make sure not to end up with the
// same start/end in the special case where all entries are the same.
const auto index =
std::distance(std::begin(dist_table),
std::max_element(std::begin(dist_table) + 1, std::end(dist_table)));
max_from = index / number_of_locations;
max_to = index % number_of_locations;
}
@ -182,11 +184,15 @@ std::vector<NodeID> FarthestInsertionTrip(const NodeIDIterator &start,
{
for (auto y = start; y != end; ++y)
{
// don't repeat coordinates
if (*x == *y)
continue;
const auto xy_dist = dist_table(*x, *y);
// SCC decomposition done correctly?
BOOST_ASSERT(xy_dist != INVALID_EDGE_WEIGHT);
if (xy_dist > max_dist)
if (xy_dist >= max_dist)
{
max_dist = xy_dist;
max_from = *x;