Add support for non-round-trips with a single fixed endpoint (#6050)

Currently /trip supports finding round-trip routes where only the
start or end location is fixed. This PR extends this feature to
non-round-trip requests.

We do this by a new table manipulation that simulates non-round-trip
fixed endpoint requests as a round-trip request.
This commit is contained in:
Michael Bell
2022-08-22 12:56:47 +01:00
committed by GitHub
parent e3c7995b00
commit b4b1aea567
8 changed files with 188 additions and 94 deletions
+28 -27
View File
@@ -262,33 +262,19 @@ test('trip: routes Monaco with null hints', function(assert) {
});
test('trip: service combinations that are not implemented', function(assert) {
assert.plan(3);
assert.plan(1);
var osrm = new OSRM(data_path);
// fixed start, non-roundtrip
// no fixed start, no fixed end, non-roundtrip
var options = {
coordinates: two_test_coordinates,
source: 'first',
source: 'any',
destination: 'any',
roundtrip: false
};
osrm.trip(options, function(err, second) {
assert.equal('NotImplemented', err.message);
});
// fixed start, fixed end, non-roundtrip
options.source = 'any';
options.destination = 'any';
osrm.trip(options, function(err, second) {
assert.equal('NotImplemented', err.message);
});
// fixed end, non-roundtrip
delete options.source;
options.destination = 'last';
osrm.trip(options, function(err, second) {
assert.equal('NotImplemented', err.message);
});
});
test('trip: fixed start and end combinations', function(assert) {
@@ -302,16 +288,17 @@ test('trip: fixed start and end combinations', function(assert) {
geometries: 'geojson'
};
// fixed start and end, non-roundtrip
osrm.trip(options, function(err, fseTrip) {
assert.ifError(err);
assert.equal(1, fseTrip.trips.length);
var coordinates = fseTrip.trips[0].geometry.coordinates;
assert.notEqual(JSON.stringify(coordinates[0]), JSON.stringify(coordinates[coordinates.length - 1]));
});
// variations of non roundtrip
var nonRoundtripChecks = function(options) {
osrm.trip(options, function(err, fseTrip) {
assert.ifError(err);
assert.equal(1, fseTrip.trips.length);
var coordinates = fseTrip.trips[0].geometry.coordinates;
assert.notEqual(JSON.stringify(coordinates[0]), JSON.stringify(coordinates[coordinates.length - 1]));
});
};
// variations of roundtrip
var roundtripChecks = function(options) {
osrm.trip(options, function(err, trip) {
assert.ifError(err);
@@ -319,7 +306,20 @@ test('trip: fixed start and end combinations', function(assert) {
var coordinates = trip.trips[0].geometry.coordinates;
assert.equal(JSON.stringify(coordinates[0]), JSON.stringify(coordinates[coordinates.length - 1]));
});
}
};
// fixed start and end, non-roundtrip
nonRoundtripChecks(options);
// fixed start, non-roundtrip
delete options.destination;
options.source = 'first';
nonRoundtripChecks(options);
// fixed end, non-roundtrip
delete options.source;
options.destination = 'last';
nonRoundtripChecks(options);
// roundtrip, source and destination not specified
roundtripChecks({coordinates: options.coordinates, geometries: options.geometries});
@@ -327,6 +327,7 @@ test('trip: fixed start and end combinations', function(assert) {
// roundtrip, fixed destination
options.roundtrip = true;
delete options.source;
options.destination = 'last';
roundtripChecks(options);
//roundtrip, fixed source