handle trips with identical coordinates
This commit is contained in:
parent
8ed6bb8a1b
commit
46c936b48e
@ -108,4 +108,17 @@ Feature: Basic trip planning
|
|||||||
| waypoints | trips |
|
| waypoints | trips |
|
||||||
| 1,2 | |
|
| 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 | |
|
||||||
|
|
||||||
|
@ -168,9 +168,11 @@ std::vector<NodeID> FarthestInsertionTrip(const NodeIDIterator &start,
|
|||||||
if (static_cast<std::size_t>(component_size) == number_of_locations)
|
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
|
// find the pair of location with the biggest distance and make the pair the initial start
|
||||||
// trip
|
// trip. Skipping over the very first element (0,0), we make sure not to end up with the
|
||||||
const auto index = std::distance(
|
// same start/end in the special case where all entries are the same.
|
||||||
std::begin(dist_table), std::max_element(std::begin(dist_table), std::end(dist_table)));
|
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_from = index / number_of_locations;
|
||||||
max_to = 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)
|
for (auto y = start; y != end; ++y)
|
||||||
{
|
{
|
||||||
|
// don't repeat coordinates
|
||||||
|
if (*x == *y)
|
||||||
|
continue;
|
||||||
|
|
||||||
const auto xy_dist = dist_table(*x, *y);
|
const auto xy_dist = dist_table(*x, *y);
|
||||||
// SCC decomposition done correctly?
|
// SCC decomposition done correctly?
|
||||||
BOOST_ASSERT(xy_dist != INVALID_EDGE_WEIGHT);
|
BOOST_ASSERT(xy_dist != INVALID_EDGE_WEIGHT);
|
||||||
|
|
||||||
if (xy_dist > max_dist)
|
if (xy_dist >= max_dist)
|
||||||
{
|
{
|
||||||
max_dist = xy_dist;
|
max_dist = xy_dist;
|
||||||
max_from = *x;
|
max_from = *x;
|
||||||
|
Loading…
Reference in New Issue
Block a user