@Override public void handleEvent(Event e) { if (!(e instanceof PDPModelEvent)) { return; } final List<Parcel> route = new ArrayList<>(vehicle.getRoute()); final Parcel newlyAddedParcel = ((PDPModelEvent) e).parcel; route.add(newlyAddedParcel); route.add(newlyAddedParcel); vehicle.setRoute(route); } }, PDPModelEventType.NEW_PARCEL);
@Override public void handleTimedEvent(AddVehicleEvent event, SimulatorAPI sim) { sim.register(new RouteFollowingVehicle(event.getVehicleDTO(), true, RouteFollowingVehicle.nopAdjuster(), heuristic)); }
@Override public void initRoadPDP(RoadModel pRoadModel, PDPModel pPdpModel) { super.initRoadPDP(pRoadModel, pPdpModel); routePlanner.init(pRoadModel, pPdpModel, this); communicator.init(pRoadModel, pPdpModel, this); }
/** * @param time The time to use as 'now'. * @return <code>true</code> if it is the end of the day or if this vehicle * has to leave before the end of this tick to arrive back at the * depot right before the end of the day, <code>false</code> * otherwise. */ protected boolean isEndOfDay(TimeLapse time) { final long travelTime = computeTravelTimeTo( getRoadModel().getPosition(depot.get()), time.getTimeUnit()); return time.getEndTime() - 1 >= getAvailabilityTimeWindow().end() - travelTime; }
@SuppressWarnings("synthetic-access") @Override public void onEntry(StateEvent event, RouteFollowingVehicle context) { checkState( getPDPModel().getVehicleState(context) == VehicleState.IDLE, "We can only be in Wait state when the vehicle is idle, " + "vehicle is %s.", getPDPModel().getVehicleState(context)); if (event == DefaultEvent.NOGO) { checkArgument(isDiversionAllowed); } if (context.newRoute.isPresent()) { context.setRoute(context.newRoute.get()); } }
ImmutableList<ImmutableList<Parcel>> getCurrentRoutes() { // gather current routes final ImmutableList.Builder<ImmutableList<Parcel>> currentRouteBuilder = ImmutableList.builder(); for (final RouteFollowingVehicle vehicle : vehicles) { final ImmutableList<Parcel> l = ImmutableList.copyOf(vehicle.getRoute()); currentRouteBuilder.add(l); } return currentRouteBuilder.build(); }
.build(); final RouteFollowingVehicle rfv = new RouteFollowingVehicle(VehicleDTO .builder() .startPosition(new Point(1, 1)) sim.register(dp2); rfv.setRoute(asList(dp1, dp2)); while (rfv.getRoute().size() > 0) { sim.tick();
d.setRoute(asList(p1, p1)); d2.setRoute(asList(p4, p4)); tick(0, 7); d2.tick(TimeLapseFactory.create(minute(0), minute(7))); assertThat(pm.getVehicleActionInfo(d).getParcel()).isSameAs(p1); assertThat(pm.getVehicleActionInfo(d2).getParcel()).isSameAs(p4); assertThat(d.getRoute()).containsExactly(p1, p1); assertThat(d2.getRoute()).containsExactly(p4, p4); d.setRoute(asList(p1, p4, p1, p4)); assertThat(d.getRoute()).containsExactly(p1, p1); } catch (final IllegalArgumentException e) { fail = true; d2.setRoute(asList(p1, p4, p4, p1)); assertThat(d2.getRoute()).containsExactly(p4, p4); } catch (final IllegalArgumentException e) { fail = true;
assertFalse(d.gotoState.prevDestination.isPresent()); d.setRoute(asList(p1)); assertEquals(diversionIsAllowed, d.isDiversionAllowed()); assertEquals(Optional.absent(), d.newRoute); tick(5, 6); assertEquals(p1, d.getRoute().iterator().next()); d.setRoute(asList(p2)); } catch (final IllegalArgumentException e) { fail = true;
/** * Test illegal argument: delivered state. */ @Test(expected = IllegalArgumentException.class) public void isTooEarlyDeliveredStateFail() { d.setRoute(asList(p1, p1)); tick(0, 60); assertEquals(ParcelState.DELIVERED, pm.getParcelState(p1)); d.isTooEarly(p1, time(2)); }
@SuppressWarnings("synthetic-access") @Nullable @Override public DefaultEvent handle(@Nullable StateEvent event, RouteFollowingVehicle context) { if (!route.isEmpty()) { checkCurrentParcelOwnership(); if (!isTooEarly(route.peek(), currentTime.get())) { return DefaultEvent.GOTO; } // else it is too early, and we do nothing } else if (currentTime.get().hasTimeLeft() && isEndOfDay(currentTime.get()) && !getRoadModel().equalPosition(context, depot.get())) { // check if it is time to go back to the depot getRoadModel().moveTo(context, depot.get(), currentTime.get()); } currentTime.get().consumeAll(); return null; } }
/** * Tests a check what happens if someone else is picking up a parcel that a * vehicle wants to pick up. */ @Test public void testParcelOwnerShip() { d.setRoute(asList(p1)); d2.setRoute(asList(p1)); tick(0, 7); assertEquals(ParcelState.PICKING_UP, pm.getParcelState(p1)); boolean exception = false; try { d2.checkCurrentParcelOwnership(); } catch (final IllegalStateException e) { exception = true; } assertTrue(exception); }
d.setRoute(asList(p1, p2, p1)); assertEquals(VehicleState.IDLE, pm.getVehicleState(d)); d.setRoute(asList(p2)); d.computeTravelTimeTo(new Point(3, 5), SI.MILLI(SI.SECOND)));
@Override public void handleTimedEvent(AddVehicleEvent event, SimulatorAPI sim) { sim.register(new RouteFollowingVehicle(event.getVehicleDTO(), false)); }
d.setRoute(asList(p1, p1)); tick(12, 15); assertEquals(ParcelState.PICKING_UP, pm.getParcelState(p1)); d2.setRoute(asList(p1)); } catch (final IllegalArgumentException e) { exception = true; d2.setRoute(asList(p3)); d2.tick(time(minute(10), minute(16))); assertEquals(ParcelState.PICKING_UP, pm.getParcelState(p1)); assertEquals(ParcelState.PICKING_UP, pm.getParcelState(p3)); d2.setRoute(asList(p1)); } catch (final IllegalArgumentException e) { exception2 = true; d2.setRoute(asList(p1)); } catch (final IllegalArgumentException e) { exception3 = true;
.availabilityTimeWindow(TimeWindow.create(0, minute(30))) .build(); d = new RouteFollowingVehicle(v, allowDelayedRouteChanges, routeAdjuster); d2 = new RouteFollowingVehicle(v, allowDelayedRouteChanges, routeAdjuster); assertThat(d.isDelayedRouteChangingAllowed()) .isEqualTo(allowDelayedRouteChanges); assertThat(d2.isDelayedRouteChangingAllowed()) .isEqualTo(allowDelayedRouteChanges); if (register) { PDPTWTestUtil.register(rm, pm, depot, d, d2, p1, p2, p3); assertEquals(depot, d.getDepot());
/** * Test definition of isTooEarly. */ @Test public void testIsTooEarly() { // traveling 1km at 30km/h should take 2 minutes assertEquals(minute(2), d.computeTravelTimeTo(new Point(1, 2), SI.MILLI(SI.SECOND))); // if we start immediately we are too early assertTrue(d.isTooEarly(p1, time(0, 10))); assertTrue(d.isTooEarly(p1, time(minute(2), minute(3)))); assertFalse(d.isTooEarly(p1, time(minute(2) + 1, minute(3) + 1))); assertFalse(d.isTooEarly(p1, time(minute(3), minute(4)))); assertFalse(d.isTooEarly(p1, time(minute(4), minute(5)))); assertFalse(d.isTooEarly(p1, time(minute(10), minute(11)))); assertTrue(d.isTooEarly(p2, time(0, 10))); assertTrue(d.isTooEarly(p2, time(minute(10) + 10, minute(11) + 10))); assertFalse(d.isTooEarly(p2, time(minute(10) + 11, minute(11) + 11))); assertFalse(d.isTooEarly(p2, time(minute(11), minute(12)))); assertFalse(d.isTooEarly(p2, time(minute(12), minute(13)))); assertFalse(d.isTooEarly(p2, time(minute(20), minute(21)))); }
final ParcelState parcelState = getPDPModel().getParcelState(p); checkArgument( !parcelState.isTransitionState() && !parcelState.isDelivered(), "Parcel state may not be a transition state nor may it be delivered, " + "it is %s.", parcelState, parcelState.isTransitionState() ? getPDPModel() .getVehicleActionInfo(this).timeNeeded() : null); final boolean isPickup = !parcelState.isPickedUp(); final long travelTime = computeTravelTimeTo(loc, time.getTimeUnit()); final long openingTime = isPickup ? p.getPickupTimeWindow().begin() : p .getDeliveryTimeWindow().begin();
@Override public void onEntry(StateEvent event, RouteFollowingVehicle context) { if (event == DefaultEvent.REROUTE) { checkArgument(isDiversionAllowed); } checkCurrentParcelOwnership(); destination = Optional.of(route.element()); }
routeHeuristic = GeomHeuristics.euclidean(); stateMachine = createStateMachine(); waitState = stateMachine.getStateOfType(Wait.class); gotoState = stateMachine.getStateOfType(Goto.class);