Search in sources :

Example 1 with VehicleRouter

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;
}
Also used : ArrayList(java.util.ArrayList) PriorityQueue(java.util.PriorityQueue) TLongHashSet(gnu.trove.set.hash.TLongHashSet) RouteDataObject(net.osmand.binary.RouteDataObject) VehicleRouter(net.osmand.router.VehicleRouter) RouteSegment(net.osmand.router.BinaryRoutePlanner.RouteSegment)

Aggregations

TLongHashSet (gnu.trove.set.hash.TLongHashSet)1 ArrayList (java.util.ArrayList)1 PriorityQueue (java.util.PriorityQueue)1 RouteDataObject (net.osmand.binary.RouteDataObject)1 RouteSegment (net.osmand.router.BinaryRoutePlanner.RouteSegment)1 VehicleRouter (net.osmand.router.VehicleRouter)1