Don't snap to avoided streets

This commit is contained in:
Patrick Niklaus 2017-07-28 13:59:48 +00:00 committed by Patrick Niklaus
parent 960a595268
commit 97952a9289
2 changed files with 40 additions and 10 deletions

View File

@ -59,7 +59,7 @@ Feature: Testbot - Avoid flags
| from | to | route | | from | to | route |
| a | d | | | a | d | |
| a | g | | | a | g | |
| a | c | ab,bc,bc | | a | c | |
| a | f | | | a | f | |
| f | d | fg,gd,gd | | f | d | fg,gd,gd |

View File

@ -57,7 +57,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
auto results = rtree.Nearest( auto results = rtree.Nearest(
input_coordinate, input_coordinate,
[this, approach, &input_coordinate](const CandidateSegment &segment) { [this, approach, &input_coordinate](const CandidateSegment &segment) {
return boolPairAnd(HasValidEdge(segment), return boolPairAnd(boolPairAnd(HasValidEdge(segment), CheckSegmentAvoid(segment)),
CheckApproach(input_coordinate, segment, approach)); CheckApproach(input_coordinate, segment, approach));
}, },
[this, max_distance, input_coordinate](const std::size_t, [this, max_distance, input_coordinate](const std::size_t,
@ -81,8 +81,9 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
input_coordinate, input_coordinate,
[this, approach, &input_coordinate, bearing, bearing_range, max_distance]( [this, approach, &input_coordinate, bearing, bearing_range, max_distance](
const CandidateSegment &segment) { const CandidateSegment &segment) {
auto use_direction = boolPairAnd( auto use_direction =
CheckSegmentBearing(segment, bearing, bearing_range), HasValidEdge(segment)); boolPairAnd(CheckSegmentBearing(segment, bearing, bearing_range),
boolPairAnd(HasValidEdge(segment), CheckSegmentAvoid(segment)));
use_direction = use_direction =
boolPairAnd(use_direction, CheckApproach(input_coordinate, segment, approach)); boolPairAnd(use_direction, CheckApproach(input_coordinate, segment, approach));
return use_direction; return use_direction;
@ -108,8 +109,9 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
input_coordinate, input_coordinate,
[this, approach, &input_coordinate, bearing, bearing_range]( [this, approach, &input_coordinate, bearing, bearing_range](
const CandidateSegment &segment) { const CandidateSegment &segment) {
auto use_direction = boolPairAnd( auto use_direction =
CheckSegmentBearing(segment, bearing, bearing_range), HasValidEdge(segment)); boolPairAnd(CheckSegmentBearing(segment, bearing, bearing_range),
boolPairAnd(HasValidEdge(segment), CheckSegmentAvoid(segment)));
return boolPairAnd(use_direction, return boolPairAnd(use_direction,
CheckApproach(input_coordinate, segment, approach)); CheckApproach(input_coordinate, segment, approach));
}, },
@ -135,8 +137,9 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
input_coordinate, input_coordinate,
[this, approach, &input_coordinate, bearing, bearing_range]( [this, approach, &input_coordinate, bearing, bearing_range](
const CandidateSegment &segment) { const CandidateSegment &segment) {
auto use_direction = boolPairAnd( auto use_direction =
CheckSegmentBearing(segment, bearing, bearing_range), HasValidEdge(segment)); boolPairAnd(CheckSegmentBearing(segment, bearing, bearing_range),
boolPairAnd(HasValidEdge(segment), CheckSegmentAvoid(segment)));
return boolPairAnd(use_direction, return boolPairAnd(use_direction,
CheckApproach(input_coordinate, segment, approach)); CheckApproach(input_coordinate, segment, approach));
}, },
@ -159,7 +162,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
auto results = rtree.Nearest( auto results = rtree.Nearest(
input_coordinate, input_coordinate,
[this, approach, &input_coordinate](const CandidateSegment &segment) { [this, approach, &input_coordinate](const CandidateSegment &segment) {
return boolPairAnd(HasValidEdge(segment), return boolPairAnd(boolPairAnd(HasValidEdge(segment), CheckSegmentAvoid(segment)),
CheckApproach(input_coordinate, segment, approach)); CheckApproach(input_coordinate, segment, approach));
}, },
[max_results](const std::size_t num_results, const CandidateSegment &) { [max_results](const std::size_t num_results, const CandidateSegment &) {
@ -180,7 +183,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
auto results = rtree.Nearest( auto results = rtree.Nearest(
input_coordinate, input_coordinate,
[this, approach, &input_coordinate](const CandidateSegment &segment) { [this, approach, &input_coordinate](const CandidateSegment &segment) {
return boolPairAnd(HasValidEdge(segment), return boolPairAnd(boolPairAnd(HasValidEdge(segment), CheckSegmentAvoid(segment)),
CheckApproach(input_coordinate, segment, approach)); CheckApproach(input_coordinate, segment, approach));
}, },
[this, max_distance, max_results, input_coordinate](const std::size_t num_results, [this, max_distance, max_results, input_coordinate](const std::size_t num_results,
@ -209,6 +212,8 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
(!has_small_component || (!has_big_component && !IsTinyComponent(segment))); (!has_small_component || (!has_big_component && !IsTinyComponent(segment)));
auto use_directions = std::make_pair(use_segment, use_segment); auto use_directions = std::make_pair(use_segment, use_segment);
const auto valid_edges = HasValidEdge(segment); const auto valid_edges = HasValidEdge(segment);
const auto admissible_segments = CheckSegmentAvoid(segment);
use_directions = boolPairAnd(use_directions, admissible_segments);
use_directions = boolPairAnd(use_directions, valid_edges); use_directions = boolPairAnd(use_directions, valid_edges);
use_directions = use_directions =
boolPairAnd(use_directions, CheckApproach(input_coordinate, segment, approach)); boolPairAnd(use_directions, CheckApproach(input_coordinate, segment, approach));
@ -254,6 +259,8 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
auto use_directions = std::make_pair(use_segment, use_segment); auto use_directions = std::make_pair(use_segment, use_segment);
const auto valid_edges = HasValidEdge(segment); const auto valid_edges = HasValidEdge(segment);
const auto admissible_segments = CheckSegmentAvoid(segment);
use_directions = boolPairAnd(use_directions, admissible_segments);
use_directions = boolPairAnd(use_directions, valid_edges); use_directions = boolPairAnd(use_directions, valid_edges);
use_directions = use_directions =
boolPairAnd(use_directions, CheckApproach(input_coordinate, segment, approach)); boolPairAnd(use_directions, CheckApproach(input_coordinate, segment, approach));
@ -302,6 +309,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
auto use_segment = auto use_segment =
(!has_small_component || (!has_big_component && !IsTinyComponent(segment))); (!has_small_component || (!has_big_component && !IsTinyComponent(segment)));
auto use_directions = std::make_pair(use_segment, use_segment); auto use_directions = std::make_pair(use_segment, use_segment);
const auto admissible_segments = CheckSegmentAvoid(segment);
use_directions = boolPairAnd(use_directions, HasValidEdge(segment)); use_directions = boolPairAnd(use_directions, HasValidEdge(segment));
if (use_segment) if (use_segment)
@ -309,6 +317,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
use_directions = use_directions =
boolPairAnd(CheckSegmentBearing(segment, bearing, bearing_range), boolPairAnd(CheckSegmentBearing(segment, bearing, bearing_range),
HasValidEdge(segment)); HasValidEdge(segment));
use_directions = boolPairAnd(use_directions, admissible_segments);
use_directions = boolPairAnd( use_directions = boolPairAnd(
use_directions, CheckApproach(input_coordinate, segment, approach)); use_directions, CheckApproach(input_coordinate, segment, approach));
@ -358,6 +367,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
auto use_segment = auto use_segment =
(!has_small_component || (!has_big_component && !IsTinyComponent(segment))); (!has_small_component || (!has_big_component && !IsTinyComponent(segment)));
auto use_directions = std::make_pair(use_segment, use_segment); auto use_directions = std::make_pair(use_segment, use_segment);
const auto admissible_segments = CheckSegmentAvoid(segment);
use_directions = boolPairAnd(use_directions, HasValidEdge(segment)); use_directions = boolPairAnd(use_directions, HasValidEdge(segment));
if (use_segment) if (use_segment)
@ -365,6 +375,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
use_directions = use_directions =
boolPairAnd(CheckSegmentBearing(segment, bearing, bearing_range), boolPairAnd(CheckSegmentBearing(segment, bearing, bearing_range),
HasValidEdge(segment)); HasValidEdge(segment));
use_directions = boolPairAnd(use_directions, admissible_segments);
use_directions = boolPairAnd( use_directions = boolPairAnd(
use_directions, CheckApproach(input_coordinate, segment, approach)); use_directions, CheckApproach(input_coordinate, segment, approach));
@ -528,6 +539,25 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
max_distance; max_distance;
} }
std::pair<bool, bool> CheckSegmentAvoid(const CandidateSegment &segment) const
{
std::pair<bool, bool> valid = {true, true};
if (segment.data.forward_segment_id.enabled &&
datafacade.AvoidNode(segment.data.forward_segment_id.id))
{
valid.first = false;
}
if (segment.data.reverse_segment_id.enabled &&
datafacade.AvoidNode(segment.data.reverse_segment_id.id))
{
valid.second = false;
}
return valid;
}
std::pair<bool, bool> CheckSegmentBearing(const CandidateSegment &segment, std::pair<bool, bool> CheckSegmentBearing(const CandidateSegment &segment,
const int filter_bearing, const int filter_bearing,
const int filter_bearing_range) const const int filter_bearing_range) const