1
0
Fork 0
mirror of https://github.com/graphhopper/jsprit.git synced 2020-01-24 07:45:05 +01:00
This commit is contained in:
oblonski 2015-09-20 16:17:56 +02:00
parent e543665da2
commit 55e1baa205
4 changed files with 65 additions and 56 deletions

View file

@ -42,6 +42,7 @@ import jsprit.core.algorithm.termination.VariationCoefficientTermination;
import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.VehicleRoutingProblem.FleetSize;
import jsprit.core.problem.constraint.ConstraintManager;
import jsprit.core.problem.constraint.SwitchNotFeasible;
import jsprit.core.problem.solution.SolutionCostCalculator;
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
import jsprit.core.problem.solution.route.VehicleRoute;
@ -478,6 +479,7 @@ public class VehicleRoutingAlgorithms {
constraintManager.addTimeWindowConstraint();
constraintManager.addLoadConstraint();
constraintManager.addSkillsConstraint();
constraintManager.addConstraint(new SwitchNotFeasible(stateManager));
return readAndCreateAlgorithm(vrp, config, nuOfThreads, null, stateManager, constraintManager, true);
}

View file

@ -18,7 +18,7 @@ public class SwitchNotFeasible implements HardRouteConstraint{
@Override
public boolean fulfilled(JobInsertionContext insertionContext) {
Boolean notFeasible = stateManager.getRouteState(insertionContext.getRoute(),insertionContext.getNewVehicle(), InternalStates.SWITCH_NOT_FEASIBLE,Boolean.class);
if(notFeasible == null) return true;
if(notFeasible == null || insertionContext.getRoute().getVehicle().getVehicleTypeIdentifier().equals(insertionContext.getNewVehicle().getVehicleTypeIdentifier())) return true;
else return !notFeasible;
}

View file

@ -18,6 +18,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.algorithm.io.VehicleRoutingAlgorithms;
@ -550,7 +551,7 @@ public class MeetTimeWindowConstraint_IT {
}
@Test
public void driverTimesShouldBeMet() throws IOException {
public void whenUsingJsprit_driverTimesShouldBeMet() throws IOException {
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(vrpBuilder).read("src/test/resources/twbug.xml");
final FastVehicleRoutingTransportCostsMatrix matrix = createMatrix();
@ -565,6 +566,39 @@ public class MeetTimeWindowConstraint_IT {
}
}
@Test
public void whenUsingSchrimpf_driverTimesShouldBeMet() throws IOException {
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(vrpBuilder).read("src/test/resources/twbug.xml");
final FastVehicleRoutingTransportCostsMatrix matrix = createMatrix();
vrpBuilder.setRoutingCost(matrix);
VehicleRoutingProblem vrp = vrpBuilder.build();
VehicleRoutingAlgorithm algorithm = new SchrimpfFactory().createAlgorithm(vrp);
algorithm.setMaxIterations(1000);
VehicleRoutingProblemSolution solution = Solutions.bestOf(algorithm.searchSolutions());
for(VehicleRoute r : solution.getRoutes()){
assertTrue(r.getVehicle().getEarliestDeparture() <= r.getDepartureTime());
assertTrue(r.getVehicle().getLatestArrival() >= r.getEnd().getArrTime());
}
}
@Test
public void whenUsingGreedySchrimpf_driverTimesShouldBeMet() throws IOException {
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(vrpBuilder).read("src/test/resources/twbug.xml");
final FastVehicleRoutingTransportCostsMatrix matrix = createMatrix();
vrpBuilder.setRoutingCost(matrix);
VehicleRoutingProblem vrp = vrpBuilder.build();
VehicleRoutingAlgorithm algorithm = new GreedySchrimpfFactory().createAlgorithm(vrp);
algorithm.setMaxIterations(1000);
VehicleRoutingProblemSolution solution = Solutions.bestOf(algorithm.searchSolutions());
for(VehicleRoute r : solution.getRoutes()){
assertTrue(r.getVehicle().getEarliestDeparture() <= r.getDepartureTime());
assertTrue(r.getVehicle().getLatestArrival() >= r.getEnd().getArrTime());
}
}
private FastVehicleRoutingTransportCostsMatrix createMatrix() throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(new File("src/test/resources/matrix.txt")));
String line;

View file

@ -2,9 +2,24 @@
<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>INFINITE</fleetSize>
<fleetSize>FINITE</fleetSize>
</problemType>
<vehicles>
<vehicle>
<id>v2</id>
<typeId>vehType2</typeId>
<startLocation>
<id>loc</id>
</startLocation>
<endLocation>
<id>loc</id>
</endLocation>
<timeSchedule>
<start>0.0</start>
<end>1.7976931348623157E308</end>
</timeSchedule>
<returnToDepot>true</returnToDepot>
</vehicle>
<vehicle>
<id>v1</id>
<typeId>vehType</typeId>
@ -33,58 +48,16 @@
<time>0.0</time>
</costs>
</type>
<type>
<id>vehType2</id>
<capacity-dimensions>
<dimension index="0">200</dimension>
</capacity-dimensions>
<costs>
<fixed>0.0</fixed>
<distance>1.0</distance>
<time>0.0</time>
</costs>
</type>
</vehicleTypes>
<services>
<service id="1" type="service">
<location>
<id>loc</id>
</location>
<capacity-dimensions>
<dimension index="0">1</dimension>
</capacity-dimensions>
<duration>2.0</duration>
<timeWindows>
<timeWindow>
<start>0.0</start>
<end>1.7976931348623157E308</end>
</timeWindow>
</timeWindows>
</service>
<service id="2" type="service">
<location>
<id>loc2</id>
</location>
<capacity-dimensions>
<dimension index="0">1</dimension>
</capacity-dimensions>
<duration>4.0</duration>
<timeWindows>
<timeWindow>
<start>0.0</start>
<end>1.7976931348623157E308</end>
</timeWindow>
</timeWindows>
</service>
</services>
<solutions>
<solution>
<cost>10.0</cost>
<routes>
<route>
<driverId>noDriver</driverId>
<vehicleId>v1</vehicleId>
<start>0.0</start>
<act type="service">
<serviceId>1</serviceId>
<arrTime>0.0</arrTime>
<endTime>0.0</endTime>
</act>
<end>0.0</end>
</route>
</routes>
<unassignedJobs>
<job id="2"/>
</unassignedJobs>
</solution>
</solutions>
</problem>