-
Notifications
You must be signed in to change notification settings - Fork 613
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
221 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
jsprit-core/src/test/java/jsprit/core/algorithm/InitialRoutesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package jsprit.core.algorithm; | ||
|
||
|
||
import jsprit.core.algorithm.box.SchrimpfFactory; | ||
import jsprit.core.problem.VehicleRoutingProblem; | ||
import jsprit.core.problem.io.VrpXMLReader; | ||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution; | ||
import jsprit.core.problem.solution.route.VehicleRoute; | ||
import jsprit.core.problem.solution.route.activity.TourActivity; | ||
import jsprit.core.reporting.SolutionPrinter; | ||
import jsprit.core.util.Solutions; | ||
import org.junit.Test; | ||
|
||
import java.util.Collection; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class InitialRoutesTest { | ||
|
||
@Test | ||
public void whenReading_thereShouldBeNoDuplicates(){ | ||
|
||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); | ||
new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_iniRoutes.xml"); | ||
VehicleRoutingProblem vrp = vrpBuilder.build(); | ||
|
||
assertEquals(1,vrp.getJobs().size()); | ||
|
||
} | ||
|
||
@Test | ||
public void whenSolving_nuJobsShouldBe2(){ | ||
|
||
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().getTourActivities().getJobs().size()); | ||
} | ||
|
||
@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()); | ||
} | ||
|
||
@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); | ||
|
||
assertTrue(hasActivityIn(solution.getRoutes().iterator().next(),"1")); | ||
} | ||
|
||
private boolean hasActivityIn(VehicleRoute route, String jobId){ | ||
boolean isInRoute = false; | ||
for(TourActivity act : route.getActivities()){ | ||
if(act instanceof TourActivity.JobActivity){ | ||
if(((TourActivity.JobActivity) act).getJob().getId().equals(jobId)) isInRoute = true; | ||
} | ||
} | ||
return isInRoute; | ||
} | ||
|
||
@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")); | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
jsprit-core/src/test/resources/simpleProblem_iniRoutes.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?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=0.0][y=0.0]</id> | ||
<coord x="0.0" y="0.0"/> | ||
</startLocation> | ||
<endLocation> | ||
<id>[x=0.0][y=0.0]</id> | ||
<coord x="0.0" y="0.0"/> | ||
</endLocation> | ||
<timeSchedule> | ||
<start>0.0</start> | ||
<end>46800.0</end> | ||
</timeSchedule> | ||
<returnToDepot>true</returnToDepot> | ||
</vehicle> | ||
<vehicle> | ||
<id>2</id> | ||
<typeId>type1</typeId> | ||
<startLocation> | ||
<id>[x=0.0][y=0.0]</id> | ||
<coord x="0.0" y="0.0"/> | ||
</startLocation> | ||
<endLocation> | ||
<id>[x=0.0][y=0.0]</id> | ||
<coord x="0.0" y="0.0"/> | ||
</endLocation> | ||
<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> |