commit
c26e4146d9
4 changed files with 36 additions and 29 deletions
|
@ -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,40 +798,41 @@ 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) {
|
|
||||||
next.distanceFromStart = distFromStart;
|
|
||||||
next.distanceToEnd = distanceToEnd;
|
|
||||||
if (TRACE_ROUTING) {
|
|
||||||
printRoad(" "+segmentPoint+">>" , next, null);
|
|
||||||
}
|
|
||||||
// put additional information to recover whole route after
|
|
||||||
next.setParentRoute(segment);
|
|
||||||
next.setParentSegmentEnd(segmentPoint);
|
|
||||||
graphSegments.add(next);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// the segment was already visited! We need to follow better route if it exists
|
// 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
|
// that is very exceptional situation and almost exception, it can happen
|
||||||
// 1. when we underestimate distnceToEnd - wrong h()
|
// 1. when we underestimate distnceToEnd - wrong h()
|
||||||
// 2. because we process not small segments but the whole road, it could be that
|
// 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!
|
// 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 (distFromStart < next.distanceFromStart) {
|
||||||
if (ctx.config.heuristicCoefficient <= 1) {
|
if (ctx.config.heuristicCoefficient <= 1) {
|
||||||
System.err.println("! Alert distance from start " + distFromStart + " < "
|
System.err.println("! Alert distance from start " + distFromStart + " < "
|
||||||
+ next.distanceFromStart + " id=" + next.road.id);
|
+ 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
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.distanceToEnd = distanceToEnd;
|
||||||
|
if (TRACE_ROUTING) {
|
||||||
|
printRoad(" " + segmentPoint + ">>", next, null);
|
||||||
|
}
|
||||||
|
// put additional information to recover whole route after
|
||||||
|
next.setParentRoute(segment);
|
||||||
|
next.setParentSegmentEnd(segmentPoint);
|
||||||
|
graphSegments.add(next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -301,7 +301,8 @@ public class RoutePlannerFrontEnd {
|
||||||
int py = MapUtils.get31TileNumberY(point.getLatitude());
|
int py = MapUtils.get31TileNumberY(point.getLatitude());
|
||||||
int pind = st ? routeSegmentResult.getStartPointIndex() : routeSegmentResult.getEndPointIndex();
|
int pind = st ? routeSegmentResult.getStartPointIndex() : routeSegmentResult.getEndPointIndex();
|
||||||
|
|
||||||
RouteDataObject r = routeSegmentResult.getObject();
|
RouteDataObject r = new RouteDataObject(routeSegmentResult.getObject());
|
||||||
|
routeSegmentResult.setObject(r);
|
||||||
QuadPoint before = null;
|
QuadPoint before = null;
|
||||||
QuadPoint after = null;
|
QuadPoint after = null;
|
||||||
if (pind > 0) {
|
if (pind > 0) {
|
||||||
|
|
|
@ -394,7 +394,6 @@ public class RouteResultPreparation {
|
||||||
}
|
}
|
||||||
// reverse it just to attach good direction roads
|
// reverse it just to attach good direction roads
|
||||||
Collections.reverse(result);
|
Collections.reverse(result);
|
||||||
|
|
||||||
segment = finalSegment.reverseWaySearch ? finalSegment.opposite.getParentRoute() : finalSegment;
|
segment = finalSegment.reverseWaySearch ? finalSegment.opposite.getParentRoute() : finalSegment;
|
||||||
int parentSegmentEnd = finalSegment.reverseWaySearch ? finalSegment.opposite.getParentSegmentEnd() : finalSegment.opposite.getSegmentStart();
|
int parentSegmentEnd = finalSegment.reverseWaySearch ? finalSegment.opposite.getParentSegmentEnd() : finalSegment.opposite.getSegmentStart();
|
||||||
parentRoutingTime = -1;
|
parentRoutingTime = -1;
|
||||||
|
|
|
@ -23,7 +23,7 @@ import gnu.trove.map.hash.TIntObjectHashMap;
|
||||||
public class RouteSegmentResult implements StringExternalizable<RouteDataBundle> {
|
public class RouteSegmentResult implements StringExternalizable<RouteDataBundle> {
|
||||||
// this should be bigger (50-80m) but tests need to be fixed first
|
// this should be bigger (50-80m) but tests need to be fixed first
|
||||||
private static final float DIST_BEARING_DETECT = 5;
|
private static final float DIST_BEARING_DETECT = 5;
|
||||||
private final RouteDataObject object;
|
private RouteDataObject object;
|
||||||
private int startPointIndex;
|
private int startPointIndex;
|
||||||
private int endPointIndex;
|
private int endPointIndex;
|
||||||
private List<RouteSegmentResult>[] attachedRoutes;
|
private List<RouteSegmentResult>[] attachedRoutes;
|
||||||
|
@ -536,9 +536,15 @@ public class RouteSegmentResult implements StringExternalizable<RouteDataBundle>
|
||||||
this.description = description;
|
this.description = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setObject(RouteDataObject r) {
|
||||||
|
this.object = r;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return object.toString() + ": " + startPointIndex + "-" + endPointIndex;
|
return object.toString() + ": " + startPointIndex + "-" + endPointIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue