Пример #1
0
  @Test
  public void whenReadingProblemFromFile_maxCapacityShouldNotBeExceeded() {
    VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
    new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_iniRoutes_2.xml");
    VehicleRoutingAlgorithm vra = new GreedySchrimpfFactory().createAlgorithm(vrpBuilder.build());
    vra.setNuOfIterations(10);

    Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();

    assertFalse(secondActIsPickup(solutions));
  }
Пример #2
0
  @Test
  public void whenSolving_deliverService2_shouldBeInRoute() {

    VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
    new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_iniRoutes.xml");
    VehicleRoutingProblem vrp = vrpBuilder.build();

    VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
    Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
    VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);

    assertTrue(hasActivityIn(solution.getRoutes().iterator().next(), "2"));
  }
Пример #3
0
  @Test
  public void whenSolving_nuActsShouldBe2() {

    VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
    new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_iniRoutes.xml");
    VehicleRoutingProblem vrp = vrpBuilder.build();

    VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
    Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
    VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);

    SolutionPrinter.print(vrp, solution, SolutionPrinter.Print.VERBOSE);

    assertEquals(2, solution.getRoutes().iterator().next().getActivities().size());
  }
Пример #4
0
  @Test
  public void maxCapacityShouldNotBeExceeded() {
    VehicleType type =
        VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, 100).build();
    VehicleImpl vehicle =
        VehicleImpl.Builder.newInstance("veh")
            .setStartLocationCoordinate(Coordinate.newInstance(0, 0))
            .setType(type)
            .setStartLocationId("start")
            .build();

    Shipment shipment =
        Shipment.Builder.newInstance("s")
            .setPickupLocationId("pick")
            .setDeliveryLocationId("del")
            .setPickupCoord(Coordinate.newInstance(10, 0))
            .setDeliveryCoord(Coordinate.newInstance(0, 10))
            .addSizeDimension(0, 100)
            .build();

    Shipment another_shipment =
        Shipment.Builder.newInstance("another_s")
            .setPickupLocationId("pick")
            .setDeliveryLocationId("del")
            .setPickupCoord(Coordinate.newInstance(10, 0))
            .setDeliveryCoord(Coordinate.newInstance(0, 10))
            .addSizeDimension(0, 50)
            .build();

    VehicleRoute iniRoute =
        VehicleRoute.Builder.newInstance(vehicle).addPickup(shipment).addDelivery(shipment).build();

    VehicleRoutingProblem vrp =
        VehicleRoutingProblem.Builder.newInstance()
            .addJob(shipment)
            .addVehicle(vehicle)
            .addJob(another_shipment)
            .setFleetSize(VehicleRoutingProblem.FleetSize.FINITE)
            .addInitialVehicleRoute(iniRoute)
            .build();

    VehicleRoutingAlgorithm vra = new GreedySchrimpfFactory().createAlgorithm(vrp);
    vra.setNuOfIterations(10);

    Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();

    assertFalse(secondActIsPickup(solutions));
  }
Пример #5
0
  @Test
  public void whenSolvingProblem2_nuActsShouldBe6() {

    VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
    new VrpXMLReader(vrpBuilder)
        .read("src/test/resources/simpleProblem_inclShipments_iniRoutes.xml");
    VehicleRoutingProblem vrp = vrpBuilder.build();

    VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
    Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
    VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);

    int nuActs = 0;
    for (VehicleRoute r : solution.getRoutes()) {
      nuActs += r.getActivities().size();
    }
    assertEquals(6, nuActs);
  }
Пример #6
0
  @Test
  public void whenSolvingProblem2_nuJobsInSolutionShouldBe4() {

    VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
    new VrpXMLReader(vrpBuilder)
        .read("src/test/resources/simpleProblem_inclShipments_iniRoutes.xml");
    VehicleRoutingProblem vrp = vrpBuilder.build();

    VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
    Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
    VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);

    SolutionPrinter.print(vrp, solution, SolutionPrinter.Print.VERBOSE);

    int jobsInSolution = 0;
    for (VehicleRoute r : solution.getRoutes()) {
      jobsInSolution += r.getTourActivities().jobSize();
    }
    assertEquals(4, jobsInSolution);
  }