use of net.osmand.router.VehicleRouter in project OsmAnd-tools by osmandapp.
the class CheckRoadConnectivity method findConnectedRoads.
private List<RouteDataObject> findConnectedRoads(RoutingContext ctx, RouteDataObject initial, boolean begin, TLongObjectHashMap<List<RouteDataObject>> all) {
PriorityQueue<RouteSegment> queue = new PriorityQueue<RouteSegment>(10, new Comparator<RouteSegment>() {
@Override
public int compare(RouteSegment o1, RouteSegment o2) {
return Double.compare(o1.getDistanceFromStart(), o2.getDistanceFromStart());
}
});
VehicleRouter router = ctx.getRouter();
ArrayList<RouteDataObject> next = new ArrayList<RouteDataObject>();
ctx.loadTileData(initial.getPoint31XTile(0), initial.getPoint31YTile(0), 17, next);
for (RouteDataObject n : next) {
if (n.id == initial.id) {
initial = n;
break;
}
}
queue.add(new RouteSegment(initial, begin ? 1 : initial.getPointsLength() - 2));
TLongHashSet visited = new TLongHashSet();
RouteSegment finalSegment = null;
while (!queue.isEmpty() && finalSegment == null) {
RouteSegment segment = queue.poll();
int oneWay = router.isOneWay(segment.getRoad());
boolean start = initial.id == segment.getRoad().id;
if (start) {
oneWay = begin ? -1 : 1;
}
if (oneWay >= 0) {
finalSegment = processSegment(ctx, segment, queue, visited, all, true, start);
}
if (oneWay <= 0) {
finalSegment = processSegment(ctx, segment, queue, visited, all, false, start);
}
}
if (finalSegment == null) {
if (TRACE) {
System.out.println("Isolated " + initial.id);
}
} else {
StringBuilder b = new StringBuilder("Route for " + initial.id + " : ");
RouteSegment s = finalSegment;
List<RouteDataObject> rdoToAdd = new ArrayList<RouteDataObject>();
while (s != null) {
if (s.getRoad().id != initial.id) {
b.append(s.getRoad().id).append(", ");
rdoToAdd.add(s.getRoad());
}
s = s.getParentRoute();
}
if (TRACE) {
System.out.println(b);
}
return rdoToAdd;
}
return null;
}
Aggregations