Skip to content

Commit

Permalink
[Trip] Support more parameter combinations of fixed start/end when re…
Browse files Browse the repository at this point in the history
…questing roundtrips (#3675)

* support all combinations of fixed start/end when requesting roundtrips
  • Loading branch information
chaupow authored and ghoshkaj committed Feb 8, 2017
1 parent 085579d commit 9330a5b
Show file tree
Hide file tree
Showing 6 changed files with 258 additions and 270 deletions.
56 changes: 35 additions & 21 deletions docs/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,49 +312,62 @@ All other properties might be undefined.
### Trip service

The trip plugin solves the Traveling Salesman Problem using a greedy heuristic (farthest-insertion algorithm) for 10 or more waypoints and uses brute force for less than 10 waypoints.
The returned path does not have to be the fastest path, as TSP is NP-hard it is only an approximation.
Note that all input coordinates have to be connected.
The returned path does not have to be the fastest path. As TSP is NP-hard it only returns an approximation.
Note that all input coordinates have to be connected for the trip service to work.

```endpoint
GET /trip/v1/{profile}/{coordinates}?steps={true|false}&geometries={polyline|polyline6|geojson}&overview={simplified|full|false}&annotations={true|false}'
GET /trip/v1/{profile}/{coordinates}?roundtrip={true|false}&source{any|first}&destination{any|last}&steps={true|false}&geometries={polyline|polyline6|geojson}&overview={simplified|full|false}&annotations={true|false}'
```

####

In addition to the [general options](#general-options) the following options are supported for this service:

|Option |Values |Description |
|------------|------------------------------------------------|---------------------------------------------------------------------------|
|roundtrip |`true` (default), `false` | Return route is a round-trip |
|source |`any` (default), `first` | Return route starts at `any|first` coordinate
|destination |`any` (default), `last` |Return route ends at `any|last` coordinate |
|steps |`true`, `false` (default) |Return route instructions for each trip |
|annotations |`true`, `false` (default) |Returns additional metadata for each coordinate along the route geometry. |
|geometries |`polyline` (default), `polyline6`, `geojson` |Returned route geometry format (influences overview and per step) |
|overview |`simplified` (default), `full`, `false` |Add overview geometry either full, simplified according to highest zoom level it could be display on, or not at all.|

A second feature of the trip plugin returns the route from a source to a destination while visiting all the other waypoints in the middle.
As with the roundtrip service, for fewer than 10 waypoints, the brute force algorithm is used, while for 10 or more waypoints the farthest insertion heuristic is used.
**Fixing Start and End Points**

|Option |Values |Description |
|------------|------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------|
|source |`{index of coordinate in coordinates provided}` |Will error if destination is not provided as well. Returns trip from source to destination routing through all other locations provided.|
|destination |`{index of coordinate in coordinates provided}` |Will error if source is not provided as well. Returns trip from source to destination routing through all other locations provided. |
It is possible to explicitely set the start or end point of the trip. Depending on whether `source` or `destination` is set to `any|first` or `any|last` the resulting output will start/end at the first/last coordinate.

However, if `source=any&destination=any` the returned round-trip will still start at the first coordinate by default.

```endpoint
GET /trip/v1/{profile}/{coordinates}?source={elem}&destination={elem}&steps={true|false}&geometries={polyline|polyline6|geojson}&overview={simplified|full|false}&annotations={true|false}'
```
Currently, not all combinations of roundtrip, source and destination are supported.
By now, the following combinations are possible:

**Example:**
| roundtrip | source | destination | supported |
| :-- | :-- | :-- | :-- |
| true | first | last | **yes** |
| true | first | any | **yes** |
| true | any | last | **yes** |
| true | any | any | **yes** |
| false | first | last | **yes** |
| false | first | any | no |
| false | any | last | no |
| false | any | any | no |

```
source=0&destination=5
```
#### Example Requests

|Element |Values |
|------------|------------------------------|
|index |`0 <= integer < #coordinates` |
```curl
# Round trip in Berlin with three stops:
curl 'http://router.project-osrm.org/trip/v1/driving/13.388860,52.517037;13.397634,52.529407;13.428555,52.523219'
```

```curl
# Round trip in Berlin with four stops, starting at the first stop, ending at the last:
curl 'http://router.project-osrm.org/trip/v1/driving/13.388860,52.517037;13.397634,52.529407;13.428555,52.523219;13.418555,52.523215?source=first&destination=last'
```

**Response**
#### Response

- `code` if the request was successful `Ok` otherwise see the service dependent and general status codes.
- `code`: if the request was successful `Ok` otherwise see the service dependent and general status codes.
- `waypoints`: Array of `Waypoint` objects representing all waypoints in input order. Each `Waypoint` object has the following additional properties:
- `trips_index`: Index to `trips` of the sub-trip the point was matched to.
- `waypoint_index`: Index of the point in the trip.
Expand All @@ -365,6 +378,7 @@ In case of error the following `code`s are supported in addition to the general
| Type | Description |
|-------------------|---------------------|
| `NoTrips` | No trips found because input coordinates are not connected. |
| `NotImplemented` | This request is not supported |

All other properties might be undefined.

Expand Down
7 changes: 5 additions & 2 deletions features/step_definitions/trip.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,15 @@ module.exports = function () {
});
got = { waypoints: row.waypoints };

if (row.source && row.destination) {
if (row.source) {
params.source = got.source = row.source;
}

if (row.destination) {
params.destination = got.destination = row.destination;
}

if (row.hasOwnProperty('roundtrip')) {
if (row.hasOwnProperty('roundtrip')) { //roundtrip is a boolean so row.roundtrip alone doesn't work as a check here
params.roundtrip = got.roundtrip = row.roundtrip;
}

Expand Down
108 changes: 94 additions & 14 deletions features/testbot/trip.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Feature: Basic trip planning
Given the profile "testbot"
Given a grid size of 10 meters

Scenario: Testbot - Roundtrip with waypoints <10
Scenario: Testbot - Trip: Roundtrip with waypoints <10
Given the node map
"""
a b
Expand All @@ -24,7 +24,7 @@ Feature: Basic trip planning
| a,b,c,d | abcda | 7.6 |
| d,b,c,a | dbcad | 7.6 |

Scenario: Testbot - Roundtrip waypoints >10
Scenario: Testbot - Trip: Roundtrip waypoints >10
Given the node map
"""
a b c d
Expand All @@ -51,7 +51,63 @@ Feature: Basic trip planning
| waypoints | trips |
| a,b,c,d,e,f,g,h,i,j,k,l | alkjihgfedcba |

Scenario: Testbot - Unroutable roundtrip with waypoints <10
Scenario: Testbot - Trip: Roundtrip FS waypoints >10
Given the node map
"""
a b c d
l e
k f
j i h g
"""

And the ways
| nodes |
| ab |
| bc |
| de |
| ef |
| fg |
| gh |
| hi |
| ij |
| jk |
| kl |
| la |

When I plan a trip I should get
| waypoints | trips | source |
| a,b,c,d,e,f,g,h,i,j,k,l | alkjihgfedcba | first |

Scenario: Testbot - Trip: Roundtrip FE waypoints >10
Given the query options
| source | last |
Given the node map
"""
a b c d
l e
k f
j i h g
"""

And the ways
| nodes |
| ab |
| bc |
| de |
| ef |
| fg |
| gh |
| hi |
| ij |
| jk |
| kl |
| la |

When I plan a trip I should get
| waypoints | trips |
| a,b,c,d,e,f,g,h,i,j,k,l | lkjihgfedcbal |

Scenario: Testbot - Trip: Unroutable roundtrip with waypoints <10
Given the node map
"""
a b
Expand All @@ -69,7 +125,7 @@ Feature: Basic trip planning
| a,b,c,d | NoTrips | No trip visiting all destinations possible. |


Scenario: Testbot - Unroutable roundtrip with waypoints >10
Scenario: Testbot - Trip: Unroutable roundtrip with waypoints >10
Given the node map
"""
a b c d
Expand Down Expand Up @@ -106,7 +162,7 @@ Feature: Basic trip planning
| a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p | NoTrips | No trip visiting all destinations possible. |

# Test TFSE
Scenario: Testbot - TFSE with errors
Scenario: Testbot - Trip: TFSE with errors
Given the node map
"""
a b
Expand All @@ -122,9 +178,8 @@ Feature: Basic trip planning
When I plan a trip I should get
| waypoints | source | destination | roundtrip | status | message |
| a,b,c,d | first | last | false | NoTrips | No trip visiting all destinations possible. |
| a,b,c,d | first | last | true | NotImplemented | This request is not implemented |

Scenario: Testbot - TFSE with waypoints <10
Scenario: Testbot - Trip: FSE with waypoints <10
Given the node map
"""
a b
Expand All @@ -151,7 +206,7 @@ Feature: Basic trip planning
| a,b,d,e,c | first | last | false | abedc | 8.200000000000001 | 81.6 |


Scenario: Testbot - TFSE with waypoints >10
Scenario: Testbot - Trip: FSE with waypoints >10
Given the node map
"""
a b c d e f g h i j k
Expand All @@ -174,9 +229,34 @@ Feature: Basic trip planning
| waypoints | source | destination | roundtrip | trips | durations | distance |
| a,b,c,d,e,h,i,j,k,g,f | first | last | false | abcdeghijkf | 15 | 149.8 |

Scenario: Testbot - Trip: FSE roundtrip with waypoints <10
Given the node map
"""
a b
c
e d
"""

And the ways
| nodes |
| ab |
| ac |
| ad |
| ae |
| bc |
| bd |
| be |
| cd |
| ce |
| de |

When I plan a trip I should get
| waypoints | source | destination | roundtrip | trips |
| a,b,d,e,c | first | last | true | abedca |


# Test single node in each component #1850
Scenario: Testbot - Trip planning with less than 10 nodes
Scenario: Testbot - Trip: midway points in isoldated roads should return no trips
Given the node map
"""
a 1 b
Expand All @@ -193,7 +273,7 @@ Feature: Basic trip planning
| waypoints | trips |
| 1,2 | |

Scenario: Testbot - Repeated Coordinate
Scenario: Testbot - Trip: Repeated Coordinate
Given the node map
"""
a b
Expand All @@ -208,7 +288,7 @@ Feature: Basic trip planning
| a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a | |


Scenario: Testbot - Trip with geometry details of geojson
Scenario: Testbot - Trip: geometry details of geojson
Given the query options
| geometries | geojson |

Expand All @@ -230,7 +310,7 @@ Feature: Basic trip planning
| a,b,c,d | abcda | 7.6 | 1,1,1.00009,1,1,0.99991,1.00009,1,1,1,1.00009,0.99991,1,1 |
| d,b,c,a | dbcad | 7.6 | 1.00009,0.99991,1,1,1.00009,1,1,0.99991,1.00009,1,1,1,1.00009,0.99991 |

Scenario: Testbot - Trip with geometry details of polyline
Scenario: Testbot - Trip: geometry details of polyline
Given the query options
| geometries | polyline |

Expand All @@ -252,7 +332,7 @@ Feature: Basic trip planning
| a,b,c,d | abcda | 7.6 | 1,1,1,1.00009,0.99991,1,1,1.00009,1,1,0.99991,1.00009,1,1 |
| d,b,c,a | dbcad | 7.6 | 0.99991,1.00009,1,1,1,1.00009,0.99991,1,1,1.00009,1,1,0.99991,1.00009 |

Scenario: Testbot - Trip with geometry details of polyline6
Scenario: Testbot - Trip: geometry details of polyline6
Given the query options
| geometries | polyline6 |

Expand Down
2 changes: 2 additions & 0 deletions include/util/typedefs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ using NameID = std::uint32_t;
using EdgeWeight = std::int32_t;
using TurnPenalty = std::int16_t; // turn penalty in 100ms units

static const std::size_t INVALID_SIZE_T = std::numeric_limits<std::size_t>::max();

using LaneID = std::uint8_t;
static const LaneID INVALID_LANEID = std::numeric_limits<LaneID>::max();
using LaneDataID = std::uint16_t;
Expand Down
Loading

0 comments on commit 9330a5b

Please sign in to comment.