forked from organicmaps/organicmaps
AStar result distance fix.
This commit is contained in:
parent
c04a68cf8a
commit
c4141880f8
2 changed files with 11 additions and 9 deletions
|
@ -221,7 +221,7 @@ typename AStarAlgorithm<TGraph>::Result AStarAlgorithm<TGraph>::FindPath(
|
|||
if (stateV.vertex == finalVertex)
|
||||
{
|
||||
ReconstructPath(stateV.vertex, parent, result.path);
|
||||
result.distance = stateV.distance;
|
||||
result.distance = stateV.distance - graph.HeuristicCostEstimate(stateV.vertex, finalVertex) + graph.HeuristicCostEstimate(startVertex, finalVertex);
|
||||
ASSERT_EQUAL(graph.HeuristicCostEstimate(stateV.vertex, finalVertex), 0, ());
|
||||
return Result::OK;
|
||||
}
|
||||
|
@ -271,6 +271,7 @@ typename AStarAlgorithm<TGraph>::Result AStarAlgorithm<TGraph>::FindPathBidirect
|
|||
|
||||
bool foundAnyPath = false;
|
||||
double bestPathReducedLength = 0.0;
|
||||
double bestPathRealLength = 0.0;
|
||||
|
||||
forward.bestDistance[startVertex] = 0.0;
|
||||
forward.queue.push(State(startVertex, 0.0 /* distance */));
|
||||
|
@ -321,11 +322,7 @@ typename AStarAlgorithm<TGraph>::Result AStarAlgorithm<TGraph>::FindPathBidirect
|
|||
{
|
||||
ReconstructPathBidirectional(cur->bestVertex, nxt->bestVertex, cur->parent, nxt->parent,
|
||||
result.path);
|
||||
result.distance = bestPathReducedLength;
|
||||
if (curTop > 0)
|
||||
result.distance -= cur->ConsistentHeuristic(nxt->bestVertex);
|
||||
if (nxtTop > 0)
|
||||
result.distance -= nxt->ConsistentHeuristic(nxt->bestVertex);
|
||||
result.distance = bestPathRealLength;
|
||||
CHECK(!result.path.empty(), ());
|
||||
if (!cur->forward)
|
||||
reverse(result.path.begin(), result.path.end());
|
||||
|
@ -372,6 +369,11 @@ typename AStarAlgorithm<TGraph>::Result AStarAlgorithm<TGraph>::FindPathBidirect
|
|||
if (!foundAnyPath || bestPathReducedLength > curPathReducedLength)
|
||||
{
|
||||
bestPathReducedLength = curPathReducedLength;
|
||||
|
||||
bestPathRealLength = stateV.distance + len + distW;
|
||||
bestPathRealLength += cur->pS - pV;
|
||||
bestPathRealLength += nxt->pS - nxt->ConsistentHeuristic(stateW.vertex);
|
||||
|
||||
foundAnyPath = true;
|
||||
cur->bestVertex = stateV.vertex;
|
||||
nxt->bestVertex = stateW.vertex;
|
||||
|
|
|
@ -213,7 +213,7 @@ UNIT_TEST(AStarRouter_SimpleGraph_PickTheFasterRoad1)
|
|||
());
|
||||
TEST_EQUAL(result.path, vector<Junction>({m2::PointD(2,2), m2::PointD(2,3), m2::PointD(4,3), m2::PointD(6,3),
|
||||
m2::PointD(8,3), m2::PointD(10,3), m2::PointD(10,2)}), ());
|
||||
TEST(my::AlmostEqualAbs(result.distance, 159655., 1.), ("Distance error:", result.distance));
|
||||
TEST(my::AlmostEqualAbs(result.distance, 800451., 1.), ("Distance error:", result.distance));
|
||||
}
|
||||
|
||||
UNIT_TEST(AStarRouter_SimpleGraph_PickTheFasterRoad2)
|
||||
|
@ -240,7 +240,7 @@ UNIT_TEST(AStarRouter_SimpleGraph_PickTheFasterRoad2)
|
|||
algorithm.CalculateRoute(graph, m2::PointD(2, 2), m2::PointD(10, 2), delegate, result),
|
||||
());
|
||||
TEST_EQUAL(result.path, vector<Junction>({m2::PointD(2,2), m2::PointD(6,2), m2::PointD(10,2)}), ());
|
||||
TEST(my::AlmostEqualAbs(result.distance, 140663., 1.), ("Distance error:", result.distance));
|
||||
TEST(my::AlmostEqualAbs(result.distance, 781458., 1.), ("Distance error:", result.distance));
|
||||
}
|
||||
|
||||
UNIT_TEST(AStarRouter_SimpleGraph_PickTheFasterRoad3)
|
||||
|
@ -267,5 +267,5 @@ UNIT_TEST(AStarRouter_SimpleGraph_PickTheFasterRoad3)
|
|||
algorithm.CalculateRoute(graph, m2::PointD(2, 2), m2::PointD(10, 2), delegate, result),
|
||||
());
|
||||
TEST_EQUAL(result.path, vector<Junction>({m2::PointD(2,2), m2::PointD(2,1), m2::PointD(10,1), m2::PointD(10,2)}), ());
|
||||
TEST(my::AlmostEqualAbs(result.distance, 173616., 1.), ("Distance error:", result.distance));
|
||||
TEST(my::AlmostEqualAbs(result.distance, 814412., 1.), ("Distance error:", result.distance));
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue