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

Merge branch 'master' into vrph

This commit is contained in:
oblonski 2014-01-13 22:58:28 +01:00
commit e49fb8dd9b
2 changed files with 108 additions and 4 deletions

View file

@ -18,15 +18,42 @@ package jsprit.core.problem.vehicle;
import jsprit.core.problem.vehicle.VehicleTypeImpl.VehicleCostParams; import jsprit.core.problem.vehicle.VehicleTypeImpl.VehicleCostParams;
/**
* Basic interface for vehicle-type-data.
*
* @author schroeder
*
*/
public interface VehicleType { public interface VehicleType {
/**
* Returns typeId.
*
* @return typeId
*/
public String getTypeId(); public String getTypeId();
/**
* Returns capacity.
*
* <p>In future versions there will be a capacity-object with an arbitrary number of capacity dimensions. (stefan,11.01.14)
*
* @return cap
*/
public int getCapacity(); public int getCapacity();
/**
* Returns maximum velocity of this vehicle-type.
*
* @return max velocity
*/
public double getMaxVelocity(); public double getMaxVelocity();
/**
* Return the cost-parameter of this vehicle-type.
*
* @return parameter
*/
public VehicleCostParams getVehicleCostParams(); public VehicleCostParams getVehicleCostParams();
} }

View file

@ -16,9 +16,22 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.problem.vehicle; package jsprit.core.problem.vehicle;
/**
* Implementation of {@link VehicleType}.
*
* <p>Two vehicle-types are equal if they have the same typeId.
*
* @author schroeder
*
*/
public class VehicleTypeImpl implements VehicleType { public class VehicleTypeImpl implements VehicleType {
/**
* CostParameter consisting of fixed cost parameter, time-based cost parameter and distance-based cost parameter.
*
* @author schroeder
*
*/
public static class VehicleCostParams { public static class VehicleCostParams {
public static VehicleTypeImpl.VehicleCostParams newInstance(double fix, double perTimeUnit,double perDistanceUnit){ public static VehicleTypeImpl.VehicleCostParams newInstance(double fix, double perTimeUnit,double perDistanceUnit){
@ -42,9 +55,24 @@ public class VehicleTypeImpl implements VehicleType {
} }
} }
/**
* Builder that builds the vehicle-type.
*
* @author schroeder
*
*/
public static class Builder{ public static class Builder{
/**
* Returns a new instance.
*
* <p>Input parameters are id and capacity. Note that two vehicle-types are equal
* if they have the same vehicleId.
*
* @param id
* @param capacity
* @return
*/
public static VehicleTypeImpl.Builder newInstance(String id, int capacity){ public static VehicleTypeImpl.Builder newInstance(String id, int capacity){
return new Builder(id,capacity); return new Builder(id,capacity);
} }
@ -59,20 +87,61 @@ public class VehicleTypeImpl implements VehicleType {
private double perDistance = 1.0; private double perDistance = 1.0;
private double perTime = 0.0; private double perTime = 0.0;
public Builder(String id, int capacity) { /**
* Constructs the builder.
*
* @param id
* @param capacity
*/
private Builder(String id, int capacity) {
super(); super();
this.id = id; this.id = id;
this.capacity = capacity; this.capacity = capacity;
} }
/**
* Sets the maximum velocity this vehicle-type can go [in meter per seconds].
*
* @param inMeterPerSeconds
* @return this builder
*/
public VehicleTypeImpl.Builder setMaxVelocity(double inMeterPerSeconds){ this.maxVelo = inMeterPerSeconds; return this; } public VehicleTypeImpl.Builder setMaxVelocity(double inMeterPerSeconds){ this.maxVelo = inMeterPerSeconds; return this; }
/**
* Sets the fixed costs of the vehicle-type.
*
* <p>by default it is 0.
*
* @param fixedCost
* @return this builder
*/
public VehicleTypeImpl.Builder setFixedCost(double fixedCost) { this.fixedCost = fixedCost; return this; } public VehicleTypeImpl.Builder setFixedCost(double fixedCost) { this.fixedCost = fixedCost; return this; }
/**
* Sets the cost per distance unit, for instance per meter.
*
* <p>by default it is 1.0
*
* @param perDistance
* @return this builder
*/
public VehicleTypeImpl.Builder setCostPerDistance(double perDistance){ this.perDistance = perDistance; return this; } public VehicleTypeImpl.Builder setCostPerDistance(double perDistance){ this.perDistance = perDistance; return this; }
/**
* Sets cost per time unit, for instance per second.
*
* <p>by default it is 0.0
*
* @param perTime
* @return
*/
public VehicleTypeImpl.Builder setCostPerTime(double perTime){ this.perTime = perTime; return this; } public VehicleTypeImpl.Builder setCostPerTime(double perTime){ this.perTime = perTime; return this; }
/**
* Builds the vehicle-type.
*
* @return
*/
public VehicleTypeImpl build(){ public VehicleTypeImpl build(){
return new VehicleTypeImpl(this); return new VehicleTypeImpl(this);
} }
@ -88,6 +157,9 @@ public class VehicleTypeImpl implements VehicleType {
return result; return result;
} }
/**
* Two vehicle-types are equal if they have the same vehicleId.
*/
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj)
@ -121,6 +193,11 @@ public class VehicleTypeImpl implements VehicleType {
return new VehicleTypeImpl(typeId, capacity, para); return new VehicleTypeImpl(typeId, capacity, para);
} }
/**
* priv constructor constructing vehicle-type
*
* @param builder
*/
private VehicleTypeImpl(VehicleTypeImpl.Builder builder){ private VehicleTypeImpl(VehicleTypeImpl.Builder builder){
typeId = builder.id; typeId = builder.id;
capacity = builder.capacity; capacity = builder.capacity;