MCPcopy Create free account
hub / github.com/Project-OSRM/osrm-backend / HandleRequest

Method HandleRequest

src/engine/plugins/table.cpp:23–156  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21}
22
23Status TablePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
24 const api::TableParameters &params,
25 osrm::engine::api::ResultT &result) const
26{
27 if (!algorithms.HasManyToManySearch())
28 {
29 return Error("NotImplemented",
30 "Many to many search is not implemented for the chosen search algorithm.",
31 result);
32 }
33
34 BOOST_ASSERT(params.IsValid());
35
36 if (!CheckAllCoordinates(params.coordinates))
37 {
38 return Error("InvalidOptions", "Coordinates are invalid", result);
39 }
40
41 if (!params.bearings.empty() && params.coordinates.size() != params.bearings.size())
42 {
43 return Error(
44 "InvalidOptions", "Number of bearings does not match number of coordinates", result);
45 }
46
47 // Empty sources or destinations means the user wants all of them included, respectively
48 // The ManyToMany routing algorithm we dispatch to below already handles this perfectly.
49 const auto num_sources =
50 params.sources.empty() ? params.coordinates.size() : params.sources.size();
51 const auto num_destinations =
52 params.destinations.empty() ? params.coordinates.size() : params.destinations.size();
53
54 if (max_locations_distance_table > 0 &&
55 ((num_sources * num_destinations) >
56 static_cast<std::size_t>(max_locations_distance_table * max_locations_distance_table)))
57 {
58 return Error("TooBig", "Too many table coordinates", result);
59 }
60
61 if (!CheckAlgorithms(params, algorithms, result))
62 return Status::Error;
63
64 const auto &facade = algorithms.GetFacade();
65 auto phantom_nodes = GetPhantomNodes(facade, params);
66
67 if (phantom_nodes.size() != params.coordinates.size())
68 {
69 return Error(
70 "NoSegment", MissingPhantomErrorMessage(phantom_nodes, params.coordinates), result);
71 }
72
73 auto snapped_phantoms = SnapPhantomNodes(std::move(phantom_nodes));
74
75 bool request_distance = params.annotations & api::TableParameters::AnnotationsType::Distance;
76 bool request_duration = params.annotations & api::TableParameters::AnnotationsType::Duration;
77
78 auto result_tables_pair = algorithms.ManyToManySearch(
79 snapped_phantoms, params.sources, params.destinations, request_distance);
80

Callers

nothing calls this directly

Calls 10

greatCircleDistanceFunction · 0.85
candidatesInputLocationFunction · 0.85
HasManyToManySearchMethod · 0.80
ManyToManySearchMethod · 0.80
IsValidMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45
emplace_backMethod · 0.45
MakeResponseMethod · 0.45

Tested by

no test coverage detected