1
0
Fork 0
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:
oblonski 2016-06-21 07:21:06 +02:00
parent 667db19f32
commit 2d0274b441
3 changed files with 30 additions and 144 deletions

View file

@ -1,6 +1,6 @@
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.VehicleRoutingProblem;
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();
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithm_without_construction.xml");
VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
/*
create ini sol

View file

@ -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.UpdateEndLocationIfRouteIsOpen;
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.VehicleRoutingProblem;
import com.graphhopper.jsprit.core.problem.constraint.ConstraintManager;
import com.graphhopper.jsprit.core.problem.constraint.ServiceLoadActivityLevelConstraint;
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.Service;
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.util.Coordinate;
import com.graphhopper.jsprit.core.util.Solutions;
import org.junit.Before;
import org.junit.Test;
import java.util.Collection;
import java.util.List;
import static org.junit.Assert.*;
public class InitialRoutesTest {
@Test
public void whenReading_jobMapShouldOnlyContainJob2() {
private VehicleRoutingProblem vrp;
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_iniRoutes.xml");
VehicleRoutingProblem vrp = vrpBuilder.build();
private VehicleRoute initialRoute;
assertEquals(1, getNuServices(vrp));
assertTrue(vrp.getJobs().containsKey("2"));
@Before
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
public void whenSolving_nuJobsInSolutionShouldBe2() {
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 = Jsprit.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().getTourActivities().getJobs().size());
}
@ -174,17 +99,9 @@ public class InitialRoutesTest {
@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());
}
@ -208,17 +125,9 @@ public class InitialRoutesTest {
@Test
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);
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
SolutionPrinter.print(vrp, solution, SolutionPrinter.Print.VERBOSE);
Job job = getInitialJob("1", vrp);
assertTrue(hasActivityIn(solution, "veh1", job));
}
@ -326,11 +235,6 @@ public class InitialRoutesTest {
@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);

View file

@ -18,12 +18,9 @@
package com.graphhopper.jsprit.core.algorithm;
import com.graphhopper.jsprit.core.IntegrationTest;
import com.graphhopper.jsprit.core.algorithm.recreate.NoSolutionFoundException;
import com.graphhopper.jsprit.core.algorithm.state.StateManager;
import com.graphhopper.jsprit.core.algorithm.box.Jsprit;
import com.graphhopper.jsprit.core.problem.Skills;
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.Service;
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.VehicleImpl;
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.TestUtils;
import com.graphhopper.jsprit.io.algorithm.VehicleRoutingAlgorithmBuilder;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@ -50,7 +47,7 @@ public class SolomonSkills_IT {
@Category(IntegrationTest.class)
public void itShouldMakeCorrectAssignmentAccordingToSkills() {
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();
//y >= 50 skill1 otherwise skill2
@ -81,20 +78,8 @@ public class SolomonSkills_IT {
skillProblemBuilder.setFleetSize(VehicleRoutingProblem.FleetSize.FINITE);
VehicleRoutingProblem skillProblem = skillProblemBuilder.build();
VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(skillProblem, "src/test/resources/algorithmConfig.xml");
vraBuilder.addCoreConstraints();
vraBuilder.addDefaultCostCalculators();
VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(skillProblem);
StateManager stateManager = new StateManager(skillProblem);
stateManager.updateSkillStates();
ConstraintManager constraintManager = new ConstraintManager(skillProblem, stateManager);
constraintManager.addSkillsConstraint();
VehicleRoutingAlgorithm vra = vraBuilder.build();
vra.setMaxIterations(2000);
try {
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
assertEquals(828.94, solution.getCost(), 0.01);
@ -109,8 +94,5 @@ public class SolomonSkills_IT {
}
}
assertTrue(true);
} catch (NoSolutionFoundException e) {
assertFalse(true);
}
}
}