Skip to content
New issue

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

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

Already on GitHub? # to your account

Distance support for table service #2764

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
07278fd
The table service now supports queries for both durations and distances.
mniemeier Mar 9, 2017
244dd8d
Defaulting to "Durations" payload if no Payload has been selected in …
mniemeier Mar 9, 2017
0e118b6
Trying to fix build issues on build servers (works on my test systems…
mniemeier Mar 9, 2017
42b8300
Merge branch 'master' into table-distances. Resolved conflicts.
mniemeier Mar 9, 2017
6e372c3
Fixed another merge issue.
mniemeier Mar 9, 2017
2a7ecfc
Added payload.hpp header reference to buildscript.
mniemeier Mar 9, 2017
368617a
Whitespace change only: Clang format.
mniemeier Mar 9, 2017
722a949
Whitespace only: clang encore
mniemeier Mar 9, 2017
50f7833
Merge branch 'master' of https://github.com/Project-OSRM/osrm-backend…
mniemeier Mar 9, 2017
4f73721
Bugfix: Do not use payload references where one shouldn't...
mniemeier Mar 10, 2017
53c2d00
Payloads can now get initialized with generator functions. Moved dist…
mniemeier Mar 10, 2017
15f0592
Version bump from 'v1' to 'v2' in NodeJS
mniemeier Mar 10, 2017
5dbc41d
Fixed strongly connected component detection in trip service (By usin…
mniemeier Mar 10, 2017
ce6c6cd
Merge branch 'master' into table-distances
mniemeier Mar 10, 2017
d60e451
Merge branch 'master' into table-distances
niemeier-PSI Mar 13, 2017
d552c3d
Merge branch 'master' into table-distances (again)
mniemeier Mar 20, 2017
37ad241
Formatting only: Restored clang formatting that broke during the last…
mniemeier Mar 20, 2017
3d6516e
Merge branch 'master' into table-distances
niemeier-PSI Mar 21, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ 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(UtilHeader include/util/coordinate.hpp include/util/json_container.hpp include/util/typedefs.hpp include/util/strong_typedef.hpp include/util/exception.hpp)
set(UtilHeader include/util/coordinate.hpp include/util/json_container.hpp include/util/typedefs.hpp include/util/strong_typedef.hpp include/util/exception.hpp include/util/payload.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)
set(ContractorHeader include/contractor/contractor.hpp include/contractor/contractor_config.hpp)
Expand Down Expand Up @@ -830,3 +830,15 @@ foreach(header ${headers_to_check})
endforeach()
add_library(check-headers STATIC EXCLUDE_FROM_ALL ${sources})
set_target_properties(check-headers PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${check_headers_dir})

if(PAYLOAD_TYPE MATCHES DurationsAndDistances)
message(STATUS "Configuring OSRM to support duration+distance payload")
add_definitions("-DPAYLOAD_TYPE_DURATIONS_AND_DISTANCES")
elseif(PAYLOAD_TYPE MATCHES Durations)
message(STATUS "Configuring OSRM to support duration payload")
add_definitions("-DPAYLOAD_TYPE_DURATIONS")
else()
message(STATUS "Unrecognized or missing payload type - will default to duration payload")
add_definitions("-DPAYLOAD_TYPE_DURATIONS")
endif()

11 changes: 7 additions & 4 deletions docs/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,11 @@ GET /table/v1/{profile}/{coordinates}?{sources}=[{elem}...];&destinations=[{elem

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

|Option |Values |Description |
|------------|--------------------------------------------------|---------------------------------------------|
|sources |`{index};{index}[;{index} ...]` or `all` (default)|Use location with given index as source. |
|destinations|`{index};{index}[;{index} ...]` or `all` (default)|Use location with given index as destination.|
|Option |Values |Description |
|-------------|---------------------------------------------------|---------------------------------------------|
|sources |`{index};{index}[;{index} ...]` or `all` (default) |Use location with given index as source. |
|destinations |`{index};{index}[;{index} ...]` or `all` (default) |Use location with given index as destination.|
|output_fields|`{durations|distances}[;{durations|distances} ...]`|Matrix fields to output in the reponse. Defaults to `durations` is missing. |

Unlike other array encoded options, the length of `sources` and `destinations` can be **smaller or equal**
to number of input locations;
Expand Down Expand Up @@ -248,6 +249,8 @@ curl 'http://router.project-osrm.org/table/v1/driving/polyline(egs_Iq_aqAppHzbHu
- `code` if the request was successful `Ok` otherwise see the service dependent and general status codes.
- `durations` array of arrays that stores the matrix in row-major order. `durations[i][j]` gives the travel time from
the i-th waypoint to the j-th waypoint. Values are given in seconds. Can be `null` if no route between `i` and `j` can be found.
- `distances` array of arrays that stores the matrix in row-major order. `distances[i][j]` gives the distance from
the i-th waypoint to the j-th waypoint. Values are given in meters.
- `sources` array of `Waypoint` objects describing all sources in order
- `destinations` array of `Waypoint` objects describing all destinations in order

Expand Down
2 changes: 1 addition & 1 deletion features/support/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = function () {
if (service == 'timestamp') {
uri = [this.HOST, service].join('/');
} else {
uri = [this.HOST, service, 'v1', this.profile].join('/');
uri = [this.HOST, service, 'v2', this.profile].join('/');
}

return this.sendRequest(uri, params, callback);
Expand Down
32 changes: 16 additions & 16 deletions features/testbot/status.feature
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,23 @@ Feature: Status messages

When I route I should get
| request | status | message |
| route/v1/driving/1,1;1,2 | 200 | |
| route/v1/driving/-74697224,5.191564 | 400 | Query string malformed close to position 18 |
| route/v1/driving/200,5.191564;44,5 | 400 | Invalid coordinate value. |
| route/v2/driving/1,1;1,2 | 200 | |
| route/v2/driving/-74697224,5.191564 | 400 | Query string malformed close to position 18 |
| route/v2/driving/200,5.191564;44,5 | 400 | Invalid coordinate value. |
| nonsense | 400 | URL string malformed close to position 9: "nse" |
| nonsense/v1/driving/1,1;1,2 | 400 | Service nonsense not found! |
| nonsense/v2/driving/1,1;1,2 | 400 | Service nonsense not found! |
| | 400 | URL string malformed close to position 1: "/" |
| / | 400 | URL string malformed close to position 1: "//" |
| ? | 400 | URL string malformed close to position 1: "/?" |
| route/v1/driving | 400 | URL string malformed close to position 17: "ing" |
| route/v1/driving/ | 400 | URL string malformed close to position 18: "ng/" |
| route/v1/driving/1 | 400 | Query string malformed close to position 19 |
| route/v1/driving/1,1 | 400 | Number of coordinates needs to be at least two. |
| route/v1/driving/1,1,1 | 400 | Query string malformed close to position 21 |
| route/v1/driving/x | 400 | Query string malformed close to position 18 |
| route/v1/driving/x,y | 400 | Query string malformed close to position 18 |
| route/v1/driving/1,1; | 400 | Query string malformed close to position 21 |
| route/v1/driving/1,1;1 | 400 | Query string malformed close to position 23 |
| route/v1/driving/1,1;1,1,1 | 400 | Query string malformed close to position 25 |
| route/v1/driving/1,1;x | 400 | Query string malformed close to position 21 |
| route/v1/driving/1,1;x,y | 400 | Query string malformed close to position 21 |
| route/v2/driving | 400 | URL string malformed close to position 17: "ing" |
| route/v2/driving/ | 400 | URL string malformed close to position 18: "ng/" |
| route/v2/driving/1 | 400 | Query string malformed close to position 19 |
| route/v2/driving/1,1 | 400 | Number of coordinates needs to be at least two. |
| route/v2/driving/1,1,1 | 400 | Query string malformed close to position 21 |
| route/v2/driving/x | 400 | Query string malformed close to position 18 |
| route/v2/driving/x,y | 400 | Query string malformed close to position 18 |
| route/v2/driving/1,1; | 400 | Query string malformed close to position 21 |
| route/v2/driving/1,1;1 | 400 | Query string malformed close to position 23 |
| route/v2/driving/1,1;1,1,1 | 400 | Query string malformed close to position 25 |
| route/v2/driving/1,1;x | 400 | Query string malformed close to position 21 |
| route/v2/driving/1,1;x,y | 400 | Query string malformed close to position 21 |
9 changes: 5 additions & 4 deletions include/contractor/contractor_graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define OSRM_CONTRACTOR_CONTRACTOR_GRAPH_HPP_

#include "util/dynamic_graph.hpp"
#include "util/payload.hpp"
#include <algorithm>

namespace osrm
Expand All @@ -12,24 +13,24 @@ namespace contractor
struct ContractorEdgeData
{
ContractorEdgeData()
: weight(0), duration(0), id(0), originalEdges(0), shortcut(0), forward(0), backward(0),
: weight(0), payload(), id(0), originalEdges(0), shortcut(0), forward(0), backward(0),
is_original_via_node_ID(false)
{
}
ContractorEdgeData(EdgeWeight weight,
EdgeWeight duration,
EdgePayload payload,
unsigned original_edges,
unsigned id,
bool shortcut,
bool forward,
bool backward)
: weight(weight), duration(duration), id(id),
: weight(weight), payload(payload), id(id),
originalEdges(std::min((1u << 28) - 1u, original_edges)), shortcut(shortcut),
forward(forward), backward(backward), is_original_via_node_ID(false)
{
}
EdgeWeight weight;
EdgeWeight duration;
EdgePayload payload;
unsigned id;
unsigned originalEdges : 28;
bool shortcut : 1;
Expand Down
10 changes: 5 additions & 5 deletions include/contractor/graph_contractor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class GraphContractor
BOOST_ASSERT_MSG(SPECIAL_NODEID != new_edge.source, "Source id invalid");
BOOST_ASSERT_MSG(SPECIAL_NODEID != new_edge.target, "Target id invalid");
new_edge.data.weight = data.weight;
new_edge.data.duration = data.duration;
new_edge.data.payload = data.payload;
new_edge.data.shortcut = data.shortcut;
if (!data.is_original_via_node_ID && !orig_node_id_from_new_node_id_map.empty())
{
Expand Down Expand Up @@ -244,7 +244,7 @@ class GraphContractor
inserted_edges.emplace_back(source,
target,
path_weight,
in_data.duration + out_data.duration,
in_data.payload + out_data.payload,
out_data.originalEdges +
in_data.originalEdges,
node,
Expand All @@ -255,7 +255,7 @@ class GraphContractor
inserted_edges.emplace_back(target,
source,
path_weight,
in_data.duration + out_data.duration,
in_data.payload + out_data.payload,
out_data.originalEdges +
in_data.originalEdges,
node,
Expand Down Expand Up @@ -316,7 +316,7 @@ class GraphContractor
inserted_edges.emplace_back(source,
target,
path_weight,
in_data.duration + out_data.duration,
in_data.payload + out_data.payload,
out_data.originalEdges + in_data.originalEdges,
node,
SHORTCUT_ARC,
Expand All @@ -326,7 +326,7 @@ class GraphContractor
inserted_edges.emplace_back(target,
source,
path_weight,
in_data.duration + out_data.duration,
in_data.payload + out_data.payload,
out_data.originalEdges + in_data.originalEdges,
node,
SHORTCUT_ARC,
Expand Down
4 changes: 2 additions & 2 deletions include/contractor/graph_contractor_adaptors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ std::vector<ContractorEdge> adaptToContractorInput(InputEdgeContainer input_edge
edges.emplace_back(input_edge.source,
input_edge.target,
std::max(input_edge.data.weight, 1),
input_edge.data.duration,
input_edge.data.payload,
1,
input_edge.data.turn_id,
false,
Expand All @@ -46,7 +46,7 @@ std::vector<ContractorEdge> adaptToContractorInput(InputEdgeContainer input_edge
edges.emplace_back(input_edge.target,
input_edge.source,
std::max(input_edge.data.weight, 1),
input_edge.data.duration,
input_edge.data.payload,
1,
input_edge.data.turn_id,
false,
Expand Down
15 changes: 8 additions & 7 deletions include/contractor/query_edge.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef QUERYEDGE_HPP
#define QUERYEDGE_HPP

#include "util/payload.hpp"
#include "util/typedefs.hpp"

#include <tuple>
Expand All @@ -17,28 +18,28 @@ struct QueryEdge
struct EdgeData
{
explicit EdgeData()
: turn_id(0), shortcut(false), weight(0), duration(0), forward(false), backward(false)
: turn_id(0), shortcut(false), weight(0), forward(false), backward(false), payload()
{
}

template <class OtherT> EdgeData(const OtherT &other)
{
weight = other.weight;
duration = other.duration;
shortcut = other.shortcut;
turn_id = other.id;
forward = other.forward;
backward = other.backward;
payload = other.payload;
}
// this ID is either the middle node of the shortcut, or the ID of the edge based node (node
// based edge) storing the appropriate data. If `shortcut` is set to true, we get the middle
// node. Otherwise we see the edge based node to access node data.
NodeID turn_id : 31;
bool shortcut : 1;
EdgeWeight weight;
EdgeWeight duration : 30;
EdgeWeight weight : 30;
std::uint32_t forward : 1;
std::uint32_t backward : 1;
EdgePayload payload;
} data;

QueryEdge() : source(SPECIAL_NODEID), target(SPECIAL_NODEID) {}
Expand All @@ -56,9 +57,9 @@ struct QueryEdge
bool operator==(const QueryEdge &right) const
{
return (source == right.source && target == right.target &&
data.weight == right.data.weight && data.duration == right.data.duration &&
data.shortcut == right.data.shortcut && data.forward == right.data.forward &&
data.backward == right.data.backward && data.turn_id == right.data.turn_id);
data.weight == right.data.weight && data.shortcut == right.data.shortcut &&
data.forward == right.data.forward && data.backward == right.data.backward &&
data.payload == right.data.payload && data.turn_id == right.data.turn_id);
}
};
}
Expand Down
38 changes: 22 additions & 16 deletions include/engine/api/table_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "engine/api/base_api.hpp"
#include "engine/api/json_factory.hpp"
#include "engine/api/table_parameters.hpp"
#include "engine/api/table_payload.hpp"

#include "engine/datafacade/datafacade_base.hpp"

Expand Down Expand Up @@ -36,9 +37,10 @@ class TableAPI final : public BaseAPI
{
}

virtual void MakeResponse(const std::vector<EdgeWeight> &durations,
virtual void MakeResponse(const std::vector<RoutingPayload> &entries,
const std::vector<PhantomNode> &phantoms,
util::json::Object &response) const
util::json::Object &response,
const std::vector<TableOutputField> &output_fields) const
{
auto number_of_sources = parameters.sources.size();
auto number_of_destinations = parameters.destinations.size();
Expand All @@ -65,8 +67,15 @@ class TableAPI final : public BaseAPI
response.values["destinations"] = MakeWaypoints(phantoms, parameters.destinations);
}

response.values["durations"] =
MakeTable(durations, number_of_sources, number_of_destinations);
for (auto &component : output_fields.size() == 0 ? DEFAULT_FIELDS : output_fields)
{
response.values[TableOutputFieldName[component]] =
MakeTable(entries,
number_of_sources,
number_of_destinations,
get_encoder<RoutingPayload>(component));
}

response.values["code"] = "Ok";
}

Expand Down Expand Up @@ -98,9 +107,10 @@ class TableAPI final : public BaseAPI
return json_waypoints;
}

virtual util::json::Array MakeTable(const std::vector<EdgeWeight> &values,
virtual util::json::Array MakeTable(const std::vector<RoutingPayload> &values,
std::size_t number_of_rows,
std::size_t number_of_columns) const
std::size_t number_of_columns,
PAYLOAD_ENCODER<RoutingPayload> encoder) const
{
util::json::Array json_table;
for (const auto row : util::irange<std::size_t>(0UL, number_of_rows))
Expand All @@ -109,24 +119,20 @@ class TableAPI final : public BaseAPI
auto row_begin_iterator = values.begin() + (row * number_of_columns);
auto row_end_iterator = values.begin() + ((row + 1) * number_of_columns);
json_row.values.resize(number_of_columns);
std::transform(row_begin_iterator,
row_end_iterator,
json_row.values.begin(),
[](const EdgeWeight duration) {
if (duration == MAXIMAL_EDGE_DURATION)
{
return util::json::Value(util::json::Null());
}
return util::json::Value(util::json::Number(duration / 10.));
});
std::transform(row_begin_iterator, row_end_iterator, json_row.values.begin(), encoder);
json_table.values.push_back(std::move(json_row));
}
return json_table;
}

const TableParameters &parameters;

static const std::vector<TableOutputField> DEFAULT_FIELDS;
};

const std::vector<TableOutputField> TableAPI::DEFAULT_FIELDS =
std::vector<TableOutputField>(1, DURATION);

} // ns api
} // ns engine
} // ns osrm
Expand Down
Loading