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

extend interface TransportDistance - breaking change

This commit is contained in:
oblonski 2016-06-14 19:53:19 +02:00
parent 3d84c714d2
commit 151754c79c
17 changed files with 188 additions and 174 deletions

View file

@ -340,7 +340,7 @@ public class SolutionAnalyser {
} }
private double distance(TourActivity activity) { private double distance(TourActivity activity) {
return distanceCalculator.getDistance(prevAct.getLocation(), activity.getLocation()); return distanceCalculator.getDistance(prevAct.getLocation(), activity.getLocation(),prevActDeparture, route.getVehicle());
} }
@Override @Override
@ -381,7 +381,7 @@ public class SolutionAnalyser {
@Override @Override
public void visit(TourActivity activity) { public void visit(TourActivity activity) {
double distance = distanceCalculator.getDistance(prevAct.getLocation(), activity.getLocation()); double distance = distanceCalculator.getDistance(prevAct.getLocation(), activity.getLocation(), prevAct.getEndTime(), route.getVehicle());
sum_distance += distance; sum_distance += distance;
stateManager.putActivityState(activity, distance_id, sum_distance); stateManager.putActivityState(activity, distance_id, sum_distance);
prevAct = activity; prevAct = activity;
@ -389,7 +389,7 @@ public class SolutionAnalyser {
@Override @Override
public void finish() { public void finish() {
double distance = distanceCalculator.getDistance(prevAct.getLocation(), route.getEnd().getLocation()); double distance = distanceCalculator.getDistance(prevAct.getLocation(), route.getEnd().getLocation(),prevAct.getEndTime(), route.getVehicle());
sum_distance += distance; sum_distance += distance;
stateManager.putRouteState(route, distance_id, sum_distance); stateManager.putRouteState(route, distance_id, sum_distance);
} }

View file

@ -1,12 +1,13 @@
package com.graphhopper.jsprit.core.problem.cost; package com.graphhopper.jsprit.core.problem.cost;
import com.graphhopper.jsprit.core.problem.Location; import com.graphhopper.jsprit.core.problem.Location;
import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
/** /**
* Created by schroeder on 23/12/14. * Created by schroeder on 23/12/14.
*/ */
public interface TransportDistance { public interface TransportDistance {
public double getDistance(Location from, Location to); public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle);
} }

View file

@ -94,7 +94,7 @@ public class CrowFlyCosts extends AbstractForwardVehicleRoutingTransportCosts im
} }
@Override @Override
public double getDistance(Location from, Location to) { public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
return calculateDistance(from, to); return calculateDistance(from, to);
} }
} }

View file

@ -84,7 +84,7 @@ public class EuclideanCosts extends AbstractForwardVehicleRoutingTransportCosts
} }
@Override @Override
public double getDistance(Location from, Location to) { public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
return calculateDistance(from, to); return calculateDistance(from, to);
} }
} }

View file

@ -155,7 +155,7 @@ public class FastVehicleRoutingTransportCostsMatrix extends AbstractForwardVehic
} }
@Override @Override
public double getDistance(Location from, Location to) { public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
return getDistance(from.getIndex(), to.getIndex()); return getDistance(from.getIndex(), to.getIndex());
} }

View file

@ -95,7 +95,7 @@ public class GreatCircleCosts extends AbstractForwardVehicleRoutingTransportCost
} }
@Override @Override
public double getDistance(Location from, Location to) { public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
return calculateDistance(from, to); return calculateDistance(from, to);
} }
} }

View file

@ -83,7 +83,7 @@ public class ManhattanCosts extends AbstractForwardVehicleRoutingTransportCosts
} }
@Override @Override
public double getDistance(Location from, Location to) { public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
return calculateDistance(from, to); return calculateDistance(from, to);
} }
} }

View file

@ -86,7 +86,7 @@ public class CVRPwithMatrix_IT {
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions(); Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
SolutionAnalyser sa = new SolutionAnalyser(vrp, Solutions.bestOf(solutions), new TransportDistance() { SolutionAnalyser sa = new SolutionAnalyser(vrp, Solutions.bestOf(solutions), new TransportDistance() {
@Override @Override
public double getDistance(Location from, Location to) { public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null);
} }
}); });

View file

@ -27,6 +27,7 @@ import com.graphhopper.jsprit.core.problem.cost.TransportDistance;
import com.graphhopper.jsprit.core.problem.job.Delivery; import com.graphhopper.jsprit.core.problem.job.Delivery;
import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution; 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.VehicleRoute;
import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
import com.graphhopper.jsprit.core.problem.vehicle.VehicleImpl; import com.graphhopper.jsprit.core.problem.vehicle.VehicleImpl;
import com.graphhopper.jsprit.core.problem.vehicle.VehicleTypeImpl; import com.graphhopper.jsprit.core.problem.vehicle.VehicleTypeImpl;
import com.graphhopper.jsprit.core.reporting.SolutionPrinter; import com.graphhopper.jsprit.core.reporting.SolutionPrinter;
@ -95,8 +96,8 @@ public class CapacityConstraint_IT {
SolutionPrinter.print(vrp,solution, SolutionPrinter.Print.VERBOSE); SolutionPrinter.print(vrp,solution, SolutionPrinter.Print.VERBOSE);
SolutionAnalyser sa = new SolutionAnalyser(vrp, solution, new TransportDistance() { SolutionAnalyser sa = new SolutionAnalyser(vrp, solution, new TransportDistance() {
@Override @Override
public double getDistance(Location from, Location to) { public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
return new ManhattanCosts().getDistance(from,to); return new ManhattanCosts().getDistance(from,to, 0d, null);
} }
}); });

View file

@ -66,7 +66,7 @@ public class VariableDepartureAndWaitingTime_IT {
public double getCosts(VehicleRoutingProblemSolution solution) { public double getCosts(VehicleRoutingProblemSolution solution) {
SolutionAnalyser sa = new SolutionAnalyser(vrp, solution, new TransportDistance() { SolutionAnalyser sa = new SolutionAnalyser(vrp, solution, new TransportDistance() {
@Override @Override
public double getDistance(Location from, Location to) { public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null);
} }
}); });

View file

@ -101,6 +101,8 @@
<fixed>0.0</fixed> <fixed>0.0</fixed>
<distance>0.0</distance> <distance>0.0</distance>
<time>0.0</time> <time>0.0</time>
<service>0.0</service>
<wait>0.0</wait>
</costs> </costs>
</type> </type>
<type> <type>
@ -112,6 +114,8 @@
<fixed>0.0</fixed> <fixed>0.0</fixed>
<distance>0.0</distance> <distance>0.0</distance>
<time>0.0</time> <time>0.0</time>
<service>0.0</service>
<wait>0.0</wait>
</costs> </costs>
</type> </type>
<type> <type>
@ -133,6 +137,8 @@
<fixed>0.0</fixed> <fixed>0.0</fixed>
<distance>0.0</distance> <distance>0.0</distance>
<time>0.0</time> <time>0.0</time>
<service>0.0</service>
<wait>0.0</wait>
</costs> </costs>
</type> </type>
</vehicleTypes> </vehicleTypes>

View file

@ -31,6 +31,8 @@
<fixed>0.0</fixed> <fixed>0.0</fixed>
<distance>1.0</distance> <distance>1.0</distance>
<time>0.0</time> <time>0.0</time>
<service>0.0</service>
<wait>0.0</wait>
</costs> </costs>
</type> </type>
</vehicleTypes> </vehicleTypes>

View file

@ -43,6 +43,7 @@ import com.graphhopper.jsprit.core.problem.solution.SolutionCostCalculator;
import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution; 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.VehicleRoute;
import com.graphhopper.jsprit.core.problem.vehicle.FiniteFleetManagerFactory; 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.problem.vehicle.VehicleFleetManager;
import com.graphhopper.jsprit.core.reporting.SolutionPrinter; import com.graphhopper.jsprit.core.reporting.SolutionPrinter;
import com.graphhopper.jsprit.core.util.Solutions; import com.graphhopper.jsprit.core.util.Solutions;
@ -206,7 +207,7 @@ public class BuildAlgorithmFromScratch {
public double getCosts(VehicleRoutingProblemSolution solution) { public double getCosts(VehicleRoutingProblemSolution solution) {
SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() {
@Override @Override
public double getDistance(Location from, Location to) { public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null);
} }
}); });

View file

@ -25,6 +25,7 @@ import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
import com.graphhopper.jsprit.core.problem.cost.TransportDistance; import com.graphhopper.jsprit.core.problem.cost.TransportDistance;
import com.graphhopper.jsprit.core.problem.job.Service; import com.graphhopper.jsprit.core.problem.job.Service;
import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution; 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;
import com.graphhopper.jsprit.core.problem.vehicle.VehicleImpl.Builder; import com.graphhopper.jsprit.core.problem.vehicle.VehicleImpl.Builder;
import com.graphhopper.jsprit.core.problem.vehicle.VehicleType; import com.graphhopper.jsprit.core.problem.vehicle.VehicleType;
@ -136,7 +137,7 @@ public class MultipleTimeWindowExample2 {
SolutionAnalyser a = new SolutionAnalyser(problem, bestSolution, new TransportDistance() { SolutionAnalyser a = new SolutionAnalyser(problem, bestSolution, new TransportDistance() {
@Override @Override
public double getDistance(Location from, Location to) { public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
return problem.getTransportCosts().getTransportTime(from,to,0.,null,null); return problem.getTransportCosts().getTransportTime(from,to,0.,null,null);
} }
}); });

View file

@ -28,6 +28,7 @@ import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
import com.graphhopper.jsprit.core.problem.cost.TransportDistance; import com.graphhopper.jsprit.core.problem.cost.TransportDistance;
import com.graphhopper.jsprit.core.problem.io.VrpXMLReader; import com.graphhopper.jsprit.core.problem.io.VrpXMLReader;
import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution; 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.core.reporting.SolutionPrinter;
import com.graphhopper.jsprit.util.Examples; import com.graphhopper.jsprit.util.Examples;
@ -101,7 +102,7 @@ public class PickupAndDeliveryExample {
SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() {
@Override @Override
public double getDistance(Location from, Location to) { public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null);
} }

View file

@ -33,6 +33,7 @@ import com.graphhopper.jsprit.core.problem.io.VrpXMLReader;
import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution; 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.VehicleRoute;
import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity; 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.core.reporting.SolutionPrinter;
import com.graphhopper.jsprit.util.Examples; import com.graphhopper.jsprit.util.Examples;
@ -126,7 +127,7 @@ public class VRPWithBackhaulsExample2 {
SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() {
@Override @Override
public double getDistance(Location from, Location to) { public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null);
} }