Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameter for keep waypoints on the left/right #4039

Merged
merged 13 commits into from
May 30, 2017
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ set_property(TARGET osrm-routed PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE)
file(GLOB VariantGlob third_party/variant/include/mapbox/*.hpp)
file(GLOB LibraryGlob include/osrm/*.hpp)
file(GLOB ParametersGlob include/engine/api/*_parameters.hpp)
set(EngineHeader include/engine/status.hpp include/engine/engine_config.hpp include/engine/hint.hpp include/engine/bearing.hpp include/engine/phantom_node.hpp)
set(EngineHeader include/engine/status.hpp include/engine/engine_config.hpp include/engine/hint.hpp include/engine/bearing.hpp include/engine/approach.hpp include/engine/phantom_node.hpp)
set(UtilHeader include/util/coordinate.hpp include/util/json_container.hpp include/util/typedefs.hpp include/util/alias.hpp include/util/exception.hpp)
set(ExtractorHeader include/extractor/extractor.hpp include/extractor/extractor_config.hpp include/extractor/travel_mode.hpp)
set(PartitionerHeader include/partition/partitioner.hpp include/partition/partition_config.hpp)
Expand Down
2 changes: 1 addition & 1 deletion features/step_definitions/routability.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ module.exports = function () {

r.which = dir;

this.requestRoute((dir === 'forw' ? [a, b] : [b, a]), [], this.queryParams, (err, res, body) => {
this.requestRoute((dir === 'forw' ? [a, b] : [b, a]), [], [], this.queryParams, (err, res, body) => {
if (err) return callback(err);

r.query = this.query;
Expand Down
10 changes: 9 additions & 1 deletion features/support/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ module.exports = function () {
return waypoints.map(w => [w.lon, w.lat].map(ensureDecimal).join(','));
};

this.requestRoute = (waypoints, bearings, userParams, callback) => {
this.requestRoute = (waypoints, bearings, approaches, userParams, callback) => {
if (bearings.length && bearings.length !== waypoints.length) throw new Error('*** number of bearings does not equal the number of waypoints');
if (approaches.length && approaches.length !== waypoints.length) throw new Error('*** number of approaches does not equal the number of waypoints');

var defaults = {
output: 'json',
Expand All @@ -67,6 +68,9 @@ module.exports = function () {
}).join(';');
}

if (approaches.length) {
params.approaches = approaches.join(';');
}
return this.requestPath('route', params, callback);
};

Expand Down Expand Up @@ -163,6 +167,10 @@ module.exports = function () {
('out' in s.intersections[0] ? s.intersections[0].bearings[s.intersections[0].out] : 0));
};

this.approachList = (instructions) => {
return this.extractInstructionList(instructions, s => s.approaches || '');
};

this.annotationList = (instructions) => {
if (!('annotation' in instructions.legs[0]))
return '';
Expand Down
21 changes: 16 additions & 5 deletions features/support/shared_steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = function () {
if (err) return cb(err);
if (body && body.length) {
let destinations, pronunciations, instructions, refs, bearings, turns, modes, times,
distances, summary, intersections, lanes, locations, annotation, weight_name, weights;
distances, summary, intersections, lanes, locations, annotation, weight_name, weights, approaches;

let json = JSON.parse(body);

Expand All @@ -60,6 +60,7 @@ module.exports = function () {
annotation = this.annotationList(json.routes[0]);
weight_name = this.weightName(json.routes[0]);
weights = this.weightList(json.routes[0]);
approaches = this.approachList(json.routes[0]);
}

if (headers.has('status')) {
Expand Down Expand Up @@ -146,7 +147,10 @@ module.exports = function () {
if (headers.has('locations')){
got.locations = (locations || '').trim();
}

/*
if (headers.has('approaches')){
got.approaches = (approaches || '').trim();
}*/
// if header matches 'a:*', parse out the values for *
// and return in that header
headers.forEach((k) => {
Expand Down Expand Up @@ -176,6 +180,7 @@ module.exports = function () {
putValue('weight_name', weight_name);
putValue('weights', weights);
putValue('weight', weight);
putValue('approach', approaches);

for (var key in row) {
if (this.FuzzyMatch.match(got[key], row[key])) {
Expand Down Expand Up @@ -210,13 +215,19 @@ module.exports = function () {

var params = this.overwriteParams(defaultParams, userParams),
waypoints = [],
bearings = [];
bearings = [],
approaches = [];

if (row.bearings) {
got.bearings = row.bearings;
bearings = row.bearings.split(' ').filter(b => !!b);
}

if (row.approaches) {
got.approaches = row.approaches;
approaches = row.approaches.split(' ').filter(b => !!b);
}

if (row.from && row.to) {
var fromNode = this.findNodeByName(row.from);
if (!fromNode) return cb(new Error(util.format('*** unknown from-node "%s"', row.from)));
Expand All @@ -228,15 +239,15 @@ module.exports = function () {

got.from = row.from;
got.to = row.to;
this.requestRoute(waypoints, bearings, params, afterRequest);
this.requestRoute(waypoints, bearings, approaches, params, afterRequest);
} else if (row.waypoints) {
row.waypoints.split(',').forEach((n) => {
var node = this.findNodeByName(n.trim());
if (!node) return cb(new Error('*** unknown waypoint node "%s"', n.trim()));
waypoints.push(node);
});
got.waypoints = row.waypoints;
this.requestRoute(waypoints, bearings, params, afterRequest);
this.requestRoute(waypoints, bearings, approaches, params, afterRequest);
} else {
return cb(new Error('*** no waypoints'));
}
Expand Down
192 changes: 192 additions & 0 deletions features/testbot/approach_param.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
@routing @approach_param @testbot
Feature: Approach parameter

Background:
Given the profile "car"
And a grid size of 10 meters

Scenario: Testbot - Start End same approach, option unrestricted for Start and End
Given the node map
"""
s e
a------b------c
"""

And the ways
| nodes |
| ab |
| bc |

When I route I should get
| from | to | approaches | route |
| s | e | unrestricted unrestricted | ab,bc |

Scenario: Testbot - Start End same approach, option unrestricted for Start and curb for End
Given the node map
"""
s e
a------b------c
"""

And the ways
| nodes |
| ab |
| bc |

When I route I should get
| from | to | approaches | route |
| s | e | unrestricted curb | ab,bc,bc |

Scenario: Testbot - Start End opposite approach, option unrestricted for Start and End
Given the node map
"""
s
a------b------c
e
"""

And the ways
| nodes |
| ab |
| bc |

When I route I should get
| from | to | approaches | route |
| s | e | unrestricted unrestricted | ab,bc |

Scenario: Testbot - Start End opposite approach, option unrestricted for Start and curb for End
Given the node map
"""
s
a------b------c
e
"""

And the ways
| nodes |
| ab |
| bc |

When I route I should get
| from | to | approaches | route |
| s | e | unrestricted curb | ab,bc |

###############
# Oneway Test #
###############


Scenario: Testbot - Test on oneway segment, Start End same approach, option unrestricted for Start and End
Given the node map
"""
s e
a------b------c
"""

And the ways
| nodes | oneway |
| ab | yes |
| bc | yes |

When I route I should get
| from | to | approaches | route |
| s | e | unrestricted unrestricted | ab,bc |

Scenario: Testbot - Test on oneway segment, Start End same approach, option unrestricted for Start and curb for End
Given the node map
"""
s e
a------b------c
"""

And the ways
| nodes | oneway |
| ab | yes |
| bc | yes |

When I route I should get
| from | to | approaches | route |
| s | e | unrestricted curb | ab,bc |

Scenario: Testbot - Test on oneway segment, Start End opposite approach, option unrestricted for Start and End
Given the node map
"""
s
a------b------c
e
"""

And the ways
| nodes | oneway |
| ab | yes |
| bc | yes |

When I route I should get
| from | to | approaches | route |
| s | e | unrestricted unrestricted | ab,bc |

Scenario: Testbot - Test on oneway segment, Start End opposite approach, option unrestricted for Start and curb for End
Given the node map
"""
s
a------b------c
e
"""

And the ways
| nodes | oneway |
| ab | yes |
| bc | yes |

When I route I should get
| from | to | approaches | route |
| s | e | unrestricted curb | ab,bc |

##############
# UTurn Test #
##############

Scenario: Testbot - UTurn test, router can't found a route because uturn unauthorized on the segment selected
Given the node map
"""
s e
a------b------c
"""

And the ways
| nodes |
| ab |
| bc |

And the relations
| type | way:from | way:to | node:via | restriction |
| restriction | bc | bc | c | no_u_turn |

When I route I should get
| from | to | approaches | route |
| s | e | unrestricted curb | |


Scenario: Testbot - UTurn test, router can found a route because he can use the roundabout
Given the node map
"""
h
s e / \
a------b------c g
\ /
f
"""

And the ways
| nodes | junction |
| ab | |
| bc | |
| cfghc | roundabout |

And the relations
| type | way:from | way:to | node:via | restriction |
| restriction | bc | bc | c | no_u_turn |

When I route I should get
| from | to | approaches | route |
| s | e | unrestricted curb | ab,bc,bc |
7 changes: 6 additions & 1 deletion include/engine/api/base_parameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "engine/bearing.hpp"
#include "engine/hint.hpp"
#include "engine/approach.hpp"
#include "util/coordinate.hpp"

#include <boost/optional.hpp>
Expand All @@ -55,6 +56,7 @@ namespace api
* optional per coordinate
* - bearings: limits the search for segments in the road network to given bearing(s) in degree
* towards true north in clockwise direction, optional per coordinate
* - approaches: force the phantom node to start towards the node with the road country side.
*
* \see OSRM, Coordinate, Hint, Bearing, RouteParame, RouteParameters, TableParameters,
* NearestParameters, TripParameters, MatchParameters and TileParameters
Expand All @@ -65,6 +67,7 @@ struct BaseParameters
std::vector<boost::optional<Hint>> hints;
std::vector<boost::optional<double>> radiuses;
std::vector<boost::optional<Bearing>> bearings;
std::vector<boost::optional<Approach>> approaches;

// Adds hints to response which can be included in subsequent requests, see `hints` above.
bool generate_hints = true;
Expand All @@ -73,9 +76,10 @@ struct BaseParameters
const std::vector<boost::optional<Hint>> hints_ = {},
std::vector<boost::optional<double>> radiuses_ = {},
std::vector<boost::optional<Bearing>> bearings_ = {},
std::vector<boost::optional<Approach>> approaches_ = {},
bool generate_hints_ = true)
: coordinates(coordinates_), hints(hints_), radiuses(radiuses_), bearings(bearings_),
generate_hints(generate_hints_)
approaches(approaches_), generate_hints(generate_hints_)
{
}

Expand All @@ -85,6 +89,7 @@ struct BaseParameters
return (hints.empty() || hints.size() == coordinates.size()) &&
(bearings.empty() || bearings.size() == coordinates.size()) &&
(radiuses.empty() || radiuses.size() == coordinates.size()) &&
(approaches.empty() || approaches.size() == coordinates.size()) &&
std::all_of(bearings.begin(),
bearings.end(),
[](const boost::optional<Bearing> bearing_and_range) {
Expand Down
Loading