1.Strictly follow OSRM Clang Style Format as defined in .clang-format 2.Implementing multi heading route
This commit is contained in:
parent
a1e5061799
commit
c04e295835
1
.gitignore
vendored
1
.gitignore
vendored
@ -54,6 +54,7 @@ Thumbs.db
|
||||
/test/data/corech
|
||||
/test/data/mld
|
||||
/cmake/postinst
|
||||
/cmake-build-debug/
|
||||
|
||||
# Eclipse related files #
|
||||
#########################
|
||||
|
||||
@ -290,7 +290,7 @@ curl 'http://router.project-osrm.org/table/v1/driving/13.388860,52.517037;13.397
|
||||
- `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 travel distance from
|
||||
the i-th waypoint to the j-th waypoint. Values are given in meters. Can be `null` if no route between `i` and `j` can be found. Note that computing the `distances` table is currently only implemented for CH. If `annotations=distance` or `annotations=duration,distance` is requested when running a MLD router, a `NotImplemented` error will be returned.
|
||||
the i-th waypoint to the j-th waypoint. Values are given in meters. Can be `null` if no route between `i` and `j` can be found.
|
||||
- `sources` array of `Waypoint` objects describing all sources in order
|
||||
- `destinations` array of `Waypoint` objects describing all destinations in order
|
||||
- `fallback_speed_cells` (optional) array of arrays containing `i,j` pairs indicating which cells contain estimated values based on `fallback_speed`. Will be absent if `fallback_speed` is not used.
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
#include "engine/routing_algorithms/direct_shortest_path.hpp"
|
||||
#include "engine/routing_algorithms/many_to_many.hpp"
|
||||
#include "engine/routing_algorithms/map_matching.hpp"
|
||||
#include "engine/routing_algorithms/multi_heading_path.hpp"
|
||||
#include "engine/routing_algorithms/shortest_path.hpp"
|
||||
#include "engine/routing_algorithms/tile_turns.hpp"
|
||||
|
||||
@ -23,6 +24,9 @@ class RoutingAlgorithmsInterface
|
||||
AlternativePathSearch(const PhantomNodes &phantom_node_pair,
|
||||
unsigned number_of_alternatives) const = 0;
|
||||
|
||||
virtual InternalManyRoutesResult
|
||||
MultiHeadingDirectShortestPathsSearch(const PhantomNodes &phantom_node_pair) const = 0;
|
||||
|
||||
virtual InternalRouteResult
|
||||
ShortestPathSearch(const std::vector<PhantomNodes> &phantom_node_pair,
|
||||
const boost::optional<bool> continue_straight_at_waypoint) const = 0;
|
||||
@ -50,13 +54,21 @@ class RoutingAlgorithmsInterface
|
||||
virtual const DataFacadeBase &GetFacade() const = 0;
|
||||
|
||||
virtual bool HasAlternativePathSearch() const = 0;
|
||||
|
||||
virtual bool HasShortestPathSearch() const = 0;
|
||||
|
||||
virtual bool HasDirectShortestPathSearch() const = 0;
|
||||
|
||||
virtual bool HasMapMatching() const = 0;
|
||||
|
||||
virtual bool HasManyToManySearch() const = 0;
|
||||
|
||||
virtual bool SupportsDistanceAnnotationType() const = 0;
|
||||
|
||||
virtual bool HasGetTileTurns() const = 0;
|
||||
|
||||
virtual bool HasExcludeFlags() const = 0;
|
||||
|
||||
virtual bool IsValid() const = 0;
|
||||
};
|
||||
|
||||
@ -80,6 +92,9 @@ template <typename Algorithm> class RoutingAlgorithms final : public RoutingAlgo
|
||||
const std::vector<PhantomNodes> &phantom_node_pair,
|
||||
const boost::optional<bool> continue_straight_at_waypoint) const final override;
|
||||
|
||||
InternalManyRoutesResult
|
||||
MultiHeadingDirectShortestPathsSearch(const PhantomNodes &phantom_nodes) const final override;
|
||||
|
||||
InternalRouteResult
|
||||
DirectShortestPathSearch(const PhantomNodes &phantom_nodes) const final override;
|
||||
|
||||
@ -158,6 +173,13 @@ RoutingAlgorithms<Algorithm>::AlternativePathSearch(const PhantomNodes &phantom_
|
||||
heaps, *facade, phantom_node_pair, number_of_alternatives);
|
||||
}
|
||||
|
||||
template <typename Algorithm>
|
||||
InternalManyRoutesResult RoutingAlgorithms<Algorithm>::MultiHeadingDirectShortestPathsSearch(
|
||||
const PhantomNodes &phantom_nodes) const
|
||||
{
|
||||
return routing_algorithms::multiHeadingDirectShortestPathsSearch(heaps, *facade, phantom_nodes);
|
||||
}
|
||||
|
||||
template <typename Algorithm>
|
||||
InternalRouteResult RoutingAlgorithms<Algorithm>::ShortestPathSearch(
|
||||
const std::vector<PhantomNodes> &phantom_node_pair,
|
||||
@ -230,7 +252,7 @@ inline std::vector<routing_algorithms::TurnData> RoutingAlgorithms<Algorithm>::G
|
||||
return routing_algorithms::getTileTurns(*facade, edges, sorted_edge_indexes);
|
||||
}
|
||||
|
||||
} // ns engine
|
||||
} // ns osrm
|
||||
} // namespace engine
|
||||
} // namespace osrm
|
||||
|
||||
#endif
|
||||
|
||||
27
include/engine/routing_algorithms/multi_heading_path.hpp
Normal file
27
include/engine/routing_algorithms/multi_heading_path.hpp
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef MULTI_HEADING_PATH_HPP
|
||||
#define MULTI_HEADING_PATH_HPP
|
||||
|
||||
#include "engine/algorithm.hpp"
|
||||
#include "engine/datafacade.hpp"
|
||||
#include "engine/internal_route_result.hpp"
|
||||
#include "engine/search_engine_data.hpp"
|
||||
|
||||
#include "util/typedefs.hpp"
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace engine
|
||||
{
|
||||
namespace routing_algorithms
|
||||
{
|
||||
|
||||
template <typename Algorithm>
|
||||
InternalManyRoutesResult
|
||||
multiHeadingDirectShortestPathsSearch(SearchEngineData<Algorithm> &engine_working_data,
|
||||
const DataFacade<Algorithm> &facade,
|
||||
const PhantomNodes &phantom_nodes);
|
||||
} // namespace routing_algorithms
|
||||
} // namespace engine
|
||||
} // namespace osrm
|
||||
|
||||
#endif
|
||||
@ -126,7 +126,8 @@ Status ViaRoutePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithm
|
||||
}
|
||||
else if (1 == start_end_nodes.size() && algorithms.HasDirectShortestPathSearch())
|
||||
{
|
||||
routes = algorithms.DirectShortestPathSearch(start_end_nodes.front());
|
||||
std::cout << "calling MultiHeadingDirectShortestPathsSearch in viaroute.cpp" << std::endl;
|
||||
routes = algorithms.MultiHeadingDirectShortestPathsSearch(start_end_nodes.front());
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -185,6 +186,6 @@ Status ViaRoutePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithm
|
||||
|
||||
return Status::Ok;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace plugins
|
||||
} // namespace engine
|
||||
} // namespace osrm
|
||||
|
||||
224
src/engine/routing_algorithms/multi_heading_path.cpp
Normal file
224
src/engine/routing_algorithms/multi_heading_path.cpp
Normal file
@ -0,0 +1,224 @@
|
||||
#include "engine/routing_algorithms/multi_heading_path.hpp"
|
||||
#include "engine/routing_algorithms/routing_base.hpp"
|
||||
#include "engine/routing_algorithms/routing_base_ch.hpp"
|
||||
#include "engine/routing_algorithms/routing_base_mld.hpp"
|
||||
#include "util/static_assert.hpp"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/function_output_iterator.hpp>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace engine
|
||||
{
|
||||
namespace routing_algorithms
|
||||
{
|
||||
|
||||
template <>
|
||||
InternalManyRoutesResult
|
||||
multiHeadingDirectShortestPathsSearch(SearchEngineData<ch::Algorithm> &engine_working_data,
|
||||
const DataFacade<ch::Algorithm> &facade,
|
||||
const PhantomNodes &phantom_nodes)
|
||||
{
|
||||
engine_working_data.InitializeOrClearFirstThreadLocalStorage(facade.GetNumberOfNodes());
|
||||
auto &forward_heap = *engine_working_data.forward_heap_1;
|
||||
auto &reverse_heap = *engine_working_data.reverse_heap_1;
|
||||
forward_heap.Clear();
|
||||
reverse_heap.Clear();
|
||||
|
||||
EdgeWeight weight = INVALID_EDGE_WEIGHT;
|
||||
std::vector<NodeID> packed_leg;
|
||||
insertNodesInHeaps(forward_heap, reverse_heap, phantom_nodes);
|
||||
|
||||
search(engine_working_data,
|
||||
facade,
|
||||
forward_heap,
|
||||
reverse_heap,
|
||||
weight,
|
||||
packed_leg,
|
||||
DO_NOT_FORCE_LOOPS,
|
||||
DO_NOT_FORCE_LOOPS,
|
||||
phantom_nodes);
|
||||
|
||||
std::vector<NodeID> unpacked_nodes;
|
||||
std::vector<EdgeID> unpacked_edges;
|
||||
|
||||
if (!packed_leg.empty())
|
||||
{
|
||||
unpacked_nodes.reserve(packed_leg.size());
|
||||
unpacked_edges.reserve(packed_leg.size());
|
||||
unpacked_nodes.push_back(packed_leg.front());
|
||||
ch::unpackPath(facade,
|
||||
packed_leg.begin(),
|
||||
packed_leg.end(),
|
||||
[&unpacked_nodes, &unpacked_edges](std::pair<NodeID, NodeID> &edge,
|
||||
const auto &edge_id) {
|
||||
BOOST_ASSERT(edge.first == unpacked_nodes.back());
|
||||
unpacked_nodes.push_back(edge.second);
|
||||
unpacked_edges.push_back(edge_id);
|
||||
});
|
||||
}
|
||||
|
||||
std::vector<InternalRouteResult> routes;
|
||||
routes.reserve(6);
|
||||
|
||||
InternalRouteResult route =
|
||||
extractRoute(facade, weight, phantom_nodes, unpacked_nodes, unpacked_edges);
|
||||
routes.push_back(route);
|
||||
BOOST_ASSERT(routes.size() >= 1);
|
||||
|
||||
return InternalManyRoutesResult{std::move(routes)};
|
||||
}
|
||||
|
||||
template <>
|
||||
InternalManyRoutesResult
|
||||
multiHeadingDirectShortestPathsSearch(SearchEngineData<mld::Algorithm> &engine_working_data,
|
||||
const DataFacade<mld::Algorithm> &facade,
|
||||
const PhantomNodes &phantom_nodes)
|
||||
{
|
||||
engine_working_data.InitializeOrClearFirstThreadLocalStorage(facade.GetNumberOfNodes(),
|
||||
facade.GetMaxBorderNodeID() + 1);
|
||||
|
||||
std::vector<InternalRouteResult> routes;
|
||||
routes.reserve(6);
|
||||
|
||||
// insertNodesInHeaps(forward_heap, reverse_heap, phantom_nodes);
|
||||
|
||||
const auto &source = phantom_nodes.source_phantom;
|
||||
const auto &target = phantom_nodes.target_phantom;
|
||||
|
||||
auto &forward_heap = *engine_working_data.forward_heap_1;
|
||||
auto &reverse_heap = *engine_working_data.reverse_heap_1;
|
||||
if (source.IsValidForwardSource() && target.IsValidForwardTarget())
|
||||
{
|
||||
|
||||
forward_heap.Clear();
|
||||
reverse_heap.Clear();
|
||||
forward_heap.Insert(source.forward_segment_id.id,
|
||||
-source.GetForwardWeightPlusOffset(),
|
||||
source.forward_segment_id.id);
|
||||
reverse_heap.Insert(target.forward_segment_id.id,
|
||||
target.GetForwardWeightPlusOffset(),
|
||||
target.forward_segment_id.id);
|
||||
// TODO: when structured bindings will be allowed change to
|
||||
// auto [weight, source_node, target_node, unpacked_edges] = ...
|
||||
EdgeWeight weight = INVALID_EDGE_WEIGHT;
|
||||
std::vector<NodeID> unpacked_nodes;
|
||||
std::vector<EdgeID> unpacked_edges;
|
||||
std::tie(weight, unpacked_nodes, unpacked_edges) = mld::search(engine_working_data,
|
||||
facade,
|
||||
forward_heap,
|
||||
reverse_heap,
|
||||
DO_NOT_FORCE_LOOPS,
|
||||
DO_NOT_FORCE_LOOPS,
|
||||
INVALID_EDGE_WEIGHT,
|
||||
phantom_nodes);
|
||||
InternalRouteResult route =
|
||||
extractRoute(facade, weight, phantom_nodes, unpacked_nodes, unpacked_edges);
|
||||
|
||||
routes.push_back(route);
|
||||
}
|
||||
|
||||
if (source.IsValidReverseSource() && target.IsValidForwardTarget())
|
||||
{
|
||||
forward_heap.Clear();
|
||||
reverse_heap.Clear();
|
||||
forward_heap.Insert(source.reverse_segment_id.id,
|
||||
-source.GetReverseWeightPlusOffset(),
|
||||
source.reverse_segment_id.id);
|
||||
reverse_heap.Insert(target.forward_segment_id.id,
|
||||
target.GetForwardWeightPlusOffset(),
|
||||
target.forward_segment_id.id);
|
||||
// TODO: when structured bindings will be allowed change to
|
||||
// auto [weight, source_node, target_node, unpacked_edges] = ...
|
||||
EdgeWeight weight = INVALID_EDGE_WEIGHT;
|
||||
std::vector<NodeID> unpacked_nodes;
|
||||
std::vector<EdgeID> unpacked_edges;
|
||||
std::tie(weight, unpacked_nodes, unpacked_edges) = mld::search(engine_working_data,
|
||||
facade,
|
||||
forward_heap,
|
||||
reverse_heap,
|
||||
DO_NOT_FORCE_LOOPS,
|
||||
DO_NOT_FORCE_LOOPS,
|
||||
INVALID_EDGE_WEIGHT,
|
||||
phantom_nodes);
|
||||
InternalRouteResult route =
|
||||
extractRoute(facade, weight, phantom_nodes, unpacked_nodes, unpacked_edges);
|
||||
|
||||
routes.push_back(route);
|
||||
}
|
||||
|
||||
if (source.IsValidForwardSource() && target.IsValidReverseTarget())
|
||||
{
|
||||
forward_heap.Clear();
|
||||
reverse_heap.Clear();
|
||||
forward_heap.Insert(source.forward_segment_id.id,
|
||||
-source.GetForwardWeightPlusOffset(),
|
||||
source.forward_segment_id.id);
|
||||
reverse_heap.Insert(target.reverse_segment_id.id,
|
||||
target.GetReverseWeightPlusOffset(),
|
||||
target.reverse_segment_id.id);
|
||||
// TODO: when structured bindings will be allowed change to
|
||||
// auto [weight, source_node, target_node, unpacked_edges] = ...
|
||||
EdgeWeight weight = INVALID_EDGE_WEIGHT;
|
||||
std::vector<NodeID> unpacked_nodes;
|
||||
std::vector<EdgeID> unpacked_edges;
|
||||
std::tie(weight, unpacked_nodes, unpacked_edges) = mld::search(engine_working_data,
|
||||
facade,
|
||||
forward_heap,
|
||||
reverse_heap,
|
||||
DO_NOT_FORCE_LOOPS,
|
||||
DO_NOT_FORCE_LOOPS,
|
||||
INVALID_EDGE_WEIGHT,
|
||||
phantom_nodes);
|
||||
InternalRouteResult route =
|
||||
extractRoute(facade, weight, phantom_nodes, unpacked_nodes, unpacked_edges);
|
||||
|
||||
routes.push_back(route);
|
||||
}
|
||||
if (source.IsValidReverseSource() && target.IsValidReverseTarget())
|
||||
{
|
||||
forward_heap.Clear();
|
||||
reverse_heap.Clear();
|
||||
forward_heap.Insert(source.reverse_segment_id.id,
|
||||
-source.GetReverseWeightPlusOffset(),
|
||||
source.reverse_segment_id.id);
|
||||
reverse_heap.Insert(target.reverse_segment_id.id,
|
||||
target.GetReverseWeightPlusOffset(),
|
||||
target.reverse_segment_id.id);
|
||||
// TODO: when structured bindings will be allowed change to
|
||||
// auto [weight, source_node, target_node, unpacked_edges] = ...
|
||||
EdgeWeight weight = INVALID_EDGE_WEIGHT;
|
||||
std::vector<NodeID> unpacked_nodes;
|
||||
std::vector<EdgeID> unpacked_edges;
|
||||
std::tie(weight, unpacked_nodes, unpacked_edges) = mld::search(engine_working_data,
|
||||
facade,
|
||||
forward_heap,
|
||||
reverse_heap,
|
||||
DO_NOT_FORCE_LOOPS,
|
||||
DO_NOT_FORCE_LOOPS,
|
||||
INVALID_EDGE_WEIGHT,
|
||||
phantom_nodes);
|
||||
InternalRouteResult route =
|
||||
extractRoute(facade, weight, phantom_nodes, unpacked_nodes, unpacked_edges);
|
||||
|
||||
routes.push_back(route);
|
||||
}
|
||||
|
||||
BOOST_ASSERT(routes.size() >= 1);
|
||||
|
||||
return InternalManyRoutesResult{std::move(routes)};
|
||||
}
|
||||
|
||||
} // namespace routing_algorithms
|
||||
} // namespace engine
|
||||
} // namespace osrm
|
||||
Loading…
Reference in New Issue
Block a user