コード例 #1
0
  @Test
  public void whenAddingDeliverShipmentWithVehDiffStartEndLocs_constraintShouldWork() {
    Shipment shipment =
        Shipment.Builder.newInstance("s")
            .setPickupLocation(Location.newInstance(0, 1))
            .setDeliveryLocation(Location.newInstance(4, 1))
            .build();
    VehicleImpl vehicle =
        VehicleImpl.Builder.newInstance("v")
            .setStartLocation(Location.newInstance(0, 0))
            .setEndLocation(Location.newInstance(0, 4))
            .build();
    final VehicleRoutingProblem vrp =
        VehicleRoutingProblem.Builder.newInstance().addJob(shipment).addVehicle(vehicle).build();
    VehicleRoute route = VehicleRoute.emptyRoute();
    JobInsertionContext context = new JobInsertionContext(route, shipment, vehicle, null, 0);
    context.getAssociatedActivities().add(vrp.getActivities(shipment).get(0));
    context.getAssociatedActivities().add(vrp.getActivities(shipment).get(1));
    maxDistanceMap = new HashMap<>();
    maxDistanceMap.put(vehicle, 10d);

    StateManager stateManager = new StateManager(vrp);
    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);
    Assert.assertTrue(
        maxDistanceConstraint
            .fulfilled(
                context,
                new Start(vehicle.getStartLocation(), 0, Double.MAX_VALUE),
                vrp.getActivities(shipment).get(0),
                new End(vehicle.getEndLocation(), 0, Double.MAX_VALUE),
                0)
            .equals(HardActivityConstraint.ConstraintsStatus.FULFILLED));

    ActivityContext pickupContext = new ActivityContext();
    pickupContext.setArrivalTime(1);
    pickupContext.setEndTime(1);
    pickupContext.setInsertionIndex(0);
    context.setRelatedActivityContext(pickupContext);
    Assert.assertTrue(
        maxDistanceConstraint
            .fulfilled(
                context,
                vrp.getActivities(shipment).get(0),
                vrp.getActivities(shipment).get(1),
                new End(vehicle.getEndLocation(), 0, Double.MAX_VALUE),
                1)
            .equals(HardActivityConstraint.ConstraintsStatus.FULFILLED));
  }
コード例 #2
0
  @Test
  public void whenEndLocationIsSet_constraintShouldWork() {
    VehicleImpl vehicle =
        VehicleImpl.Builder.newInstance("v")
            .setStartLocation(Location.newInstance(0, 0))
            .setEndLocation(Location.newInstance(10, 0))
            .build();
    Pickup pickup =
        Pickup.Builder.newInstance("pickup").setLocation(Location.newInstance(10, 0)).build();
    vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(vehicle).addJob(pickup).build();
    route = VehicleRoute.emptyRoute();
    maxDistanceMap = new HashMap<>();
    maxDistanceMap.put(vehicle, 5d);

    MaxDistanceConstraint maxDistanceConstraint =
        new MaxDistanceConstraint(
            new StateManager(vrp),
            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, pickup, vehicle, null, 0);
    Assert.assertTrue(
        maxDistanceConstraint
            .fulfilled(
                context,
                new Start(vehicle.getStartLocation(), 0, Double.MAX_VALUE),
                vrp.getActivities(pickup).get(0),
                new End(vehicle.getEndLocation(), 0, Double.MAX_VALUE),
                0)
            .equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
  }