コード例 #1
0
 @Test
 public void insertNewInVehicle2ShouldBeCorrect() {
   // current distance vehicle2: 160 allowed: 200
   MaxDistanceConstraint maxDistanceConstraint =
       new MaxDistanceConstraint(
           stateManager,
           traveledDistanceId,
           new TransportDistance() {
             @Override
             public double getDistance(
                 Location from, Location to, double departureTime, Vehicle vehicle) {
               return vrp.getTransportCosts()
                   .getTransportTime(from, to, departureTime, null, vehicle);
             }
           },
           maxDistanceMap);
   JobInsertionContext context = new JobInsertionContext(route, newDelivery, vehicle2, null, 0);
   Assert.assertTrue(
       maxDistanceConstraint
           .fulfilled(context, route.getStart(), newAct(), act(0), 0)
           .equals(HardActivityConstraint.ConstraintsStatus.FULFILLED));
   // additional distance: 20+35-15=40
   Assert.assertTrue(
       maxDistanceConstraint
           .fulfilled(context, act(0), newAct(), act(1), 0)
           .equals(HardActivityConstraint.ConstraintsStatus.FULFILLED));
   // additional distance: 35+65-30=70
   Assert.assertTrue(
       maxDistanceConstraint
           .fulfilled(context, act(1), newAct(), act(2), 0)
           .equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
   // additional distance: 65+100-35
   Assert.assertTrue(
       maxDistanceConstraint
           .fulfilled(context, act(2), newAct(), act(3), 0)
           .equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
   // additional distance: 100+45-55
   Assert.assertTrue(
       maxDistanceConstraint
           .fulfilled(context, act(3), newAct(), act(4), 0)
           .equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
   // additional distance: 45+20-25
   Assert.assertTrue(
       maxDistanceConstraint
           .fulfilled(context, act(4), newAct(), route.getEnd(), 0)
           .equals(HardActivityConstraint.ConstraintsStatus.FULFILLED));
 }
コード例 #2
0
ファイル: RuinWorst.java プロジェクト: baskin/jsprit
  private Job getWorst(Collection<VehicleRoute> copied) {
    Job worst = null;
    double bestSavings = Double.MIN_VALUE;

    for (VehicleRoute route : copied) {
      if (route.isEmpty()) continue;
      Map<Job, Double> savingsMap = new HashMap<Job, Double>();
      TourActivity actBefore = route.getStart();
      TourActivity actToEval = null;
      for (TourActivity act : route.getActivities()) {
        if (actToEval == null) {
          actToEval = act;
          continue;
        }
        double savings = savings(route, actBefore, actToEval, act);
        Job job = ((TourActivity.JobActivity) actToEval).getJob();
        if (!savingsMap.containsKey(job)) {
          savingsMap.put(job, savings);
        } else {
          double s = savingsMap.get(job);
          savingsMap.put(job, s + savings);
        }
        actBefore = actToEval;
        actToEval = act;
      }
      double savings = savings(route, actBefore, actToEval, route.getEnd());
      Job job = ((TourActivity.JobActivity) actToEval).getJob();
      if (!savingsMap.containsKey(job)) {
        savingsMap.put(job, savings);
      } else {
        double s = savingsMap.get(job);
        savingsMap.put(job, s + savings);
      }
      // getCounts best
      for (Job j : savingsMap.keySet()) {
        if (savingsMap.get(j) > bestSavings) {
          bestSavings = savingsMap.get(j);
          worst = j;
        }
      }
    }
    return worst;
  }
コード例 #3
0
 /*
     vehicle: 200.0
 vehicle (max distance): 200.0
 vehicle2: 160.0
 vehicle2 (max distance): 180.0
      */
 @Test
 public void insertNewInVehicleShouldFail() {
   MaxDistanceConstraint maxDistanceConstraint =
       new MaxDistanceConstraint(
           stateManager,
           traveledDistanceId,
           new TransportDistance() {
             @Override
             public double getDistance(
                 Location from, Location to, double departureTime, Vehicle vehicle) {
               return vrp.getTransportCosts()
                   .getTransportTime(from, to, departureTime, null, vehicle);
             }
           },
           maxDistanceMap);
   JobInsertionContext context = new JobInsertionContext(route, newDelivery, vehicle, null, 0);
   Assert.assertTrue(
       maxDistanceConstraint
           .fulfilled(context, route.getStart(), newAct(), act(0), 0)
           .equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
   Assert.assertTrue(
       maxDistanceConstraint
           .fulfilled(context, act(0), newAct(), act(1), 0)
           .equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
   Assert.assertTrue(
       maxDistanceConstraint
           .fulfilled(context, act(1), newAct(), act(2), 0)
           .equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
   Assert.assertTrue(
       maxDistanceConstraint
           .fulfilled(context, act(2), newAct(), act(3), 0)
           .equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
   Assert.assertTrue(
       maxDistanceConstraint
           .fulfilled(context, act(3), newAct(), act(4), 0)
           .equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
   Assert.assertTrue(
       maxDistanceConstraint
           .fulfilled(context, act(4), newAct(), route.getEnd(), 0)
           .equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
 }
コード例 #4
0
ファイル: SolutionAnalyser.java プロジェクト: sanga/jsprit
 /**
  * @param route to get the total operation time from
  * @return operation time of this route, i.e. endTime - startTime of specified route
  */
 public Double getOperationTime(VehicleRoute route) {
   if (route == null) throw new IllegalArgumentException("route is missing.");
   return route.getEnd().getArrTime() - route.getStart().getEndTime();
 }
コード例 #5
0
ファイル: SolutionAnalyser.java プロジェクト: sanga/jsprit
 @Override
 public void begin(VehicleRoute route) {
   sum_distance = 0.;
   this.route = route;
   this.prevAct = route.getStart();
 }
コード例 #6
0
ファイル: SolutionAnalyser.java プロジェクト: sanga/jsprit
 @Override
 public void begin(VehicleRoute route) {
   this.route = route;
   this.prevAct = route.getStart();
   this.prevActDeparture = route.getDepartureTime();
 }