@Override public ParcelDTO doDeserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { final Iterator<JsonElement> it = json.getAsJsonArray().iterator(); final Point p1 = context.deserialize(it.next(), Point.class); final Point p2 = context.deserialize(it.next(), Point.class); return Parcel.builder(p1, p2) .pickupTimeWindow( (TimeWindow) context.deserialize(it.next(), TimeWindow.class)) .deliveryTimeWindow( (TimeWindow) context.deserialize(it.next(), TimeWindow.class)) .neededCapacity(it.next().getAsDouble()) .orderAnnounceTime(it.next().getAsLong()) .pickupDuration(it.next().getAsLong()) .deliveryDuration(it.next().getAsLong()).buildDTO(); }
@Test public void addPackageIn() { assertTrue(model.getParcels(ParcelState.AVAILABLE).isEmpty()); final Depot d = new TestDepot(10); final Parcel p1 = Parcel.builder(new Point(0, 0), new Point(0, 0)) .neededCapacity(1d) .build(); model.register(d); model.register(p1); rm.addObjectAt(d, new Point(0, 0)); model.addParcelIn(d, p1); assertEquals(1, model.getContents(d).size()); assertTrue(model.getContents(d).contains(p1)); }
@Test(expected = IllegalArgumentException.class) public void testDeliverFail3() { final Vehicle truck = new TestVehicle( VehicleDTO.builder().startPosition(new Point(1, 1)).build()); rm.register(truck); model.register(truck); final Parcel pack1 = Parcel.builder(new Point(1, 1), new Point(2, 2)) .pickupDuration(10) .deliveryDuration(10) .neededCapacity(2d) .build(); rm.register(pack1); model.register(pack1); rm.addObjectAtSamePosition(pack1, truck); model.deliver(truck, pack1, TimeLapseFactory.create(0, 1)); }
@Test(expected = IllegalArgumentException.class) public void testPickupFail6A() { // package does not fit in truck final Vehicle truck = new TestVehicle( VehicleDTO.builder().startPosition(new Point(1, 1)).build()); rm.register(truck); model.register(truck); final Parcel pack1 = Parcel.builder(new Point(0, 0), new Point(2, 2)) .neededCapacity(2d) .build(); rm.register(pack1); model.register(pack1); rm.addObjectAtSamePosition(pack1, truck); assertTrue(rm.equalPosition(truck, pack1)); model.pickup(truck, pack1, TimeLapseFactory.create(0, 100)); }
@Test(expected = IllegalArgumentException.class) public void testPickupFail5() { // wrong position final Vehicle truck = new TestVehicle( VehicleDTO.builder().startPosition(new Point(1, 1)).build()); rm.register(truck); model.register(truck); final Parcel pack1 = Parcel.builder(new Point(0, 0), new Point(2, 2)) .neededCapacity(2d) .build(); rm.register(pack1); rm.addObjectAt(pack1, new Point(0, 0)); model.register(pack1); model.pickup(truck, pack1, TimeLapseFactory.create(0, 1)); }
@Override public void tick(TimeLapse time) { if (time.getStartTime() > endTime) { simulator.stop(); } else if (rng.nextDouble() < NEW_CUSTOMER_PROB) { simulator.register(new Customer( Parcel .builder(roadModel.getRandomPosition(rng), roadModel.getRandomPosition(rng)) .serviceDuration(SERVICE_DURATION) .neededCapacity(1 + rng.nextInt(MAX_CAPACITY)) .buildDTO())); } }
@Test(expected = IllegalArgumentException.class) public void testPickupFail3B() { // package is not registered final Vehicle truck = new TestVehicle( VehicleDTO.builder().startPosition(new Point(1, 1)).build()); rm.register(truck); final Parcel pack1 = Parcel.builder(new Point(0, 0), new Point(2, 2)) .neededCapacity(2d) .build(); rm.register(pack1); rm.addObjectAtSamePosition(pack1, truck); model.pickup(truck, pack1, TimeLapseFactory.create(0, 1)); }
@Override public void tick(TimeLapse time) { if (time.getStartTime() > endTime) { simulator.stop(); } else if (rng.nextDouble() < NEW_CUSTOMER_PROB) { simulator.register(new Customer( Parcel .builder(roadModel.getRandomPosition(rng), roadModel.getRandomPosition(rng)) .serviceDuration(SERVICE_DURATION) .neededCapacity(1 + rng.nextInt(MAX_CAPACITY)) .buildDTO())); } }
@Test(expected = IllegalArgumentException.class) public void addPackageInFail5() { final Depot d = new TestDepot(10); final Parcel p1 = Parcel.builder(new Point(0, 0), new Point(0, 0)) .neededCapacity(11d) .build(); model.register(p1); model.register(d); rm.addObjectAt(d, new Point(0, 0)); model.addParcelIn(d, p1); }
@Test(expected = IllegalArgumentException.class) public void addPackageInFail2() { final Depot d = new TestDepot(10); final Parcel p1 = Parcel.builder(new Point(0, 0), new Point(0, 0)) .neededCapacity(1d) .build(); model.addParcelIn(d, p1); }
Box(Point o, Point d, long duration, BoxHandle bh) { super( Parcel.builder(o, d) .serviceDuration(duration) .neededCapacity(1d) .buildDTO()); boxHandle = bh; }
@Test(expected = IllegalArgumentException.class) public void testPickupFail4() { final Vehicle truck = new TestVehicle( VehicleDTO.builder().startPosition(new Point(1, 1)).build()); rm.register(truck); final Parcel pack1 = Parcel.builder(new Point(0, 0), new Point(2, 2)) .neededCapacity(2d) .build(); rm.register(pack1); rm.addObjectAtSamePosition(pack1, truck); model.register(pack1); model.pickup(truck, pack1, TimeLapseFactory.create(0, 1)); }
@Test(expected = IllegalArgumentException.class) public void addPackageInFail4() { final Depot d = new TestDepot(10); final Parcel p1 = Parcel.builder(new Point(0, 0), new Point(0, 0)) .neededCapacity(1d) .build(); model.register(p1); model.register(d); model.addParcelIn(d, p1); }
@Test(expected = IllegalArgumentException.class) public void addPackageInFail3() { final Depot d = new TestDepot(10); final Parcel p1 = Parcel.builder(new Point(0, 0), new Point(0, 0)) .neededCapacity(1d) .build(); model.register(p1); model.addParcelIn(d, p1); }
@Test(expected = IllegalArgumentException.class) public void addPackageInFail1() { final Depot d = new TestDepot(10); final Parcel p1 = Parcel.builder(new Point(0, 0), new Point(0, 0)) .neededCapacity(1d) .build(); rm.addObjectAt(p1, new Point(0, 0)); model.addParcelIn(d, p1); }
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()); }
static Parcel create(Point p1, Point p2) { return Parcel.builder(p1, p2) .pickupTimeWindow(DEFAULT_TW) .deliveryTimeWindow(DEFAULT_TW) .neededCapacity(0) .orderAnnounceTime(0L) .pickupDuration(0L) .deliveryDuration(0L) .build(); } }
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()); }
@Test(expected = IllegalArgumentException.class) public void testPickupFail2() { // package not in roadmodel final Vehicle truck = new TestVehicle( VehicleDTO.builder().startPosition(new Point(1, 1)).build()); rm.register(truck); final Parcel pack1 = Parcel.builder(new Point(0, 0), new Point(2, 2)) .neededCapacity(2d) .build(); model.pickup(truck, pack1, TimeLapseFactory.create(0, 1)); }
Box(Point o, Point d, long duration, BoxHandle bh) { super( Parcel.builder(o, d) .serviceDuration(duration) .neededCapacity(1d) .buildDTO()); boxHandle = bh; }