Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions features/testbot/hints.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
@routing @testbot
Feature: Hints handling - incoming hints are ignored but still generated

Background:
Given the profile "testbot"
Given a grid size of 100 meters

Scenario: Normal routing works without hints
Given the node map
"""
a b
"""

And the ways
| nodes |
| ab |

When I route I should get
| from | to | route |
| a | b | ab,ab |
| b | a | ab,ab |

Scenario: Route with bogus hints is accepted and produces correct result
Given the node map
"""
a b
"""

And the ways
| nodes |
| ab |

Given the query options
| hints | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA;AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |

When I route I should get
| from | to | route | status |
| a | b | ab,ab | 200 |
| b | a | ab,ab | 200 |

Scenario: Route with empty hints parameter is accepted
Given the node map
"""
a b
"""

And the ways
| nodes |
| ab |

Given the query options
| hints | ; |

When I route I should get
| from | to | route | status |
| a | b | ab,ab | 200 |
| b | a | ab,ab | 200 |
44 changes: 2 additions & 42 deletions include/engine/plugins/plugin_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
#include "engine/status.hpp"

#include "util/coordinate.hpp"
#include "util/coordinate_calculation.hpp"
#include "util/format.hpp"

#include "util/integer_range.hpp"
#include "util/json_container.hpp"

Comment on lines 10 to 16
#include <algorithm>
#include <format>
#include <iterator>
#include <string>
#include <vector>
Expand Down Expand Up @@ -179,25 +179,11 @@ class BasePlugin
parameters.coordinates.size());
BOOST_ASSERT(radiuses.size() == parameters.coordinates.size());

const bool use_hints = !parameters.hints.empty();
const bool use_bearings = !parameters.bearings.empty();
const bool use_approaches = !parameters.approaches.empty();

for (const auto i : util::irange<std::size_t>(0UL, parameters.coordinates.size()))
{
if (use_hints && parameters.hints[i] && !parameters.hints[i]->segment_hints.empty() &&
parameters.hints[i]->IsValid(parameters.coordinates[i], facade))
{
for (const auto &seg_hint : parameters.hints[i]->segment_hints)
{
phantom_nodes[i].push_back(PhantomNodeWithDistance{
seg_hint.phantom,
util::coordinate_calculation::greatCircleDistance(
parameters.coordinates[i], seg_hint.phantom.location)});
}
continue;
}

phantom_nodes[i] = facade.NearestPhantomNodesInRange(
parameters.coordinates[i],
radiuses[i],
Comment on lines 185 to 189
Expand All @@ -218,27 +204,13 @@ class BasePlugin
std::vector<std::vector<PhantomNodeWithDistance>> phantom_nodes(
parameters.coordinates.size());

const bool use_hints = !parameters.hints.empty();
const bool use_bearings = !parameters.bearings.empty();
const bool use_radiuses = !parameters.radiuses.empty();
const bool use_approaches = !parameters.approaches.empty();

BOOST_ASSERT(parameters.IsValid());
for (const auto i : util::irange<std::size_t>(0UL, parameters.coordinates.size()))
{
if (use_hints && parameters.hints[i] && !parameters.hints[i]->segment_hints.empty() &&
parameters.hints[i]->IsValid(parameters.coordinates[i], facade))
{
for (const auto &seg_hint : parameters.hints[i]->segment_hints)
{
phantom_nodes[i].push_back(PhantomNodeWithDistance{
seg_hint.phantom,
util::coordinate_calculation::greatCircleDistance(
parameters.coordinates[i], seg_hint.phantom.location)});
}
continue;
}

phantom_nodes[i] = facade.NearestPhantomNodes(
parameters.coordinates[i],
number_of_results,
Expand All @@ -262,7 +234,6 @@ class BasePlugin
{
std::vector<PhantomCandidateAlternatives> alternatives(parameters.coordinates.size());

const bool use_hints = !parameters.hints.empty();
const bool use_bearings = !parameters.bearings.empty();
const bool use_radiuses = !parameters.radiuses.empty();
const bool use_approaches = !parameters.approaches.empty();
Expand All @@ -271,17 +242,6 @@ class BasePlugin
BOOST_ASSERT(parameters.IsValid());
for (const auto i : util::irange<std::size_t>(0UL, parameters.coordinates.size()))
{
if (use_hints && parameters.hints[i] && !parameters.hints[i]->segment_hints.empty() &&
parameters.hints[i]->IsValid(parameters.coordinates[i], facade))
{
std::transform(parameters.hints[i]->segment_hints.begin(),
parameters.hints[i]->segment_hints.end(),
std::back_inserter(alternatives[i].first),
[](const auto &seg_hint) { return seg_hint.phantom; });
// we don't set the second one - it will be marked as invalid
continue;
}

alternatives[i] = facade.NearestCandidatesWithAlternativeFromBigComponent(
parameters.coordinates[i],
use_radiuses ? parameters.radiuses[i] : default_radius,
Expand Down
Loading