/** * This test increases the travel time of a road, checks that the new travel time is accepted by * SUMO, and verifies that the first vehicle changed its route. In contrast with {@link * #testRerouting()}, the specified travel time applies to all vehicles in the simulation. * * @throws IOException */ @Test public void testChangeGlobalTravelTime() throws IOException { getFirstVehicle(); List<Edge> routeBefore = firstVehicle.getCurrentRoute(); log.info("Route before: " + routeBefore); String edgeID = "middle"; Edge edge = conn.getEdgeRepository().getByID(edgeID); ChangeGlobalTravelTimeQuery cttq = edge.queryChangeTravelTime(); cttq.setBeginTime(0); cttq.setEndTime(1000); cttq.setTravelTime(10000); cttq.run(); ReadGlobalTravelTimeQuery rgttq = edge.queryReadGlobalTravelTime(); rgttq.setTime(conn.getCurrentSimStep()); double newTravelTime = rgttq.get(); assertEquals(10000, newTravelTime, DELTA); firstVehicle.queryReroute().run(); List<Edge> routeAfter = firstVehicle.getCurrentRoute(); log.info("Route after: " + routeAfter); assertFalse(routeBefore.equals(routeAfter)); }
/** main method */ public static void main(String[] args) { SumoTraciConnection conn = new SumoTraciConnection( "test/sumo_maps/box1l/test.sumo.cfg", // config file 12345 // random seed ); try { conn.runServer(); // the first two steps of this simulation have no vehicles. conn.nextSimStep(); conn.nextSimStep(); Collection<Vehicle> vehicles = conn.getVehicleRepository().getAll().values(); Vehicle aVehicle = vehicles.iterator().next(); System.out.println( "Vehicle " + aVehicle + " will traverse these edges: " + aVehicle.getCurrentRoute()); conn.close(); } catch (Exception e) { e.printStackTrace(); } }
/** * This test checks ensures that changing the destination road also changes the vehicle's current * route list such that the last road is the new destination road. * * @throws IOException */ @Test public void testChangeTargetAlsoAffectsRouteList() throws IOException { getFirstVehicle(); Vehicle v = firstVehicle; Edge endEdge = conn.getEdgeRepository().getByID("end"); v.changeTarget(endEdge); List<Edge> route = v.getCurrentRoute(); assertEquals("end", route.get(route.size() - 1).getID()); }
/** * This test tries to explicitly set a vehicle's route, and verifies that SUMO accepts it. * * @throws IOException */ @Test public void testChangeRoute() throws IOException { getFirstVehicle(); Vehicle v = firstVehicle; List<Edge> newRoute = new ArrayList<Edge>(); newRoute.add(conn.getEdgeRepository().getByID("beg")); newRoute.add(conn.getEdgeRepository().getByID("beg2left")); newRoute.add(conn.getEdgeRepository().getByID("left")); newRoute.add(conn.getEdgeRepository().getByID("left2end")); v.changeRoute(newRoute); assertEquals(newRoute, v.getCurrentRoute()); }
/** * This test increases the travel time of a road "perceived" by the first vehicle. This will make * the vehicle look for an alternative route. * * @throws IOException */ @Test public void testRerouting() throws IOException { getFirstVehicle(); List<Edge> routeBefore = firstVehicle.getCurrentRoute(); log.info("Route before: " + routeBefore); String edgeID = "middle"; Edge edge = conn.getEdgeRepository().getByID(edgeID); ChangeEdgeTravelTimeQuery settq = firstVehicle.querySetEdgeTravelTime(); settq.setEdge(edge); settq.setTravelTime(10000); settq.run(); firstVehicle.queryReroute().run(); List<Edge> routeAfter = firstVehicle.getCurrentRoute(); log.info("Route after: " + routeAfter); assertFalse(routeBefore.equals(routeAfter)); }
/** * This test reads a vehicle's route and checks for its correctness. (they all have the same * route) * * @throws IOException */ @Test public void testRoute() throws IOException { getFirstVehicle(); List<Edge> route = firstVehicle.getCurrentRoute(); assertEquals(4, route.size()); Iterator<Edge> it = route.iterator(); assertEquals("beg", it.next().getID()); assertEquals("middle", it.next().getID()); assertEquals("end", it.next().getID()); assertEquals("rend", it.next().getID()); }