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

include fixed and variable vehicle-costs

This commit is contained in:
oblonski 2013-06-18 05:14:21 +02:00
parent cc254b2993
commit a48013bc0f

View file

@ -49,18 +49,30 @@ public class CrowFlyCosts implements VehicleRoutingTransportCosts {
@Override @Override
public double getTransportCost(String fromId, String toId, double time, Driver driver, Vehicle vehicle) { public double getTransportCost(String fromId, String toId, double time, Driver driver, Vehicle vehicle) {
double cost; double distance;
try { try {
cost = EuclideanDistanceCalculator.calculateDistance(locations.getCoord(fromId), locations.getCoord(toId)) * detourFactor; distance = EuclideanDistanceCalculator.calculateDistance(locations.getCoord(fromId), locations.getCoord(toId)) * detourFactor;
} catch (NullPointerException e) { } catch (NullPointerException e) {
throw new NullPointerException("cannot calculate euclidean distance. coordinates are missing. either add coordinates or use another transport-cost-calculator."); throw new NullPointerException("cannot calculate euclidean distance. coordinates are missing. either add coordinates or use another transport-cost-calculator.");
} }
return cost; double costs = distance;
if(vehicle != null){
if(vehicle.getType() != null){
costs = distance * vehicle.getType().getVehicleCostParams().perDistanceUnit;
}
}
return costs;
} }
@Override @Override
public double getTransportTime(String fromId, String toId, double time, Driver driver, Vehicle vehicle) { public double getTransportTime(String fromId, String toId, double time, Driver driver, Vehicle vehicle) {
double transportTime = getTransportCost(fromId, toId, 0.0, null, null) / speed; double distance;
try {
distance = EuclideanDistanceCalculator.calculateDistance(locations.getCoord(fromId), locations.getCoord(toId)) * detourFactor;
} catch (NullPointerException e) {
throw new NullPointerException("cannot calculate euclidean distance. coordinates are missing. either add coordinates or use another transport-cost-calculator.");
}
double transportTime = distance / speed;
return transportTime; return transportTime;
} }