@Override public MoveProgress moveTo(MovingRoadUser object, RoadUser destinationRoadUser, TimeLapse time) { return moveTo(object, destinationRoadUser, time, GeomHeuristics.euclidean()); }
@Test public void moveToHeuristicTest() { final MovingRoadUser fastestPathAgent = new SpeedyRoadUser(10); final MovingRoadUser shortestPathAgent = new SpeedyRoadUser(10); final Point origin = new Point(0, 0); final Point destination = new Point(0, 10); final Point midway = new Point(5, 5); // Graph with slow direct (shortest) route, but fast longer route. final Graph<MultiAttributeData> graph = new TableGraph<>(); graph.addConnection(origin, destination, MultiAttributeData.builder().setLength(10).setMaxSpeed(1).build()); graph.addConnection(origin, midway, MultiAttributeData.builder().setLength(10).setMaxSpeed(10).build()); graph.addConnection(midway, destination, MultiAttributeData.builder().setLength(10).setMaxSpeed(10).build()); final RoadModel moveModel = RoadModelBuilders.staticGraph(graph) .withDistanceUnit(SI.KILOMETER).withSpeedUnit(NonSI.KILOMETERS_PER_HOUR) .build(mock(DependencyProvider.class)); moveModel.addObjectAt(fastestPathAgent, origin); moveModel.addObjectAt(shortestPathAgent, origin); moveModel.moveTo(fastestPathAgent, destination, hour(1), GeomHeuristics.time(10)); moveModel.moveTo(shortestPathAgent, destination, hour(1), GeomHeuristics.euclidean()); // Agent chose speedy route assertEquals(midway, moveModel.getPosition(fastestPathAgent)); // Agent chose shortest route assertEquals(new Point(0, 1), moveModel.getPosition(shortestPathAgent)); }
/** * The fastest path changes based on the maximal allowed speed */ @Test public void fastestPathConnData() { final Graph<MultiAttributeData> attributeGraph = new TableGraph<>(); Point A, B, C, D; A = new Point(0, 0); B = new Point(0, 10); C = new Point(10, 10); D = new Point(10, 0); attributeGraph.addConnection(A, B, MultiAttributeData.builder().setMaxSpeed(2).build()); attributeGraph.addConnection(B, C, MultiAttributeData.builder().setMaxSpeed(2).build()); attributeGraph.addConnection(A, D, MultiAttributeData.builder().setMaxSpeed(1).build()); attributeGraph.addConnection(D, C, MultiAttributeData.builder().setMaxSpeed(1).build()); assertEquals(asList(A, B, C), Graphs.shortestPath(attributeGraph, A, C, GeomHeuristics.time(50d))); attributeGraph.setConnectionData(A, D, MultiAttributeData.builder().setMaxSpeed(10).build()); attributeGraph.setConnectionData(D, C, MultiAttributeData.builder().setMaxSpeed(10).build()); assertEquals(asList(A, D, C), Graphs.shortestPath(attributeGraph, A, C, GeomHeuristics.time(50d))); }
@Test public void fastestPathSpeedLimitationTest() { final Graph<MultiAttributeData> attributeGraph = new TableGraph<>(); Point A, B, C; A = new Point(0, 0); B = new Point(0, 1); C = new Point(1, 0); attributeGraph.addConnection(A, B, MultiAttributeData.builder().setMaxSpeed(1).build()); attributeGraph.addConnection(A, C, MultiAttributeData.builder().setMaxSpeed(3).build()); final GeomHeuristic heuristic = GeomHeuristics.time(0d); assertEquals(1d, heuristic.calculateTravelTime(attributeGraph, A, B, SI.KILOMETER, Measure.valueOf(2d, NonSI.KILOMETERS_PER_HOUR), NonSI.HOUR), DELTA); assertEquals(0.5d, heuristic.calculateTravelTime(attributeGraph, A, C, SI.KILOMETER, Measure.valueOf(2d, NonSI.KILOMETERS_PER_HOUR), NonSI.HOUR), DELTA); }
@Override public MoveProgress moveTo(MovingRoadUser object, RoadUser destinationRoadUser, TimeLapse time) { return moveTo(object, destinationRoadUser, time, GeomHeuristics.euclidean()); }
@Override public MoveProgress moveTo(MovingRoadUser object, Point destination, TimeLapse time) { return moveTo(object, destination, time, GeomHeuristics.euclidean()); }
/** * Computes the shortest path based on the Euclidean distance. * @param graph The {@link Graph} on which the shortest path is searched. * @param from The start point of the path. * @param to The destination of the path. * @param <E> The type of connection data. * @return The shortest path that exists between <code>from</code> and * <code>to</code>. */ public static <E extends ConnectionData> List<Point> shortestPathEuclideanDistance( Graph<E> graph, final Point from, final Point to) { return Graphs.shortestPath(graph, from, to, GeomHeuristics.euclidean()); }
/** * Computes the shortest path based on the Euclidean distance. * @param graph The {@link Graph} on which the shortest path is searched. * @param from The start point of the path. * @param to The destination of the path. * @param <E> The type of connection data. * @return The shortest path that exists between <code>from</code> and * <code>to</code>. */ public static <E extends ConnectionData> List<Point> shortestPathEuclideanDistance( Graph<E> graph, final Point from, final Point to) { return Graphs.shortestPath(graph, from, to, GeomHeuristics.euclidean()); }
/** * Computes a {@link StatisticsDTO} instance for the given * {@link GlobalStateObject} and routes. For each vehicle in the state the * specified route is used and its arrival times, tardiness and travel times * are computed. The resulting {@link StatisticsDTO} has the same properties * as performing a simulation with the same state. However, since the current * state may be half-way a simulation, it is possible that the returned * statistics describe only a partial simulation. As a result * {@link StatisticsDTO#totalDeliveries} does not necessarily equal * {@link StatisticsDTO#totalPickups}. The travel times and distance are * computed using {@link GeomHeuristics#euclidean()}. * @param state The state which represents a simulation. * @param routes Specifies the route the vehicles are currently following, * must be of same size as the number of vehicles (one route per * vehicle). If this is <code>null</code> the * {@link VehicleStateObject#getRoute()} field must be set instead * for <b>each</b> vehicle. * @return The statistics that will be generated when executing this * simulation. */ public static ExtendedStats computeStats(GlobalStateObject state, @Nullable ImmutableList<ImmutableList<Parcel>> routes) { return computeStats(state, routes, GeomHeuristics.euclidean()); }
allowDelayedRouteChanges = allowDelayedRouteChanging; routeAdjuster = adjuster; routeHeuristic = GeomHeuristics.euclidean();
allowDelayedRouteChanges = allowDelayedRouteChanging; routeAdjuster = adjuster; routeHeuristic = GeomHeuristics.euclidean();