This commit is contained in:
Victor Shcherb 2020-06-11 00:44:51 +02:00
parent a05ede7185
commit 41cc9fcd3f

View file

@ -138,7 +138,7 @@ public class BinaryRoutePlanner {
checkIfGraphIsEmpty(ctx, ctx.getPlanRoadDirection() >= 0, graphDirectSegments, start, visitedDirectSegments, checkIfGraphIsEmpty(ctx, ctx.getPlanRoadDirection() >= 0, graphDirectSegments, start, visitedDirectSegments,
"Route is not found from selected start point."); "Route is not found from selected start point.");
if (ctx.planRouteIn2Directions()) { if (ctx.planRouteIn2Directions()) {
forwardSearch = (nonHeuristicSegmentsComparator.compare(graphDirectSegments.peek(), graphReverseSegments.peek()) < 0); forwardSearch = nonHeuristicSegmentsComparator.compare(graphDirectSegments.peek(), graphReverseSegments.peek()) <= 0;
// if (graphDirectSegments.size() * 2 > graphReverseSegments.size()) { // if (graphDirectSegments.size() * 2 > graphReverseSegments.size()) {
// forwardSearch = false; // forwardSearch = false;
// } else if (graphDirectSegments.size() < 2 * graphReverseSegments.size()) { // } else if (graphDirectSegments.size() < 2 * graphReverseSegments.size()) {
@ -798,10 +798,32 @@ public class BinaryRoutePlanner {
" distToEnd=" + distanceToEnd + " distToEnd=" + distanceToEnd +
" segmentPoint=" + segmentPoint + " -- ", next, true); " segmentPoint=" + segmentPoint + " -- ", next, true);
} }
if (!visitedSegments.containsKey(calculateRoutePointId(next, next.isPositive()))) { RouteSegment visIt = visitedSegments.get(calculateRoutePointId(next, next.isPositive()));
if (next.getParentRoute() == null boolean toAdd = true;
|| ctx.roadPriorityComparator(next.distanceFromStart, next.distanceToEnd, if (visIt != null) {
distFromStart, distanceToEnd) > 0) { // the segment was already visited! We need to follow better route if it exists
// that is very exceptional situation and almost exception, it can happen
// 1. when we underestimate distnceToEnd - wrong h()
// 2. because we process not small segments but the whole road, it could be that
// deviation from the road is faster than following the whole road itself!
if (TRACE_ROUTING) {
printRoad(">?", visitedSegments.get(calculateRoutePointId(next, next.isPositive())),
next.isPositive());
}
if (distFromStart < next.distanceFromStart) {
if (ctx.config.heuristicCoefficient <= 1) {
System.err.println("! Alert distance from start " + distFromStart + " < "
+ next.distanceFromStart + " id=" + next.road.id);
}
}
if (distFromStart < visIt.distanceFromStart && next.getParentRoute() == null) {
toAdd = true;
} else {
toAdd = false;
}
}
if (toAdd && (next.getParentRoute() == null || ctx.roadPriorityComparator(next.distanceFromStart,
next.distanceToEnd, distFromStart, distanceToEnd) > 0)) {
next.distanceFromStart = distFromStart; next.distanceFromStart = distFromStart;
next.distanceToEnd = distanceToEnd; next.distanceToEnd = distanceToEnd;
if (TRACE_ROUTING) { if (TRACE_ROUTING) {
@ -812,27 +834,6 @@ public class BinaryRoutePlanner {
next.setParentSegmentEnd(segmentPoint); next.setParentSegmentEnd(segmentPoint);
graphSegments.add(next); graphSegments.add(next);
} }
} else {
// the segment was already visited! We need to follow better route if it exists
// that is very exceptional situation and almost exception, it can happen
// 1. when we underestimate distnceToEnd - wrong h()
// 2. because we process not small segments but the whole road, it could be that
// deviation from the road is faster than following the whole road itself!
if (distFromStart < next.distanceFromStart) {
if (ctx.config.heuristicCoefficient <= 1) {
System.err.println("! Alert distance from start " + distFromStart + " < "
+ next.distanceFromStart + " id=" + next.road.id);
}
// A: we can't change parent route just here, because we need to update visitedSegments
// presumably we can do visitedSegments.put(calculateRoutePointId(next), next);
// next.distanceFromStart = distFromStart;
// next.setParentRoute(segment);
// next.setParentSegmentEnd(segmentPoint);
if (ctx.visitor != null) {
// ctx.visitor.visitSegment(next, false);
}
}
}
} }
} }