mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
move io to jsprit-io
This commit is contained in:
parent
667db19f32
commit
2d0274b441
3 changed files with 30 additions and 144 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
package com.graphhopper.jsprit.core.algorithm;
|
package com.graphhopper.jsprit.core.algorithm;
|
||||||
|
|
||||||
import com.graphhopper.jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
|
import com.graphhopper.jsprit.core.algorithm.box.Jsprit;
|
||||||
import com.graphhopper.jsprit.core.problem.Location;
|
import com.graphhopper.jsprit.core.problem.Location;
|
||||||
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
|
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
|
||||||
import com.graphhopper.jsprit.core.problem.job.Service;
|
import com.graphhopper.jsprit.core.problem.job.Service;
|
||||||
|
|
@ -27,7 +27,7 @@ public class ExternalInitialSolutionIsInValidTest {
|
||||||
|
|
||||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s1).addJob(s2).addVehicle(vehicle).build();
|
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s1).addJob(s2).addVehicle(vehicle).build();
|
||||||
|
|
||||||
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithm_without_construction.xml");
|
VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
create ini sol
|
create ini sol
|
||||||
|
|
|
||||||
|
|
@ -25,13 +25,11 @@ import com.graphhopper.jsprit.core.algorithm.box.SchrimpfFactory;
|
||||||
import com.graphhopper.jsprit.core.algorithm.state.StateManager;
|
import com.graphhopper.jsprit.core.algorithm.state.StateManager;
|
||||||
import com.graphhopper.jsprit.core.algorithm.state.UpdateEndLocationIfRouteIsOpen;
|
import com.graphhopper.jsprit.core.algorithm.state.UpdateEndLocationIfRouteIsOpen;
|
||||||
import com.graphhopper.jsprit.core.algorithm.state.UpdateVariableCosts;
|
import com.graphhopper.jsprit.core.algorithm.state.UpdateVariableCosts;
|
||||||
import com.graphhopper.jsprit.core.problem.AbstractActivity;
|
|
||||||
import com.graphhopper.jsprit.core.problem.Location;
|
import com.graphhopper.jsprit.core.problem.Location;
|
||||||
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
|
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
|
||||||
import com.graphhopper.jsprit.core.problem.constraint.ConstraintManager;
|
import com.graphhopper.jsprit.core.problem.constraint.ConstraintManager;
|
||||||
import com.graphhopper.jsprit.core.problem.constraint.ServiceLoadActivityLevelConstraint;
|
import com.graphhopper.jsprit.core.problem.constraint.ServiceLoadActivityLevelConstraint;
|
||||||
import com.graphhopper.jsprit.core.problem.constraint.ServiceLoadRouteLevelConstraint;
|
import com.graphhopper.jsprit.core.problem.constraint.ServiceLoadRouteLevelConstraint;
|
||||||
import com.graphhopper.jsprit.core.problem.io.VrpXMLReader;
|
|
||||||
import com.graphhopper.jsprit.core.problem.job.Job;
|
import com.graphhopper.jsprit.core.problem.job.Job;
|
||||||
import com.graphhopper.jsprit.core.problem.job.Service;
|
import com.graphhopper.jsprit.core.problem.job.Service;
|
||||||
import com.graphhopper.jsprit.core.problem.job.Shipment;
|
import com.graphhopper.jsprit.core.problem.job.Shipment;
|
||||||
|
|
@ -45,110 +43,37 @@ import com.graphhopper.jsprit.core.problem.vehicle.VehicleTypeImpl;
|
||||||
import com.graphhopper.jsprit.core.reporting.SolutionPrinter;
|
import com.graphhopper.jsprit.core.reporting.SolutionPrinter;
|
||||||
import com.graphhopper.jsprit.core.util.Coordinate;
|
import com.graphhopper.jsprit.core.util.Coordinate;
|
||||||
import com.graphhopper.jsprit.core.util.Solutions;
|
import com.graphhopper.jsprit.core.util.Solutions;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class InitialRoutesTest {
|
public class InitialRoutesTest {
|
||||||
|
|
||||||
@Test
|
private VehicleRoutingProblem vrp;
|
||||||
public void whenReading_jobMapShouldOnlyContainJob2() {
|
|
||||||
|
|
||||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
private VehicleRoute initialRoute;
|
||||||
new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_iniRoutes.xml");
|
|
||||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
|
||||||
|
|
||||||
assertEquals(1, getNuServices(vrp));
|
@Before
|
||||||
assertTrue(vrp.getJobs().containsKey("2"));
|
public void before(){
|
||||||
|
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||||
|
VehicleImpl v = VehicleImpl.Builder.newInstance("veh1").setStartLocation(Location.newInstance(0,0)).setLatestArrival(48600).build();
|
||||||
|
Service s1 = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1000,0)).build();
|
||||||
|
Service s2 = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1000,1000)).build();
|
||||||
|
builder.addVehicle(v).addJob(s1).addJob(s2);
|
||||||
|
initialRoute = VehicleRoute.Builder.newInstance(v).addService(s1).build();
|
||||||
|
builder.addInitialVehicleRoute(initialRoute);
|
||||||
|
vrp = builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenReadingProblem2_jobMapShouldContain_service2() {
|
|
||||||
|
|
||||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
|
||||||
new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_inclShipments_iniRoutes.xml");
|
|
||||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
|
||||||
|
|
||||||
assertEquals(1, getNuServices(vrp));
|
|
||||||
assertTrue(vrp.getJobs().containsKey("2"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenReading_jobMapShouldContain_shipment4() {
|
|
||||||
|
|
||||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
|
||||||
new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_inclShipments_iniRoutes.xml");
|
|
||||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
|
||||||
|
|
||||||
assertEquals(1, getNuShipments(vrp));
|
|
||||||
assertTrue(vrp.getJobs().containsKey("4"));
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getNuShipments(VehicleRoutingProblem vrp) {
|
|
||||||
int nuShipments = 0;
|
|
||||||
for (Job job : vrp.getJobs().values()) {
|
|
||||||
if (job instanceof Shipment) nuShipments++;
|
|
||||||
}
|
|
||||||
return nuShipments;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getNuServices(VehicleRoutingProblem vrp) {
|
|
||||||
int nuServices = 0;
|
|
||||||
for (Job job : vrp.getJobs().values()) {
|
|
||||||
if (job instanceof Service) nuServices++;
|
|
||||||
}
|
|
||||||
return nuServices;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenReading_thereShouldBeOnlyOneActAssociatedToJob2() {
|
|
||||||
|
|
||||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
|
||||||
new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_iniRoutes.xml");
|
|
||||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
|
||||||
|
|
||||||
assertEquals(1, vrp.getActivities(vrp.getJobs().get("2")).size());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenReading_thereShouldBeOnlyOneActAssociatedToJob2_v2() {
|
|
||||||
|
|
||||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
|
||||||
new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_inclShipments_iniRoutes.xml");
|
|
||||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
|
||||||
|
|
||||||
assertEquals(1, vrp.getActivities(vrp.getJobs().get("2")).size());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenReading_thereShouldBeTwoActsAssociatedToShipment4() {
|
|
||||||
|
|
||||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
|
||||||
new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_inclShipments_iniRoutes.xml");
|
|
||||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
|
||||||
|
|
||||||
Job job = vrp.getJobs().get("4");
|
|
||||||
List<AbstractActivity> activities = vrp.getActivities(job);
|
|
||||||
|
|
||||||
assertEquals(2, activities.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenSolving_nuJobsInSolutionShouldBe2() {
|
public void whenSolving_nuJobsInSolutionShouldBe2() {
|
||||||
|
VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
|
||||||
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();
|
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||||
VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
|
VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
|
||||||
|
|
||||||
SolutionPrinter.print(vrp, solution, SolutionPrinter.Print.VERBOSE);
|
|
||||||
|
|
||||||
assertEquals(2, solution.getRoutes().iterator().next().getTourActivities().getJobs().size());
|
assertEquals(2, solution.getRoutes().iterator().next().getTourActivities().getJobs().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -174,17 +99,9 @@ public class InitialRoutesTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenSolving_nuActsShouldBe2() {
|
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);
|
VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
|
||||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||||
VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
|
VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
|
||||||
|
|
||||||
SolutionPrinter.print(vrp, solution, SolutionPrinter.Print.VERBOSE);
|
|
||||||
|
|
||||||
assertEquals(2, solution.getRoutes().iterator().next().getActivities().size());
|
assertEquals(2, solution.getRoutes().iterator().next().getActivities().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -208,17 +125,9 @@ public class InitialRoutesTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenSolving_deliverService1_shouldBeInRoute() {
|
public void whenSolving_deliverService1_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);
|
VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
|
||||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||||
VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
|
VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
|
||||||
|
|
||||||
SolutionPrinter.print(vrp, solution, SolutionPrinter.Print.VERBOSE);
|
|
||||||
|
|
||||||
Job job = getInitialJob("1", vrp);
|
Job job = getInitialJob("1", vrp);
|
||||||
assertTrue(hasActivityIn(solution, "veh1", job));
|
assertTrue(hasActivityIn(solution, "veh1", job));
|
||||||
}
|
}
|
||||||
|
|
@ -326,11 +235,6 @@ public class InitialRoutesTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenSolving_deliverService2_shouldBeInRoute() {
|
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);
|
VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
|
||||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||||
VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
|
VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
|
||||||
|
|
|
||||||
|
|
@ -18,12 +18,9 @@
|
||||||
package com.graphhopper.jsprit.core.algorithm;
|
package com.graphhopper.jsprit.core.algorithm;
|
||||||
|
|
||||||
import com.graphhopper.jsprit.core.IntegrationTest;
|
import com.graphhopper.jsprit.core.IntegrationTest;
|
||||||
import com.graphhopper.jsprit.core.algorithm.recreate.NoSolutionFoundException;
|
import com.graphhopper.jsprit.core.algorithm.box.Jsprit;
|
||||||
import com.graphhopper.jsprit.core.algorithm.state.StateManager;
|
|
||||||
import com.graphhopper.jsprit.core.problem.Skills;
|
import com.graphhopper.jsprit.core.problem.Skills;
|
||||||
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
|
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
|
||||||
import com.graphhopper.jsprit.core.problem.constraint.ConstraintManager;
|
|
||||||
import com.graphhopper.jsprit.core.problem.io.VrpXMLReader;
|
|
||||||
import com.graphhopper.jsprit.core.problem.job.Job;
|
import com.graphhopper.jsprit.core.problem.job.Job;
|
||||||
import com.graphhopper.jsprit.core.problem.job.Service;
|
import com.graphhopper.jsprit.core.problem.job.Service;
|
||||||
import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||||
|
|
@ -31,9 +28,9 @@ import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute;
|
||||||
import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
|
import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
|
||||||
import com.graphhopper.jsprit.core.problem.vehicle.VehicleImpl;
|
import com.graphhopper.jsprit.core.problem.vehicle.VehicleImpl;
|
||||||
import com.graphhopper.jsprit.core.problem.vehicle.VehicleType;
|
import com.graphhopper.jsprit.core.problem.vehicle.VehicleType;
|
||||||
|
import com.graphhopper.jsprit.core.util.SolomonReader;
|
||||||
import com.graphhopper.jsprit.core.util.Solutions;
|
import com.graphhopper.jsprit.core.util.Solutions;
|
||||||
import com.graphhopper.jsprit.core.util.TestUtils;
|
import com.graphhopper.jsprit.core.util.TestUtils;
|
||||||
import com.graphhopper.jsprit.io.algorithm.VehicleRoutingAlgorithmBuilder;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.experimental.categories.Category;
|
import org.junit.experimental.categories.Category;
|
||||||
|
|
||||||
|
|
@ -50,7 +47,7 @@ public class SolomonSkills_IT {
|
||||||
@Category(IntegrationTest.class)
|
@Category(IntegrationTest.class)
|
||||||
public void itShouldMakeCorrectAssignmentAccordingToSkills() {
|
public void itShouldMakeCorrectAssignmentAccordingToSkills() {
|
||||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||||
new VrpXMLReader(vrpBuilder).read("src/test/resources/solomon_c101.xml");
|
new SolomonReader(vrpBuilder).read("src/test/resources/C101.txt");
|
||||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||||
|
|
||||||
//y >= 50 skill1 otherwise skill2
|
//y >= 50 skill1 otherwise skill2
|
||||||
|
|
@ -81,36 +78,21 @@ public class SolomonSkills_IT {
|
||||||
skillProblemBuilder.setFleetSize(VehicleRoutingProblem.FleetSize.FINITE);
|
skillProblemBuilder.setFleetSize(VehicleRoutingProblem.FleetSize.FINITE);
|
||||||
VehicleRoutingProblem skillProblem = skillProblemBuilder.build();
|
VehicleRoutingProblem skillProblem = skillProblemBuilder.build();
|
||||||
|
|
||||||
VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(skillProblem, "src/test/resources/algorithmConfig.xml");
|
VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(skillProblem);
|
||||||
vraBuilder.addCoreConstraints();
|
|
||||||
vraBuilder.addDefaultCostCalculators();
|
|
||||||
|
|
||||||
StateManager stateManager = new StateManager(skillProblem);
|
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||||
stateManager.updateSkillStates();
|
VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
|
||||||
|
assertEquals(828.94, solution.getCost(), 0.01);
|
||||||
ConstraintManager constraintManager = new ConstraintManager(skillProblem, stateManager);
|
for (VehicleRoute route : solution.getRoutes()) {
|
||||||
constraintManager.addSkillsConstraint();
|
Skills vehicleSkill = route.getVehicle().getSkills();
|
||||||
|
for (Job job : route.getTourActivities().getJobs()) {
|
||||||
VehicleRoutingAlgorithm vra = vraBuilder.build();
|
for (String skill : job.getRequiredSkills().values()) {
|
||||||
vra.setMaxIterations(2000);
|
if (!vehicleSkill.containsSkill(skill)) {
|
||||||
|
assertFalse(true);
|
||||||
try {
|
|
||||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
|
||||||
VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
|
|
||||||
assertEquals(828.94, solution.getCost(), 0.01);
|
|
||||||
for (VehicleRoute route : solution.getRoutes()) {
|
|
||||||
Skills vehicleSkill = route.getVehicle().getSkills();
|
|
||||||
for (Job job : route.getTourActivities().getJobs()) {
|
|
||||||
for (String skill : job.getRequiredSkills().values()) {
|
|
||||||
if (!vehicleSkill.containsSkill(skill)) {
|
|
||||||
assertFalse(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertTrue(true);
|
|
||||||
} catch (NoSolutionFoundException e) {
|
|
||||||
assertFalse(true);
|
|
||||||
}
|
}
|
||||||
|
assertTrue(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue