Ejemplo n.º 1
0
  @Override
  public void insertJobWithoutTourUpdate(Job job, InsertionData insertionData) {
    if (insertionData == null || (insertionData instanceof NoInsertionFound))
      throw new IllegalStateException("insertionData null. cannot insert job.");
    if (job == null) throw new IllegalStateException("cannot insert null-job");
    if (job instanceof Shipment) {
      assert insertionData.getInsertionIndeces().length == 2
          : "a shipment needs two insertionIndeces. a pickupInsertionIndex and a deliveryInsertionIndex";
      try {
        insertJob(
            (Shipment) job,
            insertionData.getInsertionIndeces()[0],
            insertionData.getInsertionIndeces()[1]);
      } catch (IndexOutOfBoundsException e) {
        throw new IllegalStateException("insertionData are invalid for this tour. " + e);
      }
    } else if (job instanceof Service) {
      assert insertionData.getInsertionIndeces().length == 1
          : "a service needs one insertionIndeces.";
      try {
        insertJob((Service) job, insertionData.getInsertionIndeces()[0]);
      } catch (IndexOutOfBoundsException e) {
        throw new IllegalStateException("insertionData are invalid for this tour. " + e);
      }

    } else {
      throw new IllegalStateException("a job must either be a shipment or a service");
    }
    if (insertionData.getSelectedVehicle() != vehicleRoute.getVehicle()
        && !(vehicleFleetManager instanceof DefaultFleetManager)) {
      try {
        vehicleFleetManager.unlock(vehicleRoute.getVehicle());
      } catch (IllegalStateException e) {
        throw new IllegalStateException();
      }
      vehicleFleetManager.lock(insertionData.getSelectedVehicle());
      vehicleRoute.setVehicle(insertionData.getSelectedVehicle());
    }
  }
Ejemplo n.º 2
0
 public InsertionData calculateBestInsertion(Job job, double bestKnownPrice) {
   Vehicle selectedVehicle = vehicleRoute.getVehicle();
   Driver selectedDriver = vehicleRoute.getDriver();
   InsertionData bestIData = new NoInsertionFound();
   double bestKnownCost = bestKnownPrice;
   Vehicle bestVehicle = vehicleRoute.getVehicle();
   if (!(selectedVehicle instanceof NoVehicle)) {
     bestIData =
         insertionCostCalculator.calculate(
             vehicleRoute, job, selectedVehicle, selectedDriver, bestKnownCost);
     if (!(bestIData instanceof NoInsertionFound)) {
       bestVehicle = vehicleRoute.getVehicle();
       if (bestIData.getInsertionCost() < bestKnownCost) {
         bestKnownCost = bestIData.getInsertionCost();
       }
     }
   }
   for (String type : vehicleFleetManager.getAvailableVehicleTypes()) {
     if (!(vehicleRoute.getVehicle() instanceof NoVehicle)) {
       if (type.equals(vehicleRoute.getVehicle().getType().typeId)) {
         continue;
       }
     }
     Vehicle v = vehicleFleetManager.getEmptyVehicle(type);
     InsertionData iData =
         insertionCostCalculator.calculate(vehicleRoute, job, v, selectedDriver, bestKnownCost);
     if (iData.getInsertionCost() < bestKnownCost) {
       if (vehicleRoute.getTour().getLoad() + job.getCapacityDemand() > v.getCapacity())
         throw new IllegalStateException("this must not be");
       bestIData = iData;
       bestVehicle = v;
       bestKnownCost = iData.getInsertionCost();
     }
   }
   bestIData.setVehicle(bestVehicle);
   return bestIData;
 }