Search in sources :

Example 1 with Location

use of massim.scenario.city.data.Location 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 Location

use of massim.scenario.city.data.Location 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)

Example 3 with Location

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

the class CityMap method getRandomLocationInBounds.

/**
 * Tries to find a random location on this map (reachable from the center) within some bounds.
 * <b>The bounds provided must be within map bounds.</b>
 * @param roads if not empty, tries to find a location snapped to these road types (e.g. "road")
 * @param iterations if roads param is non-empty: maximum number of attempts to snap a random location to a road
 * @param minLat the minimum latitude the area to search in
 * @param maxLat the maximum latitude of the area to search in
 * @param minLon the minimum longitude of the area to search in
 * @param maxLon the maximum longitude of the area to search in
 * @return a random location on the map or the map's center, if no such location could be found
 */
public Location getRandomLocationInBounds(Set<String> roads, int iterations, double minLat, double maxLat, double minLon, double maxLon) {
    Location loc;
    for (int i = 0; i < iterations; i++) {
        double latDiff = maxLat - minLat;
        double lonDiff = maxLon - minLon;
        double lat = minLat + RNG.nextDouble() * latDiff;
        double lon = minLon + RNG.nextDouble() * lonDiff;
        loc = getNearestRoad(new Location(lon, lat));
        if (isReachable(loc, roads))
            return loc;
    }
    Log.log(Log.Level.ERROR, String.format("Exceeded max tries to find a location. %f, %f : %f, %f", minLat, minLon, maxLat, maxLon));
    return center;
}
Also used : GHPoint(com.graphhopper.util.shapes.GHPoint) Location(massim.scenario.city.data.Location)

Aggregations

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