From a48013bc0fe8b5e8ceab18d17458195a96851e79 Mon Sep 17 00:00:00 2001 From: oblonski <4sschroeder@gmail.com> Date: Tue, 18 Jun 2013 05:14:21 +0200 Subject: [PATCH] include fixed and variable vehicle-costs --- .../src/main/java/util/CrowFlyCosts.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/jsprit-core/src/main/java/util/CrowFlyCosts.java b/jsprit-core/src/main/java/util/CrowFlyCosts.java index ce4e290c..d2adaa50 100644 --- a/jsprit-core/src/main/java/util/CrowFlyCosts.java +++ b/jsprit-core/src/main/java/util/CrowFlyCosts.java @@ -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; }