1
0
Fork 0
mirror of https://github.com/graphhopper/jsprit.git synced 2020-01-24 07:45:05 +01:00

try to reproduce potential bug #116

This commit is contained in:
oblonski 2014-08-04 13:41:31 +02:00
parent f1cdc60289
commit c9f75a826e
2 changed files with 137 additions and 2 deletions

View file

@ -1,6 +1,7 @@
package jsprit.core.algorithm;
import jsprit.core.algorithm.box.GreedySchrimpfFactory;
import jsprit.core.algorithm.box.SchrimpfFactory;
import jsprit.core.problem.AbstractActivity;
import jsprit.core.problem.VehicleRoutingProblem;
@ -10,16 +11,20 @@ import jsprit.core.problem.job.Service;
import jsprit.core.problem.job.Shipment;
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
import jsprit.core.problem.solution.route.VehicleRoute;
import jsprit.core.problem.solution.route.activity.PickupShipment;
import jsprit.core.problem.solution.route.activity.TourActivity;
import jsprit.core.problem.vehicle.VehicleImpl;
import jsprit.core.problem.vehicle.VehicleType;
import jsprit.core.problem.vehicle.VehicleTypeImpl;
import jsprit.core.reporting.SolutionPrinter;
import jsprit.core.util.Coordinate;
import jsprit.core.util.Solutions;
import org.junit.Test;
import java.util.Collection;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
public class InitialRoutesTest {
@ -241,4 +246,48 @@ public class InitialRoutesTest {
assertTrue(hasActivityIn(solution.getRoutes().iterator().next(), "2"));
}
@Test
public void maxCapacityShouldNotBeExceeded(){
VehicleType type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, 100).build();
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("veh").setStartLocationCoordinate(Coordinate.newInstance(0, 0)).setType(type).setStartLocationId("start").build();
Shipment shipment = Shipment.Builder.newInstance("s").setPickupLocation("pick").setDeliveryLocation("del").setPickupCoord(Coordinate.newInstance(10, 0))
.setDeliveryCoord(Coordinate.newInstance(0, 10)).addSizeDimension(0, 100).build();
Shipment another_shipment = Shipment.Builder.newInstance("another_s").setPickupLocation("pick").setDeliveryLocation("del").setPickupCoord(Coordinate.newInstance(10, 0))
.setDeliveryCoord(Coordinate.newInstance(0, 10)).addSizeDimension(0, 50).build();
VehicleRoute iniRoute = VehicleRoute.Builder.newInstance(vehicle).addPickup(shipment).addDelivery(shipment).build();
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(shipment).addVehicle(vehicle).addJob(another_shipment)
.setFleetSize(VehicleRoutingProblem.FleetSize.FINITE).addInitialVehicleRoute(iniRoute).build();
VehicleRoutingAlgorithm vra = new GreedySchrimpfFactory().createAlgorithm(vrp);
vra.setNuOfIterations(10);
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
assertFalse(secondActIsPickup(solutions));
}
@Test
public void whenReadingProblemFromFile_maxCapacityShouldNotBeExceeded(){
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_iniRoutes_2.xml");
VehicleRoutingAlgorithm vra = new GreedySchrimpfFactory().createAlgorithm(vrpBuilder.build());
vra.setNuOfIterations(10);
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
assertFalse(secondActIsPickup(solutions));
}
private boolean secondActIsPickup(Collection<VehicleRoutingProblemSolution> solutions) {
VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
TourActivity secondAct = solution.getRoutes().iterator().next().getActivities().get(1);
return secondAct instanceof PickupShipment;
}
}

View file

@ -0,0 +1,86 @@
<?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>
</vehicles>
<vehicleTypes>
<type>
<id>type1</id>
<capacity-dimensions>
<dimension index="0">100</dimension>
</capacity-dimensions>
<costs>
<fixed>0.0</fixed>
<distance>1.0</distance>
<time>0.0</time>
</costs>
</type>
</vehicleTypes>
<shipments>
<shipment id="3">
<pickup>
<locationId>loc_pickup_shipment_3</locationId>
<coord x="0." y="10.0"/>
</pickup>
<delivery>
<locationId>loc_deliver_shipment_3</locationId>
<coord x="0." y="20.0"/>
</delivery>
<capacity-dimensions>
<dimension index="0">100</dimension>
</capacity-dimensions>
</shipment>
<shipment id="4">
<pickup>
<locationId>loc_pickup_shipment_4</locationId>
<coord x="0." y="12.0"/>
</pickup>
<delivery>
<locationId>loc_deliver_shipment_4</locationId>
<coord x="0." y="18.0"/>
</delivery>
<capacity-dimensions>
<dimension index="0">50</dimension>
</capacity-dimensions>
</shipment>
</shipments>
<initialRoutes>
<route>
<driverId>noDriver</driverId>
<vehicleId>veh1</vehicleId>
<start>0.</start>
<act type="pickupShipment">
<shipmentId>3</shipmentId>
</act>
<act type="deliverShipment">
<shipmentId>3</shipmentId>
</act>
<end/>
</route>
</initialRoutes>
</problem>