mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
bugfix #105
This commit is contained in:
parent
862341be7b
commit
7a42cef156
2 changed files with 10 additions and 86 deletions
|
|
@ -2,6 +2,7 @@ package jsprit.core.problem.constraint;
|
||||||
|
|
||||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||||
import jsprit.core.problem.misc.JobInsertionContext;
|
import jsprit.core.problem.misc.JobInsertionContext;
|
||||||
|
import jsprit.core.problem.solution.route.activity.End;
|
||||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||||
import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
|
import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
|
||||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||||
|
|
@ -78,6 +79,12 @@ import jsprit.core.util.CalculationUtils;
|
||||||
if(arrTimeAtNewAct > latestArrTimeAtNewAct){
|
if(arrTimeAtNewAct > latestArrTimeAtNewAct){
|
||||||
return ConstraintsStatus.NOT_FULFILLED;
|
return ConstraintsStatus.NOT_FULFILLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(nextAct instanceof End){
|
||||||
|
if(!iFacts.getNewVehicle().isReturnToDepot()){
|
||||||
|
return ConstraintsStatus.FULFILLED;
|
||||||
|
}
|
||||||
|
}
|
||||||
// log.info(newAct + " arrTime=" + arrTimeAtNewAct);
|
// log.info(newAct + " arrTime=" + arrTimeAtNewAct);
|
||||||
double endTimeAtNewAct = CalculationUtils.getActivityEndTime(arrTimeAtNewAct, newAct);
|
double endTimeAtNewAct = CalculationUtils.getActivityEndTime(arrTimeAtNewAct, newAct);
|
||||||
double arrTimeAtNextAct = endTimeAtNewAct + routingCosts.getTransportTime(newAct.getLocationId(), nextAct.getLocationId(), endTimeAtNewAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
double arrTimeAtNextAct = endTimeAtNewAct + routingCosts.getTransportTime(newAct.getLocationId(), nextAct.getLocationId(), endTimeAtNewAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ public class OpenRoutesTest {
|
||||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(shipment).addVehicle(vehicle).build();
|
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(shipment).addVehicle(vehicle).build();
|
||||||
|
|
||||||
VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
|
VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
|
||||||
|
vra.setNuOfIterations(10);
|
||||||
|
|
||||||
try{
|
try{
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
|
|
@ -57,6 +58,7 @@ public class OpenRoutesTest {
|
||||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(service).addVehicle(vehicle).build();
|
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(service).addVehicle(vehicle).build();
|
||||||
|
|
||||||
VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
|
VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
|
||||||
|
vra.setNuOfIterations(10);
|
||||||
|
|
||||||
try{
|
try{
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
|
|
@ -83,92 +85,7 @@ public class OpenRoutesTest {
|
||||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(shipment).addVehicle(vehicle).build();
|
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(shipment).addVehicle(vehicle).build();
|
||||||
|
|
||||||
VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
|
VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
|
||||||
|
vra.setNuOfIterations(10);
|
||||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
|
||||||
|
|
||||||
assertEquals(10.,Solutions.bestOf(solutions).getCost(),0.01);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenDealingWithOpenRouteAndShipments_insertionShouldNotRequireRouteToBeClosed(){
|
|
||||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build();
|
|
||||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setLatestArrival(11.)
|
|
||||||
.setType(type).setReturnToDepot(false).setStartLocationCoordinate(Coordinate.newInstance(0, 0)).build();
|
|
||||||
|
|
||||||
Shipment shipment = Shipment.Builder.newInstance("s").setPickupCoord(Coordinate.newInstance(5, 0))
|
|
||||||
.setDeliveryCoord(Coordinate.newInstance(10, 0)).build();
|
|
||||||
|
|
||||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(shipment).addVehicle(vehicle).build();
|
|
||||||
|
|
||||||
VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
|
|
||||||
|
|
||||||
try{
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
|
||||||
assertTrue(true);
|
|
||||||
}
|
|
||||||
catch(NoSolutionFoundException e){
|
|
||||||
assertFalse(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenDealingWithOpenRouteAndShipments_algorithmShouldCalculateCorrectCosts(){
|
|
||||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build();
|
|
||||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setLatestArrival(20.)
|
|
||||||
.setType(type).setReturnToDepot(false).setStartLocationCoordinate(Coordinate.newInstance(0, 0)).build();
|
|
||||||
|
|
||||||
Shipment shipment = Shipment.Builder.newInstance("s").setPickupCoord(Coordinate.newInstance(5, 0))
|
|
||||||
.setDeliveryCoord(Coordinate.newInstance(10, 0)).build();
|
|
||||||
|
|
||||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(shipment).addVehicle(vehicle).build();
|
|
||||||
|
|
||||||
VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
|
|
||||||
|
|
||||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
|
||||||
|
|
||||||
assertEquals(10.,Solutions.bestOf(solutions).getCost(),0.01);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenDealingWithOpenRouteAndShipments_insertionShouldNotRequireRouteToBeClosed(){
|
|
||||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build();
|
|
||||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setLatestArrival(11.)
|
|
||||||
.setType(type).setReturnToDepot(false).setStartLocationCoordinate(Coordinate.newInstance(0, 0)).build();
|
|
||||||
|
|
||||||
Shipment shipment = Shipment.Builder.newInstance("s").setPickupCoord(Coordinate.newInstance(5, 0))
|
|
||||||
.setDeliveryCoord(Coordinate.newInstance(10, 0)).build();
|
|
||||||
|
|
||||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(shipment).addVehicle(vehicle).build();
|
|
||||||
|
|
||||||
VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
|
|
||||||
|
|
||||||
try{
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
|
||||||
assertTrue(true);
|
|
||||||
}
|
|
||||||
catch(NoSolutionFoundException e){
|
|
||||||
assertFalse(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenDealingWithOpenRouteAndShipments_algorithmShouldCalculateCorrectCosts(){
|
|
||||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build();
|
|
||||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setLatestArrival(20.)
|
|
||||||
.setType(type).setReturnToDepot(false).setStartLocationCoordinate(Coordinate.newInstance(0, 0)).build();
|
|
||||||
|
|
||||||
Shipment shipment = Shipment.Builder.newInstance("s").setPickupCoord(Coordinate.newInstance(5, 0))
|
|
||||||
.setDeliveryCoord(Coordinate.newInstance(10, 0)).build();
|
|
||||||
|
|
||||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(shipment).addVehicle(vehicle).build();
|
|
||||||
|
|
||||||
VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
|
|
||||||
|
|
||||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue