From aff590a44d9250ebeb4da04fc320d837206172b5 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 16 Apr 2015 16:12:08 +0200 Subject: [PATCH] make implementation of FindEdge consistent among graph implementations, introduce FindSmallestEdge() function to return the edge with smallest weight if there are multiple, fixes #1427 --- data_structures/dynamic_graph.hpp | 19 +++++++++++++++++++ data_structures/static_graph.hpp | 13 +++++++++++++ 2 files changed, 32 insertions(+) diff --git a/data_structures/dynamic_graph.hpp b/data_structures/dynamic_graph.hpp index 31aac5b58..021a3bc37 100644 --- a/data_structures/dynamic_graph.hpp +++ b/data_structures/dynamic_graph.hpp @@ -30,6 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "deallocating_vector.hpp" #include "../util/integer_range.hpp" +#include "../typedefs.h" #include @@ -264,6 +265,24 @@ template class DynamicGraph return EndEdges(from); } + // searches for a specific edge + EdgeIterator FindSmallestEdge(const NodeIterator from, const NodeIterator to) const + { + EdgeIterator smallest_edge = SPECIAL_EDGEID; + EdgeWeight smallest_weight = INVALID_EDGE_WEIGHT; + for (auto edge : GetAdjacentEdgeRange(from)) + { + const NodeID target = GetTarget(edge); + const EdgeWeight weight = GetEdgeData(edge).distance; + if (target == to && weight < smallest_weight) + { + smallest_edge = edge; + smallest_weight = weight; + } + } + return smallest_edge; + } + protected: bool isDummy(const EdgeIterator edge) const { diff --git a/data_structures/static_graph.hpp b/data_structures/static_graph.hpp index d4fcdf7a5..09ba2c436 100644 --- a/data_structures/static_graph.hpp +++ b/data_structures/static_graph.hpp @@ -157,6 +157,19 @@ template class StaticGraph // searches for a specific edge EdgeIterator FindEdge(const NodeIterator from, const NodeIterator to) const + { + for (const auto i : osrm::irange(BeginEdges(from), EndEdges(from))) + { + if (to == edge_array[i].target) + { + return i; + } + } + return EndEdges(from); + } + + // searches for a specific edge + EdgeIterator FindSmallestEdge(const NodeIterator from, const NodeIterator to) const { EdgeIterator smallest_edge = SPECIAL_EDGEID; EdgeWeight smallest_weight = INVALID_EDGE_WEIGHT;