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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,17 +25,15 @@ import static org.junit.Assert.assertThat;
|
|||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import algorithms.VehicleFleetManager.TypeKey;
|
||||
import basics.Service;
|
||||
import basics.route.TimeWindow;
|
||||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleImpl;
|
||||
import basics.route.VehicleRoute;
|
||||
import basics.route.VehicleTypeImpl;
|
||||
|
||||
|
||||
|
||||
|
|
@ -53,18 +51,13 @@ public class CalcVehicleTypeDependentServiceInsertionTest {
|
|||
public void doBefore(){
|
||||
veh1 = mock(Vehicle.class);
|
||||
veh2 = mock(Vehicle.class);
|
||||
when(veh1.getType()).thenReturn(VehicleImpl.VehicleType.Builder.newInstance("type1", 0).build());
|
||||
when(veh2.getType()).thenReturn(VehicleImpl.VehicleType.Builder.newInstance("type2", 0).build());
|
||||
when(veh1.getType()).thenReturn(VehicleTypeImpl.Builder.newInstance("type1", 0).build());
|
||||
when(veh2.getType()).thenReturn(VehicleTypeImpl.Builder.newInstance("type2", 0).build());
|
||||
when(veh1.getLocationId()).thenReturn("loc1");
|
||||
when(veh2.getLocationId()).thenReturn("loc2");
|
||||
fleetManager = mock(VehicleFleetManager.class);
|
||||
service = mock(Service.class);
|
||||
vehicleRoute = mock(VehicleRoute.class);
|
||||
TypeKey typeKey1 = new TypeKey(veh1.getType().getTypeId(),veh1.getLocationId());
|
||||
TypeKey typeKey2 = new TypeKey(veh2.getType().getTypeId(),veh2.getLocationId());
|
||||
when(fleetManager.getAvailableVehicleTypes()).thenReturn(Arrays.asList(typeKey1,typeKey2));
|
||||
when(fleetManager.getEmptyVehicle(typeKey1)).thenReturn(veh1);
|
||||
when(fleetManager.getEmptyVehicle(typeKey2)).thenReturn(veh2);
|
||||
|
||||
when(veh1.getCapacity()).thenReturn(10);
|
||||
when(veh2.getCapacity()).thenReturn(10);
|
||||
|
|
|
|||
|
|
@ -36,8 +36,8 @@ import basics.costs.VehicleRoutingTransportCosts;
|
|||
import basics.route.Driver;
|
||||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleImpl;
|
||||
import basics.route.VehicleImpl.VehicleType;
|
||||
import basics.route.VehicleRoute;
|
||||
import basics.route.VehicleTypeImpl;
|
||||
|
||||
public class CalcWithTimeSchedulingTest {
|
||||
|
||||
|
|
@ -46,7 +46,7 @@ public class CalcWithTimeSchedulingTest {
|
|||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
Vehicle vehicle = VehicleImpl.VehicleBuilder.newInstance("myVehicle").setEarliestStart(0.0).setLatestArrival(100.0).
|
||||
setLocationCoord(Coordinate.newInstance(0, 0)).setLocationId("0,0")
|
||||
.setType(VehicleType.Builder.newInstance("myType", 20).setCostPerDistance(1.0).build()).build();
|
||||
.setType(VehicleTypeImpl.Builder.newInstance("myType", 20).setCostPerDistance(1.0).build()).build();
|
||||
vrpBuilder.addVehicle(vehicle);
|
||||
vrpBuilder.addService(Service.Builder.newInstance("myService", 2).setLocationId("0,20").setCoord(Coordinate.newInstance(0, 20)).build());
|
||||
vrpBuilder.setFleetSize(FleetSize.INFINITE);
|
||||
|
|
|
|||
|
|
@ -44,8 +44,9 @@ import basics.route.TimeWindow;
|
|||
import basics.route.TourActivities;
|
||||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleImpl;
|
||||
import basics.route.VehicleImpl.VehicleType;
|
||||
import basics.route.VehicleRoute;
|
||||
import basics.route.VehicleType;
|
||||
import basics.route.VehicleTypeImpl;
|
||||
|
||||
public class GendreauPostOptTest {
|
||||
|
||||
|
|
@ -109,7 +110,7 @@ public class GendreauPostOptTest {
|
|||
|
||||
double costPerDistanceUnit;
|
||||
if(vehicle != null){
|
||||
costPerDistanceUnit = vehicle.getType().vehicleCostParams.perDistanceUnit;
|
||||
costPerDistanceUnit = vehicle.getType().getVehicleCostParams().perDistanceUnit;
|
||||
}
|
||||
else{
|
||||
costPerDistanceUnit = 1;
|
||||
|
|
@ -124,8 +125,8 @@ public class GendreauPostOptTest {
|
|||
}
|
||||
};
|
||||
|
||||
VehicleType lightType = VehicleImpl.VehicleType.Builder.newInstance("light", 10).setFixedCost(10).setCostPerDistance(1.0).build();
|
||||
VehicleType heavyType = VehicleImpl.VehicleType.Builder.newInstance("heavy", 10).setFixedCost(30).setCostPerDistance(2.0).build();
|
||||
VehicleTypeImpl lightType = VehicleTypeImpl.Builder.newInstance("light", 10).setFixedCost(10).setCostPerDistance(1.0).build();
|
||||
VehicleTypeImpl heavyType = VehicleTypeImpl.Builder.newInstance("heavy", 10).setFixedCost(30).setCostPerDistance(2.0).build();
|
||||
|
||||
lightVehicle1 = VehicleImpl.VehicleBuilder.newInstance("light").setLocationId("0,0").setType(lightType).build();
|
||||
lightVehicle2 = VehicleImpl.VehicleBuilder.newInstance("light2").setLocationId("0,0").setType(lightType).build();
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
******************************************************************************/
|
||||
package algorithms;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.util.Collection;
|
||||
|
|
@ -40,7 +40,8 @@ import basics.route.TimeWindow;
|
|||
import basics.route.TourActivity;
|
||||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleImpl;
|
||||
import basics.route.VehicleImpl.VehicleType;
|
||||
import basics.route.VehicleType;
|
||||
import basics.route.VehicleTypeImpl;
|
||||
|
||||
public class TestDepartureTimeOpt {
|
||||
|
||||
|
|
@ -48,9 +49,9 @@ public class TestDepartureTimeOpt {
|
|||
public void whenSettingOneCustWithTWAnd_NO_DepTimeChoice_totalCostsShouldBe50(){
|
||||
TimeWindow timeWindow = TimeWindow.newInstance(40, 45);
|
||||
Service service = Service.Builder.newInstance("s", 0).setLocationId("servLoc").setCoord(Coordinate.newInstance(0, 10)).setTimeWindow(timeWindow).build();
|
||||
VehicleType type = mock(VehicleType.class);
|
||||
VehicleType type = mock(VehicleTypeImpl.class);
|
||||
Vehicle vehicle = VehicleImpl.VehicleBuilder.newInstance("v").setLocationId("vehLoc").setLocationCoord(Coordinate.newInstance(0, 0))
|
||||
.setType(VehicleType.Builder.newInstance("vType", 0).build()).build();
|
||||
.setType(VehicleTypeImpl.Builder.newInstance("vType", 0).build()).build();
|
||||
|
||||
Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
vrpBuilder.setActivityCosts(new VehicleRoutingActivityCosts(){
|
||||
|
|
@ -76,9 +77,9 @@ public class TestDepartureTimeOpt {
|
|||
public void whenSettingOneCustWithTWAnd_NO_DepTimeChoice_depTimeShouldBe0(){
|
||||
TimeWindow timeWindow = TimeWindow.newInstance(40, 45);
|
||||
Service service = Service.Builder.newInstance("s", 0).setLocationId("servLoc").setCoord(Coordinate.newInstance(0, 10)).setTimeWindow(timeWindow).build();
|
||||
VehicleType type = mock(VehicleType.class);
|
||||
VehicleType type = mock(VehicleTypeImpl.class);
|
||||
Vehicle vehicle = VehicleImpl.VehicleBuilder.newInstance("v").setLocationId("vehLoc").setLocationCoord(Coordinate.newInstance(0, 0))
|
||||
.setType(VehicleType.Builder.newInstance("vType", 0).build()).build();
|
||||
.setType(VehicleTypeImpl.Builder.newInstance("vType", 0).build()).build();
|
||||
|
||||
Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
vrpBuilder.setActivityCosts(new VehicleRoutingActivityCosts(){
|
||||
|
|
@ -105,7 +106,7 @@ public class TestDepartureTimeOpt {
|
|||
TimeWindow timeWindow = TimeWindow.newInstance(40, 45);
|
||||
Service service = Service.Builder.newInstance("s", 0).setLocationId("servLoc").setCoord(Coordinate.newInstance(0, 10)).setTimeWindow(timeWindow).build();
|
||||
Vehicle vehicle = VehicleImpl.VehicleBuilder.newInstance("v").setLocationId("vehLoc").setLocationCoord(Coordinate.newInstance(0, 0))
|
||||
.setType(VehicleType.Builder.newInstance("vType", 0).build()).build();
|
||||
.setType(VehicleTypeImpl.Builder.newInstance("vType", 0).build()).build();
|
||||
|
||||
Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
vrpBuilder.setActivityCosts(new VehicleRoutingActivityCosts(){
|
||||
|
|
@ -133,7 +134,7 @@ public class TestDepartureTimeOpt {
|
|||
TimeWindow timeWindow = TimeWindow.newInstance(40, 45);
|
||||
Service service = Service.Builder.newInstance("s", 0).setLocationId("servLoc").setCoord(Coordinate.newInstance(0, 10)).setTimeWindow(timeWindow).build();
|
||||
Vehicle vehicle = VehicleImpl.VehicleBuilder.newInstance("v").setLocationId("vehLoc").setLocationCoord(Coordinate.newInstance(0, 0))
|
||||
.setType(VehicleType.Builder.newInstance("vType", 0).build()).build();
|
||||
.setType(VehicleTypeImpl.Builder.newInstance("vType", 0).build()).build();
|
||||
|
||||
Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
vrpBuilder.setActivityCosts(new VehicleRoutingActivityCosts(){
|
||||
|
|
@ -165,7 +166,7 @@ public class TestDepartureTimeOpt {
|
|||
setTimeWindow(TimeWindow.newInstance(30, 40)).build();
|
||||
|
||||
Vehicle vehicle = VehicleImpl.VehicleBuilder.newInstance("v").setLocationId("vehLoc").setLocationCoord(Coordinate.newInstance(0, 0))
|
||||
.setType(VehicleType.Builder.newInstance("vType", 0).build()).build();
|
||||
.setType(VehicleTypeImpl.Builder.newInstance("vType", 0).build()).build();
|
||||
|
||||
Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
vrpBuilder.setActivityCosts(new VehicleRoutingActivityCosts(){
|
||||
|
|
@ -197,7 +198,7 @@ public class TestDepartureTimeOpt {
|
|||
setTimeWindow(TimeWindow.newInstance(30, 40)).build();
|
||||
|
||||
Vehicle vehicle = VehicleImpl.VehicleBuilder.newInstance("v").setLocationId("vehLoc").setLocationCoord(Coordinate.newInstance(0, 0))
|
||||
.setType(VehicleType.Builder.newInstance("vType", 0).build()).build();
|
||||
.setType(VehicleTypeImpl.Builder.newInstance("vType", 0).build()).build();
|
||||
|
||||
Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
vrpBuilder.setActivityCosts(new VehicleRoutingActivityCosts(){
|
||||
|
|
|
|||
|
|
@ -36,8 +36,9 @@ import basics.route.TimeWindow;
|
|||
import basics.route.TourActivities;
|
||||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleImpl;
|
||||
import basics.route.VehicleImpl.VehicleType;
|
||||
import basics.route.VehicleRoute;
|
||||
import basics.route.VehicleType;
|
||||
import basics.route.VehicleTypeImpl;
|
||||
|
||||
|
||||
public class TestTourStateUpdaterWithService {
|
||||
|
|
@ -102,7 +103,7 @@ public class TestTourStateUpdaterWithService {
|
|||
states = new RouteStates();
|
||||
states.initialiseStateOfJobs(services);
|
||||
|
||||
VehicleType type = VehicleImpl.VehicleType.Builder.newInstance("test", 0).build();
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("test", 0).build();
|
||||
vehicle = VehicleImpl.VehicleBuilder.newInstance("testvehicle").setType(type).setLocationId("0,0")
|
||||
.setEarliestStart(0.0).setLatestArrival(50.0).build();
|
||||
|
||||
|
|
|
|||
|
|
@ -24,17 +24,11 @@ import java.util.ArrayList;
|
|||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import algorithms.VehicleFleetManager.TypeKey;
|
||||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleImpl;
|
||||
import basics.route.VehicleImpl.VehicleBuilder;
|
||||
import basics.route.VehicleImpl.VehicleType;
|
||||
import basics.route.VehicleImpl.VehicleType.Builder;
|
||||
|
||||
import algorithms.VehicleFleetManager;
|
||||
import algorithms.VehicleFleetManagerImpl;
|
||||
import algorithms.VehicleFleetManager.TypeKey;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import basics.route.VehicleTypeImpl;
|
||||
|
||||
public class TestVehicleFleetManager extends TestCase{
|
||||
|
||||
|
|
@ -47,8 +41,8 @@ public class TestVehicleFleetManager extends TestCase{
|
|||
public void setUp(){
|
||||
List<Vehicle> vehicles = new ArrayList<Vehicle>();
|
||||
|
||||
v1 = VehicleImpl.VehicleBuilder.newInstance("standard").setLocationId("loc").setType(VehicleImpl.VehicleType.Builder.newInstance("standard", 0).build()).build();
|
||||
v2 = VehicleImpl.VehicleBuilder.newInstance("foo").setLocationId("fooLoc").setType(VehicleImpl.VehicleType.Builder.newInstance("foo", 0).build()).build();
|
||||
v1 = VehicleImpl.VehicleBuilder.newInstance("standard").setLocationId("loc").setType(VehicleTypeImpl.Builder.newInstance("standard", 0).build()).build();
|
||||
v2 = VehicleImpl.VehicleBuilder.newInstance("foo").setLocationId("fooLoc").setType(VehicleTypeImpl.Builder.newInstance("foo", 0).build()).build();
|
||||
|
||||
vehicles.add(v1);
|
||||
vehicles.add(v2);
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ import org.junit.Test;
|
|||
import basics.VehicleRoutingProblem.FleetSize;
|
||||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleImpl;
|
||||
import basics.route.VehicleImpl.VehicleType;
|
||||
import basics.route.VehicleTypeImpl;
|
||||
|
||||
public class VehicleRoutingProblemBuilderTest {
|
||||
|
||||
|
|
@ -48,8 +48,8 @@ public class VehicleRoutingProblemBuilderTest {
|
|||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
builder.setFleetSize(FleetSize.FINITE);
|
||||
|
||||
VehicleType type1 = VehicleType.Builder.newInstance("t1", 20).build();
|
||||
VehicleType type2 = VehicleType.Builder.newInstance("t2", 200).build();
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("t1", 20).build();
|
||||
VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("t2", 200).build();
|
||||
|
||||
Vehicle v1 = VehicleImpl.VehicleBuilder.newInstance("v1").setLocationId("yo").setType(type1).build();
|
||||
Vehicle v2 = VehicleImpl.VehicleBuilder.newInstance("v2").setLocationId("yo").setType(type1).build();
|
||||
|
|
|
|||
|
|
@ -43,7 +43,8 @@ import basics.route.Start;
|
|||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleImpl;
|
||||
import basics.route.VehicleRoute;
|
||||
import basics.route.VehicleImpl.VehicleType;
|
||||
import basics.route.VehicleType;
|
||||
import basics.route.VehicleTypeImpl;
|
||||
|
||||
public class VrpWriterV2Test {
|
||||
|
||||
|
|
@ -65,7 +66,7 @@ public class VrpWriterV2Test {
|
|||
// builder.addDepot(depot2);
|
||||
// builder.assignVehicleType(depot, VehicleType.Builder.newInstance("vehType", 20).build());
|
||||
// builder.assignVehicleType(depot, VehicleType.Builder.newInstance("vehType2", 200).build());
|
||||
VehicleType type = VehicleType.Builder.newInstance("vehType", 20).build();
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("vehType", 20).build();
|
||||
Vehicle vehicle = VehicleImpl.VehicleBuilder.newInstance("myVehicle").setLocationId("loc").setType(type).build();
|
||||
builder.addVehicle(vehicle);
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
|
|
@ -80,8 +81,8 @@ public class VrpWriterV2Test {
|
|||
// Depot depot = new Depot("depotLoc",Coordinate.newInstance(0, 0));
|
||||
// Depot depot2 = new Depot("depotLoc2",Coordinate.newInstance(100, 100));
|
||||
// builder.addDepot(depot2);
|
||||
VehicleType type1 = VehicleType.Builder.newInstance("vehType", 20).build();
|
||||
VehicleType type2 = VehicleType.Builder.newInstance("vehType2", 200).build();
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType", 20).build();
|
||||
VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2", 200).build();
|
||||
Vehicle v1 = VehicleImpl.VehicleBuilder.newInstance("v1").setLocationId("loc").setType(type1).build();
|
||||
Vehicle v2 = VehicleImpl.VehicleBuilder.newInstance("v2").setLocationId("loc").setType(type2).build();
|
||||
builder.addVehicleType(type1);
|
||||
|
|
@ -100,8 +101,8 @@ public class VrpWriterV2Test {
|
|||
// Depot depot = new Depot("depotLoc",Coordinate.newInstance(0, 0));
|
||||
// Depot depot2 = new Depot("depotLoc2",Coordinate.newInstance(100, 100));
|
||||
// builder.addDepot(depot2);
|
||||
VehicleType type1 = VehicleType.Builder.newInstance("vehType", 20).build();
|
||||
VehicleType type2 = VehicleType.Builder.newInstance("vehType2", 200).build();
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType", 20).build();
|
||||
VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2", 200).build();
|
||||
Vehicle v1 = VehicleImpl.VehicleBuilder.newInstance("v1").setLocationId("loc").setType(type1).build();
|
||||
Vehicle v2 = VehicleImpl.VehicleBuilder.newInstance("v2").setLocationId("loc").setType(type2).build();
|
||||
builder.addVehicleType(type1);
|
||||
|
|
@ -119,8 +120,8 @@ public class VrpWriterV2Test {
|
|||
public void whenWritingServices_itWritesThemCorrectly(){
|
||||
Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
||||
VehicleType type1 = VehicleType.Builder.newInstance("vehType", 20).build();
|
||||
VehicleType type2 = VehicleType.Builder.newInstance("vehType2", 200).build();
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType", 20).build();
|
||||
VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2", 200).build();
|
||||
Vehicle v1 = VehicleImpl.VehicleBuilder.newInstance("v1").setLocationId("loc").setType(type1).build();
|
||||
Vehicle v2 = VehicleImpl.VehicleBuilder.newInstance("v2").setLocationId("loc").setType(type2).build();
|
||||
|
||||
|
|
@ -152,8 +153,8 @@ public class VrpWriterV2Test {
|
|||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
builder.setFleetComposition(FleetComposition.HETEROGENEOUS);
|
||||
builder.setFleetSize(FleetSize.FINITE);
|
||||
VehicleType type1 = VehicleType.Builder.newInstance("vehType", 20).build();
|
||||
VehicleType type2 = VehicleType.Builder.newInstance("vehType2", 200).build();
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType", 20).build();
|
||||
VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2", 200).build();
|
||||
Vehicle v1 = VehicleImpl.VehicleBuilder.newInstance("v1").setLocationId("loc").setType(type1).build();
|
||||
Vehicle v2 = VehicleImpl.VehicleBuilder.newInstance("v2").setLocationId("loc").setType(type2).build();
|
||||
builder.addVehicleType(type1);
|
||||
|
|
|
|||
|
|
@ -43,7 +43,8 @@ import basics.route.Start;
|
|||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleImpl;
|
||||
import basics.route.VehicleRoute;
|
||||
import basics.route.VehicleImpl.VehicleType;
|
||||
import basics.route.VehicleType;
|
||||
import basics.route.VehicleTypeImpl;
|
||||
|
||||
public class VrpWriterV3Test {
|
||||
|
||||
|
|
@ -59,8 +60,8 @@ public class VrpWriterV3Test {
|
|||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
builder.setFleetComposition(FleetComposition.HETEROGENEOUS);
|
||||
builder.setFleetSize(FleetSize.FINITE);
|
||||
VehicleType type1 = VehicleType.Builder.newInstance("vehType", 20).build();
|
||||
VehicleType type2 = VehicleType.Builder.newInstance("vehType2", 200).build();
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType", 20).build();
|
||||
VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2", 200).build();
|
||||
Vehicle v1 = VehicleImpl.VehicleBuilder.newInstance("v1").setLocationId("loc").setType(type1).build();
|
||||
Vehicle v2 = VehicleImpl.VehicleBuilder.newInstance("v2").setLocationId("loc").setType(type2).build();
|
||||
builder.addVehicleType(type1);
|
||||
|
|
|
|||
|
|
@ -29,15 +29,6 @@ import org.junit.Before;
|
|||
import org.junit.Test;
|
||||
|
||||
import basics.Service;
|
||||
import basics.Service.Builder;
|
||||
import basics.route.DriverImpl;
|
||||
import basics.route.ServiceActivity;
|
||||
import basics.route.Start;
|
||||
import basics.route.TourActivities;
|
||||
import basics.route.TourActivity;
|
||||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleImpl;
|
||||
import basics.route.VehicleRoute;
|
||||
import basics.route.DriverImpl.NoDriver;
|
||||
|
||||
public class TestVehicleRoute {
|
||||
|
|
@ -47,7 +38,7 @@ public class TestVehicleRoute {
|
|||
|
||||
@Before
|
||||
public void doBefore(){
|
||||
vehicle = VehicleImpl.VehicleBuilder.newInstance("v").setLocationId("loc").setType(VehicleImpl.VehicleType.Builder.newInstance("yo", 0).build()).build();
|
||||
vehicle = VehicleImpl.VehicleBuilder.newInstance("v").setLocationId("loc").setType(VehicleTypeImpl.Builder.newInstance("yo", 0).build()).build();
|
||||
driver = DriverImpl.noDriver();
|
||||
}
|
||||
|
||||
|
|
@ -97,7 +88,7 @@ public class TestVehicleRoute {
|
|||
@Test
|
||||
public void whenBuildingEmptyTour_tourIterIteratesOverAnEmptyList(){
|
||||
TourActivities tour = new TourActivities();
|
||||
Vehicle v = VehicleImpl.VehicleBuilder.newInstance("v").setLocationId("loc").setType(VehicleImpl.VehicleType.Builder.newInstance("yo", 0).build()).build();
|
||||
Vehicle v = VehicleImpl.VehicleBuilder.newInstance("v").setLocationId("loc").setType(VehicleTypeImpl.Builder.newInstance("yo", 0).build()).build();
|
||||
VehicleRoute route = VehicleRoute.newInstance(tour,DriverImpl.noDriver(),v);
|
||||
Iterator<TourActivity> iter = route.getTourActivities().iterator();
|
||||
int count = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue