Point getParcelPos(RoadUser obj) { if (!containsObject(obj) && obj instanceof Parcel) { final ParcelState state = pdpModel.get().getParcelState( (Parcel) obj); checkArgument( state == ParcelState.IN_CARGO, "Can only move to parcels which are either on the map or in cargo, " + "state is %s, obj is %s.", state, obj); return ((Parcel) obj).getDeliveryLocation(); } return getPosition(obj); }
Point getParcelPos(RoadUser obj) { if (!containsObject(obj) && obj instanceof Parcel) { final ParcelState state = pdpModel.get().getParcelState( (Parcel) obj); checkArgument( state == ParcelState.IN_CARGO, "Can only move to parcels which are either on the map or in cargo, " + "state is %s, obj is %s.", state, obj); return ((Parcel) obj).getDeliveryLocation(); } return getPosition(obj); }
Point convertToPos(Truck t) { Point p; if (t.getRoute().isEmpty() || heuristic == SelectNegotiatorsHeuristic.VEHICLE_POSITION) { p = roadModel.get().getPosition(t); } else { final Parcel firstDestination = t.getRoute().iterator().next(); if (pdpModel.get().getParcelState(firstDestination).isPickedUp()) { p = firstDestination.getDto().getDeliveryLocation(); } else { p = firstDestination.getDto().getPickupLocation(); } } return p; }
return VehicleStateObject.create(vehicle.getDTO(), rm.getPosition(vehicle), conn, contents, remainingServiceTime,
@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)); }
} else { newDestinationObject = DestinationObject.create(DestType.DEPOT, getPosition(destinationRoadUser), destinationRoadUser); if (destinations.containsKey(object) && !allowDiversion) { final DestinationObject prev = destinations.get(object); final boolean atDestination = getPosition(object).equals(prev.dest());
} else { newDestinationObject = DestinationObject.create(DestType.DEPOT, getPosition(destinationRoadUser), destinationRoadUser); if (destinations.containsKey(object) && !allowDiversion) { final DestinationObject prev = destinations.get(object); final boolean atDestination = getPosition(object).equals(prev.dest());
/** * 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); }
VehicleStateObject.create( mv1.getDTO(), graphRm.getPosition(mv1), vehicleConnection, ImmutableSet.<Parcel>of(mp1), assertEquals(new Point(1, 0), graphRm.getPosition(mv1)); VehicleStateObject.create( mv1.getDTO(), graphRm.getPosition(mv1), vehicleConnection, ImmutableSet.<Parcel>of(mp1),
/** * 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); }
/** * 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()); } }
tick(2, 3); assertEquals(d.waitState, d.stateMachine.getCurrentState()); assertEquals(new Point(1, 1), rm.getPosition(d));
void checkVehicles(List<? extends TestVehicle> expected, ImmutableList<VehicleStateObject> states) { assertEquals(expected.size(), states.size()); for (int i = 0; i < expected.size(); i++) { final TestVehicle vehicle = expected.get(i); final VehicleDTO dto = vehicle.dto; final VehicleStateObject vs = states.get(i); assertEquals(dto.getAvailabilityTimeWindow(), vs.getDto().getAvailabilityTimeWindow()); assertEquals(dto.getCapacity(), vs.getDto().getCapacity()); assertEquals(dto.getSpeed(), vs.getDto().getSpeed(), 0); assertEquals(dto.getStartPosition(), vs.getDto().getStartPosition()); assertEquals(rm.getPosition(expected.get(i)), vs.getLocation()); final Parcel dest = rm.getDestinationToParcel(vehicle); if (dest == null) { assertFalse(vs.getDestination().isPresent()); } else { assertEquals(dest, vs.getDestination().get()); } if (pm.getVehicleState(vehicle) == VehicleState.IDLE) { assertEquals(0, vs.getRemainingServiceTime()); } else { assertEquals(pm.getVehicleActionInfo(vehicle).timeNeeded(), vs.getRemainingServiceTime()); } } }
assertEquals(new Point(0, 1), rm.getPosition(v1)); sim.tick(); assertFalse(new Point(0, 1).equals(rm.getPosition(v1))); state = s.convert(SolveArgs.create().useAllParcels().noCurrentRoutes()); assertEquals(2, state.getVehicles().size()); assertEquals(new Point(3, 0), rm.getPosition(v1)); assertEquals(v1.getWaitForServiceState(), v1.getState()); state = s.convert(SolveArgs.create().useAllParcels().noCurrentRoutes());
assertEquals(rm.getPosition(destination), rm.getPosition(v1)); rm.getPosition(v1)); pm.deliver(v1, p1, TimeLapseFactory.create(0, 1)); assertNull(rm.getDestinationToParcel(v1));
tick(2, 3); assertEquals(d.waitState, d.stateMachine.getCurrentState()); assertEquals(new Point(1, 1), rm.getPosition(d)); assertEquals(new Point(1, 1.5), rm.getPosition(d)); assertEquals(d.gotoState, d.stateMachine.getCurrentState()); assertEquals(new Point(1, 2.0), rm.getPosition(d)); assertEquals(d.gotoState, d.stateMachine.getCurrentState());
tick(2, 3); assertEquals(d.waitState, d.stateMachine.getCurrentState()); assertEquals(new Point(1, 1), rm.getPosition(d)); assertEquals(new Point(1, 1.5), rm.getPosition(d)); assertEquals(d.gotoState, d.stateMachine.getCurrentState()); assertEquals(new Point(1, 2.0), rm.getPosition(d)); assertEquals(d.gotoState, d.stateMachine.getCurrentState());
tick(2, 3); assertEquals(d.waitState, d.stateMachine.getCurrentState()); assertEquals(new Point(1, 1), rm.getPosition(d)); assertEquals(new Point(1, 1.5), rm.getPosition(d)); assertEquals(d.gotoState, d.stateMachine.getCurrentState()); assertEquals(new Point(1, 1.99), rm.getPosition(d)); assertEquals(d.waitForServiceState, d.stateMachine.getCurrentState());
/** * 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)); }