Skip to content

Commit 279f8aa

Browse files
TheMarexPatrick Niklaus
authored and
Patrick Niklaus
committed
Allow specifing a weight for routing that is independent of duration
1 parent e463733 commit 279f8aa

File tree

85 files changed

+2085
-838
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+2085
-838
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# 6.0.0
2+
- Profiles:
3+
- `turn_function` now does not return an integer but takes in a `turn` object and modifies it
4+
- `uturn_penalty` is deprecated set it over the `turn_function`
5+
- traffic light penalties now need to be set over the node function, `traffic_light_penalty` is deprecated:
6+
result.weight_penalty and result.duration_penalty
7+
18
# 5.6.0
29
- Changes from 5.5
310
- Bugfixes

features/car/traffic_speeds.feature

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

features/options/contract/invalid.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ Feature: osrm-contract command line options: invalid options
2424
Scenario: osrm-contract - Someone forgot --generate-edge-lookup on osrm-extract
2525
When I try to run "osrm-contract --segment-speed-file /dev/null {processed_file}"
2626
Then stderr should contain "Error while trying to mmap"
27-
Then stderr should contain ".osrm.edge_penalties"
27+
Then stderr should contain ".osrm.turn_penalties_index"
2828
And it should exit with an error

features/options/profiles/version0.feature

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ end
2727
Scenario: Out-bound API version
2828
Given the profile file
2929
"""
30-
api_version = 1
30+
api_version = 2
3131
"""
3232
And the node map
3333
"""
@@ -55,6 +55,7 @@ properties.max_speed_for_map_matching = 180/3.6
5555
properties.use_turn_restrictions = true
5656
properties.continue_straight_at_waypoint = true
5757
properties.left_hand_driving = false
58+
properties.weight_name = 'duration'
5859
5960
function node_function (node, result)
6061
print ('node_function ' .. node:id())
@@ -71,7 +72,7 @@ end
7172
7273
function turn_function (angle)
7374
print('turn_function ' .. angle)
74-
return angle == 0 and 0 or 42
75+
return angle == 0 and 0 or 17
7576
end
7677
7778
function segment_function (source, target, distance, weight)
@@ -101,6 +102,6 @@ end
101102

102103
When I route I should get
103104
| from | to | route | time |
104-
| a | b | ac,cb,cb | 19.2s |
105-
| a | d | ac,cd,cd | 19.2s |
105+
| a | b | ac,cb,cb | 16.7s |
106+
| a | d | ac,cd,cd | 16.7s |
106107
| a | e | ac,ce,ce | 20s |
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
Feature: Profile API version 1
2+
3+
Background:
4+
Given a grid size of 100 meters
5+
6+
Scenario: Basic profile function calls and property values
7+
Given the profile file
8+
"""
9+
api_version = 1
10+
11+
-- set profile properties
12+
properties.max_speed_for_map_matching = 180/3.6
13+
properties.use_turn_restrictions = true
14+
properties.continue_straight_at_waypoint = true
15+
properties.weight_name = 'test_version1'
16+
17+
function node_function (node, result)
18+
print ('node_function ' .. node:id())
19+
end
20+
21+
function way_function(way, result)
22+
result.name = way:get_value_by_key('name')
23+
result.weight = 10
24+
result.forward_mode = mode.driving
25+
result.backward_mode = mode.driving
26+
result.forward_speed = 36
27+
result.backward_speed = 36
28+
print ('way_function ' .. way:id() .. ' ' .. result.name)
29+
end
30+
31+
function turn_function (turn)
32+
print('turn_function', turn.angle, turn.turn_type, turn.direction_modifier, turn.has_traffic_light)
33+
turn.weight = turn.angle == 0 and 0 or 4.2
34+
turn.duration = turn.weight
35+
end
36+
37+
function segment_function (segment)
38+
print ('segment_function ' .. segment.source.lon .. ' ' .. segment.source.lat)
39+
end
40+
"""
41+
And the node map
42+
"""
43+
a
44+
bcd
45+
e
46+
"""
47+
And the ways
48+
| nodes |
49+
| ac |
50+
| cb |
51+
| cd |
52+
| ce |
53+
And the data has been saved to disk
54+
55+
When I run "osrm-extract --profile {profile_file} {osm_file}"
56+
Then it should exit successfully
57+
And stdout should contain "node_function"
58+
And stdout should contain "way_function"
59+
And stdout should contain "turn_function"
60+
And stdout should contain "segment_function"
61+
62+
When I route I should get
63+
| from | to | route | time |
64+
| a | b | ac,cb,cb | 19.2s |
65+
| a | d | ac,cd,cd | 19.2s |
66+
| a | e | ac,ce,ce | 20s |

features/support/route.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,21 @@ module.exports = function () {
164164
};
165165

166166
this.annotationList = (instructions) => {
167-
function zip(list_1, list_2, list_3)
167+
if (!('annotation' in instructions.legs[0]))
168+
return '';
169+
170+
function zip(list_1, list_2, list_3, list_4)
168171
{
169172
let tuples = [];
170-
for (let i = 0; i < list_1.length; ++i) {
171-
tuples.push([list_1[i], list_2[i], list_3[i]]);
173+
for (let i = 0; i < list_1.length; ++i) {
174+
tuples.push([list_1[i], list_2[i], list_3[i], list_4[i]]);
172175
}
173176
return tuples;
174177
}
175-
return instructions.legs.map(l => {return zip(l.annotation.duration, l.annotation.distance, l.annotation.datasources).map(p => { return p.join(':'); }).join(','); }).join(',');
178+
return instructions.legs.map(l => {
179+
const values = zip( l.annotation.weight, l.annotation.duration, l.annotation.distance, l.annotation.datasources);
180+
return values.map(p => { return p.join(':'); }).join(',');
181+
}).join(',');
176182
};
177183

178184
this.OSMIDList = (instructions) => {
@@ -250,4 +256,12 @@ module.exports = function () {
250256
this.distanceList = (instructions) => {
251257
return this.extractInstructionList(instructions, s => s.distance + 'm');
252258
};
259+
260+
this.weightName = (instructions) => {
261+
return instructions ? instructions.weight_name : '';
262+
};
263+
264+
this.weightList = (instructions) => {
265+
return this.extractInstructionList(instructions, s => s.weight);
266+
};
253267
};

features/support/shared_steps.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module.exports = function () {
3535
if (err) return cb(err);
3636
if (body && body.length) {
3737
let destinations, pronunciations, instructions, refs, bearings, turns, modes, times,
38-
distances, summary, intersections, lanes, locations;
38+
distances, summary, intersections, lanes, locations, annotation, weight_name, weights;
3939

4040
let json = JSON.parse(body);
4141

@@ -55,6 +55,9 @@ module.exports = function () {
5555
lanes = this.lanesList(json.routes[0]);
5656
summary = this.summary(json.routes[0]);
5757
locations = this.locations(json.routes[0]);
58+
annotation = this.annotationList(json.routes[0]);
59+
weight_name = this.weightName(json.routes[0]);
60+
weights = this.weightList(json.routes[0]);
5861
}
5962

6063
if (headers.has('status')) {
@@ -130,6 +133,10 @@ module.exports = function () {
130133
got.locations = (locations || '').trim();
131134
}
132135

136+
if (headers.has('annotation')){
137+
got.annotation = (annotation || '').trim();
138+
}
139+
133140
var putValue = (key, value) => {
134141
if (headers.has(key)) got[key] = instructions ? value : '';
135142
};
@@ -142,6 +149,8 @@ module.exports = function () {
142149
putValue('distances', distances);
143150
putValue('pronunciations', pronunciations);
144151
putValue('destinations', destinations);
152+
putValue('weight_name', weight_name);
153+
putValue('weights', weights);
145154
}
146155

147156
for (var key in row) {

features/testbot/matching.feature

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ Feature: Basic Map Matching
141141
And the contract extra arguments "--segment-speed-file {speeds_file}"
142142

143143
When I match I should get
144-
| trace | matchings | annotation |
145-
| abeh | abeh | 1:10.008842:1,0:0:0,1:10.008842:0,1:10.008842:0,1:10.008842:0,0:0:0,2:19.906475:0,1:10.008842:0 |
146-
| abci | abci | 1:10.008842:1,0:0:0,1:10.008842:0,0:0:0,1:10.010367:0 |
144+
| trace | matchings | annotation |
145+
| abeh | abeh | 1:1:10.008842:1,0:0:0:0,1:1:10.008842:0,1:1:10.008842:0,1:1:10.008842:0,0:0:0:0,2:2:19.906475:0,1:1:10.008842:0 |
146+
| abci | abci | 1:1:10.008842:1,0:0:0:0,1:1:10.008842:0,0:0:0:0,1:1:10.010367:0 |
147147

148148
# The following is the same as the above, but separated for readability (line length)
149149
When I match I should get
@@ -337,4 +337,3 @@ Feature: Basic Map Matching
337337
| trace | OSM IDs |
338338
| 12 | 1,2,3,4,5,6 |
339339
| 21 | 6,5,4,3,2,1 |
340-

features/testbot/side_bias.feature

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,10 @@ Feature: Testbot - side bias
99
"""
1010

1111
Scenario: Left hand bias
12-
Given the profile file "testbot" extended with
12+
Given the profile file "car" extended with
1313
"""
1414
properties.left_hand_driving = true
15-
function turn_function (angle)
16-
local k = 10 * angle * angle * 50 / (90.0 * 90.0)
17-
return (angle >= 0) and k * 1.2 or k / 1.2
18-
end
15+
turn_bias = properties.left_hand_driving and 1/1.075 or 1.075
1916
"""
2017
Given the node map
2118
"""
@@ -31,17 +28,14 @@ Feature: Testbot - side bias
3128

3229
When I route I should get
3330
| from | to | route | time |
34-
| d | a | bd,ab,ab | 82s +-1 |
35-
| d | c | bd,bc,bc | 100s +-1 |
31+
| d | a | bd,ab,ab | 29s +-1 |
32+
| d | c | bd,bc,bc | 33s +-1 |
3633

3734
Scenario: Right hand bias
38-
Given the profile file "testbot" extended with
35+
Given the profile file "car" extended with
3936
"""
4037
properties.left_hand_driving = false
41-
function turn_function (angle)
42-
local k = 10 * angle * angle * 50 / (90.0 * 90.0)
43-
return (angle >= 0) and k / 1.2 or k * 1.2
44-
end
38+
turn_bias = properties.left_hand_driving and 1/1.075 or 1.075
4539
"""
4640
And the node map
4741
"""
@@ -57,8 +51,8 @@ Feature: Testbot - side bias
5751

5852
When I route I should get
5953
| from | to | route | time |
60-
| d | a | bd,ab,ab | 100s +-1 |
61-
| d | c | bd,bc,bc | 82s +-1 |
54+
| d | a | bd,ab,ab | 33s +-1 |
55+
| d | c | bd,bc,bc | 29s +-1 |
6256

6357
Scenario: Roundabout exit counting for left sided driving
6458
And a grid size of 10 meters

0 commit comments

Comments
 (0)