Search in sources :

Example 1 with Route

use of massim.scenario.city.data.Route in project massim by agentcontest.

the class CityMap method getNewAirRoute.

/**
 * Computes a new air route. GH not needed for this. Map bounds are not checked.
 * @param from source location
 * @param to target location
 * @return a new route or null if no such route exists
 */
private Route getNewAirRoute(Location from, Location to) {
    Route route = new Route();
    double fractions = getLength(from, to) / (double) cellSize;
    Location loc = null;
    for (long i = 1; i <= fractions; i++) {
        loc = getIntermediateLoc(from, to, fractions, i);
        route.addPoint(loc);
    }
    if (!to.equals(loc)) {
        route.addPoint(to);
    }
    return route;
}
Also used : Route(massim.scenario.city.data.Route) Location(massim.scenario.city.data.Location)

Example 2 with Route

use of massim.scenario.city.data.Route in project massim by agentcontest.

the class CityMap method getNewCarRoute.

private Route getNewCarRoute(Location from, Location to) {
    GHResponse rsp = queryGH(from, to);
    if (rsp.hasErrors())
        return null;
    Route route = new Route();
    // points, distance in meters and time in millis of the full path
    PointList pointList = rsp.getBest().getPoints();
    Iterator<GHPoint3D> pIterator = pointList.iterator();
    if (!pIterator.hasNext())
        return null;
    GHPoint prevPoint = pIterator.next();
    double remainder = 0;
    Location loc = null;
    while (pIterator.hasNext()) {
        GHPoint nextPoint = pIterator.next();
        double length = getLength(prevPoint, nextPoint);
        if (length == 0) {
            prevPoint = nextPoint;
            continue;
        }
        long i = 0;
        for (; i * cellSize + remainder < length; i++) {
            loc = getIntermediateLoc(prevPoint, nextPoint, length, i * cellSize + remainder);
            if (!from.equals(loc)) {
                route.addPoint(loc);
            }
        }
        remainder = i * cellSize + remainder - length;
        prevPoint = nextPoint;
    }
    if (!to.equals(loc)) {
        route.addPoint(to);
    }
    return route;
}
Also used : PointList(com.graphhopper.util.PointList) GHPoint3D(com.graphhopper.util.shapes.GHPoint3D) GHResponse(com.graphhopper.GHResponse) GHPoint(com.graphhopper.util.shapes.GHPoint) Route(massim.scenario.city.data.Route) Location(massim.scenario.city.data.Location)

Aggregations

Location (massim.scenario.city.data.Location)2 Route (massim.scenario.city.data.Route)2 GHResponse (com.graphhopper.GHResponse)1 PointList (com.graphhopper.util.PointList)1 GHPoint (com.graphhopper.util.shapes.GHPoint)1 GHPoint3D (com.graphhopper.util.shapes.GHPoint3D)1