LoadPart(long st, long end, double value) { tw = TimeWindow.create(st, end); load = value; }
/** * Set the length (duration) of the scenario. Note that the time at which * the simulation is stopped is defined by * {@link #setStopCondition(StopCondition)} . * @param length The length of the scenario, expressed in the time unit as * defined by the {@link TimeModel}. * @return This, as per the builder pattern. */ public T scenarioLength(long length) { timeWindow = TimeWindow.create(0, length); return self(); }
/** * Set the length (duration) of the scenario. Note that the time at which * the simulation is stopped is defined by * {@link #setStopCondition(StopCondition)} . * @param length The length of the scenario, expressed in the time unit as * defined by the {@link TimeModel}. * @return This, as per the builder pattern. */ public T scenarioLength(long length) { timeWindow = TimeWindow.create(0, length); return self(); }
@Nullable @Override public TimeWindow read(@Nullable JsonReader reader) throws IOException { if (reader == null) { return null; } if (reader.peek() == JsonToken.NULL) { reader.nextNull(); return null; } final String xy = reader.nextString(); final String[] parts = xy.split(VALUE_SEPARATOR); final long x = Long.parseLong(parts[0]); final long y = Long.parseLong(parts[1]); return TimeWindow.create(x, y); }
@Nullable @Override public TimeWindow read(@Nullable JsonReader reader) throws IOException { if (reader == null) { return null; } if (reader.peek() == JsonToken.NULL) { reader.nextNull(); return null; } final String xy = reader.nextString(); final String[] parts = xy.split(VALUE_SEPARATOR); final long x = Long.parseLong(parts[0]); final long y = Long.parseLong(parts[1]); return TimeWindow.create(x, y); }
static TimeWindow msToNs(TimeWindow tw) { if (tw.equals(TimeWindow.always())) { return TimeWindow.always(); } return TimeWindow.create(msToNs(tw.begin()), msToNs(tw.end())); }
TimeWindow urgencyTimeWindow(long earliestOpening, long earliestClosing, long latestClosing, StochasticSupplier<Long> urgency, StochasticSupplier<Long> length) { final long closing = boundValue( earliestClosing + urgency.get(rng.nextLong()), earliestClosing, latestClosing); final long opening = boundValue(closing - length.get(rng.nextLong()), earliestOpening, closing); return TimeWindow.create(opening, closing); } }
Agent() { super(VehicleDTO.builder() .startPosition(new Point(1, 1)) .availabilityTimeWindow(TimeWindow.create(0, 1 * 60 * 60 * 1000)) .build(), true); solver = Optional.absent(); }
static AddParcelEvent createParcel(int i, long delay, Point p1, Point p2) { final long announceTime = (i + 1) * 60 * 1000; return AddParcelEvent.create( Parcel.builder(p1, p2) .orderAnnounceTime(announceTime + delay) .pickupTimeWindow( TimeWindow.create(announceTime + delay, announceTime + 1 * 60 * 1000)) .deliveryTimeWindow( TimeWindow.create(announceTime + delay + 5 * 60 * 1000, announceTime + 6 * 60 * 1000)) .serviceDuration(5 * 60 * 1000) .buildDTO()); }
@Test public void convertTWtest() { final UnitConverter timeConverter = MILLI(SECOND).getConverterTo(SECOND); final int[] tw1 = convertTW(TimeWindow.create(300, 800), 5, timeConverter); assertEquals(0, tw1[0]); assertEquals(1, tw1[1]); final int[] tw2 = convertTW(TimeWindow.create(7300, 8800), 0, timeConverter); assertEquals(8, tw2[0]); assertEquals(8, tw2[1]); final int[] tw3 = convertTW(TimeWindow.create(7300, 8800), 7300, timeConverter); assertEquals(0, tw3[0]); assertEquals(1, tw3[1]); }
static Parcel createParcel(Point origin, Point dest) { return new Parcel( Parcel.builder(origin, dest) .pickupTimeWindow(TimeWindow.create(380001, 380002)) .deliveryTimeWindow(TimeWindow.create(0, 1000)) .neededCapacity(0) .orderAnnounceTime(0L) .pickupDuration(3000L) .deliveryDuration(3000L) .buildDTO()); }
static AddParcelEvent parcelEvent(double x1, double y1, double x2, double y2, long tw1b, long tw1e, long tw2b, long tw2e) { return AddParcelEvent.create( Parcel.builder(new Point(x1, y1), new Point(x2, y2)) .pickupTimeWindow(TimeWindow.create(tw1b, tw1e)) .deliveryTimeWindow(TimeWindow.create(tw2b, tw2e)) .neededCapacity(0) .orderAnnounceTime(0L) .pickupDuration(0L) .deliveryDuration(0L) .buildDTO()); }
/** * Test for changing values in builder. */ @Test public void overridingTest() { final Parcel.Builder b = Parcel.builder(new Point(0, 0), new Point(2, 2)); final IParcel dto1 = b.timeWindows(TimeWindow.create(7, 10)).buildDTO(); assertEquals(TimeWindow.create(7, 10), dto1.getPickupTimeWindow()); assertEquals(TimeWindow.create(7, 10), dto1.getDeliveryTimeWindow()); final IParcel dto2 = b.pickupTimeWindow(TimeWindow.create(8, 11)).buildDTO(); assertEquals(TimeWindow.create(8, 11), dto2.getPickupTimeWindow()); assertEquals(TimeWindow.create(7, 10), dto2.getDeliveryTimeWindow()); final IParcel dto3 = b.serviceDuration(560L).buildDTO(); assertEquals(TimeWindow.create(8, 11), dto3.getPickupTimeWindow()); assertEquals(TimeWindow.create(7, 10), dto3.getDeliveryTimeWindow()); assertEquals(560, dto3.getPickupDuration()); assertEquals(560, dto3.getDeliveryDuration()); final IParcel dto4 = b.pickupDuration(230L).buildDTO(); assertEquals(230, dto4.getPickupDuration()); assertEquals(560, dto4.getDeliveryDuration()); }
TestVehicle(Point start) { super(VehicleDTO.builder() .startPosition(start) .speed(30d) .capacity(1) .availabilityTimeWindow(TimeWindow.create(0, 1000)) .build(), false); }
/** * Test the default settings of a scenario. */ @Test public void testDefaults() { final Scenario.Builder builder = Scenario .builder(Scenario.DEFAULT_PROBLEM_CLASS); assertThat(builder.getTimeWindow()) .isEqualTo(TimeWindow.create(0, 8 * 60 * 60 * 1000)); assertThat(builder.getStopCondition()) .isEqualTo(StopConditions.alwaysFalse()); final Scenario scenario = builder.build(); assertTrue(scenario.getModelBuilders().isEmpty()); assertSame(Scenario.DEFAULT_PROBLEM_CLASS, scenario.getProblemClass()); assertEquals("", scenario.getProblemInstanceId()); assertThat(scenario.getStopCondition()).isEqualTo( StopConditions.alwaysFalse()); assertEquals(TimeWindow.create(0, 8 * 60 * 60 * 1000), scenario.getTimeWindow()); }
/** * Sets up simple problem with two agents and two parcels. */ @Before public void setUp() { final List<TimedEvent> events = asList( AddParcelEvent.create( Parcel.builder(new Point(0, 0), new Point(3, 3)) .orderAnnounceTime(200) .pickupTimeWindow(TimeWindow.create(1000, 2000)) .buildDTO()), AddParcelEvent.create( Parcel.builder(new Point(0, 0), new Point(3, 3)) .orderAnnounceTime(999) .pickupTimeWindow(TimeWindow.create(60000, 80000)) .serviceDuration(180000L) .buildDTO()), TimeOutEvent.create(3000)); sim = RealtimeTestHelper.init(Handler.INSTANCE, events) .addModel(RtSolverModel.builder() .withThreadPoolSize(3) .withThreadGrouping(false)) .build(); }
/** * Checks whether overtime is computed correctly. */ @Test public void overtimeScenario() { final Gendreau06Scenario scenario = create(1, minutes(6), AddParcelEvent.create( Parcel.builder(new Point(2, 1), new Point(4, 1)) .pickupTimeWindow(TimeWindow.create(0, minutes(12))) .deliveryTimeWindow(TimeWindow.create(5, minutes(12))) .neededCapacity(0) .orderAnnounceTime(0L) .pickupDuration(0L) .deliveryDuration(0L) .buildDTO())); final StatisticsDTO dto = runProblem(scenario, useGui); assertTrue(dto.simFinish); assertEquals(6, dto.totalDistance, EPSILON); assertEquals(1, dto.totalDeliveries); assertEquals(minutes(6) - 1000, dto.overTime); assertEquals(0, dto.pickupTardiness); assertEquals(0, dto.deliveryTardiness); }
@Test public void simpleScenario() throws IOException { final Gendreau06Scenario scenario = create(2, minutes(15), AddParcelEvent.create( Parcel.builder(new Point(2, 1), new Point(4, 1)) .pickupTimeWindow(TimeWindow.create(0, 720000)) .deliveryTimeWindow(TimeWindow.create(5, 720000)) .neededCapacity(0) .orderAnnounceTime(0L) .pickupDuration(0L) .deliveryDuration(0L) .buildDTO())); final StatisticsDTO dto = runProblem(scenario, useGui); // the second truck will turn around just one tick distance before // reaching the package. the reason is that it is too late since the // first truck will pickup the parcel. final double distInOneTick = 30.0 / 3600.0; assertTrue(dto.simFinish); assertEquals(9 - 2.0 * distInOneTick, dto.totalDistance, EPSILON); assertEquals(1, dto.totalParcels); assertEquals(0, dto.overTime); assertEquals(0, dto.pickupTardiness); assertEquals(0, dto.deliveryTardiness); assertEquals(2, dto.totalVehicles); assertEquals(2, dto.movedVehicles); }
/** * Tests a subclass that changes the state machine. */ @Test public void testExtension() { final VehicleDTO v = VehicleDTO.builder() .startPosition(new Point(1, 1)) .speed(30d) .capacity(1) .availabilityTimeWindow(TimeWindow.create(0, minute(30))) .build(); final SubVehicle vehicle = new SubVehicle(v, allowDelayedRouteChanges); d = vehicle; PDPTWTestUtil.register(rm, pm, vehicle); tick(0, 1); assertEquals(vehicle.waitState, vehicle.stateMachine.getCurrentState()); vehicle.stateMachine.handle(ExtraEvent.TEST_EVENT, vehicle); assertEquals(vehicle.extraState, vehicle.stateMachine.getCurrentState()); tick(1, 2); assertEquals(vehicle.waitState, vehicle.stateMachine.getCurrentState()); }
static Scenario createScenario(long... delays) { final long endTime = 15 * 60 * 1000; final VehicleDTO vehicle = VehicleDTO.builder() .startPosition(new Point(5, 5)) .availabilityTimeWindow(TimeWindow.create(0, endTime)) .build(); final Scenario.Builder scenario = Scenario.builder() .addEvent(AddDepotEvent.create(-1, new Point(5, 5))) .addEvent(AddVehicleEvent.create(-1, vehicle)) .addEvent(AddVehicleEvent.create(-1, vehicle)) .addEvent(TimeOutEvent.create(endTime)) .addModel(PDPRoadModel.builder(RoadModelBuilders.plane()) .withAllowVehicleDiversion(true)) .addModel(DefaultPDPModel.builder()) .addModel(TimeModel.builder().withTickLength(250)) .setStopCondition(StopConditions.and( StatsStopConditions.vehiclesDoneAndBackAtDepot(), StatsStopConditions.timeOutEvent())); final long[] dls = new long[3]; System.arraycopy(delays, 0, dls, 0, delays.length); scenario .addEvent(createParcel(0, dls[0], new Point(1, 1), new Point(9, 1))); scenario .addEvent(createParcel(1, dls[1], new Point(1, 2), new Point(9, 2))); scenario .addEvent(createParcel(2, dls[2], new Point(9, 9), new Point(1, 9))); return scenario.build(); }