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:
parent
cc254b2993
commit
a48013bc0f
1 changed files with 16 additions and 4 deletions
|
|
@ -49,18 +49,30 @@ public class CrowFlyCosts implements VehicleRoutingTransportCosts {
|
|||
|
||||
@Override
|
||||
public double getTransportCost(String fromId, String toId, double time, Driver driver, Vehicle vehicle) {
|
||||
double cost;
|
||||
double distance;
|
||||
try {
|
||||
cost = EuclideanDistanceCalculator.calculateDistance(locations.getCoord(fromId), locations.getCoord(toId)) * detourFactor;
|
||||
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.");
|
||||
}
|
||||
return cost;
|
||||
double costs = distance;
|
||||
if(vehicle != null){
|
||||
if(vehicle.getType() != null){
|
||||
costs = distance * vehicle.getType().getVehicleCostParams().perDistanceUnit;
|
||||
}
|
||||
}
|
||||
return costs;
|
||||
}
|
||||
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue