Package jsprit.core.problem.misc

Examples of jsprit.core.problem.misc.JobInsertionContext


        assertEquals(60.,route.getEnd().getArrTime(),0.01);

        Service s4 = Service.Builder.newInstance("s4").setLocationId("40,0").build();
        PickupService serviceAct = new PickupService(s4);

        JobInsertionContext insertionContext = new JobInsertionContext(route,s4,v6,route.getDriver(),0.);

        HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager,routingCosts);

        HardActivityConstraint.ConstraintsStatus status = twConstraint.fulfilled(insertionContext, route.getActivities().get(1), serviceAct, route.getActivities().get(2), 30.);
        assertFalse(status.equals(HardActivityConstraint.ConstraintsStatus.FULFILLED));
View Full Code Here


        assertEquals(60.,route.getEnd().getArrTime(),0.01);

        Service s4 = Service.Builder.newInstance("s4").setLocationId("40,0").build();
        PickupService serviceAct = new PickupService(s4);

        JobInsertionContext insertionContext = new JobInsertionContext(route,s4,v6,route.getDriver(),0.);

        HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager,routingCosts);

        HardActivityConstraint.ConstraintsStatus status = twConstraint.fulfilled(insertionContext, route.getActivities().get(0), serviceAct, route.getActivities().get(1), 10.);
        assertFalse(status.equals(HardActivityConstraint.ConstraintsStatus.FULFILLED));
View Full Code Here

        assertEquals(60.,route.getEnd().getArrTime(),0.01);

        Service s4 = Service.Builder.newInstance("s4").setLocationId("40,0").build();
        PickupService serviceAct = new PickupService(s4);

        JobInsertionContext insertionContext = new JobInsertionContext(route,s4,v6,route.getDriver(),0.);

        HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager,routingCosts);

        HardActivityConstraint.ConstraintsStatus status = twConstraint.fulfilled(insertionContext, route.getActivities().get(2), serviceAct, route.getEnd(), 30.);
        assertTrue(status.equals(HardActivityConstraint.ConstraintsStatus.FULFILLED));
View Full Code Here

        assertEquals(60.,route.getEnd().getArrTime(),0.01);

        Service s4 = Service.Builder.newInstance("s4").setLocationId("40,0").build();
        PickupService serviceAct = new PickupService(s4);

        JobInsertionContext insertionContext = new JobInsertionContext(route,s4,v5,route.getDriver(),60.);

        HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager,routingCosts);

        HardActivityConstraint.ConstraintsStatus status = twConstraint.fulfilled(insertionContext, route.getActivities().get(2), serviceAct, route.getEnd(), 90.);
        assertFalse(status.equals(HardActivityConstraint.ConstraintsStatus.FULFILLED));
View Full Code Here

   * assumption that cost changes can entirely covered by only looking at the predecessor i-1 and its successor i+1.
  
   */
  @Override
  public InsertionData getInsertionData(final VehicleRoute currentRoute, final Job jobToInsert, final Vehicle newVehicle, double newVehicleDepartureTime, final Driver newDriver, final double bestKnownCosts) {
        JobInsertionContext insertionContext = new JobInsertionContext(currentRoute, jobToInsert, newVehicle, newDriver, newVehicleDepartureTime);
        Shipment shipment = (Shipment)jobToInsert;
        TourActivity pickupShipment = activityFactory.createActivities(shipment).get(0);
        TourActivity deliverShipment = activityFactory.createActivities(shipment).get(1);
        insertionContext.getAssociatedActivities().add(pickupShipment);
        insertionContext.getAssociatedActivities().add(deliverShipment);

        /*
        check hard route constraints
         */
        if(!hardRouteLevelConstraint.fulfilled(insertionContext)){
      return InsertionData.createEmptyInsertionData();
    }
        /*
        check soft route constraints
         */
        double additionalICostsAtRouteLevel = softRouteConstraint.getCosts(insertionContext);

        double bestCost = bestKnownCosts;
        additionalICostsAtRouteLevel += additionalAccessEgressCalculator.getCosts(insertionContext);

        int pickupInsertionIndex = InsertionData.NO_INDEX;
    int deliveryInsertionIndex = InsertionData.NO_INDEX;
   
    Start start = Start.newInstance(newVehicle.getStartLocationId(), newVehicle.getEarliestDeparture(), newVehicle.getLatestArrival());
    start.setEndTime(newVehicleDepartureTime);
   
    End end = End.newInstance(newVehicle.getEndLocationId(), 0.0, newVehicle.getLatestArrival());

        ActivityContext pickupContext = new ActivityContext();

    TourActivity prevAct = start;
    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);
View Full Code Here

    public void whenNewJobIsInsertedWithOldVeh_itJustShouldReturnTrue(){

        Service s4 = Service.Builder.newInstance("s4").setLocationId("50,0").build();
        PickupService serviceAct = new PickupService(s4);

        JobInsertionContext insertionContext = new JobInsertionContext(route,s4,vehicle,route.getDriver(),0.);

        HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager,routingCosts);

        HardActivityConstraint.ConstraintsStatus status = twConstraint.fulfilled(insertionContext, route.getActivities().get(2), serviceAct, route.getEnd(), 30.);
        assertTrue(status.equals(HardActivityConstraint.ConstraintsStatus.FULFILLED));
View Full Code Here

    public void whenNewJobIsInsertedWithOldVeh_itJustShouldReturnFalse(){

        Service s4 = Service.Builder.newInstance("s4").setLocationId("1000,0").build();
        PickupService serviceAct = new PickupService(s4);

        JobInsertionContext insertionContext = new JobInsertionContext(route,s4,vehicle,route.getDriver(),0.);

        HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager,routingCosts);

        HardActivityConstraint.ConstraintsStatus status = twConstraint.fulfilled(insertionContext, route.getActivities().get(2), serviceAct, route.getEnd(), 30.);
        assertFalse(status.equals(HardActivityConstraint.ConstraintsStatus.FULFILLED));
View Full Code Here

    public void whenNewJobIsInsertedInBetweenAct1And2WithOldVeh_itJustShouldReturnTrue(){

        Service s4 = Service.Builder.newInstance("s4").setLocationId("50,0").build();
        PickupService serviceAct = new PickupService(s4);

        JobInsertionContext insertionContext = new JobInsertionContext(route,s4,vehicle,route.getDriver(),0.);

        HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager,routingCosts);
        /*
        driverTime = 10 + 10 + 30 + 20 + 30 = 100
         */
 
View Full Code Here

    public void whenNewJobIsInsertedInBetweenAct1And2WithOldVeh_itJustShouldReturnFalse(){

        Service s4 = Service.Builder.newInstance("s4").setLocationId("51,0").build();
        PickupService serviceAct = new PickupService(s4);

        JobInsertionContext insertionContext = new JobInsertionContext(route,s4,vehicle,route.getDriver(),0.);

        /*
        driverTime = 10 + 10 + 31 + 21 + 30 = 102
         */

 
View Full Code Here

        assertEquals(60.,route.getEnd().getArrTime(),0.01);

        Service s4 = Service.Builder.newInstance("s4").setLocationId("40,0").build();
        PickupService serviceAct = new PickupService(s4);

        JobInsertionContext insertionContext = new JobInsertionContext(route,s4,v2,route.getDriver(),0.);

        HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager,routingCosts);

        HardActivityConstraint.ConstraintsStatus status = twConstraint.fulfilled(insertionContext, route.getActivities().get(2), serviceAct, route.getEnd(), 30.);
View Full Code Here

TOP

Related Classes of jsprit.core.problem.misc.JobInsertionContext

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.