Skip to content

Commit 189f8c3

Browse files
author
Moritz Kobitzsch
committed
move summaries to car profile, test for references, use boost adaptors
1 parent 12238eb commit 189f8c3

File tree

5 files changed

+132
-54
lines changed

5 files changed

+132
-54
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
- Changes from 5.4.0-rc.5
33
- Bugfixes
44
- fixed a bug where polyline decoding on a defective polyline could end up in out-of-bound access on a vector
5+
- Guidance
6+
- Summaries have been improved to consider references as well
57

68
# 5.4.0-rc.5
79
- Changes from 5.4.0-rc.4

features/car/summaries.feature

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
@routing @basic @car
2+
Feature: Basic Routing
3+
4+
Background:
5+
Given the profile "car"
6+
Given a grid size of 500 meters
7+
8+
@smallest
9+
Scenario: Summaries when routing on a simple network
10+
Given the node map
11+
| b | | | f |
12+
| | | | |
13+
| c | d | | g |
14+
| | | | |
15+
| a | | e | |
16+
17+
And the ways
18+
| nodes | name |
19+
| acb | road |
20+
| de | 1 st |
21+
| cd | |
22+
| dg | blvd |
23+
| df | street |
24+
25+
When I route I should get
26+
| waypoints | route | summary |
27+
| a,e | road,,1 st,1 st | road,1 st |
28+
| a,d,f | road,,,street,street | road;street |
29+
| a,e,f | road,,1 st,1 st,1 st,street,street | road,1 st;1 st,street |
30+
31+
Scenario: Name Empty
32+
Given the node map
33+
| a | | b | | | c |
34+
35+
And the ways
36+
| nodes | name |
37+
| ab | road |
38+
| bc | |
39+
40+
When I route I should get
41+
| waypoints | route | summary |
42+
| a,c | road, | road |
43+
44+
Scenario: Name Empty But Ref
45+
Given the node map
46+
| a | | b | | | c |
47+
48+
And the ways
49+
| nodes | name | ref |
50+
| ab | road | |
51+
| bc | | 101 |
52+
53+
When I route I should get
54+
| waypoints | route | summary |
55+
| a,c | road, | road,101 |
56+
57+
Scenario: Only Refs
58+
Given the node map
59+
| a | | b | | | c |
60+
61+
And the ways
62+
| nodes | name | ref |
63+
| ab | | 100 |
64+
| bc | | 101 |
65+
66+
When I route I should get
67+
| waypoints | route | summary |
68+
| a,c | , | 100,101 |
69+
70+
Scenario: Single Ref
71+
Given the node map
72+
| a | | b | | | c |
73+
74+
And the ways
75+
| nodes | name | ref |
76+
| ab | | |
77+
| bc | | 101 |
78+
79+
When I route I should get
80+
| waypoints | route | summary |
81+
| a,c | ,, | 101 |
82+
83+
Scenario: Nothing
84+
Given the node map
85+
| a | | b | | | c |
86+
87+
And the ways
88+
| nodes | name |
89+
| ab | |
90+
| bc | |
91+
92+
When I route I should get
93+
| waypoints | route | summary |
94+
| a,c | , | |

features/testbot/summaries.feature

Lines changed: 0 additions & 29 deletions
This file was deleted.

features/testbot/summary.feature

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ Feature: Basic Routing
1818
| de |
1919

2020
When I route I should get
21-
| from | to | route | summary |
22-
| a | e | ab,bc,cd,de,de | ab, bc |
23-
| e | a | de,cd,bc,ab,ab | de, bc |
24-
| a | b | ab,ab | ab |
25-
| b | d | bc,cd,cd | bc, cd |
26-
| 1 | c | bc,bc | bc |
21+
| from | to | route | summary |
22+
| a | e | ab,bc,cd,de,de | ab,bc |
23+
| e | a | de,cd,bc,ab,ab | de,bc |
24+
| a | b | ab,ab | ab |
25+
| b | d | bc,cd,cd | bc,cd |
26+
| 1 | c | bc,bc | bc |
2727

2828
@smallest
2929
Scenario: Check handling empty values
@@ -40,8 +40,8 @@ Feature: Basic Routing
4040
| df | df |
4141

4242
When I route I should get
43-
| from | to | route | summary |
44-
| e | a | de,,bc,ab,ab | de, bc |
43+
| from | to | route | summary |
44+
| e | a | de,,bc,ab,ab | de,bc |
4545

4646
@smallest @todo
4747
Scenario: Summaries when routing on a simple network
@@ -53,9 +53,9 @@ Feature: Basic Routing
5353
| ab |
5454

5555
When I route I should get
56-
| from | to | route | summary |
57-
| a | b | ab,ab | ab |
58-
| b | a | ab,ab | ab |
56+
| from | to | route | summary |
57+
| a | b | ab,ab | ab |
58+
| b | a | ab,ab | ab |
5959

6060
@repeated
6161
Scenario: Check handling empty values
@@ -74,6 +74,6 @@ Feature: Basic Routing
7474
| xey | cross |we need this because phantom node segments are not considered for the summary |
7575

7676
When I route I should get
77-
| from | to | route | summary |
78-
| a | 1 | first,first,second,second | first, second |
77+
| from | to | route | summary |
78+
| a | 1 | first,first,second,second | first,second |
7979

include/engine/guidance/assemble_leg.hpp

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
#include "engine/guidance/route_leg.hpp"
77
#include "engine/guidance/route_step.hpp"
88
#include "engine/internal_route_result.hpp"
9+
#include "util/typedefs.hpp"
10+
911
#include <boost/algorithm/string/join.hpp>
12+
#include <boost/range/adaptor/filtered.hpp>
13+
#include <boost/range/adaptor/transformed.hpp>
1014

1115
#include <cstddef>
1216
#include <cstdint>
@@ -108,7 +112,7 @@ std::array<std::uint32_t, SegmentNumber> summarizeRoute(const std::vector<PathDa
108112
});
109113

110114
std::array<std::uint32_t, SegmentNumber> summary;
111-
std::fill(summary.begin(), summary.end(), 0);
115+
std::fill(summary.begin(), summary.end(), EMPTY_NAMEID);
112116
std::transform(segments.begin(),
113117
segments.end(),
114118
summary.begin(),
@@ -173,21 +177,28 @@ inline RouteLeg assembleLeg(const datafacade::BaseDataFacade &facade,
173177
{
174178
auto summary_array = detail::summarizeRoute<detail::MAX_USED_SEGMENTS>(
175179
route_data, target_node, target_traversed_in_reverse);
176-
if (route_data.empty())
177-
summary_array[0] = source_node.name_id;
178180

179181
BOOST_ASSERT(detail::MAX_USED_SEGMENTS > 0);
180182
BOOST_ASSERT(summary_array.begin() != summary_array.end());
181-
std::vector<std::string> summary_names;
182-
for (auto nameIt = summary_array.begin(), end = summary_array.end(); nameIt != end; ++nameIt)
183-
{
184-
auto name = facade.GetNameForID(* nameIt);
185-
name = name.empty() ? facade.GetRefForID(* nameIt) : name;
183+
184+
// transform a name_id into a string containing either the name, or -if the name is empty-
185+
// the reference.
186+
const auto name_id_to_string = [&](const NameID name_id) {
187+
const auto name = facade.GetNameForID(name_id);
186188
if (!name.empty())
187-
summary_names.push_back(name);
188-
}
189-
BOOST_ASSERT(summary_names.size() =< MAX_USED_SEGMENTS);
190-
summary = boost::algorithm::join(summary_names, ", ");
189+
return name;
190+
else
191+
{
192+
const auto ref = facade.GetRefForID(name_id);
193+
return ref;
194+
}
195+
};
196+
197+
const auto not_empty = [&](const std::string &name) { return !name.empty(); };
198+
199+
const auto summary_names = summary_array | boost::adaptors::transformed(name_id_to_string) |
200+
boost::adaptors::filtered(not_empty);
201+
summary = boost::algorithm::join(summary_names, ",");
191202
}
192203

193204
return RouteLeg{duration, distance, summary, {}};

0 commit comments

Comments
 (0)