mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
rename vehicleType to vehicleTypeImpl, extract interface vehicleType;
refactor vehicleType to new file; add penaltyVehicleType; improve vehicleFleetManagerImpl
This commit is contained in:
parent
d223475cb4
commit
c1849a9d5a
39 changed files with 319 additions and 572 deletions
|
|
@ -88,13 +88,13 @@ final class CalculatesServiceInsertionConsideringFixCost implements JobInsertion
|
|||
double currentFix = 0.0;
|
||||
if(route.getVehicle() != null){
|
||||
if(!(route.getVehicle() instanceof NoVehicle)){
|
||||
currentFix += route.getVehicle().getType().vehicleCostParams.fix;
|
||||
currentFix += route.getVehicle().getType().getVehicleCostParams().fix;
|
||||
}
|
||||
}
|
||||
if(newVehicle.getCapacity() < load){
|
||||
return Double.MAX_VALUE;
|
||||
}
|
||||
return newVehicle.getType().vehicleCostParams.fix - currentFix;
|
||||
return newVehicle.getType().getVehicleCostParams().fix - currentFix;
|
||||
}
|
||||
|
||||
private double getDeltaRelativeFixCost(VehicleRoute route, Vehicle newVehicle, Job job) {
|
||||
|
|
@ -103,13 +103,13 @@ final class CalculatesServiceInsertionConsideringFixCost implements JobInsertion
|
|||
double currentRelFix = 0.0;
|
||||
if(route.getVehicle() != null){
|
||||
if(!(route.getVehicle() instanceof NoVehicle)){
|
||||
currentRelFix += route.getVehicle().getType().vehicleCostParams.fix*currentLoad/route.getVehicle().getCapacity();
|
||||
currentRelFix += route.getVehicle().getType().getVehicleCostParams().fix*currentLoad/route.getVehicle().getCapacity();
|
||||
}
|
||||
}
|
||||
if(newVehicle.getCapacity() < load){
|
||||
return Double.MAX_VALUE;
|
||||
}
|
||||
double relativeFixCost = newVehicle.getType().vehicleCostParams.fix*(load/newVehicle.getCapacity()) - currentRelFix;
|
||||
double relativeFixCost = newVehicle.getType().getVehicleCostParams().fix*(load/newVehicle.getCapacity()) - currentRelFix;
|
||||
return relativeFixCost;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ import basics.Job;
|
|||
import basics.route.Driver;
|
||||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleImpl.NoVehicle;
|
||||
import basics.route.VehicleImpl.VehicleType;
|
||||
import basics.route.VehicleRoute;
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -82,11 +82,11 @@ final class FindCheaperVehicleAlgo {
|
|||
|
||||
for(Vehicle vehicle : fleetManager.getAvailableVehicle(vehicleRoute.getVehicle().getType().getTypeId(), vehicleRoute.getVehicle().getLocationId())){
|
||||
// Vehicle vehicle = fleetManager.getEmptyVehicle(vehicleType);
|
||||
if(vehicle.getType().typeId.equals(vehicleRoute.getVehicle().getType().typeId)){
|
||||
if(vehicle.getType().getTypeId().equals(vehicleRoute.getVehicle().getType().getTypeId())){
|
||||
continue;
|
||||
}
|
||||
if(states.getRouteState(vehicleRoute).getLoad() <= vehicle.getCapacity()){
|
||||
double fixCostSaving = vehicleRoute.getVehicle().getType().vehicleCostParams.fix - vehicle.getType().vehicleCostParams.fix;
|
||||
double fixCostSaving = vehicleRoute.getVehicle().getType().getVehicleCostParams().fix - vehicle.getType().getVehicleCostParams().fix;
|
||||
double departureTime = vehicleRoute.getStart().getEndTime();
|
||||
double newCost = auxilliaryCostCalculator.costOfPath(path, departureTime, vehicleRoute.getDriver(), vehicle);
|
||||
double varCostSaving = states.getRouteState(vehicleRoute).getCosts() - newCost;
|
||||
|
|
|
|||
|
|
@ -23,10 +23,8 @@ package algorithms;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
|
@ -72,16 +70,6 @@ class InfiniteVehicles implements VehicleFleetManager{
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Vehicle getEmptyVehicle(TypeKey typeId) {
|
||||
return types.get(typeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<TypeKey> getAvailableVehicleTypes() {
|
||||
return sortedTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lock(Vehicle vehicle) {
|
||||
|
||||
|
|
@ -92,12 +80,6 @@ class InfiniteVehicles implements VehicleFleetManager{
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<TypeKey> getAvailableVehicleTypes(TypeKey withoutThisType) {
|
||||
Set<TypeKey> typeSet = new HashSet<TypeKey>(types.keySet());
|
||||
typeSet.remove(withoutThisType);
|
||||
return typeSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLocked(Vehicle vehicle) {
|
||||
|
|
|
|||
|
|
@ -23,11 +23,10 @@ package algorithms;
|
|||
import java.util.Collection;
|
||||
|
||||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleImpl.VehicleType;
|
||||
|
||||
interface VehicleFleetManager {
|
||||
|
||||
public static class TypeKey {
|
||||
static class TypeKey {
|
||||
|
||||
public final String type;
|
||||
public final String locationId;
|
||||
|
|
@ -74,21 +73,15 @@ interface VehicleFleetManager {
|
|||
|
||||
}
|
||||
|
||||
public abstract Vehicle getEmptyVehicle(TypeKey typeId);
|
||||
abstract void lock(Vehicle vehicle);
|
||||
|
||||
public abstract Collection<TypeKey> getAvailableVehicleTypes();
|
||||
abstract void unlock(Vehicle vehicle);
|
||||
|
||||
public abstract void lock(Vehicle vehicle);
|
||||
abstract boolean isLocked(Vehicle vehicle);
|
||||
|
||||
public abstract void unlock(Vehicle vehicle);
|
||||
abstract void unlockAll();
|
||||
|
||||
public abstract Collection<TypeKey> getAvailableVehicleTypes(TypeKey withoutThisType);
|
||||
|
||||
public abstract boolean isLocked(Vehicle vehicle);
|
||||
|
||||
public abstract void unlockAll();
|
||||
|
||||
public abstract Collection<? extends Vehicle> getAvailableVehicles();
|
||||
abstract Collection<? extends Vehicle> getAvailableVehicles();
|
||||
|
||||
Collection<? extends Vehicle> getAvailableVehicle(String withoutThisType, String locationId);
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import java.util.Set;
|
|||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import basics.route.PenaltyVehicleType;
|
||||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleImpl.NoVehicle;
|
||||
|
||||
|
|
@ -136,10 +137,9 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
|
|||
if(v.getType() == null){
|
||||
throw new IllegalStateException("vehicle needs type");
|
||||
}
|
||||
String typeId = v.getType().typeId;
|
||||
if(typeId.contains("penalty")){
|
||||
String[] typeIdTokens = typeId.split("#");
|
||||
TypeKey typeKey = new TypeKey(typeIdTokens[0],v.getLocationId());
|
||||
String typeId = v.getType().getTypeId();
|
||||
if(v.getType() instanceof PenaltyVehicleType){
|
||||
TypeKey typeKey = new TypeKey(typeId,v.getLocationId());
|
||||
penaltyVehicles.put(typeKey, v);
|
||||
}
|
||||
else{
|
||||
|
|
@ -153,7 +153,7 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
|
|||
|
||||
private void removeVehicle(Vehicle v){
|
||||
//it might be better to introduce a class PenaltyVehicle
|
||||
if(!v.getType().getTypeId().contains("penalty")){
|
||||
if(!(v.getType() instanceof PenaltyVehicleType)){
|
||||
TypeKey key = new TypeKey(v.getType().getTypeId(),v.getLocationId());
|
||||
if(typeMapOfAvailableVehicles.containsKey(key)){
|
||||
typeMapOfAvailableVehicles.get(key).remove(v);
|
||||
|
|
@ -161,34 +161,6 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
|
|||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.matsim.contrib.freight.vrp.basics.VehicleFleetManager#getEmptyVehicle(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public Vehicle getEmptyVehicle(TypeKey typeId){
|
||||
Vehicle v = null;
|
||||
if(typeMapOfAvailableVehicles.containsKey(typeId)){
|
||||
v = typeMapOfAvailableVehicles.get(typeId).getVehicle();
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.matsim.contrib.freight.vrp.basics.VehicleFleetManager#getAvailableVehicleTypes()
|
||||
*/
|
||||
@Override
|
||||
public Collection<TypeKey> getAvailableVehicleTypes(){
|
||||
List<TypeKey> types = new ArrayList<TypeKey>();
|
||||
for(TypeKey key : typeMapOfAvailableVehicles.keySet()){
|
||||
if(!typeMapOfAvailableVehicles.get(key).isEmpty()){
|
||||
types.add(key);
|
||||
}
|
||||
else{
|
||||
|
||||
}
|
||||
}
|
||||
return types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of available vehicles.
|
||||
|
|
@ -250,7 +222,7 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
|
|||
if(vehicles.isEmpty() || vehicle instanceof NoVehicle){
|
||||
return;
|
||||
}
|
||||
if(vehicle.getType().getTypeId().contains("penalty")) return;
|
||||
if(vehicle.getType() instanceof PenaltyVehicleType) return;
|
||||
boolean locked = lockedVehicles.add(vehicle);
|
||||
removeVehicle(vehicle);
|
||||
if(!locked){
|
||||
|
|
@ -267,30 +239,11 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
|
|||
return;
|
||||
}
|
||||
if(vehicle == null) return;
|
||||
if(vehicle.getType().getTypeId().contains("penalty")) return;
|
||||
if(vehicle.getType() instanceof PenaltyVehicleType) return;
|
||||
lockedVehicles.remove(vehicle);
|
||||
addVehicle(vehicle);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.matsim.contrib.freight.vrp.basics.VehicleFleetManager#getAvailableVehicleTypes(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public Collection<TypeKey> getAvailableVehicleTypes(TypeKey withoutThisType) {
|
||||
List<TypeKey> types = new ArrayList<TypeKey>();
|
||||
for(TypeKey typeKey : typeMapOfAvailableVehicles.keySet()){
|
||||
if(typeKey.equals(withoutThisType)){
|
||||
continue;
|
||||
}
|
||||
if(!typeMapOfAvailableVehicles.get(typeKey).isEmpty()){
|
||||
types.add(typeKey);
|
||||
}
|
||||
}
|
||||
return types;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.matsim.contrib.freight.vrp.basics.VehicleFleetManager#isLocked(org.matsim.contrib.freight.vrp.basics.Vehicle)
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -29,7 +29,8 @@ import basics.costs.VehicleRoutingActivityCosts;
|
|||
import basics.costs.VehicleRoutingTransportCosts;
|
||||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleImpl;
|
||||
import basics.route.VehicleImpl.VehicleType;
|
||||
import basics.route.VehicleType;
|
||||
import basics.route.VehicleTypeImpl;
|
||||
|
||||
/**
|
||||
* Contains and describes the vehicle routing problem.
|
||||
|
|
@ -96,7 +97,7 @@ public class VehicleRoutingProblem {
|
|||
jobs = new HashMap<String, Job>();
|
||||
vehicles = new ArrayList<Vehicle>();
|
||||
coordinates = new HashMap<String, Coordinate>();
|
||||
vehicleTypes = new ArrayList<VehicleImpl.VehicleType>();
|
||||
vehicleTypes = new ArrayList<VehicleType>();
|
||||
services = new ArrayList<Service>();
|
||||
}
|
||||
|
||||
|
|
@ -237,7 +238,7 @@ public class VehicleRoutingProblem {
|
|||
* @param type
|
||||
* @return builder
|
||||
*/
|
||||
public Builder addVehicleType(VehicleType type){
|
||||
public Builder addVehicleType(VehicleTypeImpl type){
|
||||
vehicleTypes.add(type);
|
||||
return this;
|
||||
}
|
||||
|
|
@ -445,7 +446,7 @@ public class VehicleRoutingProblem {
|
|||
* Returns the entire, unmodifiable collection of types.
|
||||
*
|
||||
* @return unmodifiable collection of types
|
||||
* @see VehicleType
|
||||
* @see VehicleTypeImpl
|
||||
*/
|
||||
public Collection<VehicleType> getTypes(){
|
||||
return Collections.unmodifiableCollection(vehicleTypes);
|
||||
|
|
|
|||
|
|
@ -52,8 +52,9 @@ import basics.route.TimeWindow;
|
|||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleImpl;
|
||||
import basics.route.VehicleImpl.VehicleBuilder;
|
||||
import basics.route.VehicleImpl.VehicleType;
|
||||
import basics.route.VehicleRoute;
|
||||
import basics.route.VehicleType;
|
||||
import basics.route.VehicleTypeImpl;
|
||||
|
||||
public class VrpXMLReader{
|
||||
|
||||
|
|
@ -255,7 +256,7 @@ public class VrpXMLReader{
|
|||
private void readVehiclesAndTheirTypes(XMLConfiguration vrpProblem) {
|
||||
|
||||
//read vehicle-types
|
||||
Map<String, VehicleType> types = new HashMap<String, VehicleType>();
|
||||
Map<String, VehicleTypeImpl> types = new HashMap<String, VehicleTypeImpl>();
|
||||
List<HierarchicalConfiguration> typeConfigs = vrpProblem.configurationsAt("vehicleTypes.type");
|
||||
for(HierarchicalConfiguration typeConfig : typeConfigs){
|
||||
String typeId = typeConfig.getString("id");
|
||||
|
|
@ -267,12 +268,12 @@ public class VrpXMLReader{
|
|||
// Double end = typeConfig.getDouble("timeSchedule.end");
|
||||
if(typeId == null) throw new IllegalStateException("typeId is missing.");
|
||||
if(capacity == null) throw new IllegalStateException("capacity is missing.");
|
||||
VehicleType.Builder typeBuilder = VehicleType.Builder.newInstance(typeId, capacity);
|
||||
VehicleTypeImpl.Builder typeBuilder = VehicleTypeImpl.Builder.newInstance(typeId, capacity);
|
||||
if(fix != null) typeBuilder.setFixedCost(fix);
|
||||
if(timeC != null) typeBuilder.setCostPerTime(timeC);
|
||||
if(distC != null) typeBuilder.setCostPerDistance(distC);
|
||||
// if(start != null && end != null) typeBuilder.setTimeSchedule(new TimeSchedule(start, end));
|
||||
VehicleType type = typeBuilder.build();
|
||||
VehicleTypeImpl type = typeBuilder.build();
|
||||
types.put(type.typeId, type);
|
||||
vrpBuilder.addVehicleType(type);
|
||||
}
|
||||
|
|
@ -286,7 +287,7 @@ public class VrpXMLReader{
|
|||
VehicleBuilder builder = VehicleImpl.VehicleBuilder.newInstance(vehicleId);
|
||||
String typeId = vehicleConfig.getString("typeId");
|
||||
if(typeId == null) throw new IllegalStateException("typeId is missing.");
|
||||
VehicleType type = types.get(typeId);
|
||||
VehicleTypeImpl type = types.get(typeId);
|
||||
if(type == null) throw new IllegalStateException("vehicleType with typeId " + typeId + " is missing.");
|
||||
builder.setType(type);
|
||||
String locationId = vehicleConfig.getString("location.id");
|
||||
|
|
|
|||
|
|
@ -40,8 +40,8 @@ import basics.VehicleRoutingProblemSolution;
|
|||
import basics.route.ServiceActivity;
|
||||
import basics.route.TourActivity;
|
||||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleImpl.VehicleType;
|
||||
import basics.route.VehicleRoute;
|
||||
import basics.route.VehicleType;
|
||||
|
||||
public class VrpXMLWriter {
|
||||
|
||||
|
|
@ -226,7 +226,7 @@ public class VrpXMLWriter {
|
|||
int counter = 0;
|
||||
for(Vehicle vehicle : vrp.getVehicles()){
|
||||
xmlConfig.setProperty(vehiclePathString + "("+counter+").id", vehicle.getId());
|
||||
xmlConfig.setProperty(vehiclePathString + "("+counter+").typeId", vehicle.getType().typeId);
|
||||
xmlConfig.setProperty(vehiclePathString + "("+counter+").typeId", vehicle.getType().getTypeId());
|
||||
xmlConfig.setProperty(vehiclePathString + "("+counter+").location.id", vehicle.getLocationId());
|
||||
if(vehicle.getCoord() != null){
|
||||
xmlConfig.setProperty(vehiclePathString + "("+counter+").location.coord[@x]", vehicle.getCoord().getX());
|
||||
|
|
@ -248,13 +248,13 @@ public class VrpXMLWriter {
|
|||
String typePathString = Schema.builder().append(Schema.TYPES).dot(Schema.TYPE).build();
|
||||
int typeCounter = 0;
|
||||
for(VehicleType type : vrp.getTypes()){
|
||||
xmlConfig.setProperty(typePathString + "("+typeCounter+").id", type.typeId);
|
||||
xmlConfig.setProperty(typePathString + "("+typeCounter+").capacity", type.capacity);
|
||||
xmlConfig.setProperty(typePathString + "("+typeCounter+").id", type.getTypeId());
|
||||
xmlConfig.setProperty(typePathString + "("+typeCounter+").capacity", type.getCapacity());
|
||||
// xmlConfig.setProperty(typePathString + "("+typeCounter+").timeSchedule.start", type.getTimeSchedule().getEarliestStart());
|
||||
// xmlConfig.setProperty(typePathString + "("+typeCounter+").timeSchedule.end", type.getTimeSchedule().getLatestEnd());
|
||||
xmlConfig.setProperty(typePathString + "("+typeCounter+").costs.fixed", type.vehicleCostParams.fix);
|
||||
xmlConfig.setProperty(typePathString + "("+typeCounter+").costs.distance", type.vehicleCostParams.perDistanceUnit);
|
||||
xmlConfig.setProperty(typePathString + "("+typeCounter+").costs.time", type.vehicleCostParams.perTimeUnit);
|
||||
xmlConfig.setProperty(typePathString + "("+typeCounter+").costs.fixed", type.getVehicleCostParams().fix);
|
||||
xmlConfig.setProperty(typePathString + "("+typeCounter+").costs.distance", type.getVehicleCostParams().perDistanceUnit);
|
||||
xmlConfig.setProperty(typePathString + "("+typeCounter+").costs.time", type.getVehicleCostParams().perTimeUnit);
|
||||
typeCounter++;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@
|
|||
******************************************************************************/
|
||||
package basics.route;
|
||||
|
||||
import basics.route.VehicleImpl.VehicleType;
|
||||
|
||||
|
||||
public class DefaultVehicleRouteCostCalculator implements VehicleRouteCostCalculator {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
package basics.route;
|
||||
|
||||
import basics.route.VehicleTypeImpl.VehicleCostParams;
|
||||
|
||||
public class PenaltyVehicleType implements VehicleType{
|
||||
|
||||
private VehicleType type;
|
||||
|
||||
public PenaltyVehicleType(VehicleType type) {
|
||||
super();
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeId() {
|
||||
return type.getTypeId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCapacity() {
|
||||
return type.getCapacity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VehicleCostParams getVehicleCostParams() {
|
||||
return type.getVehicleCostParams();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -21,7 +21,6 @@
|
|||
package basics.route;
|
||||
|
||||
import util.Coordinate;
|
||||
import basics.route.VehicleImpl.VehicleType;
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ public class VehicleImpl implements Vehicle {
|
|||
public static class NoVehicle extends VehicleImpl {
|
||||
|
||||
public NoVehicle() {
|
||||
super(VehicleBuilder.newInstance("noVehicle").setType(VehicleType.newInstance(null, 0, null)));
|
||||
super(VehicleBuilder.newInstance("noVehicle").setType(VehicleTypeImpl.newInstance(null, 0, null)));
|
||||
}
|
||||
|
||||
public int getCapacity(){
|
||||
|
|
@ -40,129 +40,6 @@ public class VehicleImpl implements Vehicle {
|
|||
|
||||
}
|
||||
|
||||
public static class VehicleType {
|
||||
|
||||
public static class Builder{
|
||||
|
||||
public static Builder newInstance(String id, int capacity){
|
||||
return new Builder(id,capacity);
|
||||
}
|
||||
|
||||
private String id;
|
||||
private int capacity;
|
||||
/**
|
||||
* 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();
|
||||
this.id = id;
|
||||
this.capacity = capacity;
|
||||
}
|
||||
|
||||
public Builder setFixedCost(double fixedCost) { this.fixedCost = fixedCost; return this; }
|
||||
|
||||
public Builder setCostPerDistance(double perDistance){ this.perDistance = perDistance; return this; }
|
||||
|
||||
public Builder setCostPerTime(double perTime){ this.perTime = perTime; return this; }
|
||||
|
||||
public VehicleType build(){
|
||||
return new VehicleType(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result
|
||||
+ ((typeId == null) ? 0 : typeId.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
VehicleType other = (VehicleType) obj;
|
||||
if (typeId == null) {
|
||||
if (other.typeId != null)
|
||||
return false;
|
||||
} else if (!typeId.equals(other.typeId))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public final String typeId;
|
||||
public final int capacity;
|
||||
public final VehicleCostParams vehicleCostParams;
|
||||
|
||||
public static VehicleType newInstance(String typeId, int capacity, VehicleCostParams para){
|
||||
return new VehicleType(typeId, capacity, para);
|
||||
}
|
||||
|
||||
private VehicleType(Builder builder){
|
||||
typeId = builder.id;
|
||||
capacity = builder.capacity;
|
||||
vehicleCostParams = new VehicleCostParams(builder.fixedCost, builder.perTime, builder.perDistance);
|
||||
}
|
||||
|
||||
public VehicleType(String typeId, int capacity,VehicleCostParams vehicleCostParams) {
|
||||
super();
|
||||
this.typeId = typeId;
|
||||
this.capacity = capacity;
|
||||
this.vehicleCostParams = vehicleCostParams;
|
||||
}
|
||||
|
||||
public String getTypeId() {
|
||||
return typeId;
|
||||
}
|
||||
|
||||
public int getCapacity() {
|
||||
return capacity;
|
||||
}
|
||||
|
||||
public VehicleCostParams getVehicleCostParams() {
|
||||
return vehicleCostParams;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[typeId="+typeId+"][capacity="+capacity+"]" + vehicleCostParams;
|
||||
}
|
||||
}
|
||||
|
||||
public static class VehicleCostParams {
|
||||
|
||||
public static VehicleCostParams newInstance(double fix, double perTimeUnit,double perDistanceUnit){
|
||||
return new VehicleCostParams(fix, perTimeUnit, perDistanceUnit);
|
||||
}
|
||||
|
||||
public final double fix;
|
||||
public final double perTimeUnit;
|
||||
public final double perDistanceUnit;
|
||||
|
||||
private VehicleCostParams(double fix, double perTimeUnit,double perDistanceUnit) {
|
||||
super();
|
||||
this.fix = fix;
|
||||
this.perTimeUnit = perTimeUnit;
|
||||
this.perDistanceUnit = perDistanceUnit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[fixed="+fix+"][perTime="+perTimeUnit+"][perDistance="+perDistanceUnit+"]";
|
||||
}
|
||||
}
|
||||
|
||||
public static class VehicleBuilder {
|
||||
static Logger log = Logger.getLogger(VehicleBuilder.class);
|
||||
private String id;
|
||||
|
|
@ -172,7 +49,7 @@ public class VehicleImpl implements Vehicle {
|
|||
private double earliestStart = 0.0;
|
||||
private double latestArrival = Double.MAX_VALUE;
|
||||
|
||||
private VehicleType type = VehicleType.Builder.newInstance("default", 0).build();
|
||||
private VehicleType type = VehicleTypeImpl.Builder.newInstance("default", 0).build();
|
||||
|
||||
private VehicleBuilder(String id) {
|
||||
super();
|
||||
|
|
@ -309,7 +186,7 @@ public class VehicleImpl implements Vehicle {
|
|||
*/
|
||||
@Override
|
||||
public int getCapacity() {
|
||||
return type.capacity;
|
||||
return type.getCapacity();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
14
jsprit-core/src/main/java/basics/route/VehicleType.java
Normal file
14
jsprit-core/src/main/java/basics/route/VehicleType.java
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
package basics.route;
|
||||
|
||||
import basics.route.VehicleTypeImpl.VehicleCostParams;
|
||||
|
||||
|
||||
public interface VehicleType {
|
||||
|
||||
public String getTypeId();
|
||||
|
||||
public int getCapacity();
|
||||
|
||||
public VehicleCostParams getVehicleCostParams();
|
||||
|
||||
}
|
||||
138
jsprit-core/src/main/java/basics/route/VehicleTypeImpl.java
Normal file
138
jsprit-core/src/main/java/basics/route/VehicleTypeImpl.java
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
package basics.route;
|
||||
|
||||
|
||||
public class VehicleTypeImpl implements VehicleType {
|
||||
|
||||
public static class VehicleCostParams {
|
||||
|
||||
public static VehicleTypeImpl.VehicleCostParams newInstance(double fix, double perTimeUnit,double perDistanceUnit){
|
||||
return new VehicleCostParams(fix, perTimeUnit, perDistanceUnit);
|
||||
}
|
||||
|
||||
public final double fix;
|
||||
public final double perTimeUnit;
|
||||
public final double perDistanceUnit;
|
||||
|
||||
private VehicleCostParams(double fix, double perTimeUnit,double perDistanceUnit) {
|
||||
super();
|
||||
this.fix = fix;
|
||||
this.perTimeUnit = perTimeUnit;
|
||||
this.perDistanceUnit = perDistanceUnit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[fixed="+fix+"][perTime="+perTimeUnit+"][perDistance="+perDistanceUnit+"]";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class Builder{
|
||||
|
||||
public static VehicleTypeImpl.Builder newInstance(String id, int capacity){
|
||||
return new Builder(id,capacity);
|
||||
}
|
||||
|
||||
private String id;
|
||||
private int capacity;
|
||||
/**
|
||||
* 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();
|
||||
this.id = id;
|
||||
this.capacity = capacity;
|
||||
}
|
||||
|
||||
public VehicleTypeImpl.Builder setFixedCost(double fixedCost) { this.fixedCost = fixedCost; return this; }
|
||||
|
||||
public VehicleTypeImpl.Builder setCostPerDistance(double perDistance){ this.perDistance = perDistance; return this; }
|
||||
|
||||
public VehicleTypeImpl.Builder setCostPerTime(double perTime){ this.perTime = perTime; return this; }
|
||||
|
||||
public VehicleTypeImpl build(){
|
||||
return new VehicleTypeImpl(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result
|
||||
+ ((typeId == null) ? 0 : typeId.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
VehicleTypeImpl other = (VehicleTypeImpl) obj;
|
||||
if (typeId == null) {
|
||||
if (other.typeId != null)
|
||||
return false;
|
||||
} else if (!typeId.equals(other.typeId))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public final String typeId;
|
||||
public final int capacity;
|
||||
public final VehicleTypeImpl.VehicleCostParams vehicleCostParams;
|
||||
|
||||
public static VehicleTypeImpl newInstance(String typeId, int capacity, VehicleTypeImpl.VehicleCostParams para){
|
||||
return new VehicleTypeImpl(typeId, capacity, para);
|
||||
}
|
||||
|
||||
private VehicleTypeImpl(VehicleTypeImpl.Builder builder){
|
||||
typeId = builder.id;
|
||||
capacity = builder.capacity;
|
||||
vehicleCostParams = new VehicleCostParams(builder.fixedCost, builder.perTime, builder.perDistance);
|
||||
}
|
||||
|
||||
public VehicleTypeImpl(String typeId, int capacity,VehicleTypeImpl.VehicleCostParams vehicleCostParams) {
|
||||
super();
|
||||
this.typeId = typeId;
|
||||
this.capacity = capacity;
|
||||
this.vehicleCostParams = vehicleCostParams;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see basics.route.VehicleType#getTypeId()
|
||||
*/
|
||||
@Override
|
||||
public String getTypeId() {
|
||||
return typeId;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see basics.route.VehicleType#getCapacity()
|
||||
*/
|
||||
@Override
|
||||
public int getCapacity() {
|
||||
return capacity;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see basics.route.VehicleType#getVehicleCostParams()
|
||||
*/
|
||||
@Override
|
||||
public VehicleTypeImpl.VehicleCostParams getVehicleCostParams() {
|
||||
return vehicleCostParams;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[typeId="+typeId+"][capacity="+capacity+"]" + vehicleCostParams;
|
||||
}
|
||||
}
|
||||
|
|
@ -20,7 +20,6 @@ import org.apache.log4j.Logger;
|
|||
import basics.costs.VehicleRoutingTransportCosts;
|
||||
import basics.route.Driver;
|
||||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleImpl.VehicleType;
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ public class RouteUtils {
|
|||
if(r.getTourActivities().isEmpty()){
|
||||
continue;
|
||||
}
|
||||
total += r.getVehicle().getType().vehicleCostParams.fix;
|
||||
total += r.getVehicle().getType().getVehicleCostParams().fix;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue