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

refine error messages

This commit is contained in:
oblonski 2017-11-30 09:49:00 +01:00
parent 76aa6938db
commit b610626b1d
No known key found for this signature in database
GPG key ID: 179DE487285680D1
5 changed files with 43 additions and 35 deletions

View file

@ -232,9 +232,9 @@ public class VehicleRoutingProblem {
*/ */
public Builder addJob(AbstractJob job) { public Builder addJob(AbstractJob job) {
if (tentativeJobs.containsKey(job.getId())) if (tentativeJobs.containsKey(job.getId()))
throw new IllegalArgumentException("vehicle routing problem already contains a service or shipment with id " + job.getId() + ". make sure you use unique ids for all services and shipments"); throw new IllegalArgumentException("The vehicle routing problem already contains a service or shipment with id " + job.getId() + ". Please make sure you use unique ids for all services and shipments.");
if (!(job instanceof Service || job instanceof Shipment)) if (!(job instanceof Service || job instanceof Shipment))
throw new IllegalArgumentException("job must be either a service or a shipment"); throw new IllegalArgumentException("Job must be either a service or a shipment.");
job.setIndex(jobIndexCounter); job.setIndex(jobIndexCounter);
incJobIndexCounter(); incJobIndexCounter();
tentativeJobs.put(job.getId(), job); tentativeJobs.put(job.getId(), job);
@ -285,10 +285,11 @@ public class VehicleRoutingProblem {
for (Vehicle v : uniqueVehicles) { for (Vehicle v : uniqueVehicles) {
if (v.getBreak() != null) { if (v.getBreak() != null) {
if (!uniqueBreakIds.add(v.getBreak().getId())) if (!uniqueBreakIds.add(v.getBreak().getId()))
throw new IllegalArgumentException("problem already contains a vehicle break with id " + v.getBreak().getId() + ". choose unique ids for each vehicle break."); throw new IllegalArgumentException("The vehicle routing roblem already contains a vehicle break with id " + v.getBreak().getId() + ". Please choose unique ids for each vehicle break.");
hasBreaks = true; hasBreaks = true;
List<AbstractActivity> breakActivities = jobActivityFactory.createActivities(v.getBreak()); List<AbstractActivity> breakActivities = jobActivityFactory.createActivities(v.getBreak());
if(breakActivities.isEmpty()) throw new IllegalArgumentException("at least one activity for break needs to be created by activityFactory"); if (breakActivities.isEmpty())
throw new IllegalArgumentException("At least one activity for break needs to be created by activityFactory.");
for(AbstractActivity act : breakActivities){ for(AbstractActivity act : breakActivities){
act.setIndex(activityIndexCounter); act.setIndex(activityIndexCounter);
incActivityIndexCounter(); incActivityIndexCounter();
@ -351,7 +352,7 @@ public class VehicleRoutingProblem {
private void addShipment(Shipment job) { private void addShipment(Shipment job) {
if (jobs.containsKey(job.getId())) { if (jobs.containsKey(job.getId())) {
logger.warn("job " + job + " already in job list. overrides existing job."); logger.warn("The job " + job + " has already been added to the job list. This overrides the existing job.");
} }
addLocationToTentativeLocations(job); addLocationToTentativeLocations(job);
// tentative_coordinates.put(job.getPickupLocation().getId(), job.getPickupLocation().getCoordinate()); // tentative_coordinates.put(job.getPickupLocation().getId(), job.getPickupLocation().getCoordinate());
@ -367,7 +368,7 @@ public class VehicleRoutingProblem {
* */ * */
public Builder addVehicle(Vehicle vehicle) { public Builder addVehicle(Vehicle vehicle) {
if (!(vehicle instanceof AbstractVehicle)) if (!(vehicle instanceof AbstractVehicle))
throw new IllegalArgumentException("vehicle must be an AbstractVehicle"); throw new IllegalArgumentException("A vehicle must be an AbstractVehicle.");
return addVehicle((AbstractVehicle) vehicle); return addVehicle((AbstractVehicle) vehicle);
} }
@ -379,7 +380,7 @@ public class VehicleRoutingProblem {
*/ */
public Builder addVehicle(AbstractVehicle vehicle) { public Builder addVehicle(AbstractVehicle vehicle) {
if(addedVehicleIds.contains(vehicle.getId())){ if(addedVehicleIds.contains(vehicle.getId())){
throw new IllegalArgumentException("problem already contains a vehicle with id " + vehicle.getId() + ". choose unique ids for each vehicle."); throw new IllegalArgumentException("The vehicle routing problem already contains a vehicle with id " + vehicle.getId() + ". Please choose unique ids for each vehicle.");
} }
else addedVehicleIds.add(vehicle.getId()); else addedVehicleIds.add(vehicle.getId());
if (!uniqueVehicles.contains(vehicle)) { if (!uniqueVehicles.contains(vehicle)) {
@ -443,7 +444,7 @@ public class VehicleRoutingProblem {
} }
boolean hasBreaks = addBreaksToActivityMap(); boolean hasBreaks = addBreaksToActivityMap();
if (hasBreaks && fleetSize.equals(FleetSize.INFINITE)) if (hasBreaks && fleetSize.equals(FleetSize.INFINITE))
throw new UnsupportedOperationException("breaks are not yet supported when dealing with infinite fleet. either set it to finite or omit breaks."); throw new UnsupportedOperationException("Breaks are not yet supported when dealing with infinite fleet. Either set it to finite or omit breaks.");
return new VehicleRoutingProblem(this); return new VehicleRoutingProblem(this);
} }
@ -510,7 +511,7 @@ public class VehicleRoutingProblem {
// tentative_coordinates.put(service.getLocation().getId(), service.getLocation().getCoordinate()); // tentative_coordinates.put(service.getLocation().getId(), service.getLocation().getCoordinate());
addLocationToTentativeLocations(service); addLocationToTentativeLocations(service);
if (jobs.containsKey(service.getId())) { if (jobs.containsKey(service.getId())) {
logger.warn("service " + service + " already in job list. overrides existing job."); logger.warn("The service " + service + " has already been added to job list. This overrides existing job.");
} }
jobs.put(service.getId(), service); jobs.put(service.getId(), service);
return this; return this;

View file

@ -30,6 +30,7 @@ import com.graphhopper.jsprit.core.problem.Skills;
*/ */
public interface Job extends HasId, HasIndex { public interface Job extends HasId, HasIndex {
/** /**
* Returns the unique identifier (id) of a job. * Returns the unique identifier (id) of a job.
* *

View file

@ -135,7 +135,7 @@ public class Service extends AbstractJob {
*/ */
public Builder<T> setServiceTime(double serviceTime) { public Builder<T> setServiceTime(double serviceTime) {
if (serviceTime < 0) if (serviceTime < 0)
throw new IllegalArgumentException("serviceTime must be greater than or equal to zero"); throw new IllegalArgumentException("The service time of a service must be greater than or equal to zero.");
this.serviceTime = serviceTime; this.serviceTime = serviceTime;
return this; return this;
} }
@ -167,20 +167,20 @@ public class Service extends AbstractJob {
* @throws IllegalArgumentException if dimensionValue < 0 * @throws IllegalArgumentException if dimensionValue < 0
*/ */
public Builder<T> addSizeDimension(int dimensionIndex, int dimensionValue) { public Builder<T> addSizeDimension(int dimensionIndex, int dimensionValue) {
if (dimensionValue < 0) throw new IllegalArgumentException("capacity value cannot be negative"); if (dimensionValue < 0) throw new IllegalArgumentException("The capacity value must not be negative.");
capacityBuilder.addDimension(dimensionIndex, dimensionValue); capacityBuilder.addDimension(dimensionIndex, dimensionValue);
return this; return this;
} }
public Builder<T> setTimeWindow(TimeWindow tw){ public Builder<T> setTimeWindow(TimeWindow tw){
if(tw == null) throw new IllegalArgumentException("time-window arg must not be null"); if (tw == null) throw new IllegalArgumentException("The time window must not be null.");
this.timeWindows = new TimeWindowsImpl(); this.timeWindows = new TimeWindowsImpl();
timeWindows.add(tw); timeWindows.add(tw);
return this; return this;
} }
public Builder<T> addTimeWindow(TimeWindow timeWindow) { public Builder<T> addTimeWindow(TimeWindow timeWindow) {
if(timeWindow == null) throw new IllegalArgumentException("time-window arg must not be null"); if (timeWindow == null) throw new IllegalArgumentException("The time window must not be null.");
if(!twAdded){ if(!twAdded){
timeWindows = new TimeWindowsImpl(); timeWindows = new TimeWindowsImpl();
twAdded = true; twAdded = true;
@ -205,7 +205,7 @@ public class Service extends AbstractJob {
* @throws IllegalArgumentException if neither locationId nor coordinate is set. * @throws IllegalArgumentException if neither locationId nor coordinate is set.
*/ */
public T build() { public T build() {
if (location == null) throw new IllegalArgumentException("location is missing"); if (location == null) throw new IllegalArgumentException("The location of service " + id + " is missing.");
this.setType("service"); this.setType("service");
capacity = capacityBuilder.build(); capacity = capacityBuilder.build();
skills = skillBuilder.build(); skills = skillBuilder.build();
@ -246,13 +246,13 @@ public class Service extends AbstractJob {
*/ */
public Builder<T> setPriority(int priority) { public Builder<T> setPriority(int priority) {
if (priority < 1 || priority > 10) if (priority < 1 || priority > 10)
throw new IllegalArgumentException("incorrect priority. only priority values from 1 to 10 are allowed where 1 = high and 10 is low"); throw new IllegalArgumentException("The priority value is not valid. Only 1 (very high) to 10 (very low) are allowed.");
this.priority = priority; this.priority = priority;
return this; return this;
} }
public Builder<T> setMaxTimeInVehicle(double maxTimeInVehicle){ public Builder<T> setMaxTimeInVehicle(double maxTimeInVehicle){
throw new UnsupportedOperationException("maxTimeInVehicle is not yet supported for Pickups and Services (only for Deliveries and Shipments)"); throw new UnsupportedOperationException("The maximum time in vehicle is not yet supported for Pickups and Services (only for Deliveries and Shipments).");
// if(maxTimeInVehicle < 0) throw new IllegalArgumentException("maxTimeInVehicle should be positive"); // if(maxTimeInVehicle < 0) throw new IllegalArgumentException("maxTimeInVehicle should be positive");
// this.maxTimeInVehicle = maxTimeInVehicle; // this.maxTimeInVehicle = maxTimeInVehicle;
// return this; // return this;

View file

@ -148,7 +148,8 @@ public class Shipment extends AbstractJob {
* @throws IllegalArgumentException if servicTime < 0.0 * @throws IllegalArgumentException if servicTime < 0.0
*/ */
public Builder setPickupServiceTime(double serviceTime) { public Builder setPickupServiceTime(double serviceTime) {
if (serviceTime < 0.0) throw new IllegalArgumentException("serviceTime must not be < 0.0"); if (serviceTime < 0.0)
throw new IllegalArgumentException("The service time of a shipment must not be < 0.0.");
this.pickupServiceTime = serviceTime; this.pickupServiceTime = serviceTime;
return this; return this;
} }
@ -164,7 +165,7 @@ public class Shipment extends AbstractJob {
* @throws IllegalArgumentException if timeWindow is null * @throws IllegalArgumentException if timeWindow is null
*/ */
public Builder setPickupTimeWindow(TimeWindow timeWindow) { public Builder setPickupTimeWindow(TimeWindow timeWindow) {
if (timeWindow == null) throw new IllegalArgumentException("delivery time-window must not be null"); if (timeWindow == null) throw new IllegalArgumentException("The delivery time window must not be null.");
this.pickupTimeWindows = new TimeWindowsImpl(); this.pickupTimeWindows = new TimeWindowsImpl();
this.pickupTimeWindows.add(timeWindow); this.pickupTimeWindows.add(timeWindow);
return this; return this;
@ -193,7 +194,8 @@ public class Shipment extends AbstractJob {
* @throws IllegalArgumentException if serviceTime < 0.0 * @throws IllegalArgumentException if serviceTime < 0.0
*/ */
public Builder setDeliveryServiceTime(double deliveryServiceTime) { public Builder setDeliveryServiceTime(double deliveryServiceTime) {
if (deliveryServiceTime < 0.0) throw new IllegalArgumentException("deliveryServiceTime must not be < 0.0"); if (deliveryServiceTime < 0.0)
throw new IllegalArgumentException("The service time of a delivery must not be < 0.0.");
this.deliveryServiceTime = deliveryServiceTime; this.deliveryServiceTime = deliveryServiceTime;
return this; return this;
} }
@ -209,7 +211,7 @@ public class Shipment extends AbstractJob {
* @throws IllegalArgumentException if timeWindow is null * @throws IllegalArgumentException if timeWindow is null
*/ */
public Builder setDeliveryTimeWindow(TimeWindow timeWindow) { public Builder setDeliveryTimeWindow(TimeWindow timeWindow) {
if (timeWindow == null) throw new IllegalArgumentException("delivery time-window must not be null"); if (timeWindow == null) throw new IllegalArgumentException("The delivery time window must not be null.");
this.deliveryTimeWindows = new TimeWindowsImpl(); this.deliveryTimeWindows = new TimeWindowsImpl();
this.deliveryTimeWindows.add(timeWindow); this.deliveryTimeWindows.add(timeWindow);
return this; return this;
@ -224,7 +226,8 @@ public class Shipment extends AbstractJob {
* @throws IllegalArgumentException if dimVal < 0 * @throws IllegalArgumentException if dimVal < 0
*/ */
public Builder addSizeDimension(int dimensionIndex, int dimensionValue) { public Builder addSizeDimension(int dimensionIndex, int dimensionValue) {
if (dimensionValue < 0) throw new IllegalArgumentException("capacity value cannot be negative"); if (dimensionValue < 0)
throw new IllegalArgumentException("The capacity value must not be negative, but is " + dimensionValue + ".");
capacityBuilder.addDimension(dimensionIndex, dimensionValue); capacityBuilder.addDimension(dimensionIndex, dimensionValue);
return this; return this;
} }
@ -245,8 +248,8 @@ public class Shipment extends AbstractJob {
* is set * is set
*/ */
public Shipment build() { public Shipment build() {
if (pickupLocation_ == null) throw new IllegalArgumentException("pickup location is missing"); if (pickupLocation_ == null) throw new IllegalArgumentException("The pickup location is missing.");
if (deliveryLocation_ == null) throw new IllegalArgumentException("delivery location is missing"); if (deliveryLocation_ == null) throw new IllegalArgumentException("The delivery location is missing.");
capacity = capacityBuilder.build(); capacity = capacityBuilder.build();
skills = skillBuilder.build(); skills = skillBuilder.build();
return new Shipment(this); return new Shipment(this);
@ -271,7 +274,7 @@ public class Shipment extends AbstractJob {
} }
public Builder addDeliveryTimeWindow(TimeWindow timeWindow) { public Builder addDeliveryTimeWindow(TimeWindow timeWindow) {
if(timeWindow == null) throw new IllegalArgumentException("time-window arg must not be null"); if (timeWindow == null) throw new IllegalArgumentException("The time window must not be null.");
if(!deliveryTimeWindowAdded){ if(!deliveryTimeWindowAdded){
deliveryTimeWindows = new TimeWindowsImpl(); deliveryTimeWindows = new TimeWindowsImpl();
deliveryTimeWindowAdded = true; deliveryTimeWindowAdded = true;
@ -291,7 +294,7 @@ public class Shipment extends AbstractJob {
} }
public Builder addPickupTimeWindow(TimeWindow timeWindow) { public Builder addPickupTimeWindow(TimeWindow timeWindow) {
if(timeWindow == null) throw new IllegalArgumentException("time-window arg must not be null"); if (timeWindow == null) throw new IllegalArgumentException("The time window must not be null.");
if(!pickupTimeWindowAdded){ if(!pickupTimeWindowAdded){
pickupTimeWindows = new TimeWindowsImpl(); pickupTimeWindows = new TimeWindowsImpl();
pickupTimeWindowAdded = true; pickupTimeWindowAdded = true;
@ -319,7 +322,7 @@ public class Shipment extends AbstractJob {
*/ */
public Builder setPriority(int priority) { public Builder setPriority(int priority) {
if (priority < 1 || priority > 10) if (priority < 1 || priority > 10)
throw new IllegalArgumentException("incorrect priority. only 1 (very high) to 10 (very low) are allowed"); throw new IllegalArgumentException("The priority value is not valid. Only 1 (very high) to 10 (very low) are allowed.");
this.priority = priority; this.priority = priority;
return this; return this;
} }
@ -331,7 +334,8 @@ public class Shipment extends AbstractJob {
* @return * @return
*/ */
public Builder setMaxTimeInVehicle(double maxTimeInVehicle){ public Builder setMaxTimeInVehicle(double maxTimeInVehicle){
if(maxTimeInVehicle < 0) throw new IllegalArgumentException("maxTimeInVehicle should be positive"); if (maxTimeInVehicle < 0)
throw new IllegalArgumentException("The maximum time in vehicle must be positive.");
this.maxTimeInVehicle = maxTimeInVehicle; this.maxTimeInVehicle = maxTimeInVehicle;
return this; return this;
} }

View file

@ -151,7 +151,8 @@ public class VehicleTypeImpl implements VehicleType {
* if velocity is smaller than zero * if velocity is smaller than zero
*/ */
public VehicleTypeImpl.Builder setMaxVelocity(double inMeterPerSeconds) { public VehicleTypeImpl.Builder setMaxVelocity(double inMeterPerSeconds) {
if (inMeterPerSeconds < 0.0) throw new IllegalArgumentException("velocity cannot be smaller than zero"); if (inMeterPerSeconds < 0.0)
throw new IllegalArgumentException("The velocity of a vehicle (type) cannot be smaller than zero.");
this.maxVelo = inMeterPerSeconds; this.maxVelo = inMeterPerSeconds;
return this; return this;
} }
@ -166,7 +167,7 @@ public class VehicleTypeImpl implements VehicleType {
* @throws IllegalArgumentException if fixedCost is smaller than zero * @throws IllegalArgumentException if fixedCost is smaller than zero
*/ */
public VehicleTypeImpl.Builder setFixedCost(double fixedCost) { public VehicleTypeImpl.Builder setFixedCost(double fixedCost) {
if (fixedCost < 0.0) throw new IllegalArgumentException("fixed costs cannot be smaller than zero"); if (fixedCost < 0.0) throw new IllegalArgumentException("Fixed costs must not be smaller than zero.");
this.fixedCost = fixedCost; this.fixedCost = fixedCost;
return this; return this;
} }
@ -181,7 +182,8 @@ public class VehicleTypeImpl implements VehicleType {
* @throws IllegalArgumentException if perDistance is smaller than zero * @throws IllegalArgumentException if perDistance is smaller than zero
*/ */
public VehicleTypeImpl.Builder setCostPerDistance(double perDistance) { public VehicleTypeImpl.Builder setCostPerDistance(double perDistance) {
if (perDistance < 0.0) throw new IllegalArgumentException("cost per distance must not be smaller than zero"); if (perDistance < 0.0)
throw new IllegalArgumentException("Cost per distance must not be smaller than zero.");
this.perDistance = perDistance; this.perDistance = perDistance;
return this; return this;
} }
@ -260,9 +262,9 @@ public class VehicleTypeImpl implements VehicleType {
* @throws IllegalArgumentException if capacity dimension is already set * @throws IllegalArgumentException if capacity dimension is already set
*/ */
public Builder addCapacityDimension(int dimIndex, int dimVal) { public Builder addCapacityDimension(int dimIndex, int dimVal) {
if (dimVal < 0) throw new IllegalArgumentException("capacity value cannot be negative"); if (dimVal < 0) throw new IllegalArgumentException("The capacity value must not be negative.");
if (capacityDimensions != null) if (capacityDimensions != null)
throw new IllegalArgumentException("either build your dimension with build your dimensions with " + throw new IllegalArgumentException("Either build your dimension with build your dimensions with " +
"addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with .setCapacityDimensions(Capacity capacity)." + "addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with .setCapacityDimensions(Capacity capacity)." +
"You used both methods."); "You used both methods.");
dimensionAdded = true; dimensionAdded = true;
@ -283,7 +285,7 @@ public class VehicleTypeImpl implements VehicleType {
*/ */
public Builder setCapacityDimensions(Capacity capacity) { public Builder setCapacityDimensions(Capacity capacity) {
if (dimensionAdded) if (dimensionAdded)
throw new IllegalArgumentException("either build your dimension with build your dimensions with " + throw new IllegalArgumentException("Either build your dimension with build your dimensions with " +
"addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with .setCapacityDimensions(Capacity capacity)." + "addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with .setCapacityDimensions(Capacity capacity)." +
"You used both methods."); "You used both methods.");
this.capacityDimensions = capacity; this.capacityDimensions = capacity;