mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
refine max-time-in-vehicle constraint
This commit is contained in:
parent
b5998e1d93
commit
db0c39e1c2
22 changed files with 448 additions and 436 deletions
|
|
@ -17,14 +17,6 @@
|
|||
*/
|
||||
package com.graphhopper.jsprit.core.algorithm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.graphhopper.jsprit.core.algorithm.SearchStrategy.DiscoveredSolution;
|
||||
import com.graphhopper.jsprit.core.algorithm.listener.SearchStrategyListener;
|
||||
import com.graphhopper.jsprit.core.algorithm.listener.SearchStrategyModuleListener;
|
||||
|
|
@ -38,6 +30,13 @@ import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolutio
|
|||
import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import com.graphhopper.jsprit.core.util.Solutions;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -155,13 +154,13 @@ public class VehicleRoutingAlgorithm {
|
|||
allJobs.removeAll(route.getTourActivities().getJobs());
|
||||
if (route.getVehicle().getIndex() == 0)
|
||||
throw new IllegalStateException("vehicle used in initial solution has no index. probably a vehicle is used that has not been added to the " +
|
||||
" the VehicleRoutingProblem. only use vehicles that have already been added to the problem.");
|
||||
" the VehicleRoutingProblem. only use vehicles that have already been added to the problem.");
|
||||
for (TourActivity act : route.getActivities()) {
|
||||
if (act.getIndex() == 0)
|
||||
throw new IllegalStateException("act in initial solution has no index. activities are created and associated to their job in VehicleRoutingProblem\n." +
|
||||
" thus if you build vehicle-routes use the jobActivityFactory from vehicle routing problem like that \n" +
|
||||
" VehicleRoute.Builder.newInstance(knownVehicle).setJobActivityFactory(vrp.getJobActivityFactory).addService(..)....build() \n" +
|
||||
" then the activities that are created to build the route are identical to the ones used in VehicleRoutingProblem");
|
||||
" thus if you build vehicle-routes use the jobActivityFactory from vehicle routing problem like that \n" +
|
||||
" VehicleRoute.Builder.newInstance(knownVehicle).setJobActivityFactory(vrp.getJobActivityFactory).addService(..)....build() \n" +
|
||||
" then the activities that are created to build the route are identical to the ones used in VehicleRoutingProblem");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -190,6 +190,49 @@ public class UpdateMaxTimeInVehicle implements StateUpdater, ActivityVisitor{
|
|||
}
|
||||
}
|
||||
|
||||
public void finish(List<TourActivity> activities, Job ignore) {
|
||||
for (Vehicle v : vehicles) {
|
||||
int vehicleIndex = v.getVehicleTypeIdentifier().getIndex();
|
||||
|
||||
//!!! open routes !!!
|
||||
double routeEnd;
|
||||
if (!v.isReturnToDepot()) routeEnd = prevActEndTimes[vehicleIndex];
|
||||
else
|
||||
routeEnd = prevActEndTimes[vehicleIndex] + transportTime.getTransportTime(prevActLocations[vehicleIndex], v.getEndLocation(), prevActEndTimes[vehicleIndex], route.getDriver(), v);
|
||||
|
||||
Map<String, Double> openDeliveries = new HashMap<>();
|
||||
for (Job job : openPickupEndTimes.get(vehicleIndex).keySet()) {
|
||||
if (job == ignore) continue;
|
||||
double actEndTime = openPickupEndTimes.get(vehicleIndex).get(job);
|
||||
double slackTime = job.getMaxTimeInVehicle() - (routeEnd - actEndTime);
|
||||
openDeliveries.put(job.getId(), slackTime);
|
||||
}
|
||||
|
||||
double minSlackTimeAtEnd = minSlackTime(openDeliveries);
|
||||
stateManager.putRouteState(route, v, latestStartId, routeEnd + minSlackTimeAtEnd);
|
||||
List<TourActivity> acts = new ArrayList<>(activities);
|
||||
Collections.reverse(acts);
|
||||
for (TourActivity act : acts) {
|
||||
if (act instanceof ServiceActivity || act instanceof PickupActivity) {
|
||||
String jobId = ((TourActivity.JobActivity) act).getJob().getId();
|
||||
openDeliveries.remove(jobId);
|
||||
double minSlackTime = minSlackTime(openDeliveries);
|
||||
double latestStart = actStart(act, v) + minSlackTime;
|
||||
stateManager.putActivityState(act, v, latestStartId, latestStart);
|
||||
} else {
|
||||
String jobId = ((TourActivity.JobActivity) act).getJob().getId();
|
||||
if (slackTimes.get(vehicleIndex).containsKey(act)) {
|
||||
double slackTime = slackTimes.get(vehicleIndex).get(act);
|
||||
openDeliveries.put(jobId, slackTime);
|
||||
}
|
||||
double minSlackTime = minSlackTime(openDeliveries);
|
||||
double latestStart = actStart(act, v) + minSlackTime;
|
||||
stateManager.putActivityState(act, v, latestStartId, latestStart);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private double actStart(TourActivity act, Vehicle v) {
|
||||
return actStartTimes.get(v.getVehicleTypeIdentifier().getIndex()).get(act);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ public class VehicleDependentTraveledDistance implements StateUpdater, ActivityV
|
|||
|
||||
private List<Vehicle> uniqueVehicles;
|
||||
|
||||
private Map<VehicleTypeKey,State> states;
|
||||
private Map<VehicleTypeKey, State> states;
|
||||
|
||||
public VehicleDependentTraveledDistance(TransportDistance transportCostMatrices, StateManager stateManager, StateId distanceInRouteId, Collection<Vehicle> vehicles) {
|
||||
this.transportDistance = transportCostMatrices;
|
||||
|
|
@ -75,8 +75,8 @@ public class VehicleDependentTraveledDistance implements StateUpdater, ActivityV
|
|||
private List<Vehicle> getUniqueVehicles(Collection<Vehicle> vehicles) {
|
||||
Set<VehicleTypeKey> types = new HashSet<>();
|
||||
List<Vehicle> uniqueVehicles = new ArrayList<>();
|
||||
for(Vehicle v : vehicles){
|
||||
if(!types.contains(v.getVehicleTypeIdentifier())){
|
||||
for (Vehicle v : vehicles) {
|
||||
if (!types.contains(v.getVehicleTypeIdentifier())) {
|
||||
types.add(v.getVehicleTypeIdentifier());
|
||||
uniqueVehicles.add(v);
|
||||
}
|
||||
|
|
@ -88,32 +88,32 @@ public class VehicleDependentTraveledDistance implements StateUpdater, ActivityV
|
|||
public void begin(VehicleRoute route) {
|
||||
this.route = route;
|
||||
states = new HashMap<>();
|
||||
for(Vehicle v : uniqueVehicles){
|
||||
State state = new State(v.getStartLocation(),0);
|
||||
states.put(v.getVehicleTypeIdentifier(),state);
|
||||
for (Vehicle v : uniqueVehicles) {
|
||||
State state = new State(v.getStartLocation(), 0);
|
||||
states.put(v.getVehicleTypeIdentifier(), state);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(TourActivity activity) {
|
||||
for(Vehicle v : uniqueVehicles){
|
||||
for (Vehicle v : uniqueVehicles) {
|
||||
State old = states.get(v.getVehicleTypeIdentifier());
|
||||
double distance = old.getDistance();
|
||||
distance += transportDistance.getDistance(old.getPrevLocation(),activity.getLocation(),0,v);
|
||||
stateManager.putActivityState(activity,v,traveledDistanceId,distance);
|
||||
states.put(v.getVehicleTypeIdentifier(),new State(activity.getLocation(),distance));
|
||||
distance += transportDistance.getDistance(old.getPrevLocation(), activity.getLocation(), 0, v);
|
||||
stateManager.putActivityState(activity, v, traveledDistanceId, distance);
|
||||
states.put(v.getVehicleTypeIdentifier(), new State(activity.getLocation(), distance));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
for(Vehicle v : uniqueVehicles){
|
||||
for (Vehicle v : uniqueVehicles) {
|
||||
State old = states.get(v.getVehicleTypeIdentifier());
|
||||
double distance = old.getDistance();
|
||||
if(v.isReturnToDepot()) {
|
||||
if (v.isReturnToDepot()) {
|
||||
distance += transportDistance.getDistance(old.getPrevLocation(), v.getEndLocation(), 0, v);
|
||||
}
|
||||
stateManager.putRouteState(route,v,traveledDistanceId, distance);
|
||||
stateManager.putRouteState(route, v, traveledDistanceId, distance);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,35 +45,35 @@ public abstract class AbstractVehicle implements Vehicle {
|
|||
|
||||
private VehicleTypeKey vehicleIdentifier;
|
||||
|
||||
private Object userData;
|
||||
private Object userData;
|
||||
|
||||
/**
|
||||
* @return User-specific domain data associated with the vehicle
|
||||
*/
|
||||
@Override
|
||||
/**
|
||||
* @return User-specific domain data associated with the vehicle
|
||||
*/
|
||||
@Override
|
||||
public Object getUserData() {
|
||||
return userData;
|
||||
}
|
||||
return userData;
|
||||
}
|
||||
|
||||
protected void setUserData(Object userData) {
|
||||
this.userData = userData;
|
||||
}
|
||||
protected void setUserData(Object userData) {
|
||||
this.userData = userData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
@Override
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
protected void setIndex(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
protected void setIndex(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VehicleTypeKey getVehicleTypeIdentifier() {
|
||||
return vehicleIdentifier;
|
||||
}
|
||||
@Override
|
||||
public VehicleTypeKey getVehicleTypeIdentifier() {
|
||||
return vehicleIdentifier;
|
||||
}
|
||||
|
||||
protected void setVehicleIdentifier(VehicleTypeKey vehicleTypeIdentifier) {
|
||||
this.vehicleIdentifier = vehicleTypeIdentifier;
|
||||
}
|
||||
protected void setVehicleIdentifier(VehicleTypeKey vehicleTypeIdentifier) {
|
||||
this.vehicleIdentifier = vehicleTypeIdentifier;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,15 +74,14 @@ public final class Location implements HasIndex, HasId {
|
|||
|
||||
/**
|
||||
* Sets user specific domain data associated with the object.
|
||||
*
|
||||
* <p>
|
||||
* <p>
|
||||
* The user data is a black box for the framework, it only stores it,
|
||||
* but never interacts with it in any way.
|
||||
* </p>
|
||||
*
|
||||
* @param userData
|
||||
* any object holding the domain specific user data
|
||||
* associated with the object.
|
||||
* @param userData any object holding the domain specific user data
|
||||
* associated with the object.
|
||||
* @return builder
|
||||
*/
|
||||
public Builder setUserData(Object userData) {
|
||||
|
|
@ -130,7 +129,7 @@ public final class Location implements HasIndex, HasId {
|
|||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public Builder setName(String name){
|
||||
public Builder setName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
|
@ -191,7 +190,9 @@ public final class Location implements HasIndex, HasId {
|
|||
return coordinate;
|
||||
}
|
||||
|
||||
public String getName() { return name; }
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ import java.util.Map;
|
|||
/**
|
||||
* Created by schroeder on 11/10/16.
|
||||
*/
|
||||
public class MaxDistanceConstraint implements HardActivityConstraint{
|
||||
public class MaxDistanceConstraint implements HardActivityConstraint {
|
||||
|
||||
private StateManager stateManager;
|
||||
|
||||
|
|
@ -44,7 +44,7 @@ public class MaxDistanceConstraint implements HardActivityConstraint{
|
|||
|
||||
private Double[] maxDistances;
|
||||
|
||||
public MaxDistanceConstraint(StateManager stateManager, StateId distanceId, TransportDistance distanceCalculator, Map<Vehicle,Double> maxDistancePerVehicleMap) {
|
||||
public MaxDistanceConstraint(StateManager stateManager, StateId distanceId, TransportDistance distanceCalculator, Map<Vehicle, Double> maxDistancePerVehicleMap) {
|
||||
this.stateManager = stateManager;
|
||||
this.distanceId = distanceId;
|
||||
this.distanceCalculator = distanceCalculator;
|
||||
|
|
@ -53,50 +53,50 @@ public class MaxDistanceConstraint implements HardActivityConstraint{
|
|||
|
||||
private void makeArray(Map<Vehicle, Double> maxDistances) {
|
||||
int maxIndex = getMaxIndex(maxDistances.keySet());
|
||||
this.maxDistances = new Double[maxIndex+1];
|
||||
for(Vehicle v : maxDistances.keySet()){
|
||||
this.maxDistances[v.getIndex()]=maxDistances.get(v);
|
||||
this.maxDistances = new Double[maxIndex + 1];
|
||||
for (Vehicle v : maxDistances.keySet()) {
|
||||
this.maxDistances[v.getIndex()] = maxDistances.get(v);
|
||||
}
|
||||
}
|
||||
|
||||
private int getMaxIndex(Collection<Vehicle> vehicles) {
|
||||
int index = 0;
|
||||
for(Vehicle v : vehicles){
|
||||
if(v.getIndex() > index) index = v.getIndex();
|
||||
for (Vehicle v : vehicles) {
|
||||
if (v.getIndex() > index) index = v.getIndex();
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) {
|
||||
if(!hasMaxDistance(iFacts.getNewVehicle())) return ConstraintsStatus.FULFILLED;
|
||||
if (!hasMaxDistance(iFacts.getNewVehicle())) return ConstraintsStatus.FULFILLED;
|
||||
Double currentDistance = 0d;
|
||||
boolean routeIsEmpty = iFacts.getRoute().isEmpty();
|
||||
if(!routeIsEmpty){
|
||||
currentDistance = stateManager.getRouteState(iFacts.getRoute(),iFacts.getNewVehicle(), distanceId,Double.class);
|
||||
if (!routeIsEmpty) {
|
||||
currentDistance = stateManager.getRouteState(iFacts.getRoute(), iFacts.getNewVehicle(), distanceId, Double.class);
|
||||
}
|
||||
double maxDistance = getMaxDistance(iFacts.getNewVehicle());
|
||||
if(currentDistance > maxDistance) return ConstraintsStatus.NOT_FULFILLED_BREAK;
|
||||
if (currentDistance > maxDistance) return ConstraintsStatus.NOT_FULFILLED_BREAK;
|
||||
|
||||
double distancePrevAct2NewAct = distanceCalculator.getDistance(prevAct.getLocation(), newAct.getLocation(), iFacts.getNewDepTime(), iFacts.getNewVehicle());
|
||||
double distanceNewAct2nextAct = distanceCalculator.getDistance(newAct.getLocation(), nextAct.getLocation(), iFacts.getNewDepTime(), iFacts.getNewVehicle());
|
||||
double distancePrevAct2NextAct = distanceCalculator.getDistance(prevAct.getLocation(), nextAct.getLocation(), prevActDepTime, iFacts.getNewVehicle());
|
||||
if(prevAct instanceof Start && nextAct instanceof End) distancePrevAct2NextAct = 0;
|
||||
if(nextAct instanceof End && !iFacts.getNewVehicle().isReturnToDepot()){
|
||||
if (prevAct instanceof Start && nextAct instanceof End) distancePrevAct2NextAct = 0;
|
||||
if (nextAct instanceof End && !iFacts.getNewVehicle().isReturnToDepot()) {
|
||||
distanceNewAct2nextAct = 0;
|
||||
distancePrevAct2NextAct = 0;
|
||||
}
|
||||
double additionalDistance = distancePrevAct2NewAct + distanceNewAct2nextAct - distancePrevAct2NextAct;
|
||||
if(currentDistance + additionalDistance > maxDistance) return ConstraintsStatus.NOT_FULFILLED;
|
||||
if (currentDistance + additionalDistance > maxDistance) return ConstraintsStatus.NOT_FULFILLED;
|
||||
|
||||
|
||||
double additionalDistanceOfPickup = 0;
|
||||
if(newAct instanceof DeliverShipment){
|
||||
if (newAct instanceof DeliverShipment) {
|
||||
int iIndexOfPickup = iFacts.getRelatedActivityContext().getInsertionIndex();
|
||||
TourActivity pickup = iFacts.getAssociatedActivities().get(0);
|
||||
TourActivity actBeforePickup;
|
||||
if(iIndexOfPickup > 0) actBeforePickup = iFacts.getRoute().getActivities().get(iIndexOfPickup-1);
|
||||
else actBeforePickup = new Start(iFacts.getNewVehicle().getStartLocation(),0,Double.MAX_VALUE);
|
||||
if (iIndexOfPickup > 0) actBeforePickup = iFacts.getRoute().getActivities().get(iIndexOfPickup - 1);
|
||||
else actBeforePickup = new Start(iFacts.getNewVehicle().getStartLocation(), 0, Double.MAX_VALUE);
|
||||
TourActivity actAfterPickup;
|
||||
if (iIndexOfPickup < iFacts.getRoute().getActivities().size())
|
||||
actAfterPickup = iFacts.getRoute().getActivities().get(iIndexOfPickup);
|
||||
|
|
@ -114,21 +114,21 @@ public class MaxDistanceConstraint implements HardActivityConstraint{
|
|||
}
|
||||
|
||||
|
||||
if(currentDistance + additionalDistance + additionalDistanceOfPickup > maxDistance){
|
||||
if (currentDistance + additionalDistance + additionalDistanceOfPickup > maxDistance) {
|
||||
return ConstraintsStatus.NOT_FULFILLED;
|
||||
}
|
||||
|
||||
return ConstraintsStatus.FULFILLED;
|
||||
}
|
||||
|
||||
private boolean hasMaxDistance(Vehicle newVehicle){
|
||||
if(newVehicle.getIndex() >= this.maxDistances.length) return false;
|
||||
private boolean hasMaxDistance(Vehicle newVehicle) {
|
||||
if (newVehicle.getIndex() >= this.maxDistances.length) return false;
|
||||
return this.maxDistances[newVehicle.getIndex()] != null;
|
||||
}
|
||||
|
||||
private double getMaxDistance(Vehicle newVehicle) {
|
||||
Double maxDistance = this.maxDistances[newVehicle.getIndex()];
|
||||
if(maxDistance == null) return Double.MAX_VALUE;
|
||||
if (maxDistance == null) return Double.MAX_VALUE;
|
||||
return maxDistance;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,14 +72,15 @@ public interface Vehicle extends HasId, HasIndex {
|
|||
public abstract VehicleTypeKey getVehicleTypeIdentifier();
|
||||
|
||||
public abstract Skills getSkills();
|
||||
/**
|
||||
* @return User-specific domain data associated with the vehicle
|
||||
*/
|
||||
public Object getUserData();
|
||||
|
||||
/**
|
||||
* @return User-specific domain data associated with the vehicle
|
||||
*/
|
||||
public Object getUserData();
|
||||
|
||||
public abstract Break getBreak();
|
||||
// Switch to this as soon as we switct to Java 8:
|
||||
// default Object getUserData() {
|
||||
// return null;
|
||||
// };
|
||||
// Switch to this as soon as we switct to Java 8:
|
||||
// default Object getUserData() {
|
||||
// return null;
|
||||
// };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,13 +17,12 @@
|
|||
*/
|
||||
package com.graphhopper.jsprit.core.problem.vehicle;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.graphhopper.jsprit.core.problem.AbstractVehicle;
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import com.graphhopper.jsprit.core.problem.Skills;
|
||||
import com.graphhopper.jsprit.core.problem.job.Break;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -153,15 +152,14 @@ public class VehicleImpl extends AbstractVehicle {
|
|||
|
||||
/**
|
||||
* Sets user specific domain data associated with the object.
|
||||
*
|
||||
* <p>
|
||||
* <p>
|
||||
* The user data is a black box for the framework, it only stores it,
|
||||
* but never interacts with it in any way.
|
||||
* </p>
|
||||
*
|
||||
* @param userData
|
||||
* any object holding the domain specific user data
|
||||
* associated with the object.
|
||||
* @param userData any object holding the domain specific user data
|
||||
* associated with the object.
|
||||
* @return builder
|
||||
*/
|
||||
public Builder setUserData(Object userData) {
|
||||
|
|
@ -260,7 +258,7 @@ public class VehicleImpl extends AbstractVehicle {
|
|||
if (startLocation != null && endLocation != null) {
|
||||
if (!startLocation.getId().equals(endLocation.getId()) && !returnToDepot)
|
||||
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 you set endLocation, returnToDepot must be true. if returnToDepot is false, endLocationCoord must not be specified.");
|
||||
}
|
||||
if (startLocation != null && endLocation == null) {
|
||||
endLocation = startLocation;
|
||||
|
|
@ -344,11 +342,11 @@ public class VehicleImpl extends AbstractVehicle {
|
|||
@Override
|
||||
public String toString() {
|
||||
return "[id=" + id + "]" +
|
||||
"[type=" + type + "]" +
|
||||
"[startLocation=" + startLocation + "]" +
|
||||
"[endLocation=" + endLocation + "]" +
|
||||
"[isReturnToDepot=" + isReturnToDepot() + "]" +
|
||||
"[skills=" + skills + "]";
|
||||
"[type=" + type + "]" +
|
||||
"[startLocation=" + startLocation + "]" +
|
||||
"[endLocation=" + endLocation + "]" +
|
||||
"[isReturnToDepot=" + isReturnToDepot() + "]" +
|
||||
"[skills=" + skills + "]";
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -263,8 +263,8 @@ public class VehicleTypeImpl implements VehicleType {
|
|||
if (dimVal < 0) throw new IllegalArgumentException("capacity value cannot be negative");
|
||||
if (capacityDimensions != null)
|
||||
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.");
|
||||
"addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with .setCapacityDimensions(Capacity capacity)." +
|
||||
"You used both methods.");
|
||||
dimensionAdded = true;
|
||||
capacityBuilder.addDimension(dimIndex, dimVal);
|
||||
return this;
|
||||
|
|
@ -284,8 +284,8 @@ public class VehicleTypeImpl implements VehicleType {
|
|||
public Builder setCapacityDimensions(Capacity capacity) {
|
||||
if (dimensionAdded)
|
||||
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.");
|
||||
"addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with .setCapacityDimensions(Capacity capacity)." +
|
||||
"You used both methods.");
|
||||
this.capacityDimensions = capacity;
|
||||
return this;
|
||||
}
|
||||
|
|
@ -301,7 +301,7 @@ public class VehicleTypeImpl implements VehicleType {
|
|||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result
|
||||
+ ((typeId == null) ? 0 : typeId.hashCode());
|
||||
+ ((typeId == null) ? 0 : typeId.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -381,8 +381,8 @@ public class VehicleTypeImpl implements VehicleType {
|
|||
@Override
|
||||
public String toString() {
|
||||
return "[typeId=" + typeId + "]" +
|
||||
"[capacity=" + capacityDimensions + "]" +
|
||||
"[costs=" + vehicleCostParams + "]";
|
||||
"[capacity=" + capacityDimensions + "]" +
|
||||
"[costs=" + vehicleCostParams + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -97,9 +97,9 @@ public class FastVehicleRoutingTransportCostsMatrix extends AbstractForwardVehic
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder addTransportTimeAndDistance(int fromIndex, int toIndex, double time, double distance){
|
||||
public Builder addTransportTimeAndDistance(int fromIndex, int toIndex, double time, double distance) {
|
||||
addTransportTime(fromIndex, toIndex, time);
|
||||
addTransportDistance(fromIndex,toIndex,distance);
|
||||
addTransportDistance(fromIndex, toIndex, distance);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -138,9 +138,10 @@ public class UnassignedJobReasonTracker implements JobUnassignedListener {
|
|||
public String getHumanReadableReason(String failedConstraintName) {
|
||||
return getCodesToReason().get(getCode(failedConstraintName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the most likely reason code i.e. the reason (failed constraint) being observed most often.
|
||||
*
|
||||
* <p>
|
||||
* 1 --> "cannot serve required skill
|
||||
* 2 --> "cannot be visited within time window"
|
||||
* 3 --> "does not fit into any vehicle due to capacity"
|
||||
|
|
|
|||
|
|
@ -115,8 +115,8 @@ public class TestLocalActivityInsertionCostsCalculator {
|
|||
new StateManager(vrp));
|
||||
double cost = localActivityInsertionCostsCalculator.getCosts(
|
||||
jobInsertionContext,
|
||||
new Start(v.getStartLocation(),0,Double.MAX_VALUE),
|
||||
new End(v.getEndLocation(),0,Double.MAX_VALUE),
|
||||
new Start(v.getStartLocation(), 0, Double.MAX_VALUE),
|
||||
new End(v.getEndLocation(), 0, Double.MAX_VALUE),
|
||||
vrp.getActivities(s).get(0),
|
||||
0);
|
||||
assertEquals(20., cost, Math.ulp(20.));
|
||||
|
|
@ -146,15 +146,15 @@ public class TestLocalActivityInsertionCostsCalculator {
|
|||
new StateManager(vrp));
|
||||
double cost = localActivityInsertionCostsCalculator.getCosts(
|
||||
jobInsertionContext,
|
||||
new Start(v.getStartLocation(),0,Double.MAX_VALUE),
|
||||
new End(v.getEndLocation(),0,Double.MAX_VALUE),
|
||||
new Start(v.getStartLocation(), 0, Double.MAX_VALUE),
|
||||
new End(v.getEndLocation(), 0, Double.MAX_VALUE),
|
||||
vrp.getActivities(s).get(0),
|
||||
0);
|
||||
assertEquals(20., cost, Math.ulp(20.));
|
||||
cost = localActivityInsertionCostsCalculator.getCosts(
|
||||
jobInsertionContext,
|
||||
vrp.getActivities(s).get(0),
|
||||
new End(v.getEndLocation(),0,Double.MAX_VALUE),
|
||||
new End(v.getEndLocation(), 0, Double.MAX_VALUE),
|
||||
vrp.getActivities(s).get(1),
|
||||
0);
|
||||
assertEquals(10, cost, Math.ulp(10.));
|
||||
|
|
|
|||
|
|
@ -18,17 +18,14 @@
|
|||
|
||||
package com.graphhopper.jsprit.core.problem;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import com.graphhopper.jsprit.core.util.Coordinate;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.graphhopper.jsprit.core.util.Coordinate;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Created by schroeder on 16.12.14.
|
||||
|
|
@ -45,7 +42,7 @@ public class LocationTest {
|
|||
@Test
|
||||
public void whenNameSet_buildLocation() {
|
||||
Location l = Location.Builder.newInstance().setName("mystreet 6a").setIndex(1).build();
|
||||
Assert.assertEquals("mystreet 6a",l.getName());
|
||||
Assert.assertEquals("mystreet 6a", l.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -82,8 +79,8 @@ public class LocationTest {
|
|||
@Test
|
||||
public void whenCoordinateSet_build() {
|
||||
Location l = Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10, 20)).build();
|
||||
Assert.assertEquals(10., l.getCoordinate().getX(),0.001);
|
||||
Assert.assertEquals(20., l.getCoordinate().getY(),0.001);
|
||||
Assert.assertEquals(10., l.getCoordinate().getX(), 0.001);
|
||||
Assert.assertEquals(20., l.getCoordinate().getY(), 0.001);
|
||||
Assert.assertTrue(true);
|
||||
}
|
||||
|
||||
|
|
@ -91,8 +88,8 @@ public class LocationTest {
|
|||
public void whenCoordinateSetWithFactory_returnCorrectLocation() {
|
||||
// Location l = Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10,20)).build();
|
||||
Location l = Location.newInstance(10, 20);
|
||||
Assert.assertEquals(10., l.getCoordinate().getX(),0.001);
|
||||
Assert.assertEquals(20., l.getCoordinate().getY(),0.001);
|
||||
Assert.assertEquals(10., l.getCoordinate().getX(), 0.001);
|
||||
Assert.assertEquals(20., l.getCoordinate().getY(), 0.001);
|
||||
Assert.assertTrue(true);
|
||||
}
|
||||
|
||||
|
|
@ -100,7 +97,7 @@ public class LocationTest {
|
|||
@Test
|
||||
public void whenSettingUserData_itIsAssociatedWithTheLocation() {
|
||||
Location one = Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10, 20))
|
||||
.setUserData(new HashMap<String, Object>()).build();
|
||||
.setUserData(new HashMap<String, Object>()).build();
|
||||
Location two = Location.Builder.newInstance().setIndex(1).setUserData(42).build();
|
||||
Location three = Location.Builder.newInstance().setIndex(2).build();
|
||||
|
||||
|
|
|
|||
|
|
@ -37,14 +37,14 @@ import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
|
|||
import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
|
||||
import com.graphhopper.jsprit.core.problem.vehicle.VehicleImpl;
|
||||
import com.graphhopper.jsprit.core.util.ManhattanCosts;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by schroeder on 18/05/16.
|
||||
|
|
@ -63,31 +63,31 @@ public class VehicleDependentTraveledDistanceTest {
|
|||
|
||||
VehicleRoutingProblem vrp;
|
||||
|
||||
Delivery d1,d2,newDelivery;
|
||||
Delivery d1, d2, newDelivery;
|
||||
|
||||
Pickup pickup;
|
||||
|
||||
Shipment s1;
|
||||
|
||||
Map<Vehicle,Double> maxDistanceMap;
|
||||
Map<Vehicle, Double> maxDistanceMap;
|
||||
|
||||
|
||||
@Before
|
||||
public void doBefore(){
|
||||
vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0,0)).build();
|
||||
vehicle2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance(10,10)).build();
|
||||
public void doBefore() {
|
||||
vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build();
|
||||
vehicle2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance(10, 10)).build();
|
||||
|
||||
maxDistanceMap = new HashMap<>();
|
||||
maxDistanceMap.put(vehicle,200d);
|
||||
maxDistanceMap.put(vehicle2,200d);
|
||||
maxDistanceMap.put(vehicle, 200d);
|
||||
maxDistanceMap.put(vehicle2, 200d);
|
||||
|
||||
d1 = Delivery.Builder.newInstance("d1").setLocation(Location.newInstance(10,10)).build();
|
||||
d2 = Delivery.Builder.newInstance("d2").setLocation(Location.newInstance(20,15)).build();
|
||||
pickup = Pickup.Builder.newInstance("pickup").setLocation(Location.newInstance(50,50)).build();
|
||||
s1 = Shipment.Builder.newInstance("s1").setPickupLocation(Location.newInstance(35,30))
|
||||
.setDeliveryLocation(Location.newInstance(20,25)).build();
|
||||
d1 = Delivery.Builder.newInstance("d1").setLocation(Location.newInstance(10, 10)).build();
|
||||
d2 = Delivery.Builder.newInstance("d2").setLocation(Location.newInstance(20, 15)).build();
|
||||
pickup = Pickup.Builder.newInstance("pickup").setLocation(Location.newInstance(50, 50)).build();
|
||||
s1 = Shipment.Builder.newInstance("s1").setPickupLocation(Location.newInstance(35, 30))
|
||||
.setDeliveryLocation(Location.newInstance(20, 25)).build();
|
||||
|
||||
newDelivery = Delivery.Builder.newInstance("new").setLocation(Location.newInstance(-10,10)).build();
|
||||
newDelivery = Delivery.Builder.newInstance("new").setLocation(Location.newInstance(-10, 10)).build();
|
||||
|
||||
vrp = VehicleRoutingProblem.Builder.newInstance()
|
||||
.setRoutingCost(new ManhattanCosts()).addVehicle(vehicle).addVehicle(vehicle2)
|
||||
|
|
@ -104,35 +104,35 @@ public class VehicleDependentTraveledDistanceTest {
|
|||
new com.graphhopper.jsprit.core.algorithm.state.VehicleDependentTraveledDistance(new TransportDistance() {
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return new ManhattanCosts().getDistance(from,to,departureTime,vehicle);
|
||||
return new ManhattanCosts().getDistance(from, to, departureTime, vehicle);
|
||||
}
|
||||
},stateManager,traveledDistanceId,Arrays.asList(vehicle,vehicle2));
|
||||
}, stateManager, traveledDistanceId, Arrays.asList(vehicle, vehicle2));
|
||||
|
||||
stateManager.addStateUpdater(traveledDistance);
|
||||
stateManager.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenEndLocationIsSet_constraintShouldWork(){
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0,0))
|
||||
.setEndLocation(Location.newInstance(10,0)).build();
|
||||
Pickup pickup = Pickup.Builder.newInstance("pickup").setLocation(Location.newInstance(10,0)).build();
|
||||
public void whenEndLocationIsSet_constraintShouldWork() {
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0))
|
||||
.setEndLocation(Location.newInstance(10, 0)).build();
|
||||
Pickup pickup = Pickup.Builder.newInstance("pickup").setLocation(Location.newInstance(10, 0)).build();
|
||||
vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(vehicle).addJob(pickup).build();
|
||||
route = VehicleRoute.emptyRoute();
|
||||
maxDistanceMap = new HashMap<>();
|
||||
maxDistanceMap.put(vehicle,5d);
|
||||
maxDistanceMap.put(vehicle, 5d);
|
||||
|
||||
MaxDistanceConstraint maxDistanceConstraint =
|
||||
new MaxDistanceConstraint(new StateManager(vrp), traveledDistanceId, new TransportDistance() {
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return vrp.getTransportCosts().getTransportTime(from,to,departureTime, null, vehicle);
|
||||
return vrp.getTransportCosts().getTransportTime(from, to, departureTime, null, vehicle);
|
||||
}
|
||||
},maxDistanceMap);
|
||||
JobInsertionContext context = new JobInsertionContext(route,pickup,vehicle,null,0);
|
||||
}, maxDistanceMap);
|
||||
JobInsertionContext context = new JobInsertionContext(route, pickup, vehicle, null, 0);
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,
|
||||
new Start(vehicle.getStartLocation(),0,Double.MAX_VALUE),vrp.getActivities(pickup).get(0),
|
||||
new End(vehicle.getEndLocation(),0,Double.MAX_VALUE),0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
new Start(vehicle.getStartLocation(), 0, Double.MAX_VALUE), vrp.getActivities(pickup).get(0),
|
||||
new End(vehicle.getEndLocation(), 0, Double.MAX_VALUE), 0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -142,121 +142,121 @@ vehicle2: 160.0
|
|||
vehicle2 (max distance): 180.0
|
||||
*/
|
||||
@Test
|
||||
public void insertNewInVehicleShouldFail(){
|
||||
public void insertNewInVehicleShouldFail() {
|
||||
MaxDistanceConstraint maxDistanceConstraint =
|
||||
new MaxDistanceConstraint(stateManager, traveledDistanceId, new TransportDistance() {
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return vrp.getTransportCosts().getTransportTime(from,to,departureTime, null, vehicle);
|
||||
return vrp.getTransportCosts().getTransportTime(from, to, departureTime, null, vehicle);
|
||||
}
|
||||
},maxDistanceMap);
|
||||
JobInsertionContext context = new JobInsertionContext(route,newDelivery,vehicle,null,0);
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,route.getStart(),newAct(),act(0),0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,act(0),newAct(),act(1),0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,act(1),newAct(),act(2),0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,act(2),newAct(),act(3),0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,act(3),newAct(),act(4),0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,act(4),newAct(),route.getEnd(),0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
}, maxDistanceMap);
|
||||
JobInsertionContext context = new JobInsertionContext(route, newDelivery, vehicle, null, 0);
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context, route.getStart(), newAct(), act(0), 0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context, act(0), newAct(), act(1), 0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context, act(1), newAct(), act(2), 0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context, act(2), newAct(), act(3), 0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context, act(3), newAct(), act(4), 0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context, act(4), newAct(), route.getEnd(), 0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void insertNewInVehicle2ShouldBeCorrect(){
|
||||
public void insertNewInVehicle2ShouldBeCorrect() {
|
||||
//current distance vehicle2: 160 allowed: 200
|
||||
MaxDistanceConstraint maxDistanceConstraint =
|
||||
new MaxDistanceConstraint(stateManager, traveledDistanceId, new TransportDistance() {
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return vrp.getTransportCosts().getTransportTime(from,to,departureTime, null, vehicle);
|
||||
return vrp.getTransportCosts().getTransportTime(from, to, departureTime, null, vehicle);
|
||||
}
|
||||
},maxDistanceMap);
|
||||
JobInsertionContext context = new JobInsertionContext(route,newDelivery,vehicle2,null,0);
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,route.getStart(),newAct(),act(0),0).equals(HardActivityConstraint.ConstraintsStatus.FULFILLED));
|
||||
}, maxDistanceMap);
|
||||
JobInsertionContext context = new JobInsertionContext(route, newDelivery, vehicle2, null, 0);
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context, route.getStart(), newAct(), act(0), 0).equals(HardActivityConstraint.ConstraintsStatus.FULFILLED));
|
||||
//additional distance: 20+35-15=40
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,act(0),newAct(),act(1),0).equals(HardActivityConstraint.ConstraintsStatus.FULFILLED));
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context, act(0), newAct(), act(1), 0).equals(HardActivityConstraint.ConstraintsStatus.FULFILLED));
|
||||
//additional distance: 35+65-30=70
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,act(1),newAct(),act(2),0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context, act(1), newAct(), act(2), 0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
//additional distance: 65+100-35
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,act(2),newAct(),act(3),0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context, act(2), newAct(), act(3), 0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
//additional distance: 100+45-55
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,act(3),newAct(),act(4),0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context, act(3), newAct(), act(4), 0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
//additional distance: 45+20-25
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,act(4),newAct(),route.getEnd(),0).equals(HardActivityConstraint.ConstraintsStatus.FULFILLED));
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context, act(4), newAct(), route.getEnd(), 0).equals(HardActivityConstraint.ConstraintsStatus.FULFILLED));
|
||||
}
|
||||
|
||||
private TourActivity act(int i) {
|
||||
return route.getActivities().get(i);
|
||||
}
|
||||
|
||||
private TourActivity newAct(){
|
||||
private TourActivity newAct() {
|
||||
return vrp.getActivities(newDelivery).get(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void traveledDistanceShouldBeCorrect(){
|
||||
Assert.assertEquals(20d,stateManager.getActivityState(route.getActivities().get(0),vehicle,traveledDistanceId,Double.class),0.01);
|
||||
Assert.assertEquals(35d,stateManager.getActivityState(route.getActivities().get(1),vehicle,traveledDistanceId,Double.class),0.01);
|
||||
Assert.assertEquals(65d,stateManager.getActivityState(route.getActivities().get(2),vehicle,traveledDistanceId,Double.class),0.01);
|
||||
Assert.assertEquals(100d,stateManager.getActivityState(route.getActivities().get(3),vehicle,traveledDistanceId,Double.class),0.01);
|
||||
Assert.assertEquals(155d,stateManager.getActivityState(route.getActivities().get(4),vehicle,traveledDistanceId,Double.class),0.01);
|
||||
public void traveledDistanceShouldBeCorrect() {
|
||||
Assert.assertEquals(20d, stateManager.getActivityState(route.getActivities().get(0), vehicle, traveledDistanceId, Double.class), 0.01);
|
||||
Assert.assertEquals(35d, stateManager.getActivityState(route.getActivities().get(1), vehicle, traveledDistanceId, Double.class), 0.01);
|
||||
Assert.assertEquals(65d, stateManager.getActivityState(route.getActivities().get(2), vehicle, traveledDistanceId, Double.class), 0.01);
|
||||
Assert.assertEquals(100d, stateManager.getActivityState(route.getActivities().get(3), vehicle, traveledDistanceId, Double.class), 0.01);
|
||||
Assert.assertEquals(155d, stateManager.getActivityState(route.getActivities().get(4), vehicle, traveledDistanceId, Double.class), 0.01);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void traveledDistanceWithVehicle2ShouldBeCorrect(){
|
||||
Assert.assertEquals(0d,stateManager.getActivityState(route.getActivities().get(0),vehicle2,traveledDistanceId,Double.class),0.01);
|
||||
Assert.assertEquals(15d,stateManager.getActivityState(route.getActivities().get(1),vehicle2,traveledDistanceId,Double.class),0.01);
|
||||
Assert.assertEquals(45d,stateManager.getActivityState(route.getActivities().get(2),vehicle2,traveledDistanceId,Double.class),0.01);
|
||||
Assert.assertEquals(80d,stateManager.getActivityState(route.getActivities().get(3),vehicle2,traveledDistanceId,Double.class),0.01);
|
||||
Assert.assertEquals(135d,stateManager.getActivityState(route.getActivities().get(4),vehicle2,traveledDistanceId,Double.class),0.01);
|
||||
public void traveledDistanceWithVehicle2ShouldBeCorrect() {
|
||||
Assert.assertEquals(0d, stateManager.getActivityState(route.getActivities().get(0), vehicle2, traveledDistanceId, Double.class), 0.01);
|
||||
Assert.assertEquals(15d, stateManager.getActivityState(route.getActivities().get(1), vehicle2, traveledDistanceId, Double.class), 0.01);
|
||||
Assert.assertEquals(45d, stateManager.getActivityState(route.getActivities().get(2), vehicle2, traveledDistanceId, Double.class), 0.01);
|
||||
Assert.assertEquals(80d, stateManager.getActivityState(route.getActivities().get(3), vehicle2, traveledDistanceId, Double.class), 0.01);
|
||||
Assert.assertEquals(135d, stateManager.getActivityState(route.getActivities().get(4), vehicle2, traveledDistanceId, Double.class), 0.01);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void distanceOfShipmentInRoute(){
|
||||
double traveledDistanceBeforePickup = stateManager.getActivityState(route.getActivities().get(2), vehicle,traveledDistanceId, Double.class);
|
||||
public void distanceOfShipmentInRoute() {
|
||||
double traveledDistanceBeforePickup = stateManager.getActivityState(route.getActivities().get(2), vehicle, traveledDistanceId, Double.class);
|
||||
double traveledDistanceBeforeDelivery = stateManager.getActivityState(route.getActivities().get(4), vehicle, traveledDistanceId, Double.class);
|
||||
Assert.assertEquals(90d,traveledDistanceBeforeDelivery-traveledDistanceBeforePickup,0.01);
|
||||
Assert.assertEquals(90d, traveledDistanceBeforeDelivery - traveledDistanceBeforePickup, 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void distanceOfShipmentInRouteVehicle2(){
|
||||
double traveledDistanceBeforePickup = stateManager.getActivityState(route.getActivities().get(2), vehicle2,traveledDistanceId, Double.class);
|
||||
public void distanceOfShipmentInRouteVehicle2() {
|
||||
double traveledDistanceBeforePickup = stateManager.getActivityState(route.getActivities().get(2), vehicle2, traveledDistanceId, Double.class);
|
||||
double traveledDistanceBeforeDelivery = stateManager.getActivityState(route.getActivities().get(4), vehicle2, traveledDistanceId, Double.class);
|
||||
Assert.assertEquals(90d,traveledDistanceBeforeDelivery-traveledDistanceBeforePickup,0.01);
|
||||
Assert.assertEquals(90d, traveledDistanceBeforeDelivery - traveledDistanceBeforePickup, 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void distanceOfPickupInRoute(){
|
||||
public void distanceOfPickupInRoute() {
|
||||
double traveledDistanceBeforePickup = stateManager.getActivityState(route.getActivities().get(3), vehicle, traveledDistanceId, Double.class);
|
||||
double total = stateManager.getRouteState(route, vehicle,traveledDistanceId, Double.class);
|
||||
Assert.assertEquals(100d,total-traveledDistanceBeforePickup,0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void distanceOfPickupInRouteVehicle2(){
|
||||
double traveledDistanceBeforePickup = stateManager.getActivityState(route.getActivities().get(3), vehicle2, traveledDistanceId, Double.class);
|
||||
double total = stateManager.getRouteState(route, vehicle2,traveledDistanceId, Double.class);
|
||||
Assert.assertEquals(80d,total-traveledDistanceBeforePickup,0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void distanceToTravelShouldBeCorrect(){
|
||||
double total = stateManager.getRouteState(route, vehicle, traveledDistanceId, Double.class);
|
||||
Assert.assertEquals(180d,total - stateManager.getActivityState(route.getActivities().get(0),vehicle,traveledDistanceId,Double.class),0.01);
|
||||
Assert.assertEquals(100d, total - traveledDistanceBeforePickup, 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void distanceOfPickupInRouteVehicle2() {
|
||||
double traveledDistanceBeforePickup = stateManager.getActivityState(route.getActivities().get(3), vehicle2, traveledDistanceId, Double.class);
|
||||
double total = stateManager.getRouteState(route, vehicle2, traveledDistanceId, Double.class);
|
||||
Assert.assertEquals(80d, total - traveledDistanceBeforePickup, 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void distanceToTravelShouldBeCorrect() {
|
||||
double total = stateManager.getRouteState(route, vehicle, traveledDistanceId, Double.class);
|
||||
Assert.assertEquals(180d, total - stateManager.getActivityState(route.getActivities().get(0), vehicle, traveledDistanceId, Double.class), 0.01);
|
||||
Assert.assertEquals(165d, total - stateManager.getActivityState(route.getActivities().get(1), vehicle, traveledDistanceId, Double.class), 0.01);
|
||||
Assert.assertEquals(135d,total - stateManager.getActivityState(route.getActivities().get(2),vehicle,traveledDistanceId,Double.class),0.01);
|
||||
Assert.assertEquals(135d, total - stateManager.getActivityState(route.getActivities().get(2), vehicle, traveledDistanceId, Double.class), 0.01);
|
||||
Assert.assertEquals(100d, total - stateManager.getActivityState(route.getActivities().get(3), vehicle, traveledDistanceId, Double.class), 0.01);
|
||||
Assert.assertEquals(45d, total - stateManager.getActivityState(route.getActivities().get(4), vehicle, traveledDistanceId, Double.class), 0.01);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void distanceToTravelShouldBeCorrectVehicle2(){
|
||||
public void distanceToTravelShouldBeCorrectVehicle2() {
|
||||
double total = stateManager.getRouteState(route, vehicle2, traveledDistanceId, Double.class);
|
||||
Assert.assertEquals(160d,total - stateManager.getActivityState(route.getActivities().get(0),vehicle2,traveledDistanceId,Double.class),0.01);
|
||||
Assert.assertEquals(160d, total - stateManager.getActivityState(route.getActivities().get(0), vehicle2, traveledDistanceId, Double.class), 0.01);
|
||||
Assert.assertEquals(145d, total - stateManager.getActivityState(route.getActivities().get(1), vehicle2, traveledDistanceId, Double.class), 0.01);
|
||||
Assert.assertEquals(115d,total - stateManager.getActivityState(route.getActivities().get(2),vehicle2,traveledDistanceId,Double.class),0.01);
|
||||
Assert.assertEquals(115d, total - stateManager.getActivityState(route.getActivities().get(2), vehicle2, traveledDistanceId, Double.class), 0.01);
|
||||
Assert.assertEquals(80d, total - stateManager.getActivityState(route.getActivities().get(3), vehicle2, traveledDistanceId, Double.class), 0.01);
|
||||
Assert.assertEquals(25d, total - stateManager.getActivityState(route.getActivities().get(4), vehicle2, traveledDistanceId, Double.class), 0.01);
|
||||
|
||||
|
|
@ -280,16 +280,16 @@ vehicle2 (max distance): 180.0
|
|||
context.getAssociatedActivities().add(vrp.getActivities(shipment).get(0));
|
||||
context.getAssociatedActivities().add(vrp.getActivities(shipment).get(1));
|
||||
maxDistanceMap = new HashMap<>();
|
||||
maxDistanceMap.put(vehicle,12d);
|
||||
maxDistanceMap.put(vehicle, 12d);
|
||||
|
||||
StateManager stateManager = new StateManager(vrp);
|
||||
MaxDistanceConstraint maxDistanceConstraint =
|
||||
new MaxDistanceConstraint(stateManager, traveledDistanceId, new TransportDistance() {
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return vrp.getTransportCosts().getTransportTime(from,to,departureTime, null, vehicle);
|
||||
return vrp.getTransportCosts().getTransportTime(from, to, departureTime, null, vehicle);
|
||||
}
|
||||
},maxDistanceMap);
|
||||
}, maxDistanceMap);
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,
|
||||
new Start(vehicle.getStartLocation(), 0, Double.MAX_VALUE),
|
||||
vrp.getActivities(shipment).get(0),
|
||||
|
|
@ -327,16 +327,16 @@ vehicle2 (max distance): 180.0
|
|||
context.getAssociatedActivities().add(vrp.getActivities(shipment).get(0));
|
||||
context.getAssociatedActivities().add(vrp.getActivities(shipment).get(1));
|
||||
maxDistanceMap = new HashMap<>();
|
||||
maxDistanceMap.put(vehicle,10d);
|
||||
maxDistanceMap.put(vehicle, 10d);
|
||||
|
||||
StateManager stateManager = new StateManager(vrp);
|
||||
MaxDistanceConstraint maxDistanceConstraint =
|
||||
new MaxDistanceConstraint(stateManager, traveledDistanceId, new TransportDistance() {
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return vrp.getTransportCosts().getTransportTime(from,to,departureTime, null, vehicle);
|
||||
return vrp.getTransportCosts().getTransportTime(from, to, departureTime, null, vehicle);
|
||||
}
|
||||
},maxDistanceMap);
|
||||
}, maxDistanceMap);
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,
|
||||
new Start(vehicle.getStartLocation(), 0, Double.MAX_VALUE),
|
||||
vrp.getActivities(shipment).get(0),
|
||||
|
|
|
|||
|
|
@ -17,18 +17,14 @@
|
|||
*/
|
||||
package com.graphhopper.jsprit.core.problem.job;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class DeliveryTest {
|
||||
|
||||
|
|
@ -40,9 +36,9 @@ public class DeliveryTest {
|
|||
@Test
|
||||
public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo() {
|
||||
Delivery one = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("foofoo"))
|
||||
.addSizeDimension(0, 2)
|
||||
.addSizeDimension(1, 4)
|
||||
.build();
|
||||
.addSizeDimension(0, 2)
|
||||
.addSizeDimension(1, 4)
|
||||
.build();
|
||||
assertEquals(2, one.getSize().getNuOfDimensions());
|
||||
assertEquals(2, one.getSize().get(0));
|
||||
assertEquals(4, one.getSize().get(1));
|
||||
|
|
@ -52,7 +48,7 @@ public class DeliveryTest {
|
|||
@Test
|
||||
public void whenPickupIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero() {
|
||||
Delivery one = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("foofoo"))
|
||||
.build();
|
||||
.build();
|
||||
assertEquals(1, one.getSize().getNuOfDimensions());
|
||||
assertEquals(0, one.getSize().get(0));
|
||||
}
|
||||
|
|
@ -60,7 +56,7 @@ public class DeliveryTest {
|
|||
@Test
|
||||
public void whenPickupIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly() {
|
||||
Delivery one = Delivery.Builder.newInstance("s").addSizeDimension(0, 1).setLocation(Location.newInstance("foofoo"))
|
||||
.build();
|
||||
.build();
|
||||
assertEquals(1, one.getSize().getNuOfDimensions());
|
||||
assertEquals(1, one.getSize().get(0));
|
||||
}
|
||||
|
|
@ -68,7 +64,7 @@ public class DeliveryTest {
|
|||
@Test
|
||||
public void whenAddingSkills_theyShouldBeAddedCorrectly() {
|
||||
Delivery s = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addRequiredSkill("drill").addRequiredSkill("screwdriver").build();
|
||||
.addRequiredSkill("drill").addRequiredSkill("screwdriver").build();
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("ScrewDriver"));
|
||||
}
|
||||
|
|
@ -76,7 +72,7 @@ public class DeliveryTest {
|
|||
@Test
|
||||
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly() {
|
||||
Delivery s = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build();
|
||||
.addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build();
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drilL"));
|
||||
}
|
||||
|
|
@ -84,7 +80,7 @@ public class DeliveryTest {
|
|||
@Test
|
||||
public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() {
|
||||
Delivery s = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addRequiredSkill("screwDriver").build();
|
||||
.addRequiredSkill("screwDriver").build();
|
||||
assertFalse(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertFalse(s.getRequiredSkills().containsSkill("drilL"));
|
||||
}
|
||||
|
|
@ -92,21 +88,21 @@ public class DeliveryTest {
|
|||
@Test
|
||||
public void nameShouldBeAssigned() {
|
||||
Delivery s = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setName("name").build();
|
||||
.setName("name").build();
|
||||
assertEquals("name", s.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingPriorities_itShouldBeSetCorrectly(){
|
||||
Delivery s = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setPriority(3).build();
|
||||
.setPriority(3).build();
|
||||
Assert.assertEquals(3, s.getPriority());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenNotSettingPriorities_defaultShouldBe(){
|
||||
Delivery s = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.build();
|
||||
.build();
|
||||
Assert.assertEquals(2, s.getPriority());
|
||||
}
|
||||
|
||||
|
|
@ -129,9 +125,9 @@ public class DeliveryTest {
|
|||
@Test
|
||||
public void whenSettingUserData_itIsAssociatedWithTheJob() {
|
||||
Delivery one = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setUserData(new HashMap<String, Object>()).build();
|
||||
.setUserData(new HashMap<String, Object>()).build();
|
||||
Delivery two = Delivery.Builder.newInstance("s2").setLocation(Location.newInstance("loc")).setUserData(42)
|
||||
.build();
|
||||
.build();
|
||||
Delivery three = Delivery.Builder.newInstance("s3").setLocation(Location.newInstance("loc")).build();
|
||||
|
||||
assertTrue(one.getUserData() instanceof Map);
|
||||
|
|
|
|||
|
|
@ -17,18 +17,14 @@
|
|||
*/
|
||||
package com.graphhopper.jsprit.core.problem.job;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class PickupTest {
|
||||
|
||||
|
|
@ -40,9 +36,9 @@ public class PickupTest {
|
|||
@Test
|
||||
public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo() {
|
||||
Pickup one = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("foofoo"))
|
||||
.addSizeDimension(0, 2)
|
||||
.addSizeDimension(1, 4)
|
||||
.build();
|
||||
.addSizeDimension(0, 2)
|
||||
.addSizeDimension(1, 4)
|
||||
.build();
|
||||
assertEquals(2, one.getSize().getNuOfDimensions());
|
||||
assertEquals(2, one.getSize().get(0));
|
||||
assertEquals(4, one.getSize().get(1));
|
||||
|
|
@ -52,7 +48,7 @@ public class PickupTest {
|
|||
@Test
|
||||
public void whenPickupIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero() {
|
||||
Pickup one = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("foofoo"))
|
||||
.build();
|
||||
.build();
|
||||
assertEquals(1, one.getSize().getNuOfDimensions());
|
||||
assertEquals(0, one.getSize().get(0));
|
||||
}
|
||||
|
|
@ -60,7 +56,7 @@ public class PickupTest {
|
|||
@Test
|
||||
public void whenPickupIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly() {
|
||||
Pickup one = Pickup.Builder.newInstance("s").addSizeDimension(0, 1).setLocation(Location.newInstance("foofoo"))
|
||||
.build();
|
||||
.build();
|
||||
assertEquals(1, one.getSize().getNuOfDimensions());
|
||||
assertEquals(1, one.getSize().get(0));
|
||||
}
|
||||
|
|
@ -68,7 +64,7 @@ public class PickupTest {
|
|||
@Test
|
||||
public void whenAddingSkills_theyShouldBeAddedCorrectly() {
|
||||
Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addRequiredSkill("drill").addRequiredSkill("screwdriver").build();
|
||||
.addRequiredSkill("drill").addRequiredSkill("screwdriver").build();
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("ScrewDriver"));
|
||||
|
|
@ -77,7 +73,7 @@ public class PickupTest {
|
|||
@Test
|
||||
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly() {
|
||||
Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build();
|
||||
.addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build();
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drilL"));
|
||||
}
|
||||
|
|
@ -85,7 +81,7 @@ public class PickupTest {
|
|||
@Test
|
||||
public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() {
|
||||
Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addRequiredSkill("screwDriver").build();
|
||||
.addRequiredSkill("screwDriver").build();
|
||||
assertFalse(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertFalse(s.getRequiredSkills().containsSkill("drilL"));
|
||||
}
|
||||
|
|
@ -93,7 +89,7 @@ public class PickupTest {
|
|||
@Test
|
||||
public void nameShouldBeAssigned() {
|
||||
Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setName("name").build();
|
||||
.setName("name").build();
|
||||
assertEquals("name", s.getName());
|
||||
}
|
||||
|
||||
|
|
@ -101,21 +97,21 @@ public class PickupTest {
|
|||
@Test
|
||||
public void whenSettingPriorities_itShouldBeSetCorrectly(){
|
||||
Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setPriority(3).build();
|
||||
.setPriority(3).build();
|
||||
Assert.assertEquals(3, s.getPriority());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenNotSettingPriorities_defaultShouldBe(){
|
||||
Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.build();
|
||||
.build();
|
||||
Assert.assertEquals(2, s.getPriority());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingUserData_itIsAssociatedWithTheJob() {
|
||||
Pickup one = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setUserData(new HashMap<String, Object>()).build();
|
||||
.setUserData(new HashMap<String, Object>()).build();
|
||||
Pickup two = Pickup.Builder.newInstance("s2").setLocation(Location.newInstance("loc")).setUserData(42).build();
|
||||
Pickup three = Pickup.Builder.newInstance("s3").setLocation(Location.newInstance("loc")).build();
|
||||
|
||||
|
|
@ -123,7 +119,7 @@ public class PickupTest {
|
|||
assertEquals(42, two.getUserData());
|
||||
assertNull(three.getUserData());
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void whenAddingMaxTimeInVehicle_itShouldThrowEx(){
|
||||
Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
|
|
|
|||
|
|
@ -17,25 +17,19 @@
|
|||
*/
|
||||
package com.graphhopper.jsprit.core.problem.job;
|
||||
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.hamcrest.core.IsCollectionContaining.hasItem;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.hamcrest.core.IsCollectionContaining.hasItem;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class ServiceTest {
|
||||
|
||||
|
|
@ -75,16 +69,16 @@ public class ServiceTest {
|
|||
@Test
|
||||
public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo() {
|
||||
Service one = Service.Builder.newInstance("s").setLocation(Location.newInstance("foofoo"))
|
||||
.addSizeDimension(0, 2)
|
||||
.addSizeDimension(1, 4)
|
||||
.build();
|
||||
.addSizeDimension(0, 2)
|
||||
.addSizeDimension(1, 4)
|
||||
.build();
|
||||
assertEquals(2, one.getSize().getNuOfDimensions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenShipmentIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero() {
|
||||
Service one = Service.Builder.newInstance("s").setLocation(Location.newInstance("foofoo"))
|
||||
.build();
|
||||
.build();
|
||||
assertEquals(1, one.getSize().getNuOfDimensions());
|
||||
assertEquals(0, one.getSize().get(0));
|
||||
}
|
||||
|
|
@ -92,7 +86,7 @@ public class ServiceTest {
|
|||
@Test
|
||||
public void whenShipmentIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly() {
|
||||
Service one = Service.Builder.newInstance("s").addSizeDimension(0, 1).setLocation(Location.newInstance("foofoo"))
|
||||
.build();
|
||||
.build();
|
||||
assertEquals(1, one.getSize().getNuOfDimensions());
|
||||
assertEquals(1, one.getSize().get(0));
|
||||
}
|
||||
|
|
@ -125,58 +119,58 @@ public class ServiceTest {
|
|||
|
||||
|
||||
@Test
|
||||
public void whenSettingLocationCoord_itShouldBeSetCorrectly(){
|
||||
public void whenSettingLocationCoord_itShouldBeSetCorrectly() {
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance(1, 2)).build();
|
||||
assertEquals(1.0,s.getLocation().getCoordinate().getX(),0.01);
|
||||
assertEquals(2.0,s.getLocation().getCoordinate().getY(),0.01);
|
||||
assertEquals(1.0, s.getLocation().getCoordinate().getX(), 0.01);
|
||||
assertEquals(2.0, s.getLocation().getCoordinate().getY(), 0.01);
|
||||
assertEquals(1.0,s.getLocation().getCoordinate().getX(),0.01);
|
||||
assertEquals(2.0,s.getLocation().getCoordinate().getY(),0.01);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void whenSettingNeitherLocationIdNorCoord_throwsException(){
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSettingNeitherLocationIdNorCoord_throwsException() {
|
||||
@SuppressWarnings("unused")
|
||||
Service s = Service.Builder.newInstance("s").build();
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void whenServiceTimeSmallerZero_throwIllegalStateException(){
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenServiceTimeSmallerZero_throwIllegalStateException() {
|
||||
@SuppressWarnings("unused")
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setServiceTime(-1).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingServiceTime_itShouldBeSetCorrectly(){
|
||||
public void whenSettingServiceTime_itShouldBeSetCorrectly() {
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setServiceTime(1).build();
|
||||
assertEquals(1.0,s.getServiceDuration(),0.01);
|
||||
assertEquals(1.0, s.getServiceDuration(), 0.01);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void whenTimeWindowIsNull_throwException(){
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenTimeWindowIsNull_throwException() {
|
||||
@SuppressWarnings("unused")
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setTimeWindow(null).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingTimeWindow_itShouldBeSetCorrectly(){
|
||||
public void whenSettingTimeWindow_itShouldBeSetCorrectly() {
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setTimeWindow(TimeWindow.newInstance(1.0, 2.0)).build();
|
||||
assertEquals(1.0,s.getTimeWindow().getStart(),0.01);
|
||||
assertEquals(2.0,s.getTimeWindow().getEnd(),0.01);
|
||||
assertEquals(1.0, s.getTimeWindow().getStart(), 0.01);
|
||||
assertEquals(2.0, s.getTimeWindow().getEnd(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingSkills_theyShouldBeAddedCorrectly(){
|
||||
public void whenAddingSkills_theyShouldBeAddedCorrectly() {
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addRequiredSkill("drill").addRequiredSkill("screwdriver").build();
|
||||
.addRequiredSkill("drill").addRequiredSkill("screwdriver").build();
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("ScrewDriver"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly(){
|
||||
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly() {
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build();
|
||||
.addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build();
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drilL"));
|
||||
}
|
||||
|
|
@ -186,9 +180,9 @@ public class ServiceTest {
|
|||
TimeWindow tw1 = TimeWindow.newInstance(1.0, 2.0);
|
||||
TimeWindow tw2 = TimeWindow.newInstance(3.0, 5.0);
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addTimeWindow(tw1)
|
||||
.addTimeWindow(tw2)
|
||||
.build();
|
||||
.addTimeWindow(tw1)
|
||||
.addTimeWindow(tw2)
|
||||
.build();
|
||||
assertEquals(2, s.getTimeWindows().size());
|
||||
assertThat(s.getTimeWindows(),hasItem(is(tw1)));
|
||||
assertThat(s.getTimeWindows(),hasItem(is(tw2)));
|
||||
|
|
@ -197,7 +191,7 @@ public class ServiceTest {
|
|||
@Test
|
||||
public void whenAddingTimeWindow_itShouldBeSetCorrectly(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addTimeWindow(TimeWindow.newInstance(1.0, 2.0)).build();
|
||||
.addTimeWindow(TimeWindow.newInstance(1.0, 2.0)).build();
|
||||
assertEquals(1.0, s.getTimeWindow().getStart(), 0.01);
|
||||
assertEquals(2.0, s.getTimeWindow().getEnd(), 0.01);
|
||||
}
|
||||
|
|
@ -208,7 +202,7 @@ public class ServiceTest {
|
|||
@Test
|
||||
public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() {
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addRequiredSkill("screwDriver").build();
|
||||
.addRequiredSkill("screwDriver").build();
|
||||
assertFalse(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertFalse(s.getRequiredSkills().containsSkill("drilL"));
|
||||
}
|
||||
|
|
@ -216,73 +210,73 @@ public class ServiceTest {
|
|||
@Test
|
||||
public void nameShouldBeAssigned() {
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setName("name").build();
|
||||
.setName("name").build();
|
||||
assertEquals("name", s.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldKnowMultipleTimeWindows(){
|
||||
public void shouldKnowMultipleTimeWindows() {
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addTimeWindow(TimeWindow.newInstance(0., 10.)).addTimeWindow(TimeWindow.newInstance(20., 30.))
|
||||
.setName("name").build();
|
||||
assertEquals(2,s.getTimeWindows().size());
|
||||
.addTimeWindow(TimeWindow.newInstance(0., 10.)).addTimeWindow(TimeWindow.newInstance(20., 30.))
|
||||
.setName("name").build();
|
||||
assertEquals(2, s.getTimeWindows().size());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenMultipleTWOverlap_throwEx(){
|
||||
public void whenMultipleTWOverlap_throwEx() {
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addTimeWindow(TimeWindow.newInstance(0.,10.))
|
||||
.addTimeWindow(TimeWindow.newInstance(5., 30.))
|
||||
.setName("name").build();
|
||||
.addTimeWindow(TimeWindow.newInstance(0., 10.))
|
||||
.addTimeWindow(TimeWindow.newInstance(5., 30.))
|
||||
.setName("name").build();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenMultipleTWOverlap2_throwEx(){
|
||||
public void whenMultipleTWOverlap2_throwEx() {
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addTimeWindow(TimeWindow.newInstance(20., 30.))
|
||||
.addTimeWindow(TimeWindow.newInstance(0., 25.))
|
||||
.setName("name").build();
|
||||
.addTimeWindow(TimeWindow.newInstance(20., 30.))
|
||||
.addTimeWindow(TimeWindow.newInstance(0., 25.))
|
||||
.setName("name").build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingPriorities_itShouldBeSetCorrectly(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setPriority(1).build();
|
||||
.setPriority(1).build();
|
||||
Assert.assertEquals(1, s.getPriority());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingPriorities_itShouldBeSetCorrectly2(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setPriority(3).build();
|
||||
.setPriority(3).build();
|
||||
Assert.assertEquals(3, s.getPriority());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingPriorities_itShouldBeSetCorrectly3() {
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setPriority(10).build();
|
||||
.setPriority(10).build();
|
||||
Assert.assertEquals(10, s.getPriority());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenNotSettingPriorities_defaultShouldBe2(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.build();
|
||||
.build();
|
||||
Assert.assertEquals(2, s.getPriority());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSettingIncorrectPriorities_itShouldThrowException(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setPriority(30).build();
|
||||
.setPriority(30).build();
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSettingIncorrectPriorities_itShouldThrowException2(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setPriority(0).build();
|
||||
.setPriority(0).build();
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -304,9 +298,9 @@ public class ServiceTest {
|
|||
@Test
|
||||
public void whenSettingUserData_itIsAssociatedWithTheJob() {
|
||||
Service one = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setUserData(new HashMap<String, Object>()).build();
|
||||
.setUserData(new HashMap<String, Object>()).build();
|
||||
Service two = Service.Builder.newInstance("s2").setLocation(Location.newInstance("loc")).setUserData(42)
|
||||
.build();
|
||||
.build();
|
||||
Service three = Service.Builder.newInstance("s3").setLocation(Location.newInstance("loc")).build();
|
||||
|
||||
assertTrue(one.getUserData() instanceof Map);
|
||||
|
|
|
|||
|
|
@ -17,34 +17,28 @@
|
|||
*/
|
||||
package com.graphhopper.jsprit.core.problem.job;
|
||||
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.hamcrest.core.IsCollectionContaining.hasItem;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||
import com.graphhopper.jsprit.core.util.Coordinate;
|
||||
import com.graphhopper.jsprit.core.util.TestUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.hamcrest.core.IsCollectionContaining.hasItem;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class ShipmentTest {
|
||||
|
||||
@Test
|
||||
public void whenTwoShipmentsHaveTheSameId_theyReferencesShouldBeUnEqual() {
|
||||
Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()).
|
||||
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
||||
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
||||
Shipment two = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()).
|
||||
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
||||
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
||||
|
||||
assertTrue(one != two);
|
||||
}
|
||||
|
|
@ -52,9 +46,9 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenTwoShipmentsHaveTheSameId_theyShouldBeEqual() {
|
||||
Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()).
|
||||
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
||||
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
||||
Shipment two = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()).
|
||||
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
||||
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
||||
|
||||
assertTrue(one.equals(two));
|
||||
}
|
||||
|
|
@ -62,7 +56,7 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenShipmentIsInstantiatedWithASizeOf10_theSizeShouldBe10() {
|
||||
Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()).
|
||||
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
||||
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
||||
assertEquals(10, one.getSize().get(0));
|
||||
}
|
||||
|
||||
|
|
@ -70,24 +64,24 @@ public class ShipmentTest {
|
|||
public void whenShipmentIsBuiltWithNegativeDemand_itShouldThrowException() {
|
||||
@SuppressWarnings("unused")
|
||||
Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, -10)
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("foo").build())
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("foo").build())
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenShipmentIsBuiltWithNegativeDemand_itShouldThrowException_v2() {
|
||||
@SuppressWarnings("unused")
|
||||
Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, -10)
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("foo").build())
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("foo").build())
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenIdIsNull_itShouldThrowException() {
|
||||
@SuppressWarnings("unused")
|
||||
Shipment one = Shipment.Builder.newInstance(null).addSizeDimension(0, 10)
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("foo").build())
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("foo").build())
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -124,7 +118,7 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenPickupCoordIsSet_itShouldBeDoneCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s")
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").setCoordinate(Coordinate.newInstance(1, 2)).build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").setCoordinate(Coordinate.newInstance(1, 2)).build()).build();
|
||||
assertEquals(1.0, s.getPickupLocation().getCoordinate().getX(), 0.01);
|
||||
assertEquals(2.0, s.getPickupLocation().getCoordinate().getY(), 0.01);
|
||||
assertEquals(1.0, s.getPickupLocation().getCoordinate().getX(), 0.01);
|
||||
|
|
@ -135,7 +129,7 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenDeliveryLocationIdIsSet_itShouldBeDoneCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s")
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals("delLoc", s.getDeliveryLocation().getId());
|
||||
assertEquals("delLoc", s.getDeliveryLocation().getId());
|
||||
}
|
||||
|
|
@ -144,8 +138,8 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenDeliveryCoordIsSet_itShouldBeDoneCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").setDeliveryLocation(TestUtils.loc("delLoc", Coordinate.newInstance(1, 2)))
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build())
|
||||
.build();
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build())
|
||||
.build();
|
||||
assertEquals(1.0, s.getDeliveryLocation().getCoordinate().getX(), 0.01);
|
||||
assertEquals(2.0, s.getDeliveryLocation().getCoordinate().getY(), 0.01);
|
||||
assertEquals(1.0, s.getDeliveryLocation().getCoordinate().getX(), 0.01);
|
||||
|
|
@ -155,22 +149,22 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenPickupServiceTimeIsNotSet_itShouldBeZero() {
|
||||
Shipment s = Shipment.Builder.newInstance("s")
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(0.0, s.getPickupServiceTime(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenDeliveryServiceTimeIsNotSet_itShouldBeZero() {
|
||||
Shipment s = Shipment.Builder.newInstance("s")
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(0.0, s.getDeliveryServiceTime(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenPickupServiceTimeIsSet_itShouldBeDoneCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s")
|
||||
.setPickupServiceTime(2.0)
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setPickupServiceTime(2.0)
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(2.0, s.getPickupServiceTime(), 0.01);
|
||||
}
|
||||
|
||||
|
|
@ -178,13 +172,13 @@ public class ShipmentTest {
|
|||
public void whenPickupServiceIsSmallerThanZero_itShouldThrowException() {
|
||||
@SuppressWarnings("unused")
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupServiceTime(-2.0)
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenDeliveryServiceTimeIsSet_itShouldBeDoneCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").setDeliveryServiceTime(2.0)
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(2.0, s.getDeliveryServiceTime(), 0.01);
|
||||
}
|
||||
|
||||
|
|
@ -210,7 +204,7 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenPickupTimeWindowIsSet_itShouldBeDoneCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupTimeWindow(TimeWindow.newInstance(1, 2))
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(1.0, s.getPickupTimeWindow().getStart(), 0.01);
|
||||
assertEquals(2.0, s.getPickupTimeWindow().getEnd(), 0.01);
|
||||
}
|
||||
|
|
@ -231,7 +225,7 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenDeliveryTimeWindowIsSet_itShouldBeDoneCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").setDeliveryTimeWindow(TimeWindow.newInstance(1, 2))
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(1.0, s.getDeliveryTimeWindow().getStart(), 0.01);
|
||||
assertEquals(2.0, s.getDeliveryTimeWindow().getEnd(), 0.01);
|
||||
}
|
||||
|
|
@ -239,7 +233,7 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenUsingAddDeliveryTimeWindow_itShouldBeDoneCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").addDeliveryTimeWindow(TimeWindow.newInstance(1, 2))
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(1.0, s.getDeliveryTimeWindow().getStart(), 0.01);
|
||||
assertEquals(2.0, s.getDeliveryTimeWindow().getEnd(), 0.01);
|
||||
}
|
||||
|
|
@ -247,7 +241,7 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenUsingAddDeliveryTimeWindow2_itShouldBeDoneCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").addDeliveryTimeWindow(1, 2)
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(1.0, s.getDeliveryTimeWindow().getStart(), 0.01);
|
||||
assertEquals(2.0, s.getDeliveryTimeWindow().getEnd(), 0.01);
|
||||
}
|
||||
|
|
@ -257,7 +251,7 @@ public class ShipmentTest {
|
|||
TimeWindow tw1 = TimeWindow.newInstance(1,2);
|
||||
TimeWindow tw2 = TimeWindow.newInstance(4,5);
|
||||
Shipment s = Shipment.Builder.newInstance("s").addDeliveryTimeWindow(tw1).addDeliveryTimeWindow(tw2)
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(s.getDeliveryTimeWindows().size(),2);
|
||||
assertThat(s.getDeliveryTimeWindows(),hasItem(is(tw1)));
|
||||
assertThat(s.getDeliveryTimeWindows(),hasItem(is(tw2)));
|
||||
|
|
@ -266,7 +260,7 @@ public class ShipmentTest {
|
|||
@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();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(1.0, s.getDeliveryTimeWindow().getStart(), 0.01);
|
||||
assertEquals(2.0, s.getDeliveryTimeWindow().getEnd(), 0.01);
|
||||
}
|
||||
|
|
@ -276,7 +270,7 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenUsingAddPickupTimeWindow_itShouldBeDoneCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").addPickupTimeWindow(TimeWindow.newInstance(1, 2))
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(1.0, s.getPickupTimeWindow().getStart(), 0.01);
|
||||
assertEquals(2.0, s.getPickupTimeWindow().getEnd(), 0.01);
|
||||
}
|
||||
|
|
@ -284,7 +278,7 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenUsingAddPickupTimeWindow2_itShouldBeDoneCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").addPickupTimeWindow(1, 2)
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(1.0, s.getPickupTimeWindow().getStart(), 0.01);
|
||||
assertEquals(2.0, s.getPickupTimeWindow().getEnd(), 0.01);
|
||||
}
|
||||
|
|
@ -294,7 +288,7 @@ public class ShipmentTest {
|
|||
TimeWindow tw1 = TimeWindow.newInstance(1,2);
|
||||
TimeWindow tw2 = TimeWindow.newInstance(4,5);
|
||||
Shipment s = Shipment.Builder.newInstance("s").addPickupTimeWindow(tw1).addPickupTimeWindow(tw2)
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(s.getPickupTimeWindows().size(),2);
|
||||
assertThat(s.getPickupTimeWindows(), hasItem(is(tw1)));
|
||||
assertThat(s.getPickupTimeWindows(), hasItem(is(tw2)));
|
||||
|
|
@ -303,7 +297,7 @@ public class ShipmentTest {
|
|||
@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();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(1.0, s.getPickupTimeWindow().getStart(), 0.01);
|
||||
assertEquals(2.0, s.getPickupTimeWindow().getEnd(), 0.01);
|
||||
}
|
||||
|
|
@ -314,26 +308,26 @@ public class ShipmentTest {
|
|||
public void whenShipmentHasNegativeCapacityVal_throwIllegalStateExpception() {
|
||||
@SuppressWarnings("unused")
|
||||
Shipment one = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("foo").build())
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo"))
|
||||
.addSizeDimension(0, -2)
|
||||
.build();
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo"))
|
||||
.addSizeDimension(0, -2)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo() {
|
||||
Shipment one = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("foo").build())
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo"))
|
||||
.addSizeDimension(0, 2)
|
||||
.addSizeDimension(1, 4)
|
||||
.build();
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo"))
|
||||
.addSizeDimension(0, 2)
|
||||
.addSizeDimension(1, 4)
|
||||
.build();
|
||||
assertEquals(2, one.getSize().getNuOfDimensions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenShipmentIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero() {
|
||||
Shipment one = Shipment.Builder.newInstance("s")
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("foo").setCoordinate(Coordinate.newInstance(0, 0)).build())
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("foo").setCoordinate(Coordinate.newInstance(0, 0)).build())
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
||||
assertEquals(1, one.getSize().getNuOfDimensions());
|
||||
assertEquals(0, one.getSize().get(0));
|
||||
}
|
||||
|
|
@ -341,8 +335,8 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenShipmentIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly() {
|
||||
Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, 1)
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("foo").setCoordinate(Coordinate.newInstance(0, 0)).build())
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("foo").setCoordinate(Coordinate.newInstance(0, 0)).build())
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
||||
assertEquals(1, one.getSize().getNuOfDimensions());
|
||||
assertEquals(1, one.getSize().get(0));
|
||||
}
|
||||
|
|
@ -350,8 +344,8 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenAddingSkills_theyShouldBeAddedCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("loc").build())
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc"))
|
||||
.addRequiredSkill("drill").addRequiredSkill("screwdriver").build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc"))
|
||||
.addRequiredSkill("drill").addRequiredSkill("screwdriver").build();
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("ScrewDriver"));
|
||||
|
|
@ -360,9 +354,9 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s")
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("pick").build())
|
||||
.setDeliveryLocation(TestUtils.loc("del"))
|
||||
.addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build();
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("pick").build())
|
||||
.setDeliveryLocation(TestUtils.loc("del"))
|
||||
.addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build();
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drilL"));
|
||||
}
|
||||
|
|
@ -370,8 +364,8 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("loc").build())
|
||||
.setDeliveryLocation(TestUtils.loc("del"))
|
||||
.addRequiredSkill("screwDriver").build();
|
||||
.setDeliveryLocation(TestUtils.loc("del"))
|
||||
.addRequiredSkill("screwDriver").build();
|
||||
assertFalse(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertFalse(s.getRequiredSkills().containsSkill("drilL"));
|
||||
}
|
||||
|
|
@ -379,15 +373,15 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void nameShouldBeAssigned() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("loc").build())
|
||||
.setDeliveryLocation(TestUtils.loc("del"))
|
||||
.setName("name").build();
|
||||
.setDeliveryLocation(TestUtils.loc("del"))
|
||||
.setName("name").build();
|
||||
assertEquals("name", s.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingLocation_itShouldWork() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("loc").build())
|
||||
.setDeliveryLocation(Location.Builder.newInstance().setId("del").build()).build();
|
||||
.setDeliveryLocation(Location.Builder.newInstance().setId("del").build()).build();
|
||||
assertEquals("loc", s.getPickupLocation().getId());
|
||||
assertEquals("loc", s.getPickupLocation().getId());
|
||||
assertEquals("del", s.getDeliveryLocation().getId());
|
||||
|
|
@ -397,59 +391,59 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenSettingPriorities_itShouldBeSetCorrectly(){
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
|
||||
.setDeliveryLocation(Location.newInstance("loc"))
|
||||
.setPriority(1).build();
|
||||
.setDeliveryLocation(Location.newInstance("loc"))
|
||||
.setPriority(1).build();
|
||||
Assert.assertEquals(1, s.getPriority());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingPriorities_itShouldBeSetCorrectly2(){
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
|
||||
.setDeliveryLocation(Location.newInstance("loc"))
|
||||
.setPriority(3).build();
|
||||
.setDeliveryLocation(Location.newInstance("loc"))
|
||||
.setPriority(3).build();
|
||||
Assert.assertEquals(3, s.getPriority());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingPriorities_itShouldBeSetCorrectly3() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
|
||||
.setDeliveryLocation(Location.newInstance("loc"))
|
||||
.setPriority(10).build();
|
||||
.setDeliveryLocation(Location.newInstance("loc"))
|
||||
.setPriority(10).build();
|
||||
Assert.assertEquals(10, s.getPriority());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenNotSettingPriorities_defaultShouldBe2(){
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
|
||||
.setDeliveryLocation(Location.newInstance("loc"))
|
||||
.build();
|
||||
.setDeliveryLocation(Location.newInstance("loc"))
|
||||
.build();
|
||||
Assert.assertEquals(2, s.getPriority());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSettingIncorrectPriorities_itShouldThrowException(){
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
|
||||
.setDeliveryLocation(Location.newInstance("loc"))
|
||||
.setPriority(30).build();
|
||||
.setDeliveryLocation(Location.newInstance("loc"))
|
||||
.setPriority(30).build();
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSettingIncorrectPriorities_itShouldThrowException2(){
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
|
||||
.setDeliveryLocation(Location.newInstance("loc"))
|
||||
.setPriority(0).build();
|
||||
.setDeliveryLocation(Location.newInstance("loc"))
|
||||
.setPriority(0).build();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingUserData_itIsAssociatedWithTheJob() {
|
||||
Shipment one = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
|
||||
.setDeliveryLocation(Location.newInstance("loc")).setUserData(new HashMap<String, Object>()).build();
|
||||
.setDeliveryLocation(Location.newInstance("loc")).setUserData(new HashMap<String, Object>()).build();
|
||||
Shipment two = Shipment.Builder.newInstance("s2").setPickupLocation(Location.newInstance("loc"))
|
||||
.setDeliveryLocation(Location.newInstance("loc")).setUserData(42).build();
|
||||
.setDeliveryLocation(Location.newInstance("loc")).setUserData(42).build();
|
||||
Shipment three = Shipment.Builder.newInstance("s3").setPickupLocation(Location.newInstance("loc"))
|
||||
.setDeliveryLocation(Location.newInstance("loc")).build();
|
||||
.setDeliveryLocation(Location.newInstance("loc")).build();
|
||||
|
||||
assertTrue(one.getUserData() instanceof Map);
|
||||
assertEquals(42, two.getUserData());
|
||||
|
|
|
|||
|
|
@ -18,20 +18,15 @@
|
|||
package com.graphhopper.jsprit.core.problem.vehicle;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import com.graphhopper.jsprit.core.problem.job.Break;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import com.graphhopper.jsprit.core.problem.job.Break;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
||||
public class VehicleImplTest {
|
||||
|
|
@ -49,8 +44,8 @@ public class VehicleImplTest {
|
|||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||
Break aBreak = Break.Builder.newInstance("break").setTimeWindow(TimeWindow.newInstance(100, 200)).setServiceTime(30).build();
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start"))
|
||||
.setType(type1).setEndLocation(Location.newInstance("start"))
|
||||
.setBreak(aBreak).build();
|
||||
.setType(type1).setEndLocation(Location.newInstance("start"))
|
||||
.setBreak(aBreak).build();
|
||||
assertNotNull(v.getBreak());
|
||||
assertEquals(100., v.getBreak().getTimeWindow().getStart(), 0.1);
|
||||
assertEquals(200., v.getBreak().getTimeWindow().getEnd(), 0.1);
|
||||
|
|
@ -62,7 +57,7 @@ public class VehicleImplTest {
|
|||
public void whenAddingSkills_theyShouldBeAddedCorrectly() {
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type1).setEndLocation(Location.newInstance("start"))
|
||||
.addSkill("drill").addSkill("screwdriver").build();
|
||||
.addSkill("drill").addSkill("screwdriver").build();
|
||||
assertTrue(v.getSkills().containsSkill("drill"));
|
||||
assertTrue(v.getSkills().containsSkill("drill"));
|
||||
assertTrue(v.getSkills().containsSkill("screwdriver"));
|
||||
|
|
@ -72,7 +67,7 @@ public class VehicleImplTest {
|
|||
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly() {
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type1).setEndLocation(Location.newInstance("start"))
|
||||
.addSkill("drill").addSkill("screwdriver").build();
|
||||
.addSkill("drill").addSkill("screwdriver").build();
|
||||
assertTrue(v.getSkills().containsSkill("drill"));
|
||||
assertTrue(v.getSkills().containsSkill("dRill"));
|
||||
assertTrue(v.getSkills().containsSkill("ScrewDriver"));
|
||||
|
|
@ -241,7 +236,7 @@ public class VehicleImplTest {
|
|||
public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() {
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type1).setEndLocation(Location.newInstance("start"))
|
||||
.addSkill("drill").build();
|
||||
.addSkill("drill").build();
|
||||
assertFalse(v.getSkills().containsSkill("ScrewDriver"));
|
||||
}
|
||||
|
||||
|
|
@ -249,11 +244,11 @@ public class VehicleImplTest {
|
|||
public void whenSettingUserData_itIsAssociatedWithTheVehicle() {
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||
Vehicle one = VehicleImpl.Builder.newInstance("v").setType(type1)
|
||||
.setStartLocation(Location.newInstance("start")).setUserData(new HashMap<String, Object>()).build();
|
||||
.setStartLocation(Location.newInstance("start")).setUserData(new HashMap<String, Object>()).build();
|
||||
Vehicle two = VehicleImpl.Builder.newInstance("v").setType(type1)
|
||||
.setStartLocation(Location.newInstance("start")).setUserData(42).build();
|
||||
.setStartLocation(Location.newInstance("start")).setUserData(42).build();
|
||||
Vehicle three = VehicleImpl.Builder.newInstance("v").setType(type1)
|
||||
.setStartLocation(Location.newInstance("start")).build();
|
||||
.setStartLocation(Location.newInstance("start")).build();
|
||||
|
||||
assertTrue(one.getUserData() instanceof Map);
|
||||
assertEquals(42, two.getUserData());
|
||||
|
|
|
|||
|
|
@ -17,15 +17,12 @@
|
|||
*/
|
||||
package com.graphhopper.jsprit.core.problem.vehicle;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class VehicleTypeImplTest {
|
||||
|
||||
|
|
@ -38,18 +35,18 @@ public class VehicleTypeImplTest {
|
|||
@Test
|
||||
public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo() {
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t")
|
||||
.addCapacityDimension(0, 2)
|
||||
.addCapacityDimension(1, 4)
|
||||
.build();
|
||||
.addCapacityDimension(0, 2)
|
||||
.addCapacityDimension(1, 4)
|
||||
.build();
|
||||
assertEquals(2, type.getCapacityDimensions().getNuOfDimensions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingTwoCapDimension_dimValuesMustBeCorrect() {
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t")
|
||||
.addCapacityDimension(0, 2)
|
||||
.addCapacityDimension(1, 4)
|
||||
.build();
|
||||
.addCapacityDimension(0, 2)
|
||||
.addCapacityDimension(1, 4)
|
||||
.build();
|
||||
assertEquals(2, type.getCapacityDimensions().get(0));
|
||||
assertEquals(4, type.getCapacityDimensions().get(1));
|
||||
}
|
||||
|
|
@ -161,7 +158,7 @@ public class VehicleTypeImplTest {
|
|||
@Test
|
||||
public void whenSettingUserData_itIsAssociatedWithTheVehicleType() {
|
||||
VehicleType one = VehicleTypeImpl.Builder.newInstance("type").setUserData(new HashMap<String, Object>())
|
||||
.build();
|
||||
.build();
|
||||
VehicleType two = VehicleTypeImpl.Builder.newInstance("type").setUserData(42).build();
|
||||
VehicleType three = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ public class FastVehicleRoutingTransportCostsMatrixTest {
|
|||
@Test
|
||||
public void whenAddingTimeAndDistanceToSymmetricMatrix_itShouldReturnCorrectValues2() {
|
||||
FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(3, true);
|
||||
matrixBuilder.addTransportTimeAndDistance(1, 2, 2.,100.);
|
||||
matrixBuilder.addTransportTimeAndDistance(1, 2, 2., 100.);
|
||||
FastVehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build();
|
||||
assertEquals(2., matrix.getTransportTime(loc(1), loc(2), 0.0, null, null), 0.1);
|
||||
assertEquals(2., matrix.getTransportTime(loc(2), loc(1), 0.0, null, null), 0.1);
|
||||
|
|
|
|||
|
|
@ -373,7 +373,7 @@ public class VrpXMLWriterTest {
|
|||
|
||||
//skill names are case-insensitive
|
||||
Service s = Service.Builder.newInstance("1").addRequiredSkill("skill1").addRequiredSkill("SKILL2").addSizeDimension(0, 1)
|
||||
.setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build();
|
||||
.setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build();
|
||||
|
||||
VehicleRoutingProblem vrp = builder.addJob(s).build();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue