From 9f5b3c168be3d84cee59b093c91d871e6a1ea18f Mon Sep 17 00:00:00 2001 From: Stefan Schroeder <4sschroeder@gmail.com> Date: Thu, 6 Jun 2013 09:18:23 +0200 Subject: [PATCH] add defaultVehicleType now types do not have to be set neccessarily, since 'default' is always set with cost-param (fix=0,dist=1,time=0) --- .../main/java/basics/route/VehicleImpl.java | 67 +++---------------- .../src/main/java/util/ManhattanCosts.java | 6 +- 2 files changed, 11 insertions(+), 62 deletions(-) diff --git a/jsprit-core/src/main/java/basics/route/VehicleImpl.java b/jsprit-core/src/main/java/basics/route/VehicleImpl.java index 7708b701..af9c9a3a 100644 --- a/jsprit-core/src/main/java/basics/route/VehicleImpl.java +++ b/jsprit-core/src/main/java/basics/route/VehicleImpl.java @@ -71,11 +71,12 @@ public class VehicleImpl implements Vehicle { private String id; private int capacity; - private double fixedCost; - private double perDistance; - private double perTime; - -// private TimeSchedule timeSchedule = new TimeSchedule(0.0,Integer.MAX_VALUE); + /** + * default cost values for default vehicle type + */ + private double fixedCost = 0.0; + private double perDistance = 1.0; + private double perTime = 0.0; public Builder(String id, int capacity) { super(); @@ -89,11 +90,8 @@ public class VehicleImpl implements Vehicle { public Builder setCostPerTime(double perTime){ this.perTime = perTime; return this; } -// public Builder setTimeSchedule(TimeSchedule timeSchedule){ this.timeSchedule = timeSchedule; return this; } - public VehicleType build(){ return new VehicleType(this); -// return Type.newInstance(id, capacity, VehicleCostParams.newInstance(fixedCost, perTime, perDistance)); } } @@ -127,9 +125,6 @@ public class VehicleImpl implements Vehicle { public final String typeId; public final int capacity; public final VehicleCostParams vehicleCostParams; -// private double speed = 22.0; - - private TimeSchedule timeSchedule; public static VehicleType newInstance(String typeId, int capacity, VehicleCostParams para){ return new VehicleType(typeId, capacity, para); @@ -139,7 +134,6 @@ public class VehicleImpl implements Vehicle { typeId = builder.id; capacity = builder.capacity; vehicleCostParams = new VehicleCostParams(builder.fixedCost, builder.perTime, builder.perDistance); -// timeSchedule = builder.timeSchedule; } public VehicleType(String typeId, int capacity,VehicleCostParams vehicleCostParams) { @@ -156,24 +150,11 @@ public class VehicleImpl implements Vehicle { public int getCapacity() { return capacity; } - - @Deprecated - public TimeSchedule getTimeSchedule() { - return timeSchedule; - } public VehicleCostParams getVehicleCostParams() { return vehicleCostParams; } -// public double getSpeed() { -// return speed; -// } -// -// public void setSpeed(double speed) { -// this.speed = speed; -// } - @Override public String toString() { return "[typeId="+typeId+"][capacity="+capacity+"]" + vehicleCostParams; @@ -206,12 +187,14 @@ public class VehicleImpl implements Vehicle { public static class VehicleBuilder { static Logger log = Logger.getLogger(VehicleBuilder.class); private String id; - private VehicleType type; + private String locationId; private Coordinate locationCoord; private double earliestStart = 0.0; private double latestArrival = Double.MAX_VALUE; + private VehicleType type = VehicleType.Builder.newInstance("default", 0).build(); + private VehicleBuilder(String id) { super(); this.id = id; @@ -243,7 +226,6 @@ public class VehicleImpl implements Vehicle { } public VehicleImpl build(){ - if(type == null) throw new IllegalStateException("type must not be null"); if(locationId == null && locationCoord != null) locationId = locationCoord.toString(); if(locationId == null && locationCoord == null) throw new IllegalStateException("locationId and locationCoord is missing."); if(locationCoord == null) log.warn("locationCoord for vehicle " + id + " is missing."); @@ -291,14 +273,6 @@ public class VehicleImpl implements Vehicle { return coord; } -// public void setCoord(Coordinate coord) { -// this.coord = coord; -// } - -// public void setLocationId(String locationId) { -// this.locationId = locationId; -// } - /* * (non-Javadoc) * @@ -309,18 +283,6 @@ public class VehicleImpl implements Vehicle { return earliestDeparture; } - /* - * (non-Javadoc) - * - * @see - * org.matsim.contrib.freight.vrp.basics.Vehicle#setEarliestDeparture(double - * ) - */ - -// public void setEarliestDeparture(double earliestDeparture) { -// this.earliestDeparture = earliestDeparture; -// } - /* * (non-Javadoc) * @@ -331,17 +293,6 @@ public class VehicleImpl implements Vehicle { return latestArrival; } - /* - * (non-Javadoc) - * - * @see - * org.matsim.contrib.freight.vrp.basics.Vehicle#setLatestArrival(double) - */ - -// public void setLatestArrival(double latestArrival) { -// this.latestArrival = latestArrival; -// } - /* * (non-Javadoc) * diff --git a/jsprit-core/src/main/java/util/ManhattanCosts.java b/jsprit-core/src/main/java/util/ManhattanCosts.java index 473a1ab4..dbf15fef 100644 --- a/jsprit-core/src/main/java/util/ManhattanCosts.java +++ b/jsprit-core/src/main/java/util/ManhattanCosts.java @@ -36,14 +36,12 @@ public class ManhattanCosts implements VehicleRoutingTransportCosts { } @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) { return calculateDistance(fromId, toId); } @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 = calculateDistance(fromId, toId) / speed; return transportTime; }