mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
Merge pull request #366 from jie31best/feature/tp-costs-get-dist
make VehicleRoutingTransportCosts implement TransportDistance
This commit is contained in:
commit
0712e4599c
23 changed files with 222 additions and 1061 deletions
|
|
@ -22,6 +22,9 @@ import com.graphhopper.jsprit.core.problem.driver.Driver;
|
|||
import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
|
||||
|
||||
public abstract class AbstractForwardVehicleRoutingTransportCosts implements VehicleRoutingTransportCosts {
|
||||
|
||||
@Override
|
||||
public abstract double getDistance(Location from, Location to, double departureTime, Vehicle vehicle);
|
||||
|
||||
@Override
|
||||
public abstract double getTransportTime(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle);
|
||||
|
|
|
|||
|
|
@ -27,6 +27,6 @@ package com.graphhopper.jsprit.core.problem.cost;
|
|||
* @author schroeder
|
||||
*/
|
||||
|
||||
public interface VehicleRoutingTransportCosts extends TransportTime, TransportCost {
|
||||
public interface VehicleRoutingTransportCosts extends TransportTime, TransportCost, TransportDistance {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ package com.graphhopper.jsprit.core.util;
|
|||
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import com.graphhopper.jsprit.core.problem.cost.AbstractForwardVehicleRoutingTransportCosts;
|
||||
import com.graphhopper.jsprit.core.problem.cost.TransportDistance;
|
||||
import com.graphhopper.jsprit.core.problem.driver.Driver;
|
||||
import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
|
||||
|
||||
|
|
@ -30,7 +29,7 @@ import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
|
|||
/**
|
||||
* @author stefan schroeder
|
||||
*/
|
||||
public class CrowFlyCosts extends AbstractForwardVehicleRoutingTransportCosts implements TransportDistance {
|
||||
public class CrowFlyCosts extends AbstractForwardVehicleRoutingTransportCosts {
|
||||
|
||||
public int speed = 1;
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ package com.graphhopper.jsprit.core.util;
|
|||
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import com.graphhopper.jsprit.core.problem.cost.AbstractForwardVehicleRoutingTransportCosts;
|
||||
import com.graphhopper.jsprit.core.problem.cost.TransportDistance;
|
||||
import com.graphhopper.jsprit.core.problem.driver.Driver;
|
||||
import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
|
||||
|
||||
|
|
@ -30,7 +29,7 @@ import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
|
|||
/**
|
||||
* @author stefan schroeder
|
||||
*/
|
||||
public class EuclideanCosts extends AbstractForwardVehicleRoutingTransportCosts implements TransportDistance {
|
||||
public class EuclideanCosts extends AbstractForwardVehicleRoutingTransportCosts {
|
||||
|
||||
public int speed = 1;
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ package com.graphhopper.jsprit.core.util;
|
|||
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import com.graphhopper.jsprit.core.problem.cost.AbstractForwardVehicleRoutingTransportCosts;
|
||||
import com.graphhopper.jsprit.core.problem.cost.TransportDistance;
|
||||
import com.graphhopper.jsprit.core.problem.driver.Driver;
|
||||
import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
|
||||
import com.graphhopper.jsprit.core.problem.vehicle.VehicleTypeImpl;
|
||||
|
|
@ -32,7 +31,7 @@ import com.graphhopper.jsprit.core.problem.vehicle.VehicleTypeImpl;
|
|||
*
|
||||
* @author schroeder
|
||||
*/
|
||||
public class FastVehicleRoutingTransportCostsMatrix extends AbstractForwardVehicleRoutingTransportCosts implements TransportDistance {
|
||||
public class FastVehicleRoutingTransportCostsMatrix extends AbstractForwardVehicleRoutingTransportCosts {
|
||||
|
||||
/**
|
||||
* Builder that builds the matrix.
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ package com.graphhopper.jsprit.core.util;
|
|||
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import com.graphhopper.jsprit.core.problem.cost.AbstractForwardVehicleRoutingTransportCosts;
|
||||
import com.graphhopper.jsprit.core.problem.cost.TransportDistance;
|
||||
import com.graphhopper.jsprit.core.problem.driver.Driver;
|
||||
import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
|
||||
|
||||
|
|
@ -28,7 +27,7 @@ import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
|
|||
* @author stefan schroeder
|
||||
*/
|
||||
|
||||
public class GreatCircleCosts extends AbstractForwardVehicleRoutingTransportCosts implements TransportDistance {
|
||||
public class GreatCircleCosts extends AbstractForwardVehicleRoutingTransportCosts {
|
||||
|
||||
private double speed = 1.;
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ package com.graphhopper.jsprit.core.util;
|
|||
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import com.graphhopper.jsprit.core.problem.cost.AbstractForwardVehicleRoutingTransportCosts;
|
||||
import com.graphhopper.jsprit.core.problem.cost.TransportDistance;
|
||||
import com.graphhopper.jsprit.core.problem.driver.Driver;
|
||||
import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
|
||||
|
||||
|
|
@ -28,7 +27,7 @@ import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
|
|||
* @author stefan schroeder
|
||||
*/
|
||||
|
||||
public class ManhattanCosts extends AbstractForwardVehicleRoutingTransportCosts implements TransportDistance {
|
||||
public class ManhattanCosts extends AbstractForwardVehicleRoutingTransportCosts {
|
||||
|
||||
public double speed = 1;
|
||||
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ import java.util.Map;
|
|||
* @author schroeder
|
||||
*/
|
||||
public class VehicleRoutingTransportCostsMatrix extends AbstractForwardVehicleRoutingTransportCosts {
|
||||
|
||||
static class RelationKey {
|
||||
|
||||
static RelationKey newKey(String from, String to) {
|
||||
|
|
@ -261,4 +262,9 @@ public class VehicleRoutingTransportCostsMatrix extends AbstractForwardVehicleRo
|
|||
return costParams.perDistanceUnit * getDistance(from.getId(), to.getId()) + costParams.perTransportTimeUnit * getTime(from.getId(), to.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return getDistance(from.getId(), to.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import com.graphhopper.jsprit.core.algorithm.box.Jsprit;
|
|||
import com.graphhopper.jsprit.core.analysis.SolutionAnalyser;
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
|
||||
import com.graphhopper.jsprit.core.problem.cost.TransportDistance;
|
||||
import com.graphhopper.jsprit.core.problem.job.Job;
|
||||
import com.graphhopper.jsprit.core.problem.job.Service;
|
||||
import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
|
|
@ -78,12 +77,7 @@ public class CVRPwithMatrix_IT {
|
|||
final VehicleRoutingProblem vrp = createVrpWithLocationIndecesAndMatrix(vrp_, false);
|
||||
VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.FAST_REGRET,"true").buildAlgorithm();
|
||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||
SolutionAnalyser sa = new SolutionAnalyser(vrp, Solutions.bestOf(solutions), new TransportDistance() {
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null);
|
||||
}
|
||||
});
|
||||
SolutionAnalyser sa = new SolutionAnalyser(vrp, Solutions.bestOf(solutions), vrp.getTransportCosts());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -22,11 +22,9 @@ import com.graphhopper.jsprit.core.analysis.SolutionAnalyser;
|
|||
import com.graphhopper.jsprit.core.problem.Capacity;
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
|
||||
import com.graphhopper.jsprit.core.problem.cost.TransportDistance;
|
||||
import com.graphhopper.jsprit.core.problem.job.Delivery;
|
||||
import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
|
||||
import com.graphhopper.jsprit.core.problem.vehicle.VehicleImpl;
|
||||
import com.graphhopper.jsprit.core.problem.vehicle.VehicleTypeImpl;
|
||||
import com.graphhopper.jsprit.core.util.ManhattanCosts;
|
||||
|
|
@ -91,12 +89,7 @@ public class CapacityConstraint_IT {
|
|||
vra.setMaxIterations(2000);
|
||||
VehicleRoutingProblemSolution solution = Solutions.bestOf(vra.searchSolutions());
|
||||
|
||||
SolutionAnalyser sa = new SolutionAnalyser(vrp, solution, new TransportDistance() {
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return new ManhattanCosts().getDistance(from,to, 0d, null);
|
||||
}
|
||||
});
|
||||
SolutionAnalyser sa = new SolutionAnalyser(vrp, solution, vrp.getTransportCosts());
|
||||
|
||||
for(VehicleRoute r : solution.getRoutes()){
|
||||
Capacity loadAtBeginning = sa.getLoadAtBeginning(r);
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import com.graphhopper.jsprit.core.analysis.SolutionAnalyser;
|
|||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
|
||||
import com.graphhopper.jsprit.core.problem.constraint.ConstraintManager;
|
||||
import com.graphhopper.jsprit.core.problem.cost.TransportDistance;
|
||||
import com.graphhopper.jsprit.core.problem.cost.VehicleRoutingActivityCosts;
|
||||
import com.graphhopper.jsprit.core.problem.driver.Driver;
|
||||
import com.graphhopper.jsprit.core.problem.job.Service;
|
||||
|
|
@ -82,12 +81,7 @@ public class VariableDepartureAndWaitingTime_IT {
|
|||
.setObjectiveFunction(new SolutionCostCalculator() {
|
||||
@Override
|
||||
public double getCosts(VehicleRoutingProblemSolution solution) {
|
||||
SolutionAnalyser sa = new SolutionAnalyser(vrp, solution, new TransportDistance() {
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null);
|
||||
}
|
||||
});
|
||||
SolutionAnalyser sa = new SolutionAnalyser(vrp, solution, vrp.getTransportCosts());
|
||||
return sa.getWaitingTime() + sa.getDistance();
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -96,6 +96,11 @@ public class TestCalculatesServiceInsertion {
|
|||
};
|
||||
costs = new AbstractForwardVehicleRoutingTransportCosts() {
|
||||
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return ManhattanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()), locations.getCoord(to.getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTransportTime(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) {
|
||||
return ManhattanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()), locations.getCoord(to.getId()));
|
||||
|
|
@ -231,6 +236,11 @@ public class TestCalculatesServiceInsertion {
|
|||
|
||||
AbstractForwardVehicleRoutingTransportCosts routingCosts = new AbstractForwardVehicleRoutingTransportCosts() {
|
||||
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return EuclideanDistanceCalculator.calculateDistance(coords.get(from.getId()), coords.get(to.getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTransportTime(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) {
|
||||
return getTransportCost(from, to, departureTime, driver, vehicle);
|
||||
|
|
|
|||
|
|
@ -83,6 +83,11 @@ public class TestCalculatesServiceInsertionOnRouteLevel {
|
|||
|
||||
costs = new AbstractForwardVehicleRoutingTransportCosts() {
|
||||
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
VehicleRoutingTransportCosts routingCosts = CostFactory.createManhattanCosts();
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -30,6 +30,11 @@ public class TestJobDistanceAvgCosts {
|
|||
public static void main(String[] args) {
|
||||
VehicleRoutingTransportCosts costs = new VehicleRoutingTransportCosts() {
|
||||
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBackwardTransportTime(Location from, Location to, double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||
|
||||
|
|
@ -65,6 +70,11 @@ public class TestJobDistanceAvgCosts {
|
|||
// (expected=NullPointerException.class)
|
||||
VehicleRoutingTransportCosts costs = new VehicleRoutingTransportCosts() {
|
||||
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBackwardTransportTime(Location from, Location to, double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -280,6 +280,11 @@ public class VehicleRoutingProblemTest {
|
|||
|
||||
builder.setRoutingCost(new AbstractForwardVehicleRoutingTransportCosts() {
|
||||
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTransportTime(Location from, Location to,
|
||||
double departureTime, Driver driver, Vehicle vehicle) {
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ package com.graphhopper.jsprit.core.problem.constraint;
|
|||
|
||||
import com.graphhopper.jsprit.core.algorithm.state.StateId;
|
||||
import com.graphhopper.jsprit.core.algorithm.state.StateManager;
|
||||
import com.graphhopper.jsprit.core.algorithm.state.VehicleDependentTraveledDistance;
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
|
||||
import com.graphhopper.jsprit.core.problem.cost.TransportDistance;
|
||||
import com.graphhopper.jsprit.core.problem.job.Delivery;
|
||||
import com.graphhopper.jsprit.core.problem.job.Job;
|
||||
import com.graphhopper.jsprit.core.problem.job.Pickup;
|
||||
|
|
@ -100,13 +100,8 @@ public class VehicleDependentTraveledDistanceTest {
|
|||
|
||||
traveledDistanceId = stateManager.createStateId("traveledDistance");
|
||||
|
||||
com.graphhopper.jsprit.core.algorithm.state.VehicleDependentTraveledDistance traveledDistance =
|
||||
new com.graphhopper.jsprit.core.algorithm.state.VehicleDependentTraveledDistance(new TransportDistance() {
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return new ManhattanCosts().getDistance(from, to, departureTime, vehicle);
|
||||
}
|
||||
}, stateManager, traveledDistanceId, Arrays.asList(vehicle, vehicle2));
|
||||
VehicleDependentTraveledDistance traveledDistance =
|
||||
new VehicleDependentTraveledDistance(vrp.getTransportCosts(), stateManager, traveledDistanceId, Arrays.asList(vehicle, vehicle2));
|
||||
|
||||
stateManager.addStateUpdater(traveledDistance);
|
||||
stateManager.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
|
|
@ -123,12 +118,7 @@ public class VehicleDependentTraveledDistanceTest {
|
|||
maxDistanceMap.put(vehicle, 5d);
|
||||
|
||||
MaxDistanceConstraint maxDistanceConstraint =
|
||||
new MaxDistanceConstraint(new StateManager(vrp), traveledDistanceId, new TransportDistance() {
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return vrp.getTransportCosts().getTransportTime(from, to, departureTime, null, vehicle);
|
||||
}
|
||||
}, maxDistanceMap);
|
||||
new MaxDistanceConstraint(new StateManager(vrp), traveledDistanceId, vrp.getTransportCosts(), maxDistanceMap);
|
||||
JobInsertionContext context = new JobInsertionContext(route, pickup, vehicle, null, 0);
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,
|
||||
new Start(vehicle.getStartLocation(), 0, Double.MAX_VALUE), vrp.getActivities(pickup).get(0),
|
||||
|
|
@ -144,12 +134,7 @@ vehicle2 (max distance): 180.0
|
|||
@Test
|
||||
public void insertNewInVehicleShouldFail() {
|
||||
MaxDistanceConstraint maxDistanceConstraint =
|
||||
new MaxDistanceConstraint(stateManager, traveledDistanceId, new TransportDistance() {
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return vrp.getTransportCosts().getTransportTime(from, to, departureTime, null, vehicle);
|
||||
}
|
||||
}, maxDistanceMap);
|
||||
new MaxDistanceConstraint(stateManager, traveledDistanceId, vrp.getTransportCosts(), maxDistanceMap);
|
||||
JobInsertionContext context = new JobInsertionContext(route, newDelivery, vehicle, null, 0);
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context, route.getStart(), newAct(), act(0), 0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context, act(0), newAct(), act(1), 0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
|
|
@ -164,12 +149,7 @@ vehicle2 (max distance): 180.0
|
|||
public void insertNewInVehicle2ShouldBeCorrect() {
|
||||
//current distance vehicle2: 160 allowed: 200
|
||||
MaxDistanceConstraint maxDistanceConstraint =
|
||||
new MaxDistanceConstraint(stateManager, traveledDistanceId, new TransportDistance() {
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return vrp.getTransportCosts().getTransportTime(from, to, departureTime, null, vehicle);
|
||||
}
|
||||
}, maxDistanceMap);
|
||||
new MaxDistanceConstraint(stateManager, traveledDistanceId, vrp.getTransportCosts(), maxDistanceMap);
|
||||
JobInsertionContext context = new JobInsertionContext(route, newDelivery, vehicle2, null, 0);
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context, route.getStart(), newAct(), act(0), 0).equals(HardActivityConstraint.ConstraintsStatus.FULFILLED));
|
||||
//additional distance: 20+35-15=40
|
||||
|
|
@ -284,12 +264,7 @@ vehicle2 (max distance): 180.0
|
|||
|
||||
StateManager stateManager = new StateManager(vrp);
|
||||
MaxDistanceConstraint maxDistanceConstraint =
|
||||
new MaxDistanceConstraint(stateManager, traveledDistanceId, new TransportDistance() {
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return vrp.getTransportCosts().getTransportTime(from, to, departureTime, null, vehicle);
|
||||
}
|
||||
}, maxDistanceMap);
|
||||
new MaxDistanceConstraint(stateManager, traveledDistanceId, vrp.getTransportCosts(), maxDistanceMap);
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,
|
||||
new Start(vehicle.getStartLocation(), 0, Double.MAX_VALUE),
|
||||
vrp.getActivities(shipment).get(0),
|
||||
|
|
@ -331,12 +306,7 @@ vehicle2 (max distance): 180.0
|
|||
|
||||
StateManager stateManager = new StateManager(vrp);
|
||||
MaxDistanceConstraint maxDistanceConstraint =
|
||||
new MaxDistanceConstraint(stateManager, traveledDistanceId, new TransportDistance() {
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return vrp.getTransportCosts().getTransportTime(from, to, departureTime, null, vehicle);
|
||||
}
|
||||
}, maxDistanceMap);
|
||||
new MaxDistanceConstraint(stateManager, traveledDistanceId, vrp.getTransportCosts(), maxDistanceMap);
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,
|
||||
new Start(vehicle.getStartLocation(), 0, Double.MAX_VALUE),
|
||||
vrp.getActivities(shipment).get(0),
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ import com.graphhopper.jsprit.core.problem.Location;
|
|||
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
|
||||
import com.graphhopper.jsprit.core.problem.constraint.ConstraintManager;
|
||||
import com.graphhopper.jsprit.core.problem.constraint.MaxDistanceConstraint;
|
||||
import com.graphhopper.jsprit.core.problem.cost.TransportDistance;
|
||||
import com.graphhopper.jsprit.core.problem.job.Service;
|
||||
import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||
|
|
@ -122,12 +121,7 @@ public class UnassignedJobReasonTrackerTest {
|
|||
StateId maxDistance = stateManager.createStateId("max-distance");
|
||||
Map<Vehicle, Double> distMap = new HashMap<>();
|
||||
distMap.put(vehicle, 100d);
|
||||
MaxDistanceConstraint distanceConstraint = new MaxDistanceConstraint(stateManager, maxDistance, new TransportDistance() {
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return vrp.getTransportCosts().getTransportCost(from, to, departureTime, null, vehicle);
|
||||
}
|
||||
}, distMap);
|
||||
MaxDistanceConstraint distanceConstraint = new MaxDistanceConstraint(stateManager, maxDistance, vrp.getTransportCosts(), distMap);
|
||||
constraintManager.addConstraint(distanceConstraint, ConstraintManager.Priority.CRITICAL);
|
||||
|
||||
VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setStateAndConstraintManager(stateManager, constraintManager)
|
||||
|
|
|
|||
|
|
@ -34,16 +34,13 @@ import com.graphhopper.jsprit.core.algorithm.ruin.distance.AvgServiceAndShipment
|
|||
import com.graphhopper.jsprit.core.algorithm.selector.SelectBest;
|
||||
import com.graphhopper.jsprit.core.algorithm.state.StateManager;
|
||||
import com.graphhopper.jsprit.core.analysis.SolutionAnalyser;
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
|
||||
import com.graphhopper.jsprit.core.problem.constraint.ConstraintManager;
|
||||
import com.graphhopper.jsprit.core.problem.cost.TransportDistance;
|
||||
import com.graphhopper.jsprit.core.problem.job.Job;
|
||||
import com.graphhopper.jsprit.core.problem.solution.SolutionCostCalculator;
|
||||
import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import com.graphhopper.jsprit.core.problem.vehicle.FiniteFleetManagerFactory;
|
||||
import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
|
||||
import com.graphhopper.jsprit.core.problem.vehicle.VehicleFleetManager;
|
||||
import com.graphhopper.jsprit.core.reporting.SolutionPrinter;
|
||||
import com.graphhopper.jsprit.core.util.Solutions;
|
||||
|
|
@ -207,12 +204,7 @@ public class BuildAlgorithmFromScratch {
|
|||
|
||||
@Override
|
||||
public double getCosts(VehicleRoutingProblemSolution solution) {
|
||||
SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() {
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null);
|
||||
}
|
||||
});
|
||||
SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, vrp.getTransportCosts());
|
||||
return analyser.getVariableTransportCosts() + solution.getUnassignedJobs().size() * 500.;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,10 +23,8 @@ import com.graphhopper.jsprit.core.algorithm.box.Jsprit;
|
|||
import com.graphhopper.jsprit.core.analysis.SolutionAnalyser;
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
|
||||
import com.graphhopper.jsprit.core.problem.cost.TransportDistance;
|
||||
import com.graphhopper.jsprit.core.problem.job.Service;
|
||||
import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
|
||||
import com.graphhopper.jsprit.core.problem.vehicle.VehicleImpl;
|
||||
import com.graphhopper.jsprit.core.problem.vehicle.VehicleImpl.Builder;
|
||||
import com.graphhopper.jsprit.core.problem.vehicle.VehicleType;
|
||||
|
|
@ -136,12 +134,7 @@ public class MultipleTimeWindowExample2 {
|
|||
*/
|
||||
new Plotter(problem,bestSolution).setLabel(Plotter.Label.ID).plot("output/plot", "mtw");
|
||||
|
||||
SolutionAnalyser a = new SolutionAnalyser(problem, bestSolution, new TransportDistance() {
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return problem.getTransportCosts().getTransportTime(from,to,0.,null,null);
|
||||
}
|
||||
});
|
||||
SolutionAnalyser a = new SolutionAnalyser(problem, bestSolution, problem.getTransportCosts());
|
||||
|
||||
System.out.println("distance: " + a.getDistance());
|
||||
System.out.println("ttime: " + a.getTransportTime());
|
||||
|
|
|
|||
|
|
@ -24,11 +24,8 @@ import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm;
|
|||
import com.graphhopper.jsprit.core.algorithm.box.Jsprit;
|
||||
import com.graphhopper.jsprit.core.algorithm.selector.SelectBest;
|
||||
import com.graphhopper.jsprit.core.analysis.SolutionAnalyser;
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
|
||||
import com.graphhopper.jsprit.core.problem.cost.TransportDistance;
|
||||
import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
|
||||
import com.graphhopper.jsprit.core.reporting.SolutionPrinter;
|
||||
import com.graphhopper.jsprit.io.problem.VrpXMLReader;
|
||||
import com.graphhopper.jsprit.util.Examples;
|
||||
|
|
@ -100,14 +97,7 @@ public class PickupAndDeliveryExample {
|
|||
plotter.plot("output/pd_solomon_r101_solution.png", "pd_r101");
|
||||
|
||||
//some stats
|
||||
SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() {
|
||||
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null);
|
||||
}
|
||||
|
||||
});
|
||||
SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, vrp.getTransportCosts());
|
||||
|
||||
System.out.println("tp_distance: " + analyser.getDistance());
|
||||
System.out.println("tp_time: " + analyser.getTransportTime());
|
||||
|
|
|
|||
|
|
@ -25,15 +25,12 @@ import com.graphhopper.jsprit.core.algorithm.selector.SelectBest;
|
|||
import com.graphhopper.jsprit.core.algorithm.state.StateManager;
|
||||
import com.graphhopper.jsprit.core.analysis.SolutionAnalyser;
|
||||
import com.graphhopper.jsprit.core.problem.Capacity;
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
|
||||
import com.graphhopper.jsprit.core.problem.constraint.ConstraintManager;
|
||||
import com.graphhopper.jsprit.core.problem.constraint.ServiceDeliveriesFirstConstraint;
|
||||
import com.graphhopper.jsprit.core.problem.cost.TransportDistance;
|
||||
import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
|
||||
import com.graphhopper.jsprit.core.reporting.SolutionPrinter;
|
||||
import com.graphhopper.jsprit.io.problem.VrpXMLReader;
|
||||
import com.graphhopper.jsprit.util.Examples;
|
||||
|
|
@ -125,14 +122,7 @@ public class VRPWithBackhaulsExample2 {
|
|||
// plotter.setLabel(Plotter.Label.SIZE);
|
||||
plotter.plot("output/vrpwbh_christophides_vrpnc1_solution.png", "vrpwbh_vrpnc1");
|
||||
|
||||
SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() {
|
||||
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null);
|
||||
}
|
||||
|
||||
});
|
||||
SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, vrp.getTransportCosts());
|
||||
|
||||
for (VehicleRoute route : solution.getRoutes()) {
|
||||
System.out.println("------");
|
||||
|
|
|
|||
|
|
@ -217,6 +217,10 @@ public class Figliozzi {
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return EuclideanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()), locations.getCoord(to.getId()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue