Package jsprit.core.problem.constraint.HardActivityConstraint

Examples of jsprit.core.problem.constraint.HardActivityConstraint.ConstraintsStatus


    TourActivity prevAct = start;
    double prevActStartTime = newVehicleDepartureTime;
    int actIndex = 0;
    boolean loopBroken = false;
    for(TourActivity nextAct : currentRoute.getTourActivities().getActivities()){
      ConstraintsStatus status = hardActivityLevelConstraint.fulfilled(insertionContext, prevAct, deliveryAct2Insert, nextAct, prevActStartTime);
      if(status.equals(ConstraintsStatus.FULFILLED)){
        //from job2insert induced costs at activity level
        double additionalICostsAtActLevel = softActivityConstraint.getCosts(insertionContext, prevAct, deliveryAct2Insert, nextAct, prevActStartTime);
        double additionalTransportationCosts = additionalTransportCostsCalculator.getCosts(insertionContext, prevAct, nextAct, deliveryAct2Insert, prevActStartTime);
        if(additionalICostsAtRouteLevel + additionalICostsAtActLevel + additionalTransportationCosts < bestCost){
          bestCost = additionalICostsAtRouteLevel + additionalICostsAtActLevel + additionalTransportationCosts;
          insertionIndex = actIndex;
        }
      }
      else if(status.equals(ConstraintsStatus.NOT_FULFILLED_BREAK)){
        loopBroken = true;
        break;
      }
      double nextActArrTime = prevActStartTime + transportCosts.getTransportTime(prevAct.getLocationId(), nextAct.getLocationId(), prevActStartTime, newDriver, newVehicle);
      prevActStartTime = CalculationUtils.getActivityEndTime(nextActArrTime, nextAct);
      prevAct = nextAct;
      actIndex++;
    }
    if(!loopBroken){
      ConstraintsStatus status = hardActivityLevelConstraint.fulfilled(insertionContext, prevAct, deliveryAct2Insert, end, prevActStartTime);
      if(status.equals(ConstraintsStatus.FULFILLED)){
        double additionalICostsAtActLevel = softActivityConstraint.getCosts(insertionContext, prevAct, deliveryAct2Insert, end, prevActStartTime);
        double additionalTransportationCosts = additionalTransportCostsCalculator.getCosts(insertionContext, prevAct, end, deliveryAct2Insert, prevActStartTime);
        if(additionalICostsAtRouteLevel + additionalICostsAtActLevel + additionalTransportationCosts < bestCost){
          bestCost = additionalICostsAtRouteLevel + additionalICostsAtActLevel + additionalTransportationCosts;
          insertionIndex = actIndex;
View Full Code Here


    double prevActEndTime = newVehicleDepartureTime;
    boolean pickupShipmentLoopBroken = false;
    //pickupShipmentLoop
    List<TourActivity> activities = currentRoute.getTourActivities().getActivities();
    for(int i=0;i<activities.size();i++){
      ConstraintsStatus pickupShipmentConstraintStatus = hardActivityLevelConstraint.fulfilled(insertionContext, prevAct, pickupShipment, activities.get(i), prevActEndTime);
      if(pickupShipmentConstraintStatus.equals(ConstraintsStatus.NOT_FULFILLED)){
        double nextActArrTime = prevActEndTime + transportCosts.getTransportTime(prevAct.getLocationId(), activities.get(i).getLocationId(), prevActEndTime, newDriver, newVehicle);
        prevActEndTime = CalculationUtils.getActivityEndTime(nextActArrTime, activities.get(i));
        prevAct = activities.get(i);
        continue;
      }
      else if(pickupShipmentConstraintStatus.equals(ConstraintsStatus.NOT_FULFILLED_BREAK)){
        pickupShipmentLoopBroken = true;
        break;
      }
      double additionalPickupICosts = softActivityConstraint.getCosts(insertionContext, prevAct, pickupShipment, activities.get(i), prevActEndTime);
      double pickupAIC = calculate(insertionContext,prevAct,pickupShipment,activities.get(i),prevActEndTime);
      TourActivity prevAct_deliveryLoop = pickupShipment;
      double shipmentPickupArrTime = prevActEndTime + transportCosts.getTransportTime(prevAct.getLocationId(), pickupShipment.getLocationId(), prevActEndTime, newDriver, newVehicle);
      double shipmentPickupEndTime = CalculationUtils.getActivityEndTime(shipmentPickupArrTime, pickupShipment);

            pickupContext.setArrivalTime(shipmentPickupArrTime);
            pickupContext.setEndTime(shipmentPickupEndTime);
            pickupContext.setInsertionIndex(i);
            insertionContext.setRelatedActivityContext(pickupContext);

            double prevActEndTime_deliveryLoop = shipmentPickupEndTime;
      boolean deliverShipmentLoopBroken = false;
      //deliverShipmentLoop
      for(int j=i;j<activities.size();j++){
        ConstraintsStatus deliverShipmentConstraintStatus = hardActivityLevelConstraint.fulfilled(insertionContext, prevAct_deliveryLoop, deliverShipment, activities.get(j), prevActEndTime_deliveryLoop);
        if(deliverShipmentConstraintStatus.equals(ConstraintsStatus.FULFILLED)){
          double additionalDeliveryICosts = softActivityConstraint.getCosts(insertionContext, prevAct_deliveryLoop, deliverShipment, activities.get(j), prevActEndTime_deliveryLoop);
          double deliveryAIC = calculate(insertionContext,prevAct_deliveryLoop,deliverShipment,activities.get(j),prevActEndTime_deliveryLoop);
          double totalActivityInsertionCosts = pickupAIC + deliveryAIC
              + additionalICostsAtRouteLevel + additionalPickupICosts + additionalDeliveryICosts;
          if(totalActivityInsertionCosts < bestCost){
            bestCost = totalActivityInsertionCosts;
            pickupInsertionIndex = i;
            deliveryInsertionIndex = j;
          }
        }
        else if(deliverShipmentConstraintStatus.equals(ConstraintsStatus.NOT_FULFILLED_BREAK)){
          deliverShipmentLoopBroken = true;
          break;
       
        //update prevAct and endTime
        double nextActArrTime = prevActEndTime_deliveryLoop + transportCosts.getTransportTime(prevAct_deliveryLoop.getLocationId(), activities.get(j).getLocationId(), prevActEndTime_deliveryLoop, newDriver, newVehicle);
        prevActEndTime_deliveryLoop = CalculationUtils.getActivityEndTime(nextActArrTime, activities.get(j));
        prevAct_deliveryLoop = activities.get(j);
      }
      if(!deliverShipmentLoopBroken){ //check insertion between lastAct and endOfTour
        ConstraintsStatus deliverShipmentConstraintStatus = hardActivityLevelConstraint.fulfilled(insertionContext, prevAct_deliveryLoop, deliverShipment, end, prevActEndTime_deliveryLoop);
        if(deliverShipmentConstraintStatus.equals(ConstraintsStatus.FULFILLED)){
          double additionalDeliveryICosts = softActivityConstraint.getCosts(insertionContext, prevAct_deliveryLoop, deliverShipment, end, prevActEndTime_deliveryLoop);
          double deliveryAIC = calculate(insertionContext,prevAct_deliveryLoop,deliverShipment,end,prevActEndTime_deliveryLoop);
          double totalActivityInsertionCosts = pickupAIC + deliveryAIC
              + additionalICostsAtRouteLevel + additionalPickupICosts + additionalDeliveryICosts;
          if(totalActivityInsertionCosts < bestCost){
            bestCost = totalActivityInsertionCosts;
            pickupInsertionIndex = i;
            deliveryInsertionIndex = activities.size();
          }
        }
      }
      //update prevAct and endTime
      double nextActArrTime = prevActEndTime + transportCosts.getTransportTime(prevAct.getLocationId(), activities.get(i).getLocationId(), prevActEndTime, newDriver, newVehicle);
      prevActEndTime = CalculationUtils.getActivityEndTime(nextActArrTime, activities.get(i));
      prevAct = activities.get(i);
    }
    if(!pickupShipmentLoopBroken){ //check insertion of pickupShipment and deliverShipment at just before tour ended
      ConstraintsStatus pickupShipmentConstraintStatus = hardActivityLevelConstraint.fulfilled(insertionContext, prevAct, pickupShipment, end, prevActEndTime);
      if(pickupShipmentConstraintStatus.equals(ConstraintsStatus.FULFILLED)){
        double additionalPickupICosts = softActivityConstraint.getCosts(insertionContext, prevAct, pickupShipment, end, prevActEndTime);
        double pickupAIC = calculate(insertionContext,prevAct,pickupShipment,end,prevActEndTime);
        TourActivity prevAct_deliveryLoop = pickupShipment;
        double shipmentPickupArrTime = prevActEndTime + transportCosts.getTransportTime(prevAct.getLocationId(), pickupShipment.getLocationId(), prevActEndTime, newDriver, newVehicle);
        double shipmentPickupEndTime = CalculationUtils.getActivityEndTime(shipmentPickupArrTime, pickupShipment);
        double prevActEndTime_deliveryLoop = shipmentPickupEndTime;

                pickupContext.setArrivalTime(shipmentPickupArrTime);
                pickupContext.setEndTime(shipmentPickupEndTime);
                pickupContext.setInsertionIndex(activities.size());
                insertionContext.setRelatedActivityContext(pickupContext);

                ConstraintsStatus deliverShipmentConstraintStatus = hardActivityLevelConstraint.fulfilled(insertionContext, prevAct_deliveryLoop, deliverShipment, end, prevActEndTime_deliveryLoop);
        if(deliverShipmentConstraintStatus.equals(ConstraintsStatus.FULFILLED)){
          double additionalDeliveryICosts = softActivityConstraint.getCosts(insertionContext, prevAct_deliveryLoop, deliverShipment, end, prevActEndTime_deliveryLoop);
          double deliveryAIC = calculate(insertionContext,prevAct_deliveryLoop,deliverShipment,end,prevActEndTime_deliveryLoop);
          double totalActivityInsertionCosts = pickupAIC + deliveryAIC
              + additionalICostsAtRouteLevel + additionalPickupICosts + additionalDeliveryICosts;
          if(totalActivityInsertionCosts < bestCost){
View Full Code Here

     * i=prevAct
     * j=nextAct
     * k=serviceAct2Insert
     */
    for(TourActivity nextAct : tour.getActivities()){
            ConstraintsStatus hardActivityConstraintsStatus = hardActivityLevelConstraint.fulfilled(insertionContext, prevAct, serviceAct2Insert, nextAct, prevActDepTime_newVehicle);
            if(hardActivityConstraintsStatus.equals(ConstraintsStatus.FULFILLED)){
                /**
                 * builds a path on this route forwardPath={i,k,j,j+1,j+2,...,j+nuOfActsForwardLooking}
                 */
                double actInsertionCosts = activityInsertionCostsCalculator.getCosts(insertionContext, prevAct, nextAct, serviceAct2Insert, prevActDepTime_newVehicle);

                /**
                 * insertion_cost_approximation = c({0,1,...,i},newVehicle) + c({i,k,j,j+1,j+2,...,j+nuOfActsForwardLooking},newVehicle) - c({0,1,...,i,j,j+1,...,j+nuOfActsForwardLooking},oldVehicle)
                 */
                double insertion_cost_approximation = sumOf_prevCosts_newVehicle - sumOf_prevCosts_oldVehicle(currentRoute,prevAct) + actInsertionCosts;

                /**
                 * memorize it in insertion-queue
                 */
                if(insertion_cost_approximation < best_known_insertion_costs){
                    bestInsertionsQueue.add(new InsertionData(insertion_cost_approximation, InsertionData.NO_INDEX, actIndex, newVehicle, newDriver));
                }
            }
            else if(hardActivityConstraintsStatus.equals(ConstraintsStatus.NOT_FULFILLED_BREAK)){
                loopBroken = true;
                break;
            }


            /**
             * calculate transport and activity costs with new vehicle (without inserting k)
             */
      double transportCost_prevAct_nextAct_newVehicle = transportCosts.getTransportCost(prevAct.getLocationId(), nextAct.getLocationId(), prevActDepTime_newVehicle, newDriver, newVehicle);
      double transportTime_prevAct_nextAct_newVehicle = transportCosts.getTransportTime(prevAct.getLocationId(), nextAct.getLocationId(), prevActDepTime_newVehicle, newDriver, newVehicle);
      double arrTime_nextAct_newVehicle = prevActDepTime_newVehicle + transportTime_prevAct_nextAct_newVehicle;
      double activityCost_nextAct = activityCosts.getActivityCost(nextAct, arrTime_nextAct_newVehicle, newDriver, newVehicle);

      /**
       * memorize transport and activity costs with new vehicle without inserting k
       */
      sumOf_prevCosts_newVehicle += transportCost_prevAct_nextAct_newVehicle + activityCost_nextAct;
      activity2costWithNewVehicle.put(nextAct, sumOf_prevCosts_newVehicle);

      /**
       * departure time at nextAct with new vehicle
       */
      double depTime_nextAct_newVehicle = Math.max(arrTime_nextAct_newVehicle, nextAct.getTheoreticalEarliestOperationStartTime()) + nextAct.getOperationTime();

      /**
       * set previous to next
       */
      prevAct = nextAct;
      prevActDepTime_newVehicle = depTime_nextAct_newVehicle;

      actIndex++;
    }
    if(!loopBroken){
      End nextAct = end;
            ConstraintsStatus hardActivityConstraintsStatus = hardActivityLevelConstraint.fulfilled(insertionContext, prevAct, serviceAct2Insert, nextAct, prevActDepTime_newVehicle);
            if(hardActivityConstraintsStatus.equals(ConstraintsStatus.FULFILLED)){
                double actInsertionCosts = activityInsertionCostsCalculator.getCosts(insertionContext, prevAct, nextAct, serviceAct2Insert, prevActDepTime_newVehicle);

                    /**
                     * insertion_cost_approximation = c({0,1,...,i},newVehicle) + c({i,k,j,j+1,j+2,...,j+nuOfActsForwardLooking},newVehicle) - c({0,1,...,i,j,j+1,...,j+nuOfActsForwardLooking},oldVehicle)
                     */
 
View Full Code Here

TOP

Related Classes of jsprit.core.problem.constraint.HardActivityConstraint.ConstraintsStatus

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.