Exemplo n.º 1
0
 @Override
 public jsprit.core.problem.job.Service.Builder createBuilder(
     String serviceType, String id, Integer size) {
   if (serviceType.equals("pickup")) {
     if (size != null) return Pickup.Builder.newInstance(id).addSizeDimension(0, size);
     else return Pickup.Builder.newInstance(id);
   } else if (serviceType.equals("delivery")) {
     if (size != null) return Delivery.Builder.newInstance(id).addSizeDimension(0, size);
     else return Delivery.Builder.newInstance(id);
   } else {
     if (size != null) return Service.Builder.newInstance(id).addSizeDimension(0, size);
     else return Service.Builder.newInstance(id);
   }
 }
Exemplo n.º 2
0
  @Before
  public void doBefore() {
    Vehicle vehicle = mock(Vehicle.class);
    VehicleType type = mock(VehicleType.class);
    when(type.getCapacityDimensions())
        .thenReturn(Capacity.Builder.newInstance().addDimension(0, 20).build());
    when(vehicle.getType()).thenReturn(type);

    VehicleRoutingProblem.Builder serviceProblemBuilder =
        VehicleRoutingProblem.Builder.newInstance();
    Service s1 =
        Service.Builder.newInstance("s").addSizeDimension(0, 10).setLocationId("loc").build();
    Service s2 =
        Service.Builder.newInstance("s2").addSizeDimension(0, 5).setLocationId("loc").build();
    serviceProblemBuilder.addJob(s1).addJob(s2);
    final VehicleRoutingProblem serviceProblem = serviceProblemBuilder.build();

    final VehicleRoutingProblem.Builder pdProblemBuilder =
        VehicleRoutingProblem.Builder.newInstance();
    Pickup pickup =
        (Pickup)
            Pickup.Builder.newInstance("pick").addSizeDimension(0, 10).setLocationId("loc").build();
    Delivery delivery =
        (Delivery)
            Delivery.Builder.newInstance("del").addSizeDimension(0, 5).setLocationId("loc").build();
    pdProblemBuilder.addJob(pickup).addJob(delivery);
    final VehicleRoutingProblem pdProblem = pdProblemBuilder.build();

    final VehicleRoutingProblem.Builder shipmentProblemBuilder =
        VehicleRoutingProblem.Builder.newInstance();
    Shipment shipment1 =
        Shipment.Builder.newInstance("s1")
            .addSizeDimension(0, 10)
            .setPickupLocation("pick")
            .setDeliveryLocation("del")
            .build();
    Shipment shipment2 =
        Shipment.Builder.newInstance("s2")
            .addSizeDimension(0, 5)
            .setPickupLocation("pick")
            .setDeliveryLocation("del")
            .build();
    shipmentProblemBuilder.addJob(shipment1).addJob(shipment2).build();
    final VehicleRoutingProblem shipmentProblem = shipmentProblemBuilder.build();

    VehicleRoute.Builder serviceRouteBuilder = VehicleRoute.Builder.newInstance(vehicle);
    serviceRouteBuilder.setJobActivityFactory(
        new JobActivityFactory() {

          @Override
          public List<AbstractActivity> createActivities(Job job) {
            return serviceProblem.copyAndGetActivities(job);
          }
        });
    serviceRoute = serviceRouteBuilder.addService(s1).addService(s2).build();

    VehicleRoute.Builder pdRouteBuilder = VehicleRoute.Builder.newInstance(vehicle);
    pdRouteBuilder.setJobActivityFactory(
        new JobActivityFactory() {
          @Override
          public List<AbstractActivity> createActivities(Job job) {
            return pdProblem.copyAndGetActivities(job);
          }
        });
    pickup_delivery_route = pdRouteBuilder.addService(pickup).addService(delivery).build();

    VehicleRoute.Builder shipmentRouteBuilder = VehicleRoute.Builder.newInstance(vehicle);
    shipmentRouteBuilder.setJobActivityFactory(
        new JobActivityFactory() {
          @Override
          public List<AbstractActivity> createActivities(Job job) {
            return shipmentProblem.copyAndGetActivities(job);
          }
        });
    shipment_route =
        shipmentRouteBuilder
            .addPickup(shipment1)
            .addPickup(shipment2)
            .addDelivery(shipment2)
            .addDelivery(shipment1)
            .build();

    stateManager = new StateManager(mock(VehicleRoutingProblem.class));
    stateManager.updateLoadStates();
  }