Example #1
0
 @Test
 public void loadAtBeginningShouldBe0() {
   stateManager.informInsertionStarts(Arrays.asList(serviceRoute), Collections.<Job>emptyList());
   Capacity routeState =
       stateManager.getRouteState(serviceRoute, InternalStates.LOAD_AT_BEGINNING, Capacity.class);
   assertEquals(0, routeState.get(0));
 }
Example #2
0
  /*
  shipment_route
  shipment1 10
  shipment2 15
  pick1_pick2_deliver2_deliver1

   */
  @Test
  public void when_shipmentroute_loadAtEndShouldBe0() {
    stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.<Job>emptyList());
    Capacity routeState =
        stateManager.getRouteState(shipment_route, InternalStates.LOAD_AT_END, Capacity.class);
    assertEquals(0, routeState.get(0));
  }
Example #3
0
 @Test
 public void when_shipmentroute_pastMaxLoatAtAct4ShouldBe15() {
   stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.<Job>emptyList());
   Capacity atAct =
       stateManager.getActivityState(
           shipment_route.getActivities().get(3), InternalStates.PAST_MAXLOAD, Capacity.class);
   assertEquals(15, atAct.get(0));
 }
Example #4
0
 @Test
 public void when_shipmentroute_loadAtAct3ShouldBe10() {
   stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.<Job>emptyList());
   Capacity atAct =
       stateManager.getActivityState(
           shipment_route.getActivities().get(2), InternalStates.LOAD, Capacity.class);
   assertEquals(10, atAct.get(0));
 }
Example #5
0
 @Test
 public void pastMaxLoatAtAct2ShouldBe10() {
   stateManager.informInsertionStarts(Arrays.asList(serviceRoute), Collections.<Job>emptyList());
   Capacity atAct2 =
       stateManager.getActivityState(
           serviceRoute.getActivities().get(1), InternalStates.PAST_MAXLOAD, Capacity.class);
   assertEquals(15, atAct2.get(0));
 }
Example #6
0
 @Test
 public void futureMaxLoatAtAct1ShouldBe15() {
   stateManager.informInsertionStarts(Arrays.asList(serviceRoute), Collections.<Job>emptyList());
   Capacity atAct1 =
       stateManager.getActivityState(
           serviceRoute.getActivities().get(0), InternalStates.FUTURE_MAXLOAD, Capacity.class);
   assertEquals(15, atAct1.get(0));
 }
Example #7
0
 @Test
 public void when_pdroute_loadAtAct2ShouldBe10() {
   stateManager.informInsertionStarts(
       Arrays.asList(pickup_delivery_route), Collections.<Job>emptyList());
   Capacity atAct2 =
       stateManager.getActivityState(
           pickup_delivery_route.getActivities().get(1), InternalStates.LOAD, Capacity.class);
   assertEquals(10, atAct2.get(0));
 }
Example #8
0
 @Test
 public void when_pdroute_loadAtBeginningShouldBe5() {
   stateManager.informInsertionStarts(
       Arrays.asList(pickup_delivery_route), Collections.<Job>emptyList());
   Capacity routeState =
       stateManager.getRouteState(
           pickup_delivery_route, InternalStates.LOAD_AT_BEGINNING, Capacity.class);
   assertEquals(5, routeState.get(0));
 }
Example #9
0
 @Test
 public void when_pdroute_pastMaxLoatAtAct1ShouldBe15() {
   stateManager.informInsertionStarts(
       Arrays.asList(pickup_delivery_route), Collections.<Job>emptyList());
   Capacity atAct1 =
       stateManager.getActivityState(
           pickup_delivery_route.getActivities().get(0),
           InternalStates.PAST_MAXLOAD,
           Capacity.class);
   assertEquals(15, atAct1.get(0));
 }
Example #10
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();
  }