Пример #1
0
  @Override
  public void addParcelIn(Container container, Parcel parcel) {
    synchronized (this) {
      /* 1 */ checkArgument(
          !roadModel.get().containsObject(parcel), "this parcel is already added to the roadmodel");
      /* 2 */ checkArgument(
          parcelState.getKeys(parcel) == ParcelState.AVAILABLE,
          "parcel must be registered and in AVAILABLE state, current state: %s",
          parcelState.getKeys(parcel));
      /* 3 */ checkArgument(
          containerCapacities.containsKey(container), "the parcel container is not registered");
      /* 4 */ checkArgument(
          roadModel.get().containsObject(container),
          "the parcel container is not on the roadmodel");
      final double newSize = containerContentsSize.get(container) + parcel.getMagnitude();
      /* 5 */ checkArgument(
          newSize <= containerCapacities.get(container),
          "parcel does not fit in container. Capacity is %s, current content size is %s, new parcel size is %s",
          containerCapacities.get(container),
          containerContentsSize.get(container),
          parcel.getMagnitude());

      containerContents.put(container, parcel);
      containerContentsSize.put(container, newSize);
      parcelState.put(ParcelState.IN_CARGO, parcel);
    }
  }
Пример #2
0
 @Override
 public ParcelState getParcelState(Parcel parcel) {
   synchronized (this) {
     return parcelState.getKeys(parcel);
   }
 }
Пример #3
0
  @Override
  public void pickup(Vehicle vehicle, Parcel parcel, TimeLapse time) {
    synchronized (this) {
      /* 1 */ checkVehicleInRoadModel(vehicle);
      /* 2 */ checkArgument(
          roadModel.get().containsObject(parcel), "parcel does not exist in RoadModel");
      final ParcelState ps = parcelState.getKeys(parcel);
      /* 3 */ checkArgument(
          ps == ParcelState.AVAILABLE || ps == ParcelState.ANNOUNCED,
          "Parcel must be registered and must be either ANNOUNCED or AVAILABE, it is: %s. Parcel: %s.",
          ps,
          parcel);
      /* 4 */ checkArgument(
          vehicleState.get(vehicle) == VehicleState.IDLE,
          "vehicle must be registered and must be available");
      /* 5 */ checkArgument(
          roadModel.get().equalPosition(vehicle, parcel),
          "vehicle must be at the same location as the parcel it wishes to pickup");
      final double newSize = containerContentsSize.get(vehicle) + parcel.getMagnitude();
      /* 6 */ checkArgument(
          newSize <= containerCapacities.get(vehicle),
          "parcel does not fit in vehicle. Parcel size: %s, current contents size: %s, capacity: %s.",
          parcel.getMagnitude(),
          containerContentsSize.get(vehicle),
          containerCapacities.get(vehicle));

      checkArgument(
          timeWindowPolicy.canPickup(
              parcel.getPickupTimeWindow(), time.getTime(), parcel.getPickupDuration()),
          "parcel pickup is not allowed according to the time window policy: %s, current time: %s, time window %s.",
          timeWindowPolicy,
          time.getTime(),
          parcel.getPickupTimeWindow());

      checkArgument(
          parcel.canBePickedUp(vehicle, time.getTime()), "the parcel does not allow pickup now");

      eventDispatcher.dispatchEvent(
          new PDPModelEvent(PDPModelEventType.START_PICKUP, self, time.getTime(), parcel, vehicle));

      // remove the parcel such that no other attempts to pickup can be
      // made
      roadModel.get().removeObject(parcel);

      // in this case we know we cannot finish this action with the
      // available time. We must continue in the nextDeliverable tick.
      if (time.getTimeLeft() < parcel.getPickupDuration()) {
        vehicleState.put(vehicle, VehicleState.PICKING_UP);
        parcelState.put(ParcelState.PICKING_UP, parcel);

        pendingVehicleActions.put(
            vehicle,
            new PickupAction(
                this, vehicle, parcel, parcel.getPickupDuration() - time.getTimeLeft()));
        time.consumeAll();
      } else {
        time.consume(parcel.getPickupDuration());
        doPickup(vehicle, parcel, time.getTime());
      }
    }
  }