make implementation of FindEdge consistent among graph implementations, introduce FindSmallestEdge() function to return the edge with smallest weight if there are multiple, fixes #1427

This commit is contained in:
Dennis Luxen 2015-04-16 16:12:08 +02:00
parent 0d432f6377
commit aff590a44d
2 changed files with 32 additions and 0 deletions

View File

@ -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 <boost/assert.hpp>
@ -264,6 +265,24 @@ template <typename EdgeDataT> 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
{

View File

@ -157,6 +157,19 @@ template <typename EdgeDataT, bool UseSharedMemory = false> 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;