mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
replace IllegalStateException with IllegalArgumentException where there is bad input
This commit is contained in:
parent
5c6ef8b8d3
commit
3966590fc7
26 changed files with 146 additions and 171 deletions
|
|
@ -97,7 +97,7 @@ public class Capacity {
|
|||
double sumQuotients = 0.0;
|
||||
for (int index = 0; index < Math.max(numerator.getNuOfDimensions(), denominator.getNuOfDimensions()); index++) {
|
||||
if (numerator.get(index) != 0 && denominator.get(index) == 0) {
|
||||
throw new IllegalStateException("numerator > 0 and denominator = 0. cannot divide by 0");
|
||||
throw new IllegalArgumentException("numerator > 0 and denominator = 0. cannot divide by 0");
|
||||
} else if (numerator.get(index) == 0 && denominator.get(index) == 0) {
|
||||
continue;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ public final class Location implements HasIndex, HasId {
|
|||
|
||||
public Location build() {
|
||||
if (id == null && coordinate == null) {
|
||||
if (index == -1) throw new IllegalStateException("either id or coordinate or index must be set");
|
||||
if (index == -1) throw new IllegalArgumentException("either id or coordinate or index must be set");
|
||||
}
|
||||
if (coordinate != null && id == null) {
|
||||
this.id = coordinate.toString();
|
||||
|
|
|
|||
|
|
@ -222,9 +222,9 @@ public class VehicleRoutingProblem {
|
|||
*/
|
||||
public Builder addJob(AbstractJob job) {
|
||||
if (tentativeJobs.containsKey(job.getId()))
|
||||
throw new IllegalStateException("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("vehicle routing problem already contains a service or shipment with id " + job.getId() + ". make sure you use unique ids for all services and shipments");
|
||||
if (!(job instanceof Service || job instanceof Shipment))
|
||||
throw new IllegalStateException("job must be either a service or a shipment");
|
||||
throw new IllegalArgumentException("job must be either a service or a shipment");
|
||||
job.setIndex(jobIndexCounter);
|
||||
incJobIndexCounter();
|
||||
tentativeJobs.put(job.getId(), job);
|
||||
|
|
@ -351,7 +351,7 @@ public class VehicleRoutingProblem {
|
|||
* */
|
||||
public Builder addVehicle(Vehicle vehicle) {
|
||||
if (!(vehicle instanceof AbstractVehicle))
|
||||
throw new IllegalStateException("vehicle must be an AbstractVehicle");
|
||||
throw new IllegalArgumentException("vehicle must be an AbstractVehicle");
|
||||
return addVehicle((AbstractVehicle) vehicle);
|
||||
}
|
||||
|
||||
|
|
@ -363,7 +363,7 @@ public class VehicleRoutingProblem {
|
|||
*/
|
||||
public Builder addVehicle(AbstractVehicle vehicle) {
|
||||
if(addedVehicleIds.contains(vehicle.getId())){
|
||||
throw new IllegalStateException("problem already contains a vehicle with id " + vehicle.getId() + ". choose unique ids for each vehicle.");
|
||||
throw new IllegalArgumentException("problem already contains a vehicle with id " + vehicle.getId() + ". choose unique ids for each vehicle.");
|
||||
}
|
||||
else addedVehicleIds.add(vehicle.getId());
|
||||
if (!uniqueVehicles.contains(vehicle)) {
|
||||
|
|
|
|||
|
|
@ -193,9 +193,9 @@ public class VrpXMLReader {
|
|||
Driver driver = DriverImpl.noDriver();
|
||||
String vehicleId = routeConfig.getString("vehicleId");
|
||||
Vehicle vehicle = getVehicle(vehicleId);
|
||||
if (vehicle == null) throw new IllegalStateException("vehicle is missing.");
|
||||
if (vehicle == null) throw new IllegalArgumentException("vehicle is missing.");
|
||||
String start = routeConfig.getString("start");
|
||||
if (start == null) throw new IllegalStateException("route start-time is missing.");
|
||||
if (start == null) throw new IllegalArgumentException("route start-time is missing.");
|
||||
double departureTime = Double.parseDouble(start);
|
||||
|
||||
VehicleRoute.Builder routeBuilder = VehicleRoute.Builder.newInstance(vehicle, driver);
|
||||
|
|
@ -204,7 +204,7 @@ public class VrpXMLReader {
|
|||
List<HierarchicalConfiguration> actConfigs = routeConfig.configurationsAt("act");
|
||||
for (HierarchicalConfiguration actConfig : actConfigs) {
|
||||
String type = actConfig.getString("[@type]");
|
||||
if (type == null) throw new IllegalStateException("act[@type] is missing.");
|
||||
if (type == null) throw new IllegalArgumentException("act[@type] is missing.");
|
||||
double arrTime = 0.;
|
||||
double endTime = 0.;
|
||||
String arrTimeS = actConfig.getString("arrTime");
|
||||
|
|
@ -221,24 +221,24 @@ public class VrpXMLReader {
|
|||
if (serviceId != null) {
|
||||
Service service = getService(serviceId);
|
||||
if (service == null)
|
||||
throw new IllegalStateException("service to serviceId " + serviceId + " is missing (reference in one of your initial routes). make sure you define the service you refer to here in <services> </services>.");
|
||||
throw new IllegalArgumentException("service to serviceId " + serviceId + " is missing (reference in one of your initial routes). make sure you define the service you refer to here in <services> </services>.");
|
||||
//!!!since job is part of initial route, it does not belong to jobs in problem, i.e. variable jobs that can be assigned/scheduled
|
||||
freezedJobIds.add(serviceId);
|
||||
routeBuilder.addService(service);
|
||||
} else {
|
||||
String shipmentId = actConfig.getString("shipmentId");
|
||||
if (shipmentId == null)
|
||||
throw new IllegalStateException("either serviceId or shipmentId is missing");
|
||||
throw new IllegalArgumentException("either serviceId or shipmentId is missing");
|
||||
Shipment shipment = getShipment(shipmentId);
|
||||
if (shipment == null)
|
||||
throw new IllegalStateException("shipment to shipmentId " + shipmentId + " is missing (reference in one of your initial routes). make sure you define the shipment you refer to here in <shipments> </shipments>.");
|
||||
throw new IllegalArgumentException("shipment to shipmentId " + shipmentId + " is missing (reference in one of your initial routes). make sure you define the shipment you refer to here in <shipments> </shipments>.");
|
||||
freezedJobIds.add(shipmentId);
|
||||
if (type.equals("pickupShipment")) {
|
||||
routeBuilder.addPickup(shipment);
|
||||
} else if (type.equals("deliverShipment")) {
|
||||
routeBuilder.addDelivery(shipment);
|
||||
} else
|
||||
throw new IllegalStateException("type " + type + " is not supported. Use 'pickupShipment' or 'deliverShipment' here");
|
||||
throw new IllegalArgumentException("type " + type + " is not supported. Use 'pickupShipment' or 'deliverShipment' here");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -262,20 +262,20 @@ public class VrpXMLReader {
|
|||
Driver driver = DriverImpl.noDriver();
|
||||
String vehicleId = routeConfig.getString("vehicleId");
|
||||
Vehicle vehicle = getVehicle(vehicleId);
|
||||
if (vehicle == null) throw new IllegalStateException("vehicle is missing.");
|
||||
if (vehicle == null) throw new IllegalArgumentException("vehicle is missing.");
|
||||
String start = routeConfig.getString("start");
|
||||
if (start == null) throw new IllegalStateException("route start-time is missing.");
|
||||
if (start == null) throw new IllegalArgumentException("route start-time is missing.");
|
||||
double departureTime = Double.parseDouble(start);
|
||||
|
||||
String end = routeConfig.getString("end");
|
||||
if (end == null) throw new IllegalStateException("route end-time is missing.");
|
||||
if (end == null) throw new IllegalArgumentException("route end-time is missing.");
|
||||
|
||||
VehicleRoute.Builder routeBuilder = VehicleRoute.Builder.newInstance(vehicle, driver);
|
||||
routeBuilder.setDepartureTime(departureTime);
|
||||
List<HierarchicalConfiguration> actConfigs = routeConfig.configurationsAt("act");
|
||||
for (HierarchicalConfiguration actConfig : actConfigs) {
|
||||
String type = actConfig.getString("[@type]");
|
||||
if (type == null) throw new IllegalStateException("act[@type] is missing.");
|
||||
if (type == null) throw new IllegalArgumentException("act[@type] is missing.");
|
||||
double arrTime = 0.;
|
||||
double endTime = 0.;
|
||||
String arrTimeS = actConfig.getString("arrTime");
|
||||
|
|
@ -294,16 +294,16 @@ public class VrpXMLReader {
|
|||
} else {
|
||||
String shipmentId = actConfig.getString("shipmentId");
|
||||
if (shipmentId == null)
|
||||
throw new IllegalStateException("either serviceId or shipmentId is missing");
|
||||
throw new IllegalArgumentException("either serviceId or shipmentId is missing");
|
||||
Shipment shipment = getShipment(shipmentId);
|
||||
if (shipment == null)
|
||||
throw new IllegalStateException("shipment with id " + shipmentId + " does not exist.");
|
||||
throw new IllegalArgumentException("shipment with id " + shipmentId + " does not exist.");
|
||||
if (type.equals("pickupShipment")) {
|
||||
routeBuilder.addPickup(shipment);
|
||||
} else if (type.equals("deliverShipment")) {
|
||||
routeBuilder.addDelivery(shipment);
|
||||
} else
|
||||
throw new IllegalStateException("type " + type + " is not supported. Use 'pickupShipment' or 'deliverShipment' here");
|
||||
throw new IllegalArgumentException("type " + type + " is not supported. Use 'pickupShipment' or 'deliverShipment' here");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -315,7 +315,7 @@ public class VrpXMLReader {
|
|||
String jobId = unassignedJobConfig.getString("[@id]");
|
||||
Job job = getShipment(jobId);
|
||||
if (job == null) job = getService(jobId);
|
||||
if (job == null) throw new IllegalStateException("cannot find unassignedJob with id " + jobId);
|
||||
if (job == null) throw new IllegalArgumentException("cannot find unassignedJob with id " + jobId);
|
||||
solution.getUnassignedJobs().add(job);
|
||||
}
|
||||
|
||||
|
|
@ -351,15 +351,15 @@ public class VrpXMLReader {
|
|||
List<HierarchicalConfiguration> shipmentConfigs = config.configurationsAt("shipments.shipment");
|
||||
for (HierarchicalConfiguration shipmentConfig : shipmentConfigs) {
|
||||
String id = shipmentConfig.getString("[@id]");
|
||||
if (id == null) throw new IllegalStateException("shipment[@id] is missing.");
|
||||
if (id == null) throw new IllegalArgumentException("shipment[@id] is missing.");
|
||||
|
||||
String capacityString = shipmentConfig.getString("capacity-demand");
|
||||
boolean capacityDimensionsExist = shipmentConfig.containsKey("capacity-dimensions.dimension(0)");
|
||||
if (capacityString == null && !capacityDimensionsExist) {
|
||||
throw new IllegalStateException("capacity of shipment is not set. use 'capacity-dimensions'");
|
||||
throw new IllegalArgumentException("capacity of shipment is not set. use 'capacity-dimensions'");
|
||||
}
|
||||
if (capacityString != null && capacityDimensionsExist) {
|
||||
throw new IllegalStateException("either use capacity or capacity-dimension, not both. prefer the use of 'capacity-dimensions' over 'capacity'.");
|
||||
throw new IllegalArgumentException("either use capacity or capacity-dimension, not both. prefer the use of 'capacity-dimensions' over 'capacity'.");
|
||||
}
|
||||
|
||||
Shipment.Builder builder;
|
||||
|
|
@ -475,17 +475,17 @@ public class VrpXMLReader {
|
|||
List<HierarchicalConfiguration> serviceConfigs = vrpProblem.configurationsAt("services.service");
|
||||
for (HierarchicalConfiguration serviceConfig : serviceConfigs) {
|
||||
String id = serviceConfig.getString("[@id]");
|
||||
if (id == null) throw new IllegalStateException("service[@id] is missing.");
|
||||
if (id == null) throw new IllegalArgumentException("service[@id] is missing.");
|
||||
String type = serviceConfig.getString("[@type]");
|
||||
if (type == null) type = "service";
|
||||
|
||||
String capacityString = serviceConfig.getString("capacity-demand");
|
||||
boolean capacityDimensionsExist = serviceConfig.containsKey("capacity-dimensions.dimension(0)");
|
||||
if (capacityString == null && !capacityDimensionsExist) {
|
||||
throw new IllegalStateException("capacity of service is not set. use 'capacity-dimensions'");
|
||||
throw new IllegalArgumentException("capacity of service is not set. use 'capacity-dimensions'");
|
||||
}
|
||||
if (capacityString != null && capacityDimensionsExist) {
|
||||
throw new IllegalStateException("either use capacity or capacity-dimension, not both. prefer the use of 'capacity-dimensions' over 'capacity'.");
|
||||
throw new IllegalArgumentException("either use capacity or capacity-dimension, not both. prefer the use of 'capacity-dimensions' over 'capacity'.");
|
||||
}
|
||||
|
||||
Service.Builder builder;
|
||||
|
|
@ -556,15 +556,15 @@ public class VrpXMLReader {
|
|||
List<HierarchicalConfiguration> typeConfigs = vrpProblem.configurationsAt("vehicleTypes.type");
|
||||
for (HierarchicalConfiguration typeConfig : typeConfigs) {
|
||||
String typeId = typeConfig.getString("id");
|
||||
if (typeId == null) throw new IllegalStateException("typeId is missing.");
|
||||
if (typeId == null) throw new IllegalArgumentException("typeId is missing.");
|
||||
|
||||
String capacityString = typeConfig.getString("capacity");
|
||||
boolean capacityDimensionsExist = typeConfig.containsKey("capacity-dimensions.dimension(0)");
|
||||
if (capacityString == null && !capacityDimensionsExist) {
|
||||
throw new IllegalStateException("capacity of type is not set. use 'capacity-dimensions'");
|
||||
throw new IllegalArgumentException("capacity of type is not set. use 'capacity-dimensions'");
|
||||
}
|
||||
if (capacityString != null && capacityDimensionsExist) {
|
||||
throw new IllegalStateException("either use capacity or capacity-dimension, not both. prefer the use of 'capacity-dimensions' over 'capacity'.");
|
||||
throw new IllegalArgumentException("either use capacity or capacity-dimension, not both. prefer the use of 'capacity-dimensions' over 'capacity'.");
|
||||
}
|
||||
|
||||
VehicleTypeImpl.Builder typeBuilder;
|
||||
|
|
@ -606,10 +606,10 @@ public class VrpXMLReader {
|
|||
boolean doNotWarnAgain = false;
|
||||
for (HierarchicalConfiguration vehicleConfig : vehicleConfigs) {
|
||||
String vehicleId = vehicleConfig.getString("id");
|
||||
if (vehicleId == null) throw new IllegalStateException("vehicleId is missing.");
|
||||
if (vehicleId == null) throw new IllegalArgumentException("vehicleId is missing.");
|
||||
Builder builder = VehicleImpl.Builder.newInstance(vehicleId);
|
||||
String typeId = vehicleConfig.getString("typeId");
|
||||
if (typeId == null) throw new IllegalStateException("typeId is missing.");
|
||||
if (typeId == null) throw new IllegalArgumentException("typeId is missing.");
|
||||
String vType = vehicleConfig.getString("[@type]");
|
||||
if (vType != null) {
|
||||
if (vType.equals("penalty")) {
|
||||
|
|
@ -617,7 +617,7 @@ public class VrpXMLReader {
|
|||
}
|
||||
}
|
||||
VehicleType type = types.get(typeId);
|
||||
if (type == null) throw new IllegalStateException("vehicleType with typeId " + typeId + " is missing.");
|
||||
if (type == null) throw new IllegalArgumentException("vehicleType with typeId " + typeId + " is missing.");
|
||||
builder.setType(type);
|
||||
|
||||
//read startlocation
|
||||
|
|
|
|||
|
|
@ -44,10 +44,10 @@ public class Delivery extends Service {
|
|||
* Builds Delivery.
|
||||
*
|
||||
* @return delivery
|
||||
* @throws IllegalStateException if neither locationId nor coord is set
|
||||
* @throws IllegalArgumentException if neither locationId nor coord is set
|
||||
*/
|
||||
public Delivery build() {
|
||||
if (location == null) throw new IllegalStateException("location is missing");
|
||||
if (location == null) throw new IllegalArgumentException("location is missing");
|
||||
this.setType("delivery");
|
||||
super.capacity = super.capacityBuilder.build();
|
||||
super.skills = super.skillBuilder.build();
|
||||
|
|
|
|||
|
|
@ -46,10 +46,10 @@ public class Pickup extends Service {
|
|||
* <p>Pickup type is "pickup"
|
||||
*
|
||||
* @return pickup
|
||||
* @throws IllegalStateException if neither locationId nor coordinate has been set
|
||||
* @throws IllegalArgumentException if neither locationId nor coordinate has been set
|
||||
*/
|
||||
public Pickup build() {
|
||||
if (location == null) throw new IllegalStateException("location is missing");
|
||||
if (location == null) throw new IllegalArgumentException("location is missing");
|
||||
this.setType("pickup");
|
||||
super.capacity = super.capacityBuilder.build();
|
||||
super.skills = super.skillBuilder.build();
|
||||
|
|
|
|||
|
|
@ -176,10 +176,10 @@ public class Service extends AbstractJob {
|
|||
* Builds the service.
|
||||
*
|
||||
* @return {@link Service}
|
||||
* @throws IllegalStateException if neither locationId nor coordinate is set.
|
||||
* @throws IllegalArgumentException if neither locationId nor coordinate is set.
|
||||
*/
|
||||
public T build() {
|
||||
if (location == null) throw new IllegalStateException("location is missing");
|
||||
if (location == null) throw new IllegalArgumentException("location is missing");
|
||||
this.setType("service");
|
||||
capacity = capacityBuilder.build();
|
||||
skills = skillBuilder.build();
|
||||
|
|
@ -219,7 +219,7 @@ public class Service extends AbstractJob {
|
|||
* @return builder
|
||||
*/
|
||||
public Builder<T> setPriority(int priority) {
|
||||
if(priority < 1 || priority > 3) throw new IllegalStateException("incorrect priority. only 1 = high, 2 = medium and 3 = low is allowed");
|
||||
if(priority < 1 || priority > 3) throw new IllegalArgumentException("incorrect priority. only 1 = high, 2 = medium and 3 = low is allowed");
|
||||
this.priority = priority;
|
||||
return this;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -216,12 +216,12 @@ public class Shipment extends AbstractJob {
|
|||
* Builds the shipment.
|
||||
*
|
||||
* @return shipment
|
||||
* @throws IllegalStateException if neither pickup-location nor pickup-coord is set or if neither delivery-location nor delivery-coord
|
||||
* @throws IllegalArgumentException if neither pickup-location nor pickup-coord is set or if neither delivery-location nor delivery-coord
|
||||
* is set
|
||||
*/
|
||||
public Shipment build() {
|
||||
if (pickupLocation_ == null) throw new IllegalStateException("pickup location is missing");
|
||||
if (deliveryLocation_ == null) throw new IllegalStateException("delivery location is missing");
|
||||
if (pickupLocation_ == null) throw new IllegalArgumentException("pickup location is missing");
|
||||
if (deliveryLocation_ == null) throw new IllegalArgumentException("delivery location is missing");
|
||||
capacity = capacityBuilder.build();
|
||||
skills = skillBuilder.build();
|
||||
return new Shipment(this);
|
||||
|
|
@ -276,7 +276,7 @@ public class Shipment extends AbstractJob {
|
|||
* @return builder
|
||||
*/
|
||||
public Builder setPriority(int priority) {
|
||||
if(priority < 1 || priority > 3) throw new IllegalStateException("incorrect priority. only 1 = high, 2 = medium and 3 = low is allowed");
|
||||
if(priority < 1 || priority > 3) throw new IllegalArgumentException("incorrect priority. only 1 = high, 2 = medium and 3 = low is allowed");
|
||||
this.priority = priority;
|
||||
return this;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -242,7 +242,7 @@ public class VehicleRoute {
|
|||
*
|
||||
* @param shipment to be picked up and added to this route
|
||||
* @return the builder
|
||||
* @throws IllegalStateException if method has already been called with the specified shipment.
|
||||
* @throws IllegalArgumentException if method has already been called with the specified shipment.
|
||||
*/
|
||||
public Builder addPickup(Shipment shipment) {
|
||||
return addPickup(shipment, shipment.getPickupTimeWindow());
|
||||
|
|
@ -250,7 +250,7 @@ public class VehicleRoute {
|
|||
|
||||
public Builder addPickup(Shipment shipment, TimeWindow pickupTimeWindow) {
|
||||
if (openShipments.contains(shipment))
|
||||
throw new IllegalStateException("shipment has already been added. cannot add it twice.");
|
||||
throw new IllegalArgumentException("shipment has already been added. cannot add it twice.");
|
||||
List<AbstractActivity> acts = jobActivityFactory.createActivities(shipment);
|
||||
TourActivity act = acts.get(0);
|
||||
act.setTheoreticalEarliestOperationStartTime(pickupTimeWindow.getStart());
|
||||
|
|
@ -266,7 +266,7 @@ public class VehicleRoute {
|
|||
*
|
||||
* @param shipment to be delivered and add to this vehicleRoute
|
||||
* @return builder
|
||||
* @throws IllegalStateException if specified shipment has not been picked up yet (i.e. method addPickup(shipment) has not been called yet).
|
||||
* @throws IllegalArgumentException if specified shipment has not been picked up yet (i.e. method addPickup(shipment) has not been called yet).
|
||||
*/
|
||||
public Builder addDelivery(Shipment shipment) {
|
||||
return addDelivery(shipment,shipment.getDeliveryTimeWindow());
|
||||
|
|
@ -280,7 +280,7 @@ public class VehicleRoute {
|
|||
tourActivities.addActivity(act);
|
||||
openShipments.remove(shipment);
|
||||
} else {
|
||||
throw new IllegalStateException("cannot deliver shipment. shipment " + shipment + " needs to be picked up first.");
|
||||
throw new IllegalArgumentException("cannot deliver shipment. shipment " + shipment + " needs to be picked up first.");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
|
@ -290,11 +290,11 @@ public class VehicleRoute {
|
|||
* Builds the route.
|
||||
*
|
||||
* @return {@link VehicleRoute}
|
||||
* @throws IllegalStateException if there are still shipments that have been picked up though but not delivery.
|
||||
* @throws IllegalArgumentException if there are still shipments that have been picked up though but not delivery.
|
||||
*/
|
||||
public VehicleRoute build() {
|
||||
if (!openShipments.isEmpty()) {
|
||||
throw new IllegalStateException("there are still shipments that have not been delivered yet.");
|
||||
throw new IllegalArgumentException("there are still shipments that have not been delivered yet.");
|
||||
}
|
||||
if (!vehicle.isReturnToDepot()) {
|
||||
if (!tourActivities.isEmpty()) {
|
||||
|
|
@ -419,11 +419,11 @@ public class VehicleRoute {
|
|||
* Returns the departureTime of this vehicle in this route.
|
||||
*
|
||||
* @return departureTime
|
||||
* @throws IllegalStateException if start is null
|
||||
* @throws IllegalArgumentException if start is null
|
||||
*/
|
||||
public double getDepartureTime() {
|
||||
if (start == null)
|
||||
throw new IllegalStateException("cannot get departureTime without having a vehicle on this route. use setVehicle(vehicle,departureTime) instead.");
|
||||
throw new IllegalArgumentException("cannot get departureTime without having a vehicle on this route. use setVehicle(vehicle,departureTime) instead.");
|
||||
return start.getEndTime();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,13 +14,13 @@ public class TimeWindowsImpl implements TimeWindows {
|
|||
public void add(TimeWindow timeWindow){
|
||||
for(TimeWindow tw : timeWindows){
|
||||
if(timeWindow.getStart() > tw.getStart() && timeWindow.getStart() < tw.getEnd()){
|
||||
throw new IllegalStateException("time-windows cannot overlap each other. overlap: " + tw + ", " + timeWindow);
|
||||
throw new IllegalArgumentException("time-windows cannot overlap each other. overlap: " + tw + ", " + timeWindow);
|
||||
}
|
||||
if(timeWindow.getEnd() > tw.getStart() && timeWindow.getEnd() < tw.getEnd()){
|
||||
throw new IllegalStateException("time-windows cannot overlap each other. overlap: " + tw + ", " + timeWindow);
|
||||
throw new IllegalArgumentException("time-windows cannot overlap each other. overlap: " + tw + ", " + timeWindow);
|
||||
}
|
||||
if(timeWindow.getStart() <= tw.getStart() && timeWindow.getEnd() >= tw.getEnd()){
|
||||
throw new IllegalStateException("time-windows cannot overlap each other. overlap: " + tw + ", " + timeWindow);
|
||||
throw new IllegalArgumentException("time-windows cannot overlap each other. overlap: " + tw + ", " + timeWindow);
|
||||
}
|
||||
}
|
||||
timeWindows.add(timeWindow);
|
||||
|
|
|
|||
|
|
@ -214,11 +214,11 @@ public class TourActivities {
|
|||
* <p>If act instanceof JobActivity, it adds underlying job also.
|
||||
*
|
||||
* @param act to be added
|
||||
* @throws IllegalStateException if activity-list already contains act.
|
||||
* @throws IllegalArgumentException if activity-list already contains act.
|
||||
*/
|
||||
public void addActivity(TourActivity act) {
|
||||
if (tourActivities.contains(act))
|
||||
throw new IllegalStateException("act " + act + " already in tour. cannot add act twice.");
|
||||
throw new IllegalArgumentException("act " + act + " already in tour. cannot add act twice.");
|
||||
tourActivities.add(act);
|
||||
addJob(act);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -139,10 +139,10 @@ public class VehicleImpl extends AbstractVehicle {
|
|||
*
|
||||
* @param type the type to be set
|
||||
* @return this builder
|
||||
* @throws IllegalStateException if type is null
|
||||
* @throws IllegalArgumentException if type is null
|
||||
*/
|
||||
public Builder setType(VehicleType type) {
|
||||
if (type == null) throw new IllegalStateException("type cannot be null.");
|
||||
if (type == null) throw new IllegalArgumentException("type cannot be null.");
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
|
@ -224,22 +224,22 @@ public class VehicleImpl extends AbstractVehicle {
|
|||
* Thus endLocationId can never be null even returnToDepot is false.
|
||||
*
|
||||
* @return vehicle
|
||||
* @throws IllegalStateException if both locationId and locationCoord is not set or (endLocationCoord!=null AND returnToDepot=false)
|
||||
* @throws IllegalArgumentException if both locationId and locationCoord is not set or (endLocationCoord!=null AND returnToDepot=false)
|
||||
* or (endLocationId!=null AND returnToDepot=false)
|
||||
*/
|
||||
public VehicleImpl build() {
|
||||
if (latestArrival < earliestStart)
|
||||
throw new IllegalStateException("latest arrival of vehicle " + id + " must not be smaller than its start time");
|
||||
throw new IllegalArgumentException("latest arrival of vehicle " + id + " must not be smaller than its start time");
|
||||
if (startLocation != null && endLocation != null) {
|
||||
if (!startLocation.getId().equals(endLocation.getId()) && !returnToDepot)
|
||||
throw new IllegalStateException("this must not be. you specified both endLocationId and open-routes. this is contradictory. <br>" +
|
||||
throw new IllegalArgumentException("this must not be. you specified both endLocationId and open-routes. this is contradictory. <br>" +
|
||||
"if you set endLocation, returnToDepot must be true. if returnToDepot is false, endLocationCoord must not be specified.");
|
||||
}
|
||||
if (startLocation != null && endLocation == null) {
|
||||
endLocation = startLocation;
|
||||
}
|
||||
if (startLocation == null && endLocation == null) {
|
||||
throw new IllegalStateException("vehicle requires startLocation. but neither locationId nor locationCoord nor startLocationId nor startLocationCoord has been set");
|
||||
throw new IllegalArgumentException("vehicle requires startLocation. but neither locationId nor locationCoord nor startLocationId nor startLocationCoord has been set");
|
||||
}
|
||||
skills = skillBuilder.build();
|
||||
return new VehicleImpl(this);
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ public class VehicleTypeImpl implements VehicleType {
|
|||
|
||||
|
||||
public static VehicleTypeImpl.Builder newInstance(String id) {
|
||||
if (id == null) throw new IllegalStateException();
|
||||
if (id == null) throw new IllegalArgumentException();
|
||||
return new Builder(id);
|
||||
}
|
||||
|
||||
|
|
@ -124,10 +124,10 @@ public class VehicleTypeImpl implements VehicleType {
|
|||
*
|
||||
* @param inMeterPerSeconds
|
||||
* @return this builder
|
||||
* @throws IllegalStateException if velocity is smaller than zero
|
||||
* @throws IllegalArgumentException if velocity is smaller than zero
|
||||
*/
|
||||
public VehicleTypeImpl.Builder setMaxVelocity(double inMeterPerSeconds) {
|
||||
if (inMeterPerSeconds < 0.0) throw new IllegalStateException("velocity cannot be smaller than zero");
|
||||
if (inMeterPerSeconds < 0.0) throw new IllegalArgumentException("velocity cannot be smaller than zero");
|
||||
this.maxVelo = inMeterPerSeconds;
|
||||
return this;
|
||||
}
|
||||
|
|
@ -139,10 +139,10 @@ public class VehicleTypeImpl implements VehicleType {
|
|||
*
|
||||
* @param fixedCost
|
||||
* @return this builder
|
||||
* @throws IllegalStateException if fixedCost is smaller than zero
|
||||
* @throws IllegalArgumentException if fixedCost is smaller than zero
|
||||
*/
|
||||
public VehicleTypeImpl.Builder setFixedCost(double fixedCost) {
|
||||
if (fixedCost < 0.0) throw new IllegalStateException("fixed costs cannot be smaller than zero");
|
||||
if (fixedCost < 0.0) throw new IllegalArgumentException("fixed costs cannot be smaller than zero");
|
||||
this.fixedCost = fixedCost;
|
||||
return this;
|
||||
}
|
||||
|
|
@ -154,10 +154,10 @@ public class VehicleTypeImpl implements VehicleType {
|
|||
*
|
||||
* @param perDistance
|
||||
* @return this builder
|
||||
* @throws IllegalStateException if perDistance is smaller than zero
|
||||
* @throws IllegalArgumentException if perDistance is smaller than zero
|
||||
*/
|
||||
public VehicleTypeImpl.Builder setCostPerDistance(double perDistance) {
|
||||
if (perDistance < 0.0) throw new IllegalStateException("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;
|
||||
return this;
|
||||
}
|
||||
|
|
@ -169,12 +169,12 @@ public class VehicleTypeImpl implements VehicleType {
|
|||
*
|
||||
* @param perTime
|
||||
* @return this builder
|
||||
* @throws IllegalStateException if costPerTime is smaller than zero
|
||||
* @throws IllegalArgumentException if costPerTime is smaller than zero
|
||||
* @deprecated use .setCostPerTransportTime(..) instead
|
||||
*/
|
||||
@Deprecated
|
||||
public VehicleTypeImpl.Builder setCostPerTime(double perTime) {
|
||||
if (perTime < 0.0) throw new IllegalStateException();
|
||||
if (perTime < 0.0) throw new IllegalArgumentException();
|
||||
this.perTime = perTime;
|
||||
return this;
|
||||
}
|
||||
|
|
@ -186,10 +186,10 @@ public class VehicleTypeImpl implements VehicleType {
|
|||
*
|
||||
* @param perTime
|
||||
* @return this builder
|
||||
* @throws IllegalStateException if costPerTime is smaller than zero
|
||||
* @throws IllegalArgumentException if costPerTime is smaller than zero
|
||||
*/
|
||||
public VehicleTypeImpl.Builder setCostPerTransportTime(double perTime) {
|
||||
if (perTime < 0.0) throw new IllegalStateException();
|
||||
if (perTime < 0.0) throw new IllegalArgumentException();
|
||||
this.perTime = perTime;
|
||||
return this;
|
||||
}
|
||||
|
|
@ -201,10 +201,10 @@ public class VehicleTypeImpl implements VehicleType {
|
|||
*
|
||||
* @param perWaitingTime
|
||||
* @return this builder
|
||||
* @throws IllegalStateException if costPerTime is smaller than zero
|
||||
* @throws IllegalArgumentException if costPerTime is smaller than zero
|
||||
*/
|
||||
public VehicleTypeImpl.Builder setCostPerWaitingTime(double perWaitingTime) {
|
||||
if (perWaitingTime < 0.0) throw new IllegalStateException();
|
||||
if (perWaitingTime < 0.0) throw new IllegalArgumentException();
|
||||
this.perWaitingTime = perWaitingTime;
|
||||
return this;
|
||||
}
|
||||
|
|
@ -233,12 +233,12 @@ public class VehicleTypeImpl implements VehicleType {
|
|||
* @param dimVal
|
||||
* @return the builder
|
||||
* @throws IllegalArgumentException if dimVal < 0
|
||||
* @throws IllegalStateException if capacity dimension is already set
|
||||
* @throws IllegalArgumentException if capacity dimension is already set
|
||||
*/
|
||||
public Builder addCapacityDimension(int dimIndex, int dimVal) {
|
||||
if (dimVal < 0) throw new IllegalArgumentException("capacity value cannot be negative");
|
||||
if (capacityDimensions != null)
|
||||
throw new IllegalStateException("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)." +
|
||||
"You used both methods.");
|
||||
dimensionAdded = true;
|
||||
|
|
@ -255,11 +255,11 @@ public class VehicleTypeImpl implements VehicleType {
|
|||
*
|
||||
* @param capacity
|
||||
* @return this builder
|
||||
* @throws IllegalStateException if capacityDimension has already been added
|
||||
* @throws IllegalArgumentException if capacityDimension has already been added
|
||||
*/
|
||||
public Builder setCapacityDimensions(Capacity capacity) {
|
||||
if (dimensionAdded)
|
||||
throw new IllegalStateException("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)." +
|
||||
"You used both methods.");
|
||||
this.capacityDimensions = capacity;
|
||||
|
|
|
|||
|
|
@ -349,7 +349,7 @@ public class CapacityTest {
|
|||
assertEquals(0.0, Capacity.divide(cap1, cap2), 0.001);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenDividingByAZeroDim_itShouldThrowException() {
|
||||
Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).build();
|
||||
Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 0).build();
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public class LocationTest {
|
|||
Location l = Location.Builder.newInstance().setIndex(-1).build();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenCoordinateAndIdAndIndexNotSet_throwException() {
|
||||
Location l = Location.Builder.newInstance().build();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -303,7 +303,7 @@ public class VehicleRoutingProblemTest {
|
|||
return Location.Builder.newInstance().setId(i).build();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenAddingVehiclesWithSameId_itShouldThrowException(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||
|
|
@ -453,7 +453,7 @@ public class VehicleRoutingProblemTest {
|
|||
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenAddingTwoServicesWithTheSameId_itShouldThrowException() {
|
||||
Service service1 = Service.Builder.newInstance("myService").setLocation(Location.newInstance("loc")).build();
|
||||
Service service2 = Service.Builder.newInstance("myService").setLocation(Location.newInstance("loc")).build();
|
||||
|
|
@ -463,7 +463,7 @@ public class VehicleRoutingProblemTest {
|
|||
@SuppressWarnings("UnusedDeclaration") VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenAddingTwoShipmentsWithTheSameId_itShouldThrowException() {
|
||||
Shipment shipment1 = Shipment.Builder.newInstance("shipment").setPickupLocation(Location.Builder.newInstance().setId("pick").build())
|
||||
.setDeliveryLocation(Location.newInstance("del")).build();
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import static org.junit.Assert.*;
|
|||
|
||||
public class DeliveryTest {
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenNeitherLocationIdNorCoordIsSet_itThrowsException() {
|
||||
Delivery.Builder.newInstance("p").build();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import static org.junit.Assert.*;
|
|||
|
||||
public class PickupTest {
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenNeitherLocationIdNorCoordIsSet_itThrowsException() {
|
||||
Pickup.Builder.newInstance("p").build();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ public class ServiceTest {
|
|||
assertEquals(2.0,s.getLocation().getCoordinate().getY(),0.01);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalStateException.class)
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void whenSettingNeitherLocationIdNorCoord_throwsException(){
|
||||
@SuppressWarnings("unused")
|
||||
Service s = Service.Builder.newInstance("s").build();
|
||||
|
|
@ -219,7 +219,7 @@ public class ServiceTest {
|
|||
assertEquals(2,s.getTimeWindows().size());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenMultipleTWOverlap_throwEx(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addTimeWindow(TimeWindow.newInstance(0.,10.))
|
||||
|
|
@ -227,7 +227,7 @@ public class ServiceTest {
|
|||
.setName("name").build();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenMultipleTWOverlap2_throwEx(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addTimeWindow(TimeWindow.newInstance(20., 30.))
|
||||
|
|
@ -256,14 +256,14 @@ public class ServiceTest {
|
|||
Assert.assertEquals(2, s.getPriority());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSettingIncorrectPriorities_itShouldThrowException(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setPriority(30).build();
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSettingIncorrectPriorities_itShouldThrowException2(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setPriority(0).build();
|
||||
|
|
|
|||
|
|
@ -86,13 +86,13 @@ public class ShipmentTest {
|
|||
assertNotNull(builder);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenNeitherPickupLocationIdNorPickupCoord_itThrowsException() {
|
||||
@SuppressWarnings("unused")
|
||||
Shipment s = Shipment.Builder.newInstance("s").setDeliveryLocation(TestUtils.loc("delLoc")).build();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenNeitherDeliveryLocationIdNorDeliveryCoord_itThrowsException() {
|
||||
@SuppressWarnings("unused")
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
|
|
@ -105,7 +105,7 @@ public class ShipmentTest {
|
|||
assertEquals("pickLoc", s.getPickupLocation().getId());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenPickupLocationIsNull_itThrowsException() {
|
||||
@SuppressWarnings("unused")
|
||||
Shipment.Builder builder = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId(null).build());
|
||||
|
|
@ -253,7 +253,7 @@ public class ShipmentTest {
|
|||
assertThat(s.getDeliveryTimeWindows(),hasItem(is(tw2)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenAddingMultipleOverlappingDeliveryTimeWindows_itShouldThrowException() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").addDeliveryTimeWindow(1, 3).addDeliveryTimeWindow(2,5)
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
|
|
@ -290,7 +290,7 @@ public class ShipmentTest {
|
|||
assertThat(s.getPickupTimeWindows(), hasItem(is(tw2)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenAddingMultipleOverlappingPickupTimeWindows_itShouldThrowException() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").addPickupTimeWindow(1, 3).addPickupTimeWindow(2,5)
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
|
|
@ -408,7 +408,7 @@ public class ShipmentTest {
|
|||
Assert.assertEquals(2, s.getPriority());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSettingIncorrectPriorities_itShouldThrowException(){
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
|
||||
.setDeliveryLocation(Location.newInstance("loc"))
|
||||
|
|
@ -416,7 +416,7 @@ public class ShipmentTest {
|
|||
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSettingIncorrectPriorities_itShouldThrowException2(){
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
|
||||
.setDeliveryLocation(Location.newInstance("loc"))
|
||||
|
|
|
|||
|
|
@ -32,14 +32,14 @@ import static org.mockito.Mockito.when;
|
|||
|
||||
public class VehicleRouteBuilderTest {
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenDeliveryIsAddedBeforePickup_throwsException() {
|
||||
Shipment s = mock(Shipment.class);
|
||||
VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class));
|
||||
builder.addDelivery(s);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenPickupIsAddedTwice_throwsException() {
|
||||
Shipment s = mock(Shipment.class);
|
||||
when(s.getSize()).thenReturn(Capacity.Builder.newInstance().build());
|
||||
|
|
@ -49,7 +49,7 @@ public class VehicleRouteBuilderTest {
|
|||
builder.addPickup(s);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenShipmentIsPickedDeliveredAndDeliveredAgain_throwsException() {
|
||||
Shipment s = mock(Shipment.class);
|
||||
Capacity capacity = Capacity.Builder.newInstance().build();
|
||||
|
|
@ -62,7 +62,7 @@ public class VehicleRouteBuilderTest {
|
|||
builder.addDelivery(s);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenShipmentIsPickedUpThoughButHasNotBeenDeliveredAndRouteIsBuilt_throwsException() {
|
||||
Shipment s = mock(Shipment.class);
|
||||
Capacity capacity = Capacity.Builder.newInstance().build();
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public class TestTourActivities {
|
|||
assertTrue(tour.servesJob(service));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenAddingServiceActTwice_anExceptionIsThrown() {
|
||||
assertFalse(tour.servesJob(service));
|
||||
tour.addActivity(act);
|
||||
|
|
|
|||
|
|
@ -7,21 +7,21 @@ import org.junit.Test;
|
|||
*/
|
||||
public class TimeWindowsImplTest {
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void overlappingTW_shouldThrowException(){
|
||||
TimeWindowsImpl tws = new TimeWindowsImpl();
|
||||
tws.add(TimeWindow.newInstance(50, 100));
|
||||
tws.add(TimeWindow.newInstance(90,150));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void overlappingTW2_shouldThrowException(){
|
||||
TimeWindowsImpl tws = new TimeWindowsImpl();
|
||||
tws.add(TimeWindow.newInstance(50, 100));
|
||||
tws.add(TimeWindow.newInstance(40,150));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void overlappingTW3_shouldThrowException(){
|
||||
TimeWindowsImpl tws = new TimeWindowsImpl();
|
||||
tws.add(TimeWindow.newInstance(50, 100));
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ import static org.junit.Assert.*;
|
|||
public class VehicleImplTest {
|
||||
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenVehicleIsBuiltWithoutSettingNeitherLocationNorCoord_itThrowsAnIllegalStateException() {
|
||||
@SuppressWarnings("unused")
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").build();
|
||||
|
|
@ -133,7 +133,7 @@ public class VehicleImplTest {
|
|||
assertEquals("startLoc", v.getStartLocation().getId());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenStartLocationIsNull_itThrowsException() {
|
||||
@SuppressWarnings("unused")
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(null)).build();
|
||||
|
|
@ -185,13 +185,13 @@ public class VehicleImplTest {
|
|||
assertEquals(v.getEndLocation().getCoordinate().toString(), v.getEndLocation().getId());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenEndLocationIdIsSpecifiedANDReturnToDepotIsFalse_itShouldThrowException() {
|
||||
@SuppressWarnings("unused")
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1.0, 2.0)).setEndLocation(Location.newInstance("endLoc")).setReturnToDepot(false).build();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenEndLocationCoordIsSpecifiedANDReturnToDepotIsFalse_itShouldThrowException() {
|
||||
@SuppressWarnings("unused")
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1.0, 2.0)).setEndLocation(Location.newInstance(3, 4)).setReturnToDepot(false).build();
|
||||
|
|
@ -209,7 +209,7 @@ public class VehicleImplTest {
|
|||
assertEquals(v.getStartLocation().getCoordinate().toString(), v.getEndLocation().getId());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenStartAndEndAreUnequalANDReturnToDepotIsFalse_itShouldThrowException() {
|
||||
@SuppressWarnings("unused")
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).setReturnToDepot(false).build();
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ public class VehicleTypeImplTest {
|
|||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("foo").addCapacityDimension(0, -10).build();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenBuildingTypeWithNullId_throwIllegalStateException() {
|
||||
@SuppressWarnings("unused")
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance(null).addCapacityDimension(0, 10).build();
|
||||
|
|
@ -99,13 +99,13 @@ public class VehicleTypeImplTest {
|
|||
}
|
||||
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenMaxVelocitySmallerThanZero_itShouldThrowException() {
|
||||
@SuppressWarnings("unused")
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setMaxVelocity(-10).build();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenFixedCostsSmallerThanZero_itShouldThrowException() {
|
||||
@SuppressWarnings("unused")
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setFixedCost(-10).build();
|
||||
|
|
@ -116,7 +116,7 @@ public class VehicleTypeImplTest {
|
|||
assertEquals(10.0, type.getVehicleCostParams().fix, 0.0);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenPerDistanceCostsSmallerThanZero_itShouldThrowException() {
|
||||
@SuppressWarnings("unused")
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setCostPerDistance(-10).build();
|
||||
|
|
@ -127,7 +127,7 @@ public class VehicleTypeImplTest {
|
|||
assertEquals(10.0, type.getVehicleCostParams().perDistanceUnit, 0.0);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenPerTimeCostsSmallerThanZero_itShouldThrowException() {
|
||||
@SuppressWarnings("unused")
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setCostPerTime(-10).build();
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
<problem xmlns="http://www.w3schools.com"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd">
|
||||
<problemType>
|
||||
<fleetSize>INFINITE</fleetSize>
|
||||
<fleetSize>FINITE</fleetSize>
|
||||
</problemType>
|
||||
<vehicles>
|
||||
<vehicle>
|
||||
|
|
@ -20,6 +20,21 @@
|
|||
</timeSchedule>
|
||||
<returnToDepot>true</returnToDepot>
|
||||
</vehicle>
|
||||
<vehicle>
|
||||
<id>v2</id>
|
||||
<typeId>vehType2</typeId>
|
||||
<startLocation>
|
||||
<id>loc</id>
|
||||
</startLocation>
|
||||
<endLocation>
|
||||
<id>loc</id>
|
||||
</endLocation>
|
||||
<timeSchedule>
|
||||
<start>0.0</start>
|
||||
<end>1.7976931348623157E308</end>
|
||||
</timeSchedule>
|
||||
<returnToDepot>true</returnToDepot>
|
||||
</vehicle>
|
||||
</vehicles>
|
||||
<vehicleTypes>
|
||||
<type>
|
||||
|
|
@ -35,58 +50,18 @@
|
|||
<wait>0.0</wait>
|
||||
</costs>
|
||||
</type>
|
||||
<type>
|
||||
<id>vehType2</id>
|
||||
<capacity-dimensions>
|
||||
<dimension index="0">200</dimension>
|
||||
</capacity-dimensions>
|
||||
<costs>
|
||||
<fixed>0.0</fixed>
|
||||
<distance>1.0</distance>
|
||||
<time>0.0</time>
|
||||
<service>0.0</service>
|
||||
<wait>0.0</wait>
|
||||
</costs>
|
||||
</type>
|
||||
</vehicleTypes>
|
||||
<services>
|
||||
<service id="1" type="service">
|
||||
<location>
|
||||
<id>loc</id>
|
||||
</location>
|
||||
<capacity-dimensions>
|
||||
<dimension index="0">1</dimension>
|
||||
</capacity-dimensions>
|
||||
<duration>2.0</duration>
|
||||
<timeWindows>
|
||||
<timeWindow>
|
||||
<start>0.0</start>
|
||||
<end>1.7976931348623157E308</end>
|
||||
</timeWindow>
|
||||
</timeWindows>
|
||||
</service>
|
||||
<service id="2" type="service">
|
||||
<location>
|
||||
<id>loc2</id>
|
||||
</location>
|
||||
<capacity-dimensions>
|
||||
<dimension index="0">1</dimension>
|
||||
</capacity-dimensions>
|
||||
<duration>4.0</duration>
|
||||
<timeWindows>
|
||||
<timeWindow>
|
||||
<start>0.0</start>
|
||||
<end>1.7976931348623157E308</end>
|
||||
</timeWindow>
|
||||
</timeWindows>
|
||||
</service>
|
||||
</services>
|
||||
<solutions>
|
||||
<solution>
|
||||
<cost>10.0</cost>
|
||||
<routes>
|
||||
<route>
|
||||
<driverId>noDriver</driverId>
|
||||
<vehicleId>v1</vehicleId>
|
||||
<start>0.0</start>
|
||||
<act type="service">
|
||||
<serviceId>1</serviceId>
|
||||
<arrTime>0.0</arrTime>
|
||||
<endTime>0.0</endTime>
|
||||
</act>
|
||||
<end>0.0</end>
|
||||
</route>
|
||||
</routes>
|
||||
<unassignedJobs>
|
||||
<job id="2"/>
|
||||
</unassignedJobs>
|
||||
</solution>
|
||||
</solutions>
|
||||
</problem>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue