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:
parent
0d432f6377
commit
aff590a44d
@ -30,6 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
#include "deallocating_vector.hpp"
|
#include "deallocating_vector.hpp"
|
||||||
#include "../util/integer_range.hpp"
|
#include "../util/integer_range.hpp"
|
||||||
|
#include "../typedefs.h"
|
||||||
|
|
||||||
#include <boost/assert.hpp>
|
#include <boost/assert.hpp>
|
||||||
|
|
||||||
@ -264,6 +265,24 @@ template <typename EdgeDataT> class DynamicGraph
|
|||||||
return EndEdges(from);
|
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:
|
protected:
|
||||||
bool isDummy(const EdgeIterator edge) const
|
bool isDummy(const EdgeIterator edge) const
|
||||||
{
|
{
|
||||||
|
@ -157,6 +157,19 @@ template <typename EdgeDataT, bool UseSharedMemory = false> class StaticGraph
|
|||||||
|
|
||||||
// searches for a specific edge
|
// searches for a specific edge
|
||||||
EdgeIterator FindEdge(const NodeIterator from, const NodeIterator to) const
|
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;
|
EdgeIterator smallest_edge = SPECIAL_EDGEID;
|
||||||
EdgeWeight smallest_weight = INVALID_EDGE_WEIGHT;
|
EdgeWeight smallest_weight = INVALID_EDGE_WEIGHT;
|
||||||
|
Loading…
Reference in New Issue
Block a user