@Override public MoveProgress moveTo(MovingRoadUser object, RoadUser destinationRoadUser, TimeLapse time) { return moveTo(object, destinationRoadUser, time, GeomHeuristics.euclidean()); }
@Override protected void tickImpl(TimeLapse time) { model.moveTo(this, target, time); } }
@Override public MoveProgress moveTo(MovingRoadUser object, RoadUser destinationRoadUser, TimeLapse time) { return moveTo(object, destinationRoadUser, time, GeomHeuristics.euclidean()); }
/** * It is not allowed to go to a delivery location twice. */ @Test(expected = IllegalArgumentException.class) public void attemptVisitFor3rdTime() { // first pickup rm.moveTo(dv1, dp1, time(11)); rm.removeObject(dp1); // then deliver rm.moveTo(dv1, dp1, time(80)); // 3rd time is not allowed! rm.moveTo(dv1, dp1, time(80)); }
/** * Check whether diversion within a route is correctly handled depending on * the configuration. */ @Test public void divertFromDest() { boolean success = true; try { rm.moveTo(dv1, dp1, time(7)); rm.moveTo(dv1, dp2, time(4)); } catch (final IllegalArgumentException e) { success = false; } assertEquals(allowDiversion, success); }
/** * A vehicle should always be allowed to go back the depot, even multiple * times. */ @Test public void revisitDepot() { // move to depot rm.moveTo(dv1, depot, time(1)); // move to pickup location rm.moveTo(dv1, dp1, time(1000)); // pickup pm.service(dv1, dp1, time(100)); // move to delivery location rm.moveTo(dv1, dp1, time(100)); // deliver pm.service(dv1, dp1, time(100)); // move to depot again rm.moveTo(dv1, depot, time(1)); }
/** * Check whether diversion (to the same parcel!) after route completion but * before pickup is correctly handled depending on the configuration. */ @Test public void divertToSameBeforePickup() { boolean success = true; try { rm.moveTo(dv1, dp1, time(7)); rm.moveTo(dv1, dp1, time(4)); assertEquals(rm.getPosition(dv1), rm.getPosition(dp1)); rm.moveTo(dv1, dp1, time(80)); } catch (final IllegalArgumentException e) { success = false; } assertEquals(allowDiversion, success); }
/** * Check whether diversion after route completion but before pickup is * correctly handled depending on the configuration. */ @Test public void divertToOtherBeforePickup() { boolean success = true; try { rm.moveTo(dv1, dp1, time(7)); rm.moveTo(dv1, dp1, time(4)); assertEquals(rm.getPosition(dv1), rm.getPosition(dp1)); rm.moveTo(dv1, dp2, time(80)); } catch (final IllegalArgumentException e) { success = false; } assertEquals(allowDiversion, success); }
/** * {@link RoadModel#moveTo(com.github.rinde.rinsim.core.model.road.MovingRoadUser, Point, TimeLapse)} * is only supported when diversion is allowed. */ @Test public void invalidMoveTo() { boolean success = true; try { rm.moveTo(dv1, new Point(0, 0), time(10)); } catch (final UnsupportedOperationException e) { success = false; } assertEquals(allowDiversion, success); }
/** * It is not allowed to go to a delivery location twice. */ @Test(expected = IllegalArgumentException.class) public void attemptVisitFor3rdTime2() { // first pickup rm.moveTo(dv1, dp1, time(11)); assertTrue(rm.equalPosition(dv1, dp1)); rm.removeObject(dp1); // then deliver rm.moveTo(dv1, dp1, time(80)); assertEquals(rm.getPosition(dv1), dp1.getDeliveryLocation()); rm.moveTo(dv1, dp2, time(180)); assertTrue(rm.equalPosition(dv1, dp2)); rm.removeObject(dp2); // it is not allowed to revisit this position rm.moveTo(dv1, dp1, time(80)); }
/** * Check whether diversion within a route before delivery is correctly handled * depending on the configuration. */ @Test public void divertToOtherBeforeDelivery() { boolean success = true; try { rm.moveTo(dv1, dp1, time(10)); assertEquals(rm.getPosition(dv1), rm.getPosition(dp1)); pm.pickup(dv1, dp1, time(10)); assertTrue(pm.containerContains(dv1, dp1)); rm.moveTo(dv1, dp1, time(1)); rm.moveTo(dv1, dp2, time(80)); } catch (final IllegalArgumentException e) { success = false; } assertEquals(allowDiversion, success); }
@Test public void twoVehiclesGoToSame() { // this is allowed rm.moveTo(dv1, dp1, time(10)); rm.moveTo(dv2, dp1, time(10)); assertEquals(rm.getPosition(dv1), rm.getPosition(dp1)); assertEquals(rm.getPosition(dv2), rm.getPosition(dp1)); pm.pickup(dv2, dp1, time(1)); assertFalse(rm.containsObject(dp1)); assertEquals(ParcelState.IN_CARGO, pm.getParcelState(dp1)); rm.moveTo(dv1, dp2, time(3)); }
@Test(expected = IllegalArgumentException.class) public void testInvalidRoadUser() { // does not exist rm.moveTo(dv1, Parcel.builder(new Point(0, 0), new Point(6, 6)) .build(), time(1)); }
/** * Check whether mixing diversion allowed/disallowed methods produce the * expected results. */ @Test public void test() { // first move by using the location rm.moveTo(dv1, dp1.getPickupLocation(), time(10)); assertEquals(rm.getPosition(dv1), dp1.getPickupLocation()); pm.pickup(dv1, dp1, time(1)); assertTrue(pm.containerContains(dv1, dp1)); // now move by using the reference to the parcel rm.moveTo(dv1, dp1, time(300)); assertEquals(rm.getPosition(dv1), dp1.getDeliveryLocation()); } }
/** * */ @Test public void brokenWaitState() { d.setRoute(asList(p1)); tick(4, 5, 30); assertEquals(d.gotoState, d.stateMachine.getCurrentState()); if (allowDelayedRouteChanges) { d.setRoute(Arrays.<Parcel>asList()); rm.moveTo(d, p1, time(minute(0), minute(10))); assertTrue(rm.equalPosition(d, p1)); pm.pickup(d, p1, time(minute(16), minute(17))); assertEquals(VehicleState.PICKING_UP, pm.getVehicleState(d)); if (diversionIsAllowed) { boolean exception = false; try { tick(5, 6); } catch (final IllegalStateException e) { exception = true; } assertTrue(exception); } } }
rm.moveTo(v1, destination, TimeLapseFactory.create(0, 1000)); assertEquals(destination, rm.getDestinationToParcel(v1)); assertEquals(ParcelState.AVAILABLE, pm.getParcelState(p1)); rm.moveTo(v1, destination, TimeLapseFactory.create(0, 1000000000)); assertEquals(rm.getPosition(destination), rm.getPosition(v1)); rm.moveTo(v1, destination, TimeLapseFactory.create(0, 1000)); assertEquals(destination, rm.getDestinationToParcel(v1)); assertEquals(ParcelState.IN_CARGO, pm.getParcelState(p1)); rm.moveTo(v1, destination, TimeLapseFactory.create(0, 1000000000)); assertEquals(destination.getDto().getDeliveryLocation(), rm.getPosition(v1));
rm.moveTo(dv1, dp1, time(7)); assertEquals(dp1, rm.getDestinationToParcel(dv1)); rm.moveTo(dv1, dp1, time(4)); assertEquals(dp1, rm.getDestinationToParcel(dv1)); assertEquals(ParcelState.IN_CARGO, pm.getParcelState(dp1)); rm.moveTo(dv1, dp1, time(1)); assertEquals(dp1, rm.getDestinationToParcel(dv1)); rm.moveTo(dv1, dp1, time(80)); assertEquals(dp1, rm.getDestinationToParcel(dv1)); pm.deliver(dv1, dp1, time(1)); rm.moveTo(dv1, dp2, time(50)); assertEquals(dp2, rm.getDestinationToParcel(dv1));