Пример #1
0
 private Double getLastTransport(TourActivity activity, VehicleRoute route, StateId id) {
   if (route == null) throw new IllegalArgumentException("route is missing.");
   if (activity == null) throw new IllegalArgumentException("activity is missing.");
   if (activity instanceof Start) return 0.;
   if (activity instanceof End) return stateManager.getRouteState(route, id, Double.class);
   verifyThatRouteContainsAct(activity, route);
   return stateManager.getActivityState(activity, id, Double.class);
 }
Пример #2
0
    @Override
    public void visit(TourActivity activity) {
      stateManager.putActivityState(activity, last_transport_distance_id, distance(activity));
      stateManager.putActivityState(activity, last_transport_time_id, transportTime(activity));
      stateManager.putActivityState(activity, last_transport_cost_id, transportCost(activity));

      prevAct = activity;
      prevActDeparture = activity.getEndTime();
    }
Пример #3
0
 @Override
 public void finish() {
   // shipment
   // pickups without deliveries
   for (TourActivity act : openShipments.values()) {
     stateManager.putActivityState(act, shipment_id, true);
     shipmentConstraintOnRouteViolated = true;
   }
   stateManager.putRouteState(route, shipment_id, shipmentConstraintOnRouteViolated);
   // backhaul
   stateManager.putRouteState(route, backhaul_id, backhaulConstraintOnRouteViolated);
 }
Пример #4
0
 @Override
 public void finish() {
   sum_transport_time += route.getEnd().getArrTime() - prevActDeparture;
   sum_too_late +=
       Math.max(
           0,
           route.getEnd().getArrTime()
               - route.getEnd().getTheoreticalLatestOperationStartTime());
   stateManager.putRouteState(route, transport_time_id, sum_transport_time);
   stateManager.putRouteState(route, waiting_time_id, sum_waiting_time);
   stateManager.putRouteState(route, service_time_id, sum_service_time);
   stateManager.putRouteState(route, too_late_id, sum_too_late);
 }
Пример #5
0
    @Override
    public void visit(TourActivity activity) {
      // waiting time & toolate
      double waitAtAct = 0.;
      double tooLate = 0.;
      if (activityPolicy.equals(ActivityTimeTracker.ActivityPolicy.AS_SOON_AS_TIME_WINDOW_OPENS)) {
        waitAtAct =
            Math.max(
                0, activity.getTheoreticalEarliestOperationStartTime() - activity.getArrTime());
        tooLate =
            Math.max(0, activity.getArrTime() - activity.getTheoreticalLatestOperationStartTime());
      }
      sum_waiting_time += waitAtAct;
      sum_too_late += tooLate;
      // transport time
      double transportTime = activity.getArrTime() - prevActDeparture;
      sum_transport_time += transportTime;
      prevActDeparture = activity.getEndTime();
      // service time
      sum_service_time +=
          activityCosts.getActivityDuration(
              activity, activity.getArrTime(), route.getDriver(), route.getVehicle());

      stateManager.putActivityState(activity, transport_time_id, sum_transport_time);
    }
Пример #6
0
 @Override
 public void finish() {
   double distance =
       distanceCalculator.getDistance(prevAct.getLocation(), route.getEnd().getLocation());
   sum_distance += distance;
   stateManager.putRouteState(route, distance_id, sum_distance);
 }
Пример #7
0
 /**
  * @param activity at which is distance of the current route is measured
  * @return distance at activity
  */
 public Double getDistanceAtActivity(TourActivity activity, VehicleRoute route) {
   if (route == null) throw new IllegalArgumentException("route is missing.");
   if (activity == null) throw new IllegalArgumentException("activity is missing.");
   if (activity instanceof Start) return 0.;
   if (activity instanceof End) return getDistance(route);
   verifyThatRouteContainsAct(activity, route);
   return stateManager.getActivityState(activity, distance_id, Double.class);
 }
Пример #8
0
 /**
  * @param activity to check skill constraint
  * @param route that must contain specified activity
  * @return true if vehicle does not have the skills to conduct specified activity, false
  *     otherwise. Returns null if specified route or activity is null or if route does not contain
  *     specified activity or if skill state connot be found. If specified activity is Start or
  *     End, it returns false.
  */
 public Boolean hasSkillConstraintViolationAtActivity(TourActivity activity, VehicleRoute route) {
   if (route == null) throw new IllegalArgumentException("route is missing.");
   if (activity == null) throw new IllegalArgumentException("activity is missing.");
   if (activity instanceof Start) return false;
   if (activity instanceof End) return false;
   verifyThatRouteContainsAct(activity, route);
   return stateManager.getActivityState(activity, skill_id, Boolean.class);
 }
Пример #9
0
 /**
  * @param activity to get the load from (after activity)
  * @return load right after the specified activity. If act is Start, it returns the load
  *     atBeginning of the specified route. If act is End, it returns the load atEnd of specified
  *     route. Returns null if no load can be found.
  */
 public Capacity getLoadRightAfterActivity(TourActivity activity, VehicleRoute route) {
   if (route == null) throw new IllegalArgumentException("route is missing.");
   if (activity == null) throw new IllegalArgumentException("activity is missing.");
   if (activity instanceof Start) return getLoadAtBeginning(route);
   if (activity instanceof End) return getLoadAtEnd(route);
   verifyThatRouteContainsAct(activity, route);
   return stateManager.getActivityState(activity, InternalStates.LOAD, Capacity.class);
 }
Пример #10
0
 /**
  * @param activity to get the variable transport costs from
  * @param route where the activity should be part of
  * @return variable transport costs at activity, i.e. sum of transport costs from start of route
  *     to the specified activity If activity is start, it returns 0.. If it is end, it returns
  *     .getVariableTransportCosts(route).
  */
 public Double getVariableTransportCostsAtActivity(TourActivity activity, VehicleRoute route) {
   if (route == null) throw new IllegalArgumentException("route is missing.");
   if (activity == null) throw new IllegalArgumentException("activity is missing.");
   if (activity instanceof Start) return 0.;
   if (activity instanceof End) return getVariableTransportCosts(route);
   verifyThatRouteContainsAct(activity, route);
   return stateManager.getActivityState(activity, InternalStates.COSTS, Double.class);
 }
Пример #11
0
 @Override
 public void visit(TourActivity activity) {
   double distance =
       distanceCalculator.getDistance(prevAct.getLocation(), activity.getLocation());
   sum_distance += distance;
   stateManager.putActivityState(activity, distance_id, sum_distance);
   prevAct = activity;
 }
Пример #12
0
    @Override
    public void visit(TourActivity activity) {
      // shipment
      if (activity instanceof PickupShipment) {
        openShipments.put(((PickupShipment) activity).getJob().getId(), (PickupShipment) activity);
      } else if (activity instanceof DeliverShipment) {
        String jobId = ((DeliverShipment) activity).getJob().getId();
        if (!openShipments.containsKey(jobId)) {
          // deliverShipment without pickupShipment
          stateManager.putActivityState(activity, shipment_id, true);
          shipmentConstraintOnRouteViolated = true;
        } else {
          PickupShipment removed = openShipments.remove(jobId);
          stateManager.putActivityState(removed, shipment_id, false);
          stateManager.putActivityState(activity, shipment_id, false);
        }
      } else stateManager.putActivityState(activity, shipment_id, false);

      // backhaul
      if (activity instanceof DeliverService && pickupOccured) {
        stateManager.putActivityState(activity, backhaul_id, true);
        backhaulConstraintOnRouteViolated = true;
      } else {
        if (activity instanceof PickupService
            || activity instanceof ServiceActivity
            || activity instanceof PickupShipment) {
          pickupOccured = true;
          stateManager.putActivityState(activity, backhaul_id, false);
        } else stateManager.putActivityState(activity, backhaul_id, false);
      }
    }
Пример #13
0
 /**
  * @param activity to get the load from (before activity)
  * @return load just before the specified activity. If act is Start, it returns the load
  *     atBeginning of the specified route. If act is End, it returns the load atEnd of specified
  *     route.
  */
 public Capacity getLoadJustBeforeActivity(TourActivity activity, VehicleRoute route) {
   if (route == null) throw new IllegalArgumentException("route is missing.");
   if (activity == null) throw new IllegalArgumentException("activity is missing.");
   if (activity instanceof Start) return getLoadAtBeginning(route);
   if (activity instanceof End) return getLoadAtEnd(route);
   verifyThatRouteContainsAct(activity, route);
   Capacity afterAct =
       stateManager.getActivityState(activity, InternalStates.LOAD, Capacity.class);
   if (afterAct != null && activity.getSize() != null) {
     return Capacity.subtract(afterAct, activity.getSize());
   } else if (afterAct != null) return afterAct;
   else return null;
 }
Пример #14
0
 private LoadAndActivityCounter(StateManager stateManager) {
   this.stateManager = stateManager;
   pickup_count_id = stateManager.createStateId(PICKUP_COUNT);
   delivery_count_id = stateManager.createStateId(DELIVERY_COUNT);
   load_picked_id = stateManager.createStateId(LOAD_PICKED);
   load_delivered_id = stateManager.createStateId(LOAD_DELIVERED);
   pickup_at_beginning_count_id = stateManager.createStateId(PICKUP_COUNT_AT_BEGINNING);
   delivery_at_end_count_id = stateManager.createStateId(DELIVERY_COUNT_AT_END);
 }
Пример #15
0
 @Override
 public void finish() {
   stateManager.putRouteState(route, pickup_count_id, pickupCounter);
   stateManager.putRouteState(route, delivery_count_id, deliveryCounter);
   stateManager.putRouteState(route, load_picked_id, pickedUp);
   stateManager.putRouteState(route, load_delivered_id, delivered);
   stateManager.putRouteState(route, pickup_at_beginning_count_id, pickupAtBeginningCounter);
   stateManager.putRouteState(route, delivery_at_end_count_id, deliverAtEndCounter);
 }
Пример #16
0
 @Override
 public void visit(TourActivity activity) {
   boolean violatedAtActivity = false;
   if (activity instanceof TourActivity.JobActivity) {
     Set<String> requiredForActivity =
         ((TourActivity.JobActivity) activity).getJob().getRequiredSkills().values();
     for (String skill : requiredForActivity) {
       if (!route.getVehicle().getSkills().containsSkill(skill)) {
         violatedAtActivity = true;
         skillConstraintViolatedOnRoute = true;
       }
     }
   }
   stateManager.putActivityState(activity, skill_id, violatedAtActivity);
 }
Пример #17
0
 /**
  * @param route to get the number of pickups at beginning from
  * @return number of pickups at beginning
  */
 public Integer getNumberOfPickupsAtBeginning(VehicleRoute route) {
   if (route == null) throw new IllegalArgumentException("route is missing.");
   return stateManager.getRouteState(
       route, stateManager.createStateId(PICKUP_COUNT_AT_BEGINNING), Integer.class);
 }
Пример #18
0
 private void refreshStates() {
   stateManager.clear();
   stateManager.informInsertionStarts(solution.getRoutes(), null);
   clearSolutionIndicators();
   recalculateSolutionIndicators();
 }
Пример #19
0
 /**
  * @param route to get delivered load from
  * @return delivered laod (without load at end)
  */
 public Capacity getLoadDelivered(VehicleRoute route) {
   if (route == null) throw new IllegalArgumentException("route is missing.");
   return stateManager.getRouteState(
       route, stateManager.createStateId(LOAD_DELIVERED), Capacity.class);
 }
Пример #20
0
 /**
  * @param route to get the time window violation from
  * @return time violation of route, i.e. sum of individual activity time window violations.
  */
 public Double getTimeWindowViolation(VehicleRoute route) {
   if (route == null) throw new IllegalArgumentException("route is missing.");
   return stateManager.getRouteState(route, too_late_id, Double.class);
 }
Пример #21
0
 @Override
 public void finish() {
   stateManager.putRouteState(route, last_transport_distance_id, distance(route.getEnd()));
   stateManager.putRouteState(route, last_transport_time_id, transportTime(route.getEnd()));
   stateManager.putRouteState(route, last_transport_cost_id, transportCost(route.getEnd()));
 }
Пример #22
0
 /**
  * @param route to get number of deliveries from
  * @return number of deliveries delivered on specified route (without load at end)
  */
 public Integer getNumberOfDeliveries(VehicleRoute route) {
   if (route == null) throw new IllegalArgumentException("route is missing.");
   return stateManager.getRouteState(
       route, stateManager.createStateId(DELIVERY_COUNT), Integer.class);
 }
Пример #23
0
 /**
  * Returns true, if shipment constraint is violated. Two activities are associated to a shipment:
  * pickupShipment and deliverShipment. If both shipments are not in the same route OR
  * deliverShipment occurs before pickupShipment then the shipment constraint is violated.
  *
  * @param route to check the shipment constraint.
  * @return true if violated, false otherwise. Null if no state can be found or specified route is
  *     null.
  */
 public Boolean hasShipmentConstraintViolation(VehicleRoute route) {
   if (route == null) throw new IllegalArgumentException("route is missing.");
   return stateManager.getRouteState(route, shipment_id, Boolean.class);
 }
Пример #24
0
 /**
  * @param route to get max load from
  * @return max load of specified route, i.e. for each capacity dimension the max value.
  */
 public Capacity getMaxLoad(VehicleRoute route) {
   if (route == null) throw new IllegalArgumentException("route is missing.");
   return stateManager.getRouteState(route, InternalStates.MAXLOAD, Capacity.class);
 }
Пример #25
0
 /**
  * @param route to get the load at beginning from
  * @return load at start location of specified route
  */
 public Capacity getLoadAtBeginning(VehicleRoute route) {
   if (route == null) throw new IllegalArgumentException("route is missing.");
   return stateManager.getRouteState(route, InternalStates.LOAD_AT_BEGINNING, Capacity.class);
 }
Пример #26
0
 @Override
 public void finish() {
   stateManager.putRouteState(route, skill_id, skillConstraintViolatedOnRoute);
 }
Пример #27
0
  private void initialise() {
    this.stateManager = new StateManager(vrp);
    this.stateManager.updateTimeWindowStates();
    this.stateManager.updateLoadStates();
    this.stateManager.updateSkillStates();
    activityPolicy = ActivityTimeTracker.ActivityPolicy.AS_SOON_AS_TIME_WINDOW_OPENS;
    this.stateManager.addStateUpdater(
        new UpdateActivityTimes(vrp.getTransportCosts(), activityPolicy, vrp.getActivityCosts()));
    this.stateManager.addStateUpdater(
        new UpdateVariableCosts(vrp.getActivityCosts(), vrp.getTransportCosts(), stateManager));
    waiting_time_id = stateManager.createStateId("waiting-time");
    transport_time_id = stateManager.createStateId("transport-time");
    service_time_id = stateManager.createStateId("service-time");
    distance_id = stateManager.createStateId("distance");
    too_late_id = stateManager.createStateId("too-late");
    shipment_id = stateManager.createStateId("shipment");
    backhaul_id = stateManager.createStateId("backhaul");
    skill_id = stateManager.createStateId("skills-violated");
    last_transport_cost_id = stateManager.createStateId("last-transport-cost");
    last_transport_distance_id = stateManager.createStateId("last-transport-distance");
    last_transport_time_id = stateManager.createStateId("last-transport-time");

    stateManager.addStateUpdater(
        new SumUpActivityTimes(
            waiting_time_id,
            transport_time_id,
            service_time_id,
            too_late_id,
            stateManager,
            activityPolicy,
            vrp.getActivityCosts()));
    stateManager.addStateUpdater(
        new DistanceUpdater(distance_id, stateManager, distanceCalculator));
    stateManager.addStateUpdater(
        new BackhaulAndShipmentUpdater(backhaul_id, shipment_id, stateManager));
    stateManager.addStateUpdater(new SkillUpdater(stateManager, skill_id));
    stateManager.addStateUpdater(new LoadAndActivityCounter(stateManager));
    stateManager.addStateUpdater(
        new LastTransportUpdater(
            stateManager,
            vrp.getTransportCosts(),
            distanceCalculator,
            last_transport_distance_id,
            last_transport_time_id,
            last_transport_cost_id));
  }
Пример #28
0
 /**
  * @param route to get the total waiting time from
  * @return total waiting time of this route, i.e. sum of waiting times at activities. Returns null
  *     if no waiting time value exists for the specified route
  */
 public Double getWaitingTime(VehicleRoute route) {
   if (route == null) throw new IllegalArgumentException("route is missing.");
   return stateManager.getRouteState(route, waiting_time_id, Double.class);
 }
Пример #29
0
  /**
   * @param route to get the transport costs from
   * @return total variable transport costs of route, i.e. sum of transport costs specified by
   *     vrp.getTransportCosts().getTransportCost(fromId,toId,...)
   */
  public Double getVariableTransportCosts(VehicleRoute route) {
    if (route == null) throw new IllegalArgumentException("route is missing.");

    return stateManager.getRouteState(route, InternalStates.COSTS, Double.class);
  }