@Test
 public void distanceToTravelShouldBeCorrectVehicle2() {
   double total = stateManager.getRouteState(route, vehicle2, traveledDistanceId, Double.class);
   Assert.assertEquals(
       160d,
       total
           - stateManager.getActivityState(
               route.getActivities().get(0), vehicle2, traveledDistanceId, Double.class),
       0.01);
   Assert.assertEquals(
       145d,
       total
           - stateManager.getActivityState(
               route.getActivities().get(1), vehicle2, traveledDistanceId, Double.class),
       0.01);
   Assert.assertEquals(
       115d,
       total
           - stateManager.getActivityState(
               route.getActivities().get(2), vehicle2, traveledDistanceId, Double.class),
       0.01);
   Assert.assertEquals(
       80d,
       total
           - stateManager.getActivityState(
               route.getActivities().get(3), vehicle2, traveledDistanceId, Double.class),
       0.01);
   Assert.assertEquals(
       25d,
       total
           - stateManager.getActivityState(
               route.getActivities().get(4), vehicle2, traveledDistanceId, Double.class),
       0.01);
 }
 @Test
 public void traveledDistanceWithVehicle2ShouldBeCorrect() {
   Assert.assertEquals(
       0d,
       stateManager.getActivityState(
           route.getActivities().get(0), vehicle2, traveledDistanceId, Double.class),
       0.01);
   Assert.assertEquals(
       15d,
       stateManager.getActivityState(
           route.getActivities().get(1), vehicle2, traveledDistanceId, Double.class),
       0.01);
   Assert.assertEquals(
       45d,
       stateManager.getActivityState(
           route.getActivities().get(2), vehicle2, traveledDistanceId, Double.class),
       0.01);
   Assert.assertEquals(
       80d,
       stateManager.getActivityState(
           route.getActivities().get(3), vehicle2, traveledDistanceId, Double.class),
       0.01);
   Assert.assertEquals(
       135d,
       stateManager.getActivityState(
           route.getActivities().get(4), vehicle2, traveledDistanceId, Double.class),
       0.01);
 }
 @Test
 public void traveledDistanceShouldBeCorrect() {
   Assert.assertEquals(
       20d,
       stateManager.getActivityState(
           route.getActivities().get(0), vehicle, traveledDistanceId, Double.class),
       0.01);
   Assert.assertEquals(
       35d,
       stateManager.getActivityState(
           route.getActivities().get(1), vehicle, traveledDistanceId, Double.class),
       0.01);
   Assert.assertEquals(
       65d,
       stateManager.getActivityState(
           route.getActivities().get(2), vehicle, traveledDistanceId, Double.class),
       0.01);
   Assert.assertEquals(
       100d,
       stateManager.getActivityState(
           route.getActivities().get(3), vehicle, traveledDistanceId, Double.class),
       0.01);
   Assert.assertEquals(
       155d,
       stateManager.getActivityState(
           route.getActivities().get(4), vehicle, traveledDistanceId, Double.class),
       0.01);
 }
 @Test
 public void whenVehicleRouteHasPickupAndDeliveryAndPickup_latestStartTimeOfAct1MustBeCorrect() {
   assertEquals(30., route.getActivities().get(0).getTheoreticalLatestOperationStartTime(), 0.01);
   assertEquals(
       10.,
       stateManager.getActivityState(
           route.getActivities().get(0), InternalStates.LATEST_OPERATION_START_TIME, Double.class),
       0.01);
 }
 @Test
 public void distanceOfShipmentInRouteVehicle2() {
   double traveledDistanceBeforePickup =
       stateManager.getActivityState(
           route.getActivities().get(2), vehicle2, traveledDistanceId, Double.class);
   double traveledDistanceBeforeDelivery =
       stateManager.getActivityState(
           route.getActivities().get(4), vehicle2, traveledDistanceId, Double.class);
   Assert.assertEquals(90d, traveledDistanceBeforeDelivery - traveledDistanceBeforePickup, 0.01);
 }
 @Test
 public void distanceOfPickupInRouteVehicle2() {
   double traveledDistanceBeforePickup =
       stateManager.getActivityState(
           route.getActivities().get(3), vehicle2, traveledDistanceId, Double.class);
   double total = stateManager.getRouteState(route, vehicle2, traveledDistanceId, Double.class);
   Assert.assertEquals(80d, total - traveledDistanceBeforePickup, 0.01);
 }
Beispiel #7
0
  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;
  }
 private TourActivity act(int i) {
   return route.getActivities().get(i);
 }