mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
test and modify ruin strategies to deal with initial routes
This commit is contained in:
parent
62e12d5153
commit
2b87155879
10 changed files with 192 additions and 29 deletions
|
|
@ -19,6 +19,7 @@ package jsprit.core.algorithm;
|
|||
|
||||
|
||||
import jsprit.core.algorithm.box.GreedySchrimpfFactory;
|
||||
import jsprit.core.algorithm.box.Jsprit;
|
||||
import jsprit.core.algorithm.box.SchrimpfFactory;
|
||||
import jsprit.core.problem.AbstractActivity;
|
||||
import jsprit.core.problem.Location;
|
||||
|
|
@ -209,11 +210,40 @@ public class InitialRoutesTest {
|
|||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||
VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
|
||||
|
||||
assertTrue(hasActivityIn(solution.getRoutes().iterator().next(),"1"));
|
||||
SolutionPrinter.print(vrp,solution, SolutionPrinter.Print.VERBOSE);
|
||||
|
||||
Job job = getInitialJob("1",vrp);
|
||||
assertTrue(hasActivityIn(solution,"veh1", job));
|
||||
}
|
||||
|
||||
private Job getInitialJob(String jobId, VehicleRoutingProblem vrp) {
|
||||
for(VehicleRoute r : vrp.getInitialVehicleRoutes()){
|
||||
for(Job j : r.getTourActivities().getJobs()){
|
||||
if(j.getId().equals(jobId)) return j;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSolvingProblem2_deliverServices_and_allShipmentActs_shouldBeInRoute(){
|
||||
public void whenSolvingWithJsprit_deliverService1_shouldBeInRoute(){
|
||||
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_iniRoutes_3.xml");
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
|
||||
VehicleRoutingAlgorithm vra = Jsprit.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));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSolvingProblem2With_deliverServices_and_allShipmentActs_shouldBeInRoute(){
|
||||
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_inclShipments_iniRoutes.xml");
|
||||
|
|
@ -227,6 +257,29 @@ public class InitialRoutesTest {
|
|||
assertTrue(hasActivityIn(solution.getRoutes(),"2"));
|
||||
assertTrue(hasActivityIn(solution.getRoutes(),"3"));
|
||||
assertTrue(hasActivityIn(solution.getRoutes(),"4"));
|
||||
|
||||
assertTrue(hasActivityIn(solution,"veh1", getInitialJob("1",vrp)));
|
||||
assertTrue(hasActivityIn(solution,"veh2", getInitialJob("3",vrp)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSolvingProblem2WithJsprit_deliverServices_and_allShipmentActs_shouldBeInRoute(){
|
||||
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_inclShipments_iniRoutes.xml");
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
|
||||
VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
|
||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||
VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
|
||||
|
||||
assertTrue(hasActivityIn(solution.getRoutes(),"1"));
|
||||
assertTrue(hasActivityIn(solution.getRoutes(),"2"));
|
||||
assertTrue(hasActivityIn(solution.getRoutes(),"3"));
|
||||
assertTrue(hasActivityIn(solution.getRoutes(),"4"));
|
||||
|
||||
assertTrue(hasActivityIn(solution,"veh1", getInitialJob("1",vrp)));
|
||||
assertTrue(hasActivityIn(solution,"veh2", getInitialJob("3",vrp)));
|
||||
}
|
||||
|
||||
private boolean hasActivityIn(Collection<VehicleRoute> routes, String jobId) {
|
||||
|
|
@ -241,6 +294,19 @@ public class InitialRoutesTest {
|
|||
return isInRoute;
|
||||
}
|
||||
|
||||
private boolean hasActivityIn(VehicleRoutingProblemSolution solution, String vehicleId, Job job) {
|
||||
for(VehicleRoute route : solution.getRoutes()){
|
||||
String vehicleId_ = route.getVehicle().getId();
|
||||
if(vehicleId_.equals(vehicleId)){
|
||||
if(route.getTourActivities().servesJob(job)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private boolean hasActivityIn(VehicleRoute route, String jobId){
|
||||
boolean isInRoute = false;
|
||||
for(TourActivity act : route.getActivities()){
|
||||
|
|
|
|||
79
jsprit-core/src/test/resources/simpleProblem_iniRoutes_3.xml
Normal file
79
jsprit-core/src/test/resources/simpleProblem_iniRoutes_3.xml
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problem xmlns="http://www.w3schools.com"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd">
|
||||
<problemType>
|
||||
<fleetSize>FINITE</fleetSize>
|
||||
<fleetComposition>HOMOGENEOUS</fleetComposition>
|
||||
</problemType>
|
||||
<vehicles>
|
||||
<vehicle>
|
||||
<id>veh1</id>
|
||||
<typeId>type1</typeId>
|
||||
<startLocation>
|
||||
<id>[x=5000.0][y=5000.0]</id>
|
||||
<coord x="5000.0" y="5000.0"/>
|
||||
</startLocation>
|
||||
<timeSchedule>
|
||||
<start>0.0</start>
|
||||
<end>46800.0</end>
|
||||
</timeSchedule>
|
||||
<returnToDepot>true</returnToDepot>
|
||||
</vehicle>
|
||||
<vehicle>
|
||||
<id>veh2</id>
|
||||
<typeId>type1</typeId>
|
||||
<startLocation>
|
||||
<id>[x=0.0][y=0.0]</id>
|
||||
<coord x="0.0" y="0.0"/>
|
||||
</startLocation>
|
||||
<timeSchedule>
|
||||
<start>0.0</start>
|
||||
<end>64800.0</end>
|
||||
</timeSchedule>
|
||||
<returnToDepot>true</returnToDepot>
|
||||
</vehicle>
|
||||
</vehicles>
|
||||
<vehicleTypes>
|
||||
<type>
|
||||
<id>type1</id>
|
||||
<capacity-dimensions>
|
||||
<dimension index="0">0</dimension>
|
||||
</capacity-dimensions>
|
||||
<costs>
|
||||
<fixed>0.0</fixed>
|
||||
<distance>1.0</distance>
|
||||
<time>0.0</time>
|
||||
</costs>
|
||||
</type>
|
||||
</vehicleTypes>
|
||||
<services>
|
||||
<service id="2" type="service">
|
||||
<locationId>loc_s2</locationId>
|
||||
<coord x="1000.0" y="0.0"/>
|
||||
<capacity-dimensions>
|
||||
<dimension index="0">0</dimension>
|
||||
</capacity-dimensions>
|
||||
<duration>0.0</duration>
|
||||
</service>
|
||||
<service id="1" type="service">
|
||||
<locationId>loc_s3</locationId>
|
||||
<coord x="1000.0" y="1000.0"/>
|
||||
<capacity-dimensions>
|
||||
<dimension index="0">0</dimension>
|
||||
</capacity-dimensions>
|
||||
<duration>0.0</duration>
|
||||
</service>
|
||||
</services>
|
||||
<initialRoutes>
|
||||
<route>
|
||||
<driverId>noDriver</driverId>
|
||||
<vehicleId>veh1</vehicleId>
|
||||
<start>0.</start>
|
||||
<act type="deliverService">
|
||||
<serviceId>1</serviceId>
|
||||
</act>
|
||||
<end/>
|
||||
</route>
|
||||
|
||||
</initialRoutes>
|
||||
</problem>
|
||||
Loading…
Add table
Add a link
Reference in a new issue