Fix routing with needles
This commit is contained in:
parent
8d75159aec
commit
107b5259f9
1 changed files with 33 additions and 5 deletions
|
@ -28,7 +28,7 @@ public class BinaryRoutePlanner {
|
|||
protected static final Log log = PlatformUtil.getLog(BinaryRoutePlanner.class);
|
||||
|
||||
private static final int ROUTE_POINTS = 11;
|
||||
private static final boolean TRACE_ROUTING = false;
|
||||
private static final boolean TRACE_ROUTING = true;
|
||||
|
||||
|
||||
public static double squareRootDist(int x1, int y1, int x2, int y2) {
|
||||
|
@ -135,6 +135,7 @@ public class BinaryRoutePlanner {
|
|||
checkIfGraphIsEmpty(ctx, ctx.getPlanRoadDirection() >= 0, graphDirectSegments, start, visitedDirectSegments,
|
||||
"Route is not found from selected start point.");
|
||||
if (ctx.planRouteIn2Directions()) {
|
||||
if(!graphDirectSegments.isEmpty() && !graphReverseSegments.isEmpty())
|
||||
forwardSearch = (nonHeuristicSegmentsComparator.compare(graphDirectSegments.peek(), graphReverseSegments.peek()) < 0);
|
||||
// if (graphDirectSegments.size() * 2 > graphReverseSegments.size()) {
|
||||
// forwardSearch = false;
|
||||
|
@ -207,13 +208,40 @@ public class BinaryRoutePlanner {
|
|||
}
|
||||
}
|
||||
|
||||
public RouteSegment initRouteSegment(final RoutingContext ctx, RouteSegment segment, boolean positiveDirection) {
|
||||
if(segment.getSegmentStart() == 0 && !positiveDirection && segment.getRoad().getPointsLength() > 0) {
|
||||
segment = loadSameSegment(ctx, segment, 1);
|
||||
} else if(segment.getSegmentStart() == segment.getRoad().getPointsLength() -1 && positiveDirection && segment.getSegmentStart() > 0) {
|
||||
segment = loadSameSegment(ctx, segment, segment.getSegmentStart() -1);
|
||||
}
|
||||
if(segment == null) {
|
||||
return null;
|
||||
}
|
||||
return segment.initRouteSegment(positiveDirection);
|
||||
}
|
||||
|
||||
|
||||
protected RouteSegment loadSameSegment(final RoutingContext ctx, RouteSegment segment, int ind) {
|
||||
int x31 = segment.getRoad().getPoint31XTile(ind);
|
||||
int y31 = segment.getRoad().getPoint31YTile(ind);
|
||||
RouteSegment s = ctx.loadRouteSegment(x31, y31, 0);
|
||||
while(s != null) {
|
||||
if(s.getRoad().getId() == segment.getRoad().getId()) {
|
||||
segment = s;
|
||||
break;
|
||||
}
|
||||
s = s.getNext();
|
||||
}
|
||||
return segment;
|
||||
}
|
||||
|
||||
|
||||
private void initQueuesWithStartEnd(final RoutingContext ctx, RouteSegment start, RouteSegment end,
|
||||
PriorityQueue<RouteSegment> graphDirectSegments, PriorityQueue<RouteSegment> graphReverseSegments) {
|
||||
RouteSegment startPos = start.initRouteSegment(true);
|
||||
RouteSegment startNeg = start.initRouteSegment(false);
|
||||
RouteSegment endPos = end.initRouteSegment(true);
|
||||
RouteSegment endNeg = end.initRouteSegment(false);
|
||||
RouteSegment startPos = initRouteSegment(ctx, start, true);
|
||||
RouteSegment startNeg = initRouteSegment(ctx, start, false);
|
||||
RouteSegment endPos = initRouteSegment(ctx, end, true);
|
||||
RouteSegment endNeg = initRouteSegment(ctx, end, false);
|
||||
// for start : f(start) = g(start) + h(start) = 0 + h(start) = h(start)
|
||||
if(ctx.config.initialDirection != null) {
|
||||
// mark here as positive for further check
|
||||
|
|
Loading…
Reference in a new issue