mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
Merge branch 'multiple-capacities'
This commit is contained in:
commit
56067dc590
135 changed files with 5020 additions and 1095 deletions
|
|
@ -22,7 +22,7 @@ public class VariablePlusFixedSolutionCostCalculatorFactory {
|
|||
public double getCosts(VehicleRoutingProblemSolution solution) {
|
||||
double c = 0.0;
|
||||
for(VehicleRoute r : solution.getRoutes()){
|
||||
c += stateManager.getRouteState(r, StateFactory.COSTS).toDouble();
|
||||
c += stateManager.getRouteState(r, StateFactory.COSTS,Double.class);
|
||||
c += r.getVehicle().getType().getVehicleCostParams().fix;
|
||||
}
|
||||
return c;
|
||||
|
|
|
|||
|
|
@ -537,7 +537,7 @@ public class VehicleRoutingAlgorithms {
|
|||
stateManager = stateMan;
|
||||
}
|
||||
else{
|
||||
stateManager = new StateManager(vrp);
|
||||
stateManager = new StateManager(vrp.getTransportCosts());
|
||||
}
|
||||
stateManager.updateLoadStates();
|
||||
stateManager.updateTimeWindowStates();
|
||||
|
|
@ -617,7 +617,7 @@ public class VehicleRoutingAlgorithms {
|
|||
public double getCosts(VehicleRoutingProblemSolution solution) {
|
||||
double costs = 0.0;
|
||||
for(VehicleRoute route : solution.getRoutes()){
|
||||
costs += stateManager.getRouteState(route, StateFactory.COSTS).toDouble() + getFixedCosts(route.getVehicle());
|
||||
costs += stateManager.getRouteState(route, StateFactory.COSTS, Double.class) + getFixedCosts(route.getVehicle());
|
||||
}
|
||||
return costs;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import jsprit.core.algorithm.recreate.InsertionData.NoInsertionFound;
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
|
|
@ -83,37 +84,40 @@ final class JobInsertionConsideringFixCostsCalculator implements JobInsertionCos
|
|||
}
|
||||
|
||||
private double getDeltaAbsoluteFixCost(VehicleRoute route, Vehicle newVehicle, Job job) {
|
||||
double load = getCurrentMaxLoadInRoute(route) + job.getCapacityDemand();
|
||||
Capacity load = Capacity.addup(getCurrentMaxLoadInRoute(route), job.getSize());
|
||||
// double load = getCurrentMaxLoadInRoute(route) + job.getCapacityDemand();
|
||||
double currentFix = 0.0;
|
||||
if(route.getVehicle() != null){
|
||||
if(!(route.getVehicle() instanceof NoVehicle)){
|
||||
currentFix += route.getVehicle().getType().getVehicleCostParams().fix;
|
||||
}
|
||||
}
|
||||
if(newVehicle.getCapacity() < load){
|
||||
if(!newVehicle.getType().getCapacityDimensions().isGreaterOrEqual(load)){
|
||||
return Double.MAX_VALUE;
|
||||
}
|
||||
return newVehicle.getType().getVehicleCostParams().fix - currentFix;
|
||||
}
|
||||
|
||||
private double getDeltaRelativeFixCost(VehicleRoute route, Vehicle newVehicle, Job job) {
|
||||
int currentLoad = getCurrentMaxLoadInRoute(route);
|
||||
double load = currentLoad + job.getCapacityDemand();
|
||||
Capacity currentLoad = getCurrentMaxLoadInRoute(route);
|
||||
// int currentLoad = getCurrentMaxLoadInRoute(route);
|
||||
Capacity load = Capacity.addup(currentLoad, job.getSize());
|
||||
// double load = currentLoad + job.getCapacityDemand();
|
||||
double currentRelFix = 0.0;
|
||||
if(route.getVehicle() != null){
|
||||
if(!(route.getVehicle() instanceof NoVehicle)){
|
||||
currentRelFix += route.getVehicle().getType().getVehicleCostParams().fix*currentLoad/route.getVehicle().getCapacity();
|
||||
currentRelFix += route.getVehicle().getType().getVehicleCostParams().fix * Capacity.divide(currentLoad, route.getVehicle().getType().getCapacityDimensions());
|
||||
}
|
||||
}
|
||||
if(newVehicle.getCapacity() < load){
|
||||
if(!newVehicle.getType().getCapacityDimensions().isGreaterOrEqual(load)){
|
||||
return Double.MAX_VALUE;
|
||||
}
|
||||
double relativeFixCost = newVehicle.getType().getVehicleCostParams().fix*(load/newVehicle.getCapacity()) - currentRelFix;
|
||||
double relativeFixCost = newVehicle.getType().getVehicleCostParams().fix* (Capacity.divide(load, newVehicle.getType().getCapacityDimensions())) - currentRelFix;
|
||||
return relativeFixCost;
|
||||
}
|
||||
|
||||
private int getCurrentMaxLoadInRoute(VehicleRoute route) {
|
||||
return (int) stateGetter.getRouteState(route, StateFactory.MAXLOAD).toDouble();
|
||||
private Capacity getCurrentMaxLoadInRoute(VehicleRoute route) {
|
||||
return stateGetter.getRouteState(route, StateFactory.MAXLOAD, Capacity.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,9 +73,9 @@ class RouteLevelActivityInsertionCostsEstimator implements ActivityInsertionCost
|
|||
|
||||
private double actCostsOld(VehicleRoute vehicleRoute, TourActivity act) {
|
||||
if(act instanceof End){
|
||||
return stateManager.getRouteState(vehicleRoute,StateFactory.COSTS).toDouble();
|
||||
return stateManager.getRouteState(vehicleRoute,StateFactory.COSTS,Double.class);
|
||||
}
|
||||
return stateManager.getActivityState(act,StateFactory.COSTS).toDouble();
|
||||
return stateManager.getActivityState(act,StateFactory.COSTS,Double.class);
|
||||
}
|
||||
|
||||
private List<TourActivity> getForwardLookingPath(VehicleRoute route, int actIndex) {
|
||||
|
|
|
|||
|
|
@ -291,7 +291,7 @@ final class ServiceInsertionOnRouteLevelCalculator implements JobInsertionCostsC
|
|||
/**
|
||||
* compute cost-diff of tour with and without new activity --> insertion_costs
|
||||
*/
|
||||
double insertion_costs = auxilliaryPathCostCalculator.costOfPath(wholeTour, start.getEndTime(), newDriver, newVehicle) - stateManager.getRouteState(currentRoute,StateFactory.COSTS).toDouble();
|
||||
double insertion_costs = auxilliaryPathCostCalculator.costOfPath(wholeTour, start.getEndTime(), newDriver, newVehicle) - stateManager.getRouteState(currentRoute,StateFactory.COSTS,Double.class);
|
||||
|
||||
/**
|
||||
* if better than best known, make it the best known
|
||||
|
|
@ -336,9 +336,9 @@ final class ServiceInsertionOnRouteLevelCalculator implements JobInsertionCostsC
|
|||
|
||||
private double sumOf_prevCosts_oldVehicle(VehicleRoute vehicleRoute, TourActivity act) {
|
||||
if(act instanceof End){
|
||||
return stateManager.getRouteState(vehicleRoute,StateFactory.COSTS).toDouble();
|
||||
return stateManager.getRouteState(vehicleRoute,StateFactory.COSTS,Double.class);
|
||||
}
|
||||
return stateManager.getActivityState(act,StateFactory.COSTS).toDouble();
|
||||
return stateManager.getActivityState(act,StateFactory.COSTS,Double.class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import jsprit.core.algorithm.recreate.listener.InsertionStartsListener;
|
|||
import jsprit.core.algorithm.recreate.listener.JobInsertedListener;
|
||||
import jsprit.core.algorithm.ruin.listener.RuinListener;
|
||||
import jsprit.core.algorithm.ruin.listener.RuinListeners;
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.job.Job;
|
||||
|
|
@ -45,14 +46,39 @@ import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
|
|||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory.State;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory.StateId;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory.States;
|
||||
|
||||
|
||||
/**
|
||||
* Manages states.
|
||||
*
|
||||
* <p>Some condition, rules or constraints are stateful. This StateManager manages these states, i.e. it offers
|
||||
* methods to add, store and retrieve states based on vehicle-routes and tour-activities.
|
||||
*
|
||||
* @author schroeder
|
||||
*
|
||||
*/
|
||||
public class StateManager implements RouteAndActivityStateGetter, IterationStartsListener, RuinListener, InsertionStartsListener, JobInsertedListener, InsertionEndsListener {
|
||||
|
||||
private Map<VehicleRoute,States> vehicleRouteStates = new HashMap<VehicleRoute, States>();
|
||||
static class States_ {
|
||||
|
||||
private Map<StateId,Object> states = new HashMap<StateId,Object>();
|
||||
|
||||
public <T> void putState(StateId id, Class<T> type, T state){
|
||||
states.put(id, type.cast(state));
|
||||
}
|
||||
|
||||
public <T> T getState(StateId id, Class<T> type){
|
||||
if(states.containsKey(id)){
|
||||
T s = type.cast(states.get(id));
|
||||
return s;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Map<VehicleRoute,States_> vehicleRouteStates_ = new HashMap<VehicleRoute, States_>();
|
||||
|
||||
private Map<TourActivity,States> activityStates = new HashMap<TourActivity, States>();
|
||||
private Map<TourActivity,States_> activityStates_ = new HashMap<TourActivity, States_>();
|
||||
|
||||
private RouteActivityVisitor routeActivityVisitor = new RouteActivityVisitor();
|
||||
|
||||
|
|
@ -66,9 +92,9 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
|
|||
|
||||
private Collection<StateUpdater> updaters = new ArrayList<StateUpdater>();
|
||||
|
||||
private Map<StateId,State> defaultRouteStates = new HashMap<StateId, State>();
|
||||
private Map<StateId,Object> defaultRouteStates_ = new HashMap<StateId,Object>();
|
||||
|
||||
private Map<StateId,State> defaultActivityStates = new HashMap<StateId, State>();
|
||||
private Map<StateId,Object> defaultActivityStates_ = new HashMap<StateId,Object>();
|
||||
|
||||
private VehicleRoutingTransportCosts routingCosts;
|
||||
|
||||
|
|
@ -76,79 +102,269 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
|
|||
|
||||
private boolean updateTWs = false;
|
||||
|
||||
/**
|
||||
* @deprecated use <code>StateManager(VehicleRoutingTransportCosts tpcosts)</code> instead.
|
||||
* @param vrp
|
||||
*/
|
||||
@Deprecated
|
||||
public StateManager(VehicleRoutingProblem vrp) {
|
||||
super();
|
||||
this.routingCosts = vrp.getTransportCosts();
|
||||
addDefaultStates();
|
||||
}
|
||||
|
||||
private void addDefaultStates() {
|
||||
defaultActivityStates_.put(StateFactory.LOAD, Capacity.Builder.newInstance().build());
|
||||
|
||||
|
||||
defaultActivityStates_.put(StateFactory.COSTS, 0.);
|
||||
defaultActivityStates_.put(StateFactory.DURATION, 0.);
|
||||
defaultActivityStates_.put(StateFactory.FUTURE_MAXLOAD, Capacity.Builder.newInstance().build());
|
||||
defaultActivityStates_.put(StateFactory.PAST_MAXLOAD, Capacity.Builder.newInstance().build());
|
||||
|
||||
defaultRouteStates_.put(StateFactory.LOAD, Capacity.Builder.newInstance().build());
|
||||
|
||||
defaultRouteStates_.put(StateFactory.COSTS, 0.);
|
||||
defaultRouteStates_.put(StateFactory.DURATION, 0.);
|
||||
defaultRouteStates_.put(StateFactory.FUTURE_MAXLOAD, Capacity.Builder.newInstance().build());
|
||||
defaultRouteStates_.put(StateFactory.PAST_MAXLOAD, Capacity.Builder.newInstance().build());
|
||||
|
||||
defaultRouteStates_.put(StateFactory.MAXLOAD, Capacity.Builder.newInstance().build());
|
||||
|
||||
defaultRouteStates_.put(StateFactory.LOAD_AT_END, Capacity.Builder.newInstance().build());
|
||||
defaultRouteStates_.put(StateFactory.LOAD_AT_BEGINNING, Capacity.Builder.newInstance().build());
|
||||
|
||||
}
|
||||
|
||||
public StateManager(VehicleRoutingTransportCosts routingCosts){
|
||||
this.routingCosts = routingCosts;
|
||||
addDefaultStates();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated use the generic methode <code>addDefaultRouteState(StateId stateId, Class<T> type, T defaultState)</code> instead.
|
||||
* @param stateId
|
||||
* @param defaultState
|
||||
*/
|
||||
@Deprecated
|
||||
public void addDefaultRouteState(StateId stateId, State defaultState){
|
||||
if(StateFactory.isReservedId(stateId)) StateFactory.throwReservedIdException(stateId.toString());
|
||||
defaultRouteStates.put(stateId, defaultState);
|
||||
addDefaultRouteState(stateId, State.class, defaultState);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic method to add a default route state.
|
||||
*
|
||||
* <p>for example if you want to store 'maximum weight' at route-level, the default might be zero and you
|
||||
* can add the default simply by coding <br>
|
||||
* <code>addDefaultRouteState(StateFactory.createStateId("max_weight"), Integer.class, 0)</code>
|
||||
*
|
||||
* @param stateId
|
||||
* @param type
|
||||
* @param defaultState
|
||||
*/
|
||||
public <T> void addDefaultRouteState(StateId stateId, Class<T> type, T defaultState){
|
||||
if(StateFactory.isReservedId(stateId)) StateFactory.throwReservedIdException(stateId.toString());
|
||||
defaultRouteStates_.put(stateId, type.cast(defaultState));
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use generic method <code>addDefaultActivityState(StateId stateId, Class<T> type, T defaultState)</code>
|
||||
* @param stateId
|
||||
* @param defaultState
|
||||
*/
|
||||
@Deprecated
|
||||
public void addDefaultActivityState(StateId stateId, State defaultState){
|
||||
if(StateFactory.isReservedId(stateId)) StateFactory.throwReservedIdException(stateId.toString());
|
||||
defaultActivityStates.put(stateId, defaultState);
|
||||
addDefaultActivityState(stateId, State.class, defaultState);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic method to add default activity state.
|
||||
*
|
||||
* @param stateId
|
||||
* @param type
|
||||
* @param defaultState
|
||||
*/
|
||||
public <T> void addDefaultActivityState(StateId stateId, Class<T> type, T defaultState){
|
||||
if(StateFactory.isReservedId(stateId)) StateFactory.throwReservedIdException(stateId.toString());
|
||||
defaultActivityStates_.put(stateId, type.cast(defaultState));
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all states.
|
||||
*
|
||||
*/
|
||||
public void clear(){
|
||||
vehicleRouteStates.clear();
|
||||
activityStates.clear();
|
||||
vehicleRouteStates_.clear();
|
||||
activityStates_.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Deprecated use generic method instead <code>getActivityState(TourActivity act, StateId stateId, Class<T> type)</code>
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
public State getActivityState(TourActivity act, StateId stateId) {
|
||||
if(!activityStates.containsKey(act)){
|
||||
return getDefaultActState(stateId,act);
|
||||
if(!activityStates_.containsKey(act)){
|
||||
return getDefaultTypedActivityState(act,stateId,State.class);
|
||||
}
|
||||
States actStates = activityStates.get(act);
|
||||
State state = actStates.getState(stateId);
|
||||
States_ actStates = activityStates_.get(act);
|
||||
State state = actStates.getState(stateId, State.class);
|
||||
if(state == null){
|
||||
return getDefaultActState(stateId,act);
|
||||
return getDefaultTypedActivityState(act,stateId,State.class);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
void putInternalActivityState(TourActivity act, StateId stateId, State state){
|
||||
if(!activityStates.containsKey(act)){
|
||||
activityStates.put(act, StateFactory.createStates());
|
||||
/**
|
||||
* Returns activity state of type 'type'.
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public <T> T getActivityState(TourActivity act, StateId stateId, Class<T> type) {
|
||||
if(!activityStates_.containsKey(act)){
|
||||
return getDefaultTypedActivityState(act, stateId, type);
|
||||
}
|
||||
States actStates = activityStates.get(act);
|
||||
actStates.putState(stateId, state);
|
||||
States_ states = activityStates_.get(act);
|
||||
T state = states.getState(stateId, type);
|
||||
if(state == null) return getDefaultTypedActivityState(act, stateId, type);
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param act
|
||||
* @param stateId
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
private <T> T getDefaultTypedActivityState(TourActivity act, StateId stateId,Class<T> type) {
|
||||
if(defaultActivityStates_.containsKey(stateId)){
|
||||
return type.cast(defaultActivityStates_.get(stateId));
|
||||
}
|
||||
if(stateId.equals(StateFactory.EARLIEST_OPERATION_START_TIME)){
|
||||
return type.cast(act.getTheoreticalEarliestOperationStartTime());
|
||||
}
|
||||
if(stateId.equals(StateFactory.LATEST_OPERATION_START_TIME)){
|
||||
return type.cast(act.getTheoreticalLatestOperationStartTime());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return route state of type 'type'.
|
||||
*
|
||||
* @return route-state
|
||||
* @throws ClassCastException if state of route and stateId is of another type
|
||||
*/
|
||||
@Override
|
||||
public <T> T getRouteState(VehicleRoute route, StateId stateId, Class<T> type) {
|
||||
if(!vehicleRouteStates_.containsKey(route)){
|
||||
return getDefaultTypedRouteState(stateId, type);
|
||||
}
|
||||
States_ states = vehicleRouteStates_.get(route);
|
||||
T state = states.getState(stateId, type);
|
||||
if(state == null) return getDefaultTypedRouteState(stateId, type);
|
||||
return state;
|
||||
}
|
||||
|
||||
private <T> T getDefaultTypedRouteState(StateId stateId, Class<T> type) {
|
||||
if(defaultRouteStates_.containsKey(stateId)){
|
||||
return type.cast(defaultRouteStates_.get(stateId));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param act
|
||||
* @param stateId
|
||||
* @param state
|
||||
* @deprecated use generic method <code>putTypedActivityState(TourActivity act, StateId stateId, Class<T> type, T state)</code> instead
|
||||
*/
|
||||
@Deprecated
|
||||
public void putActivityState(TourActivity act, StateId stateId, State state){
|
||||
putTypedActivityState(act, stateId, State.class, state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic method to memorize state 'state' of type 'type' of act and stateId.
|
||||
*
|
||||
* <p><b>For example: </b><br>
|
||||
* <code>Capacity loadAtMyActivity = Capacity.Builder.newInstance().addCapacityDimension(0,10).build();<br>
|
||||
* stateManager.putTypedActivityState(myActivity, StateFactory.createStateId("act-load"), Capacity.class, loadAtMyActivity);</code>
|
||||
* <p>you can retrieve the load at myActivity by <br>
|
||||
* <code>Capacity load = stateManager.getActivityState(myActivity, StateFactory.createStateId("act-load"), Capacity.class);</code>
|
||||
*
|
||||
* @param act
|
||||
* @param stateId
|
||||
* @param type
|
||||
* @param state
|
||||
*/
|
||||
public <T> void putTypedActivityState(TourActivity act, StateId stateId, Class<T> type, T state){
|
||||
if(StateFactory.isReservedId(stateId)) StateFactory.throwReservedIdException(stateId.toString());
|
||||
putInternalActivityState(act, stateId, state);
|
||||
putInternalTypedActivityState(act, stateId, type, state);
|
||||
}
|
||||
|
||||
void putInternalRouteState(VehicleRoute route, StateId stateId, State state){
|
||||
if(!vehicleRouteStates.containsKey(route)){
|
||||
vehicleRouteStates.put(route, StateFactory.createStates());
|
||||
|
||||
@Deprecated
|
||||
void putInternalActivityState(TourActivity act, StateId stateId, State state){
|
||||
putInternalTypedActivityState(act, stateId, State.class, state);
|
||||
}
|
||||
|
||||
<T> void putInternalTypedActivityState(TourActivity act, StateId stateId, Class<T> type, T state){
|
||||
if(!activityStates_.containsKey(act)){
|
||||
activityStates_.put(act, new States_());
|
||||
}
|
||||
States routeStates = (States) vehicleRouteStates.get(route);
|
||||
routeStates.putState(stateId, state);
|
||||
States_ actStates = activityStates_.get(act);
|
||||
actStates.putState(stateId, type, state);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
void putInternalRouteState(VehicleRoute route, StateId stateId, State state){
|
||||
putTypedInternalRouteState(route, stateId, State.class, state);
|
||||
}
|
||||
|
||||
<T> void putTypedInternalRouteState(VehicleRoute route, StateId stateId, Class<T> type, T state){
|
||||
if(!vehicleRouteStates_.containsKey(route)){
|
||||
vehicleRouteStates_.put(route, new States_());
|
||||
}
|
||||
States_ routeStates = vehicleRouteStates_.get(route);
|
||||
routeStates.putState(stateId, type, state);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void putRouteState(VehicleRoute route, StateId stateId, State state){
|
||||
if(StateFactory.isReservedId(stateId)) StateFactory.throwReservedIdException(stateId.toString());
|
||||
putInternalRouteState(route, stateId, state);
|
||||
putTypedRouteState(route, stateId, State.class, state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic method to memorize state 'state' of type 'type' of route and stateId.
|
||||
*
|
||||
* <p><b>For example:</b> <br>
|
||||
* <code>double totalRouteDuration = 100.0;<br>
|
||||
* stateManager.putTypedActivityState(myRoute, StateFactory.createStateId("route-duration"), Double.class, totalRouteDuration);</code>
|
||||
* <p>you can retrieve the duration of myRoute then by <br>
|
||||
* <code>double totalRouteDuration = stateManager.getRouteState(myRoute, StateFactory.createStateId("route-duration"), Double.class);</code>
|
||||
*
|
||||
* @param act
|
||||
* @param stateId
|
||||
* @param type
|
||||
* @param state
|
||||
*/
|
||||
public <T> void putTypedRouteState(VehicleRoute route, StateId stateId, Class<T> type, T state){
|
||||
if(StateFactory.isReservedId(stateId)) StateFactory.throwReservedIdException(stateId.toString());
|
||||
putTypedInternalRouteState(route, stateId, type, state);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public State getRouteState(VehicleRoute route, StateId stateId) {
|
||||
if(!vehicleRouteStates.containsKey(route)){
|
||||
return getDefaultRouteState(stateId,route);
|
||||
if(!vehicleRouteStates_.containsKey(route)){
|
||||
return getDefaultTypedRouteState(stateId,State.class);
|
||||
}
|
||||
States routeStates = vehicleRouteStates.get(route);
|
||||
State state = routeStates.getState(stateId);
|
||||
States_ routeStates = vehicleRouteStates_.get(route);
|
||||
State state = routeStates.getState(stateId,State.class);
|
||||
if(state == null){
|
||||
return getDefaultRouteState(stateId, route);
|
||||
return getDefaultTypedRouteState(stateId, State.class);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
|
@ -220,29 +436,7 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
|
|||
insertionListeners.removeListener(insertionListener);
|
||||
}
|
||||
|
||||
private State getDefaultActState(StateId stateId, TourActivity act){
|
||||
if(stateId.equals(StateFactory.LOAD)) return StateFactory.createState(0);
|
||||
if(stateId.equals(StateFactory.COSTS)) return StateFactory.createState(0);
|
||||
if(stateId.equals(StateFactory.DURATION)) return StateFactory.createState(0);
|
||||
if(stateId.equals(StateFactory.EARLIEST_OPERATION_START_TIME)) return StateFactory.createState(act.getTheoreticalEarliestOperationStartTime());
|
||||
if(stateId.equals(StateFactory.LATEST_OPERATION_START_TIME)) return StateFactory.createState(act.getTheoreticalLatestOperationStartTime());
|
||||
if(stateId.equals(StateFactory.FUTURE_MAXLOAD)) return StateFactory.createState(0);
|
||||
if(stateId.equals(StateFactory.PAST_MAXLOAD)) return StateFactory.createState(0);
|
||||
if(defaultActivityStates.containsKey(stateId)) return defaultActivityStates.get(stateId);
|
||||
return null;
|
||||
}
|
||||
|
||||
private State getDefaultRouteState(StateId stateId, VehicleRoute route){
|
||||
if(stateId.equals(StateFactory.MAXLOAD)) return StateFactory.createState(0);
|
||||
if(stateId.equals(StateFactory.LOAD)) return StateFactory.createState(0);
|
||||
if(stateId.equals(StateFactory.LOAD_AT_END)) return StateFactory.createState(0);
|
||||
if(stateId.equals(StateFactory.LOAD_AT_BEGINNING)) return StateFactory.createState(0);
|
||||
if(stateId.equals(StateFactory.COSTS)) return StateFactory.createState(0);
|
||||
if(stateId.equals(StateFactory.DURATION)) return StateFactory.createState(0);
|
||||
if(defaultRouteStates.containsKey(stateId)) return defaultRouteStates.get(stateId);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) {
|
||||
// log.debug("insert " + job2insert + " in " + inRoute);
|
||||
|
|
@ -294,16 +488,18 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
|
|||
UpdateLoads updateLoads = new UpdateLoads(this);
|
||||
addActivityVisitor(updateLoads);
|
||||
addListener(updateLoads);
|
||||
addActivityVisitor(new UpdatePrevMaxLoad(this));
|
||||
addActivityVisitor(new UpdateMaxLoad(this));
|
||||
addActivityVisitor(new UpdateMaxLoad_(this));
|
||||
addActivityVisitor(new UpdateMaxCapacityUtilisationAtActivitiesByLookingBackwardInRoute(this));
|
||||
addActivityVisitor(new UpdateMaxCapacityUtilisationAtActivitiesByLookingForwardInRoute(this));
|
||||
addActivityVisitor(new UpdateMaxCapacityUtilisationAtRoute(this));
|
||||
}
|
||||
}
|
||||
|
||||
public void updateTimeWindowStates() {
|
||||
if(!updateTWs){
|
||||
updateTWs=true;
|
||||
addActivityVisitor(new UpdateTimeWindow(this, routingCosts));
|
||||
addActivityVisitor(new UpdatePracticalTimeWindows(this, routingCosts));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,37 +0,0 @@
|
|||
package jsprit.core.algorithm.state;
|
||||
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.ActivityVisitor;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
import jsprit.core.util.ActivityTimeTracker;
|
||||
|
||||
class UpdateEarliestStartTime implements ActivityVisitor,StateUpdater{
|
||||
|
||||
private StateManager states;
|
||||
|
||||
private ActivityTimeTracker timeTracker;
|
||||
|
||||
public UpdateEarliestStartTime(StateManager states, VehicleRoutingTransportCosts transportCosts) {
|
||||
super();
|
||||
this.states = states;
|
||||
timeTracker = new ActivityTimeTracker(transportCosts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void begin(VehicleRoute route) {
|
||||
timeTracker.begin(route);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(TourActivity activity) {
|
||||
timeTracker.visit(activity);
|
||||
states.putInternalActivityState(activity, StateFactory.EARLIEST_OPERATION_START_TIME, StateFactory.createState(Math.max(timeTracker.getActArrTime(), activity.getTheoreticalEarliestOperationStartTime())));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {}
|
||||
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ import java.util.Collection;
|
|||
|
||||
import jsprit.core.algorithm.recreate.listener.InsertionStartsListener;
|
||||
import jsprit.core.algorithm.recreate.listener.JobInsertedListener;
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.job.Delivery;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.job.Pickup;
|
||||
|
|
@ -15,34 +16,27 @@ import jsprit.core.problem.solution.route.state.StateFactory;
|
|||
|
||||
|
||||
/**
|
||||
* Updates load at activity level.
|
||||
* Updates load at start and end of route as well as at each activity. And update is triggered when either
|
||||
* activityVisitor has been started, the insertion process has been started or a job has been inserted.
|
||||
*
|
||||
* <p>Note that this assumes that StateTypes.LOAD_AT_DEPOT is already updated, i.e. it starts by setting loadAtDepot to StateTypes.LOAD_AT_DEPOT.
|
||||
* If StateTypes.LOAD_AT_DEPOT is not set, it starts with 0 load at depot.
|
||||
*
|
||||
* <p>Thus it DEPENDS on StateTypes.LOAD_AT_DEPOT
|
||||
* <p>Note that this only works properly if you register this class as ActivityVisitor AND InsertionStartsListener AND JobInsertedListener.
|
||||
* The reason behind is that activity states are dependent on route-level states and vice versa. If this is properly registered,
|
||||
* this dependency is solved automatically.
|
||||
*
|
||||
* @author stefan
|
||||
*
|
||||
*/
|
||||
class UpdateLoads implements ActivityVisitor, StateUpdater, InsertionStartsListener, JobInsertedListener {
|
||||
|
||||
private StateManager stateManager;
|
||||
private int currentLoad = 0;
|
||||
private VehicleRoute route;
|
||||
/**
|
||||
* Updates load at activity level.
|
||||
*
|
||||
* <p>Note that this assumes that StateTypes.LOAD_AT_DEPOT is already updated, i.e. it starts by setting loadAtDepot to StateTypes.LOAD_AT_DEPOT.
|
||||
* If StateTypes.LOAD_AT_DEPOT is not set, it starts with 0 load at depot.
|
||||
*
|
||||
* <p>Thus it DEPENDS on StateTypes.LOAD_AT_DEPOT
|
||||
*
|
||||
* <p>The loads can be retrieved by <br>
|
||||
* <code>stateManager.getActivityState(activity,StateTypes.LOAD);</code>
|
||||
*
|
||||
* @author stefan
|
||||
*
|
||||
|
||||
/*
|
||||
* default has one dimension with a value of zero
|
||||
*/
|
||||
private Capacity currentLoad = Capacity.Builder.newInstance().build();
|
||||
|
||||
private VehicleRoute route;
|
||||
|
||||
public UpdateLoads(StateManager stateManager) {
|
||||
super();
|
||||
this.stateManager = stateManager;
|
||||
|
|
@ -50,37 +44,36 @@ class UpdateLoads implements ActivityVisitor, StateUpdater, InsertionStartsListe
|
|||
|
||||
@Override
|
||||
public void begin(VehicleRoute route) {
|
||||
currentLoad = (int) stateManager.getRouteState(route, StateFactory.LOAD_AT_BEGINNING).toDouble();
|
||||
currentLoad = stateManager.getRouteState(route, StateFactory.LOAD_AT_BEGINNING, Capacity.class);
|
||||
this.route = route;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(TourActivity act) {
|
||||
currentLoad += act.getCapacityDemand();
|
||||
stateManager.putInternalActivityState(act, StateFactory.LOAD, StateFactory.createState(currentLoad));
|
||||
assert currentLoad <= route.getVehicle().getCapacity() : "currentLoad at activity must not be > vehicleCapacity";
|
||||
assert currentLoad >= 0 : "currentLoad at act must not be < 0";
|
||||
currentLoad = Capacity.addup(currentLoad, act.getSize());
|
||||
stateManager.putInternalTypedActivityState(act, StateFactory.LOAD, Capacity.class, currentLoad);
|
||||
assert currentLoad.isLessOrEqual(route.getVehicle().getType().getCapacityDimensions()) : "currentLoad at activity must not be > vehicleCapacity";
|
||||
assert currentLoad.isGreaterOrEqual(Capacity.Builder.newInstance().build()) : "currentLoad at act must not be < 0 in one of the applied dimensions";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
// stateManager.putRouteState(route, StateFactory., state)
|
||||
currentLoad = 0;
|
||||
currentLoad = Capacity.Builder.newInstance().build();
|
||||
}
|
||||
|
||||
void insertionStarts(VehicleRoute route) {
|
||||
int loadAtDepot = 0;
|
||||
int loadAtEnd = 0;
|
||||
Capacity loadAtDepot = Capacity.Builder.newInstance().build();
|
||||
Capacity loadAtEnd = Capacity.Builder.newInstance().build();
|
||||
for(Job j : route.getTourActivities().getJobs()){
|
||||
if(j instanceof Delivery){
|
||||
loadAtDepot += j.getCapacityDemand();
|
||||
loadAtDepot = Capacity.addup(loadAtDepot, j.getSize());
|
||||
}
|
||||
else if(j instanceof Pickup || j instanceof Service){
|
||||
loadAtEnd += j.getCapacityDemand();
|
||||
loadAtEnd = Capacity.addup(loadAtEnd, j.getSize());
|
||||
}
|
||||
}
|
||||
stateManager.putInternalRouteState(route, StateFactory.LOAD_AT_BEGINNING, StateFactory.createState(loadAtDepot));
|
||||
stateManager.putInternalRouteState(route, StateFactory.LOAD_AT_END, StateFactory.createState(loadAtEnd));
|
||||
stateManager.putTypedInternalRouteState(route, StateFactory.LOAD_AT_BEGINNING, Capacity.class, loadAtDepot);
|
||||
stateManager.putTypedInternalRouteState(route, StateFactory.LOAD_AT_END, Capacity.class, loadAtEnd);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -90,17 +83,13 @@ class UpdateLoads implements ActivityVisitor, StateUpdater, InsertionStartsListe
|
|||
|
||||
@Override
|
||||
public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) {
|
||||
// log.debug("insert("+job2insert+").into("+inRoute+")");
|
||||
// log(inRoute);
|
||||
if(job2insert instanceof Delivery){
|
||||
int loadAtDepot = (int) stateManager.getRouteState(inRoute, StateFactory.LOAD_AT_BEGINNING).toDouble();
|
||||
// log.info("loadAtDepot="+loadAtDepot);
|
||||
stateManager.putInternalRouteState(inRoute, StateFactory.LOAD_AT_BEGINNING, StateFactory.createState(loadAtDepot + job2insert.getCapacityDemand()));
|
||||
Capacity loadAtDepot = stateManager.getRouteState(inRoute, StateFactory.LOAD_AT_BEGINNING, Capacity.class);
|
||||
stateManager.putTypedInternalRouteState(inRoute, StateFactory.LOAD_AT_BEGINNING, Capacity.class, Capacity.addup(loadAtDepot, job2insert.getSize()));
|
||||
}
|
||||
else if(job2insert instanceof Pickup || job2insert instanceof Service){
|
||||
int loadAtEnd = (int) stateManager.getRouteState(inRoute, StateFactory.LOAD_AT_END).toDouble();
|
||||
// log.info("loadAtEnd="+loadAtEnd);
|
||||
stateManager.putInternalRouteState(inRoute, StateFactory.LOAD_AT_END, StateFactory.createState(loadAtEnd + job2insert.getCapacityDemand()));
|
||||
Capacity loadAtEnd = stateManager.getRouteState(inRoute, StateFactory.LOAD_AT_END, Capacity.class);
|
||||
stateManager.putTypedInternalRouteState(inRoute, StateFactory.LOAD_AT_END, Capacity.class, Capacity.addup(loadAtEnd, job2insert.getSize()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,44 @@
|
|||
package jsprit.core.algorithm.state;
|
||||
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.ActivityVisitor;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
|
||||
/**
|
||||
* Determines and memorizes the maximum capacity utilization at each activity by looking backward in route,
|
||||
* i.e. the maximum capacity utilization at previous activities.
|
||||
*
|
||||
* @author schroeder
|
||||
*
|
||||
*/
|
||||
class UpdateMaxCapacityUtilisationAtActivitiesByLookingBackwardInRoute implements ActivityVisitor, StateUpdater {
|
||||
|
||||
private StateManager stateManager;
|
||||
|
||||
private VehicleRoute route;
|
||||
|
||||
private Capacity maxLoad;
|
||||
|
||||
public UpdateMaxCapacityUtilisationAtActivitiesByLookingBackwardInRoute(StateManager stateManager) {
|
||||
this.stateManager = stateManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void begin(VehicleRoute route) {
|
||||
this.route = route;
|
||||
maxLoad = stateManager.getRouteState(route, StateFactory.LOAD_AT_BEGINNING, Capacity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(TourActivity act) {
|
||||
maxLoad = Capacity.max(maxLoad, stateManager.getActivityState(act, StateFactory.LOAD, Capacity.class));
|
||||
stateManager.putInternalTypedActivityState(act, StateFactory.PAST_MAXLOAD, Capacity.class, maxLoad);
|
||||
assert maxLoad.isGreaterOrEqual(Capacity.Builder.newInstance().build()) : "maxLoad can never be smaller than 0";
|
||||
assert maxLoad.isLessOrEqual(route.getVehicle().getType().getCapacityDimensions()) : "maxLoad can never be bigger than vehicleCap";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {}
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
package jsprit.core.algorithm.state;
|
||||
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.ReverseActivityVisitor;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
|
||||
/**
|
||||
* A {@link ReverseActivityVisitor} that looks forward in the vehicle route and determines
|
||||
* the maximum capacity utilization (in terms of loads) at subsequent activities.
|
||||
*
|
||||
* <p>Assume a vehicle route with the following activity sequence {start,pickup(1,4),delivery(2,3),pickup(3,2),end} where
|
||||
* pickup(1,2) = pickup(id,cap-demand).<br>
|
||||
* Future maxLoad for each activity are calculated as follows:<br>
|
||||
* loadAt(end)=6 (since two pickups need to be delivered to depot)<br>
|
||||
* pickup(3)=max(loadAt(pickup(3)), futureMaxLoad(end))=max(6,6)=6
|
||||
* delivery(2)=max(loadAt(delivery(2),futureMaxLoad(pickup(3))=max(4,6)=6
|
||||
* pickup(1)=max(7,6)=7
|
||||
* start=max(7,7)=7
|
||||
* activity (apart from start and end), the maximum capacity is determined when forward looking into the route.
|
||||
* That is at each activity we know how much capacity is available whithout breaking future capacity constraints.
|
||||
*
|
||||
*
|
||||
* @author schroeder
|
||||
*
|
||||
*/
|
||||
class UpdateMaxCapacityUtilisationAtActivitiesByLookingForwardInRoute implements ReverseActivityVisitor, StateUpdater {
|
||||
|
||||
private StateManager stateManager;
|
||||
|
||||
private VehicleRoute route;
|
||||
|
||||
private Capacity maxLoad = Capacity.Builder.newInstance().build();
|
||||
// private double maxLoad;
|
||||
|
||||
public UpdateMaxCapacityUtilisationAtActivitiesByLookingForwardInRoute(StateManager stateManager) {
|
||||
super();
|
||||
this.stateManager = stateManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void begin(VehicleRoute route) {
|
||||
this.route = route;
|
||||
maxLoad = stateManager.getRouteState(route, StateFactory.LOAD_AT_END, Capacity.class);
|
||||
// maxLoad = stateManager.getRouteState(route, StateFactory.LOAD_AT_END).toDouble();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(TourActivity act) {
|
||||
maxLoad = Capacity.max(maxLoad, stateManager.getActivityState(act, StateFactory.LOAD, Capacity.class));
|
||||
// maxLoad = Math.max(maxLoad, stateManager.getActivityState(act, StateFactory.LOAD).toDouble());
|
||||
stateManager.putInternalTypedActivityState(act, StateFactory.FUTURE_MAXLOAD, Capacity.class, maxLoad);
|
||||
// stateManager.putInternalActivityState(act, StateFactory.FUTURE_MAXLOAD, StateFactory.createState(maxLoad));
|
||||
assert maxLoad.isLessOrEqual(route.getVehicle().getType().getCapacityDimensions()) : "maxLoad can in every capacity dimension never be bigger than vehicleCap";
|
||||
// assert maxLoad <= route.getVehicle().getCapacity() : "maxLoad can never be bigger than vehicleCap";
|
||||
assert maxLoad.isGreaterOrEqual(Capacity.Builder.newInstance().build()) : "maxLoad can never be smaller than 0";
|
||||
// assert maxLoad >= 0 : "maxLoad can never be smaller than 0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {}
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
package jsprit.core.algorithm.state;
|
||||
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.ActivityVisitor;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
|
||||
/**
|
||||
* Updates load at activity level.
|
||||
*
|
||||
* <p>Note that this assumes that StateTypes.LOAD_AT_DEPOT is already updated, i.e. it starts by setting loadAtDepot to StateTypes.LOAD_AT_DEPOT.
|
||||
* If StateTypes.LOAD_AT_DEPOT is not set, it starts with 0 load at depot.
|
||||
*
|
||||
* <p>Thus it DEPENDS on StateTypes.LOAD_AT_DEPOT
|
||||
*
|
||||
* @author stefan
|
||||
*
|
||||
*/
|
||||
class UpdateMaxCapacityUtilisationAtRoute implements ActivityVisitor, StateUpdater {
|
||||
|
||||
private StateManager stateManager;
|
||||
|
||||
private Capacity currentLoad = Capacity.Builder.newInstance().build();
|
||||
|
||||
private VehicleRoute route;
|
||||
|
||||
private Capacity maxLoad = Capacity.Builder.newInstance().build();
|
||||
|
||||
public UpdateMaxCapacityUtilisationAtRoute(StateManager stateManager) {
|
||||
super();
|
||||
this.stateManager = stateManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void begin(VehicleRoute route) {
|
||||
currentLoad = stateManager.getRouteState(route, StateFactory.LOAD_AT_BEGINNING, Capacity.class);
|
||||
maxLoad = currentLoad;
|
||||
this.route = route;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(TourActivity act) {
|
||||
currentLoad = Capacity.addup(currentLoad, act.getSize());
|
||||
maxLoad = Capacity.max(maxLoad, currentLoad);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
stateManager.putTypedInternalRouteState(route, StateFactory.MAXLOAD, Capacity.class, maxLoad);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
package jsprit.core.algorithm.state;
|
||||
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.ReverseActivityVisitor;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
|
||||
|
||||
class UpdateMaxLoad implements ReverseActivityVisitor, StateUpdater {
|
||||
private StateManager stateManager;
|
||||
private VehicleRoute route;
|
||||
private double maxLoad;
|
||||
public UpdateMaxLoad(StateManager stateManager) {
|
||||
super();
|
||||
this.stateManager = stateManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void begin(VehicleRoute route) {
|
||||
this.route = route;
|
||||
maxLoad = stateManager.getRouteState(route, StateFactory.LOAD_AT_END).toDouble();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(TourActivity act) {
|
||||
maxLoad = Math.max(maxLoad, stateManager.getActivityState(act, StateFactory.LOAD).toDouble());
|
||||
stateManager.putInternalActivityState(act, StateFactory.FUTURE_MAXLOAD, StateFactory.createState(maxLoad));
|
||||
assert maxLoad <= route.getVehicle().getCapacity() : "maxLoad can never be bigger than vehicleCap";
|
||||
assert maxLoad >= 0 : "maxLoad can never be smaller than 0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {}
|
||||
}
|
||||
|
|
@ -1,68 +0,0 @@
|
|||
package jsprit.core.algorithm.state;
|
||||
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.ActivityVisitor;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
|
||||
/**
|
||||
* Updates load at activity level.
|
||||
*
|
||||
* <p>Note that this assumes that StateTypes.LOAD_AT_DEPOT is already updated, i.e. it starts by setting loadAtDepot to StateTypes.LOAD_AT_DEPOT.
|
||||
* If StateTypes.LOAD_AT_DEPOT is not set, it starts with 0 load at depot.
|
||||
*
|
||||
* <p>Thus it DEPENDS on StateTypes.LOAD_AT_DEPOT
|
||||
*
|
||||
* @author stefan
|
||||
*
|
||||
*/
|
||||
class UpdateMaxLoad_ implements ActivityVisitor, StateUpdater {
|
||||
private StateManager stateManager;
|
||||
private int currentLoad = 0;
|
||||
private VehicleRoute route;
|
||||
private int maxLoad = 0;
|
||||
|
||||
/**
|
||||
* Updates load at activity level.
|
||||
*
|
||||
* <p>Note that this assumes that StateTypes.LOAD_AT_DEPOT is already updated, i.e. it starts by setting loadAtDepot to StateTypes.LOAD_AT_DEPOT.
|
||||
* If StateTypes.LOAD_AT_DEPOT is not set, it starts with 0 load at depot.
|
||||
*
|
||||
* <p>Thus it DEPENDS on StateTypes.LOAD_AT_DEPOT
|
||||
*
|
||||
*
|
||||
*
|
||||
* <p>The loads can be retrieved by <br>
|
||||
* <code>stateManager.getActivityState(activity,StateTypes.LOAD);</code>
|
||||
*
|
||||
*
|
||||
* @author stefan
|
||||
*
|
||||
*/
|
||||
public UpdateMaxLoad_(StateManager stateManager) {
|
||||
super();
|
||||
this.stateManager = stateManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void begin(VehicleRoute route) {
|
||||
currentLoad = (int) stateManager.getRouteState(route, StateFactory.LOAD_AT_BEGINNING).toDouble();
|
||||
maxLoad = currentLoad;
|
||||
this.route = route;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(TourActivity act) {
|
||||
currentLoad += act.getCapacityDemand();
|
||||
maxLoad = Math.max(maxLoad, currentLoad);
|
||||
assert currentLoad <= route.getVehicle().getCapacity() : "currentLoad at activity must not be > vehicleCapacity";
|
||||
assert currentLoad >= 0 : "currentLoad at act must not be < 0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
stateManager.putInternalRouteState(route, StateFactory.MAXLOAD, StateFactory.createState(maxLoad));
|
||||
currentLoad = 0;
|
||||
maxLoad = 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -6,8 +6,13 @@ import jsprit.core.problem.solution.route.activity.ReverseActivityVisitor;
|
|||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
|
||||
|
||||
class UpdateTimeWindow implements ReverseActivityVisitor, StateUpdater{
|
||||
/**
|
||||
* Updates and memorizes latest operation start times at activities.
|
||||
*
|
||||
* @author schroeder
|
||||
*
|
||||
*/
|
||||
class UpdatePracticalTimeWindows implements ReverseActivityVisitor, StateUpdater{
|
||||
|
||||
private StateManager states;
|
||||
|
||||
|
|
@ -19,7 +24,7 @@ class UpdateTimeWindow implements ReverseActivityVisitor, StateUpdater{
|
|||
|
||||
private TourActivity prevAct;
|
||||
|
||||
public UpdateTimeWindow(StateManager states, VehicleRoutingTransportCosts tpCosts) {
|
||||
public UpdatePracticalTimeWindows(StateManager states, VehicleRoutingTransportCosts tpCosts) {
|
||||
super();
|
||||
this.states = states;
|
||||
this.transportCosts = tpCosts;
|
||||
|
|
@ -37,7 +42,7 @@ class UpdateTimeWindow implements ReverseActivityVisitor, StateUpdater{
|
|||
double potentialLatestArrivalTimeAtCurrAct = latestArrTimeAtPrevAct - transportCosts.getBackwardTransportTime(activity.getLocationId(), prevAct.getLocationId(), latestArrTimeAtPrevAct, route.getDriver(),route.getVehicle()) - activity.getOperationTime();
|
||||
double latestArrivalTime = Math.min(activity.getTheoreticalLatestOperationStartTime(), potentialLatestArrivalTimeAtCurrAct);
|
||||
|
||||
states.putInternalActivityState(activity, StateFactory.LATEST_OPERATION_START_TIME, StateFactory.createState(latestArrivalTime));
|
||||
states.putInternalTypedActivityState(activity, StateFactory.LATEST_OPERATION_START_TIME, Double.class, latestArrivalTime);
|
||||
|
||||
latestArrTimeAtPrevAct = latestArrivalTime;
|
||||
prevAct = activity;
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
package jsprit.core.algorithm.state;
|
||||
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.ActivityVisitor;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
|
||||
|
||||
class UpdatePrevMaxLoad implements ActivityVisitor, StateUpdater {
|
||||
private StateManager stateManager;
|
||||
private VehicleRoute route;
|
||||
private double currLoad;
|
||||
private double prevMaxLoad;
|
||||
|
||||
public UpdatePrevMaxLoad(StateManager stateManager) {
|
||||
super();
|
||||
this.stateManager = stateManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void begin(VehicleRoute route) {
|
||||
this.route = route;
|
||||
currLoad = stateManager.getRouteState(route, StateFactory.LOAD_AT_BEGINNING).toDouble();
|
||||
prevMaxLoad = currLoad;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(TourActivity act) {
|
||||
prevMaxLoad = Math.max(prevMaxLoad, stateManager.getActivityState(act, StateFactory.LOAD).toDouble());
|
||||
stateManager.putInternalActivityState(act, StateFactory.PAST_MAXLOAD, StateFactory.createState(prevMaxLoad));
|
||||
assert prevMaxLoad >= 0 : "maxLoad can never be smaller than 0";
|
||||
assert prevMaxLoad <= route.getVehicle().getCapacity() : "maxLoad can never be bigger than vehicleCap";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {}
|
||||
}
|
||||
|
|
@ -61,7 +61,6 @@ public class UpdateVariableCosts implements ActivityVisitor,StateUpdater{
|
|||
@Override
|
||||
public void begin(VehicleRoute route) {
|
||||
vehicleRoute = route;
|
||||
// vehicleRoute.getVehicleRouteCostCalculator().reset();
|
||||
timeTracker.begin(route);
|
||||
prevAct = route.getStart();
|
||||
startTimeAtPrevAct = timeTracker.getActEndTime();
|
||||
|
|
@ -74,13 +73,10 @@ public class UpdateVariableCosts implements ActivityVisitor,StateUpdater{
|
|||
double transportCost = this.transportCost.getTransportCost(prevAct.getLocationId(), act.getLocationId(), startTimeAtPrevAct, vehicleRoute.getDriver(), vehicleRoute.getVehicle());
|
||||
double actCost = activityCost.getActivityCost(act, timeTracker.getActArrTime(), vehicleRoute.getDriver(), vehicleRoute.getVehicle());
|
||||
|
||||
// vehicleRoute.getVehicleRouteCostCalculator().addTransportCost(transportCost);
|
||||
// vehicleRoute.getVehicleRouteCostCalculator().addActivityCost(actCost);
|
||||
//
|
||||
totalOperationCost += transportCost;
|
||||
totalOperationCost += actCost;
|
||||
|
||||
states.putInternalActivityState(act, StateFactory.COSTS, StateFactory.createState(totalOperationCost));
|
||||
states.putInternalTypedActivityState(act, StateFactory.COSTS, Double.class, totalOperationCost);
|
||||
|
||||
prevAct = act;
|
||||
startTimeAtPrevAct = timeTracker.getActEndTime();
|
||||
|
|
@ -91,20 +87,11 @@ public class UpdateVariableCosts implements ActivityVisitor,StateUpdater{
|
|||
timeTracker.finish();
|
||||
double transportCost = this.transportCost.getTransportCost(prevAct.getLocationId(), vehicleRoute.getEnd().getLocationId(), startTimeAtPrevAct, vehicleRoute.getDriver(), vehicleRoute.getVehicle());
|
||||
double actCost = activityCost.getActivityCost(vehicleRoute.getEnd(), timeTracker.getActEndTime(), vehicleRoute.getDriver(), vehicleRoute.getVehicle());
|
||||
|
||||
// vehicleRoute.getVehicleRouteCostCalculator().addTransportCost(transportCost);
|
||||
// vehicleRoute.getVehicleRouteCostCalculator().addActivityCost(actCost);
|
||||
//
|
||||
|
||||
totalOperationCost += transportCost;
|
||||
totalOperationCost += actCost;
|
||||
// totalOperationCost += getFixCosts(vehicleRoute.getVehicle());
|
||||
|
||||
states.putInternalRouteState(vehicleRoute, StateFactory.COSTS, StateFactory.createState(totalOperationCost));
|
||||
|
||||
// //this is rather strange and likely to change
|
||||
// vehicleRoute.getVehicleRouteCostCalculator().price(vehicleRoute.getDriver());
|
||||
// vehicleRoute.getVehicleRouteCostCalculator().price(vehicleRoute.getVehicle());
|
||||
// vehicleRoute.getVehicleRouteCostCalculator().finish();
|
||||
states.putTypedInternalRouteState(vehicleRoute, StateFactory.COSTS, Double.class, totalOperationCost);
|
||||
|
||||
startTimeAtPrevAct = 0.0;
|
||||
prevAct = null;
|
||||
|
|
|
|||
276
jsprit-core/src/main/java/jsprit/core/problem/Capacity.java
Normal file
276
jsprit-core/src/main/java/jsprit/core/problem/Capacity.java
Normal file
|
|
@ -0,0 +1,276 @@
|
|||
package jsprit.core.problem;
|
||||
|
||||
/**
|
||||
* Capacity with an arbitrary number of capacity-dimension.
|
||||
*
|
||||
* <p>Note that this assumes the the values of each capacity dimension can be added up and subtracted
|
||||
*
|
||||
* @author schroeder
|
||||
*
|
||||
*/
|
||||
public class Capacity {
|
||||
|
||||
/**
|
||||
* Adds up two capacities, i.e. sums up each and every capacity dimension, and returns the resulting Capacity.
|
||||
*
|
||||
* <p>Note that this assumes that capacity dimension can be added up.
|
||||
*
|
||||
* @param cap1
|
||||
* @param cap2
|
||||
* @return new capacity
|
||||
* @throws NullPointerException if one of the args is null
|
||||
|
||||
*/
|
||||
public static Capacity addup(Capacity cap1, Capacity cap2){
|
||||
if(cap1==null || cap2==null) throw new NullPointerException("arguments must not be null");
|
||||
Capacity.Builder capacityBuilder= Capacity.Builder.newInstance();
|
||||
for(int i=0;i<Math.max(cap1.getNuOfDimensions(),cap2.getNuOfDimensions());i++){
|
||||
capacityBuilder.addDimension(i, cap1.get(i)+cap2.get(i));
|
||||
}
|
||||
return capacityBuilder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtracts cap2substract from cap and returns the resulting Capacity.
|
||||
*
|
||||
* @param cap
|
||||
* @param cap2substract
|
||||
* @return new capacity
|
||||
* @throws NullPointerException if one of the args is null
|
||||
* @throws IllegalStateException if number of capacityDimensions of cap1 and cap2 are different (i.e. <code>cap1.getNuOfDimension() != cap2.getNuOfDimension()</code>).
|
||||
*
|
||||
*/
|
||||
public static Capacity subtract(Capacity cap, Capacity cap2substract){
|
||||
if(cap==null || cap2substract==null) throw new NullPointerException("arguments must not be null");
|
||||
Capacity.Builder capacityBuilder= Capacity.Builder.newInstance();
|
||||
for(int i=0;i<Math.max(cap.getNuOfDimensions(),cap2substract.getNuOfDimensions());i++){
|
||||
int dimValue = cap.get(i)-cap2substract.get(i);
|
||||
capacityBuilder.addDimension(i, dimValue);
|
||||
}
|
||||
return capacityBuilder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the inverted capacity, i.e. it multiplies all capacity dimensions with -1.
|
||||
*
|
||||
* @param cap
|
||||
* @return inverted capacity
|
||||
* @throws NullPointerException if one of the args is null
|
||||
*/
|
||||
public static Capacity invert(Capacity cap2invert){
|
||||
if(cap2invert==null) throw new NullPointerException("arguments must not be null");
|
||||
Capacity.Builder capacityBuilder= Capacity.Builder.newInstance();
|
||||
for(int i=0;i<cap2invert.getNuOfDimensions();i++){
|
||||
int dimValue = cap2invert.get(i)*-1;
|
||||
capacityBuilder.addDimension(i, dimValue);
|
||||
}
|
||||
return capacityBuilder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Divides every dimension of numerator capacity by the corresponding dimension of denominator capacity,
|
||||
* , and averages each quotient.
|
||||
*
|
||||
* <p>If both nominator.get(i) and denominator.get(i) equal to 0, dimension i is ignored.
|
||||
* <p>If both capacities are have only dimensions with dimensionVal=0, it returns 0.0
|
||||
* @param numerator
|
||||
* @param denominator
|
||||
* @return
|
||||
* @throws IllegalStateException if numerator.get(i) != 0 and denominator.get(i) == 0
|
||||
*/
|
||||
public static double divide(Capacity numerator, Capacity denominator){
|
||||
int nuOfDimensions = 0;
|
||||
double sumQuotients = 0.0;
|
||||
for(int index=0;index<Math.max(numerator.getNuOfDimensions(), denominator.getNuOfDimensions());index++){
|
||||
if(numerator.get(index) != 0 && denominator.get(index) == 0){
|
||||
throw new IllegalStateException("numerator > 0 and denominator = 0. cannot divide by 0");
|
||||
}
|
||||
else if(numerator.get(index) == 0 && denominator.get(index) == 0){
|
||||
continue;
|
||||
}
|
||||
else{
|
||||
nuOfDimensions++;
|
||||
sumQuotients += (double)numerator.get(index)/(double)denominator.get(index);
|
||||
}
|
||||
}
|
||||
if(nuOfDimensions > 0) return sumQuotients/(double)nuOfDimensions;
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a deep copy of Capacity.
|
||||
*
|
||||
* @param capacity
|
||||
* @return
|
||||
*/
|
||||
public static Capacity copyOf(Capacity capacity){
|
||||
if(capacity == null) return null;
|
||||
return new Capacity(capacity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builder that builds Capacity
|
||||
*
|
||||
* @author schroeder
|
||||
*
|
||||
*/
|
||||
public static class Builder {
|
||||
|
||||
/**
|
||||
* default is 1 dimension with size of zero
|
||||
*/
|
||||
private int[] dimensions = new int[1];
|
||||
|
||||
/**
|
||||
* Returns a new instance of Capacity with one dimension and a value/size of 0
|
||||
*
|
||||
* @return this builder
|
||||
*/
|
||||
public static Builder newInstance(){
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
Builder(){}
|
||||
|
||||
/**
|
||||
* add capacity dimension
|
||||
*
|
||||
* <p>Note that it automatically resizes dimensions according to index, i.e. if index=7 there are 8 dimensions.
|
||||
* New dimensions then are initialized with 0
|
||||
*
|
||||
* @param index
|
||||
* @param dimValue
|
||||
* @return
|
||||
*/
|
||||
public Builder addDimension(int index, int dimValue){
|
||||
if(index < dimensions.length){
|
||||
dimensions[index] = dimValue;
|
||||
}
|
||||
else{
|
||||
int requiredSize = index + 1;
|
||||
int[] newDimensions = new int[requiredSize];
|
||||
copy(dimensions,newDimensions);
|
||||
newDimensions[index]=dimValue;
|
||||
this.dimensions=newDimensions;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
private void copy(int[] from, int[] to) {
|
||||
for(int i=0;i<dimensions.length;i++){
|
||||
to[i]=from[i];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds an immutable Capacity and returns it.
|
||||
*
|
||||
* @return Capacity
|
||||
*/
|
||||
public Capacity build() {
|
||||
return new Capacity(this);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private int[] dimensions;
|
||||
|
||||
/**
|
||||
* copy constructor
|
||||
*
|
||||
* @param capacity
|
||||
*/
|
||||
Capacity(Capacity capacity){
|
||||
this.dimensions = new int[capacity.getNuOfDimensions()];
|
||||
for(int i=0;i<capacity.getNuOfDimensions();i++){
|
||||
this.dimensions[i]=capacity.get(i);
|
||||
}
|
||||
}
|
||||
|
||||
Capacity(Builder builder) {
|
||||
dimensions = builder.dimensions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of specified capacity dimensions.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getNuOfDimensions(){
|
||||
return dimensions.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns value of capacity-dimension with specified index.
|
||||
*
|
||||
* <p>If capacity dimension does not exist, it returns 0 (rather than IndexOutOfBoundsException).
|
||||
*
|
||||
* @param index
|
||||
* @return
|
||||
*/
|
||||
public int get(int index){
|
||||
if(index<dimensions.length) return dimensions[index];
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this capacity is less or equal than the capacity toCompare, i.e. if none of the capacity dimensions > than the corresponding dimension in toCompare.
|
||||
*
|
||||
* @param toCompare
|
||||
* @return
|
||||
* @throws NullPointerException if one of the args is null
|
||||
*/
|
||||
public boolean isLessOrEqual(Capacity toCompare){
|
||||
if(toCompare == null) throw new NullPointerException();
|
||||
for(int i=0;i<this.getNuOfDimensions();i++){
|
||||
if(this.get(i) > toCompare.get(i)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this capacity is greater or equal than the capacity toCompare
|
||||
*
|
||||
* @param toCompare
|
||||
* @return
|
||||
* @throws NullPointerException if one of the args is null
|
||||
|
||||
*/
|
||||
public boolean isGreaterOrEqual(Capacity toCompare) {
|
||||
if(toCompare == null) throw new NullPointerException();
|
||||
for(int i=0;i<Math.max(this.getNuOfDimensions(), toCompare.getNuOfDimensions());i++){
|
||||
if(this.get(i) < toCompare.get(i)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sBuilder = new StringBuilder();
|
||||
sBuilder.append("[nuOfDimensions="+getNuOfDimensions()+"]");
|
||||
for(int i=0;i<getNuOfDimensions();i++){
|
||||
sBuilder.append("[[dimIndex="+i+"][dimValue="+dimensions[i]+"]]");
|
||||
}
|
||||
return sBuilder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the maximum, i.e. the maximum of each capacity dimension.
|
||||
*
|
||||
* @param cap1
|
||||
* @param cap2
|
||||
* @return
|
||||
*/
|
||||
public static Capacity max(Capacity cap1, Capacity cap2) {
|
||||
if(cap1 == null || cap2 == null) throw new IllegalArgumentException("arg must not be null");
|
||||
Capacity.Builder toReturnBuilder = Capacity.Builder.newInstance();
|
||||
for(int i=0;i<Math.max(cap1.getNuOfDimensions(), cap2.getNuOfDimensions());i++){
|
||||
toReturnBuilder.addDimension(i, Math.max(cap1.get(i), cap2.get(i)));
|
||||
}
|
||||
return toReturnBuilder.build();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -388,10 +388,11 @@ public class VehicleRoutingProblem {
|
|||
if(penaltyFixedCosts!=null){
|
||||
fixed = penaltyFixedCosts;
|
||||
}
|
||||
VehicleTypeImpl t = VehicleTypeImpl.Builder.newInstance(v.getType().getTypeId(), v.getCapacity())
|
||||
VehicleTypeImpl t = VehicleTypeImpl.Builder.newInstance(v.getType().getTypeId())
|
||||
.setCostPerDistance(penaltyFactor*v.getType().getVehicleCostParams().perDistanceUnit)
|
||||
.setCostPerTime(penaltyFactor*v.getType().getVehicleCostParams().perTimeUnit)
|
||||
.setFixedCost(fixed)
|
||||
.setCapacityDimensions(v.getType().getCapacityDimensions())
|
||||
.build();
|
||||
PenaltyVehicleType penType = new PenaltyVehicleType(t,penaltyFactor);
|
||||
String vehicleId = "penaltyVehicle_" + v.getStartLocationId() + "_" + t.getTypeId();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package jsprit.core.problem.constraint;
|
||||
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.misc.JobInsertionContext;
|
||||
import jsprit.core.problem.solution.route.activity.DeliverShipment;
|
||||
import jsprit.core.problem.solution.route.activity.PickupShipment;
|
||||
|
|
@ -36,27 +37,38 @@ public class PickupAndDeliverShipmentLoadActivityLevelConstraint implements Hard
|
|||
this.stateManager = stateManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether there is enough capacity to insert newAct between prevAct and nextAct.
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) {
|
||||
if(!(newAct instanceof PickupShipment) && !(newAct instanceof DeliverShipment)){
|
||||
return ConstraintsStatus.FULFILLED;
|
||||
}
|
||||
int loadAtPrevAct;
|
||||
Capacity loadAtPrevAct;
|
||||
// int loadAtPrevAct;
|
||||
if(prevAct instanceof Start){
|
||||
loadAtPrevAct = (int)stateManager.getRouteState(iFacts.getRoute(), StateFactory.LOAD_AT_BEGINNING).toDouble();
|
||||
loadAtPrevAct = stateManager.getRouteState(iFacts.getRoute(), StateFactory.LOAD_AT_BEGINNING, Capacity.class);
|
||||
}
|
||||
else{
|
||||
loadAtPrevAct = (int) stateManager.getActivityState(prevAct, StateFactory.LOAD).toDouble();
|
||||
loadAtPrevAct = stateManager.getActivityState(prevAct, StateFactory.LOAD, Capacity.class);
|
||||
}
|
||||
if(newAct instanceof PickupShipment){
|
||||
if(loadAtPrevAct + newAct.getCapacityDemand() > iFacts.getNewVehicle().getCapacity()){
|
||||
if(!Capacity.addup(loadAtPrevAct, newAct.getSize()).isLessOrEqual(iFacts.getNewVehicle().getType().getCapacityDimensions())){
|
||||
return ConstraintsStatus.NOT_FULFILLED;
|
||||
}
|
||||
// if(loadAtPrevAct + newAct.getCapacityDemand() > iFacts.getNewVehicle().getCapacity()){
|
||||
// return ConstraintsStatus.NOT_FULFILLED;
|
||||
// }
|
||||
}
|
||||
if(newAct instanceof DeliverShipment){
|
||||
if(loadAtPrevAct + Math.abs(newAct.getCapacityDemand()) > iFacts.getNewVehicle().getCapacity()){
|
||||
if(!Capacity.addup(loadAtPrevAct, Capacity.invert(newAct.getSize())).isLessOrEqual(iFacts.getNewVehicle().getType().getCapacityDimensions())){
|
||||
return ConstraintsStatus.NOT_FULFILLED_BREAK;
|
||||
}
|
||||
// if(loadAtPrevAct + Math.abs(newAct.getCapacityDemand()) > iFacts.getNewVehicle().getCapacity()){
|
||||
// return ConstraintsStatus.NOT_FULFILLED_BREAK;
|
||||
// }
|
||||
}
|
||||
return ConstraintsStatus.FULFILLED;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package jsprit.core.problem.constraint;
|
||||
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.misc.JobInsertionContext;
|
||||
import jsprit.core.problem.solution.route.activity.DeliverService;
|
||||
import jsprit.core.problem.solution.route.activity.PickupService;
|
||||
|
|
@ -30,28 +31,38 @@ class ServiceLoadActivityLevelConstraint implements HardActivityStateLevelConstr
|
|||
|
||||
@Override
|
||||
public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) {
|
||||
int futureMaxLoad;
|
||||
int prevMaxLoad;
|
||||
Capacity futureMaxLoad;
|
||||
Capacity prevMaxLoad;
|
||||
if(prevAct instanceof Start){
|
||||
futureMaxLoad = (int)stateManager.getRouteState(iFacts.getRoute(), StateFactory.MAXLOAD).toDouble();
|
||||
prevMaxLoad = (int)stateManager.getRouteState(iFacts.getRoute(), StateFactory.LOAD_AT_BEGINNING).toDouble();
|
||||
futureMaxLoad = stateManager.getRouteState(iFacts.getRoute(), StateFactory.MAXLOAD, Capacity.class);
|
||||
// futureMaxLoad = (int)stateManager.getRouteState(iFacts.getRoute(), StateFactory.MAXLOAD).toDouble();
|
||||
prevMaxLoad = stateManager.getRouteState(iFacts.getRoute(), StateFactory.LOAD_AT_BEGINNING, Capacity.class);
|
||||
// prevMaxLoad = (int)stateManager.getRouteState(iFacts.getRoute(), StateFactory.LOAD_AT_BEGINNING).toDouble();
|
||||
}
|
||||
else{
|
||||
futureMaxLoad = (int) stateManager.getActivityState(prevAct, StateFactory.FUTURE_MAXLOAD).toDouble();
|
||||
prevMaxLoad = (int) stateManager.getActivityState(prevAct, StateFactory.PAST_MAXLOAD).toDouble();
|
||||
futureMaxLoad = stateManager.getActivityState(prevAct, StateFactory.FUTURE_MAXLOAD, Capacity.class);
|
||||
// futureMaxLoad = (int) stateManager.getActivityState(prevAct, StateFactory.FUTURE_MAXLOAD).toDouble();
|
||||
prevMaxLoad = stateManager.getActivityState(prevAct, StateFactory.PAST_MAXLOAD, Capacity.class);
|
||||
// prevMaxLoad = (int) stateManager.getActivityState(prevAct, StateFactory.PAST_MAXLOAD).toDouble();
|
||||
|
||||
}
|
||||
if(newAct instanceof PickupService || newAct instanceof ServiceActivity){
|
||||
if(newAct.getCapacityDemand() + futureMaxLoad > iFacts.getNewVehicle().getCapacity()){
|
||||
// log.debug("insertionOf("+newAct+").BETWEEN("+prevAct+").AND("+nextAct+")=NOT_POSSIBLE");
|
||||
if(!Capacity.addup(newAct.getSize(), futureMaxLoad).isLessOrEqual(iFacts.getNewVehicle().getType().getCapacityDimensions())){
|
||||
return ConstraintsStatus.NOT_FULFILLED;
|
||||
}
|
||||
// if(newAct.getCapacityDemand() + futureMaxLoad > iFacts.getNewVehicle().getCapacity()){
|
||||
//// log.debug("insertionOf("+newAct+").BETWEEN("+prevAct+").AND("+nextAct+")=NOT_POSSIBLE");
|
||||
// return ConstraintsStatus.NOT_FULFILLED;
|
||||
// }
|
||||
}
|
||||
if(newAct instanceof DeliverService){
|
||||
if(Math.abs(newAct.getCapacityDemand()) + prevMaxLoad > iFacts.getNewVehicle().getCapacity()){
|
||||
// log.debug("insertionOf("+newAct+").BETWEEN("+prevAct+").AND("+nextAct+")=NOT_POSSIBLE[break=neverBePossibleAnymore]");
|
||||
if(!Capacity.addup(Capacity.invert(newAct.getSize()), prevMaxLoad).isLessOrEqual(iFacts.getNewVehicle().getType().getCapacityDimensions())){
|
||||
return ConstraintsStatus.NOT_FULFILLED_BREAK;
|
||||
}
|
||||
// if(Math.abs(newAct.getCapacityDemand()) + prevMaxLoad > iFacts.getNewVehicle().getCapacity()){
|
||||
//// log.debug("insertionOf("+newAct+").BETWEEN("+prevAct+").AND("+nextAct+")=NOT_POSSIBLE[break=neverBePossibleAnymore]");
|
||||
// return ConstraintsStatus.NOT_FULFILLED_BREAK;
|
||||
// }
|
||||
|
||||
}
|
||||
// log.debug("insertionOf("+newAct+").BETWEEN("+prevAct+").AND("+nextAct+")=POSSIBLE");
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package jsprit.core.problem.constraint;
|
||||
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.job.Delivery;
|
||||
import jsprit.core.problem.job.Pickup;
|
||||
import jsprit.core.problem.job.Service;
|
||||
|
|
@ -25,16 +26,25 @@ class ServiceLoadRouteLevelConstraint implements HardRouteStateLevelConstraint {
|
|||
@Override
|
||||
public boolean fulfilled(JobInsertionContext insertionContext) {
|
||||
if(insertionContext.getJob() instanceof Delivery){
|
||||
int loadAtDepot = (int) stateManager.getRouteState(insertionContext.getRoute(), StateFactory.LOAD_AT_BEGINNING).toDouble();
|
||||
if(loadAtDepot + insertionContext.getJob().getCapacityDemand() > insertionContext.getNewVehicle().getCapacity()){
|
||||
Capacity loadAtDepot = stateManager.getRouteState(insertionContext.getRoute(), StateFactory.LOAD_AT_BEGINNING, Capacity.class);
|
||||
// int loadAtDepot = (int) stateManager.getRouteState(insertionContext.getRoute(), StateFactory.LOAD_AT_BEGINNING).toDouble();
|
||||
if(!Capacity.addup(loadAtDepot, insertionContext.getJob().getSize()).isLessOrEqual(insertionContext.getNewVehicle().getType().getCapacityDimensions())){
|
||||
return false;
|
||||
}
|
||||
// if(loadAtDepot + insertionContext.getJob().getCapacityDemand() > insertionContext.getNewVehicle().getCapacity()){
|
||||
// return false;
|
||||
// }
|
||||
}
|
||||
else if(insertionContext.getJob() instanceof Pickup || insertionContext.getJob() instanceof Service){
|
||||
int loadAtEnd = (int) stateManager.getRouteState(insertionContext.getRoute(), StateFactory.LOAD_AT_END).toDouble();
|
||||
if(loadAtEnd + insertionContext.getJob().getCapacityDemand() > insertionContext.getNewVehicle().getCapacity()){
|
||||
Capacity loadAtEnd = stateManager.getRouteState(insertionContext.getRoute(), StateFactory.LOAD_AT_END, Capacity.class);
|
||||
// int loadAtEnd = (int) stateManager.getRouteState(insertionContext.getRoute(), StateFactory.LOAD_AT_END).toDouble();
|
||||
if(!Capacity.addup(loadAtEnd, insertionContext.getJob().getSize()).isLessOrEqual(insertionContext.getNewVehicle().getType().getCapacityDimensions())){
|
||||
return false;
|
||||
}
|
||||
//
|
||||
// if(loadAtEnd + insertionContext.getJob().getCapacityDemand() > insertionContext.getNewVehicle().getCapacity()){
|
||||
// return false;
|
||||
// }
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ import jsprit.core.util.CalculationUtils;
|
|||
}
|
||||
// log.info("check insertion of " + newAct + " between " + prevAct + " and " + nextAct + ". prevActDepTime=" + prevActDepTime);
|
||||
double arrTimeAtNewAct = prevActDepTime + routingCosts.getTransportTime(prevAct.getLocationId(), newAct.getLocationId(), prevActDepTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double latestArrTimeAtNewAct = states.getActivityState(newAct, StateFactory.LATEST_OPERATION_START_TIME).toDouble();
|
||||
double latestArrTimeAtNewAct = states.getActivityState(newAct, StateFactory.LATEST_OPERATION_START_TIME, Double.class);
|
||||
|
||||
if(arrTimeAtNewAct > latestArrTimeAtNewAct){
|
||||
return ConstraintsStatus.NOT_FULFILLED;
|
||||
|
|
@ -43,7 +43,7 @@ import jsprit.core.util.CalculationUtils;
|
|||
// log.info(newAct + " arrTime=" + arrTimeAtNewAct);
|
||||
double endTimeAtNewAct = CalculationUtils.getActivityEndTime(arrTimeAtNewAct, newAct);
|
||||
double arrTimeAtNextAct = endTimeAtNewAct + routingCosts.getTransportTime(newAct.getLocationId(), nextAct.getLocationId(), endTimeAtNewAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double latestArrTimeAtNextAct = states.getActivityState(nextAct, StateFactory.LATEST_OPERATION_START_TIME).toDouble();
|
||||
double latestArrTimeAtNextAct = states.getActivityState(nextAct, StateFactory.LATEST_OPERATION_START_TIME, Double.class);
|
||||
if(arrTimeAtNextAct > latestArrTimeAtNextAct){
|
||||
return ConstraintsStatus.NOT_FULFILLED;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ import jsprit.core.problem.job.Service;
|
|||
import jsprit.core.problem.job.Shipment;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.End;
|
||||
import jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivityFactory;
|
||||
import jsprit.core.problem.vehicle.PenaltyVehicleType;
|
||||
|
|
@ -60,21 +59,25 @@ import org.xml.sax.SAXException;
|
|||
public class VrpXMLReader{
|
||||
|
||||
public interface ServiceBuilderFactory {
|
||||
Service.Builder createBuilder(String serviceType, String id, int size);
|
||||
Service.Builder createBuilder(String serviceType, String id, Integer size);
|
||||
}
|
||||
|
||||
static class DefaultServiceBuilderFactory implements ServiceBuilderFactory{
|
||||
|
||||
@Override
|
||||
public jsprit.core.problem.job.Service.Builder createBuilder(String serviceType, String id, int size) {
|
||||
public jsprit.core.problem.job.Service.Builder createBuilder(String serviceType, String id, Integer size) {
|
||||
if(serviceType.equals("pickup")){
|
||||
return Pickup.Builder.newInstance(id, size);
|
||||
if(size != null) return Pickup.Builder.newInstance(id, size);
|
||||
else return Pickup.Builder.newInstance(id);
|
||||
}
|
||||
else if(serviceType.equals("delivery")){
|
||||
return Delivery.Builder.newInstance(id, size);
|
||||
if(size != null) return Delivery.Builder.newInstance(id, size);
|
||||
else return Delivery.Builder.newInstance(id);
|
||||
}
|
||||
else{
|
||||
return Service.Builder.newInstance(id, size);
|
||||
if(size != null) return Service.Builder.newInstance(id, size);
|
||||
else return Service.Builder.newInstance(id);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -236,11 +239,6 @@ public class VrpXMLReader{
|
|||
String end = routeConfig.getString("end");
|
||||
if(end == null) throw new IllegalStateException("route end-time is missing.");
|
||||
|
||||
// Start startAct = Start.newInstance(vehicle.getLocationId(), vehicle.getEarliestDeparture(), vehicle.getLatestArrival());
|
||||
// startAct.setEndTime(Double.parseDouble(start));
|
||||
End endAct = End.newInstance(vehicle.getLocationId(), vehicle.getEarliestDeparture(), vehicle.getLatestArrival());
|
||||
endAct.setArrTime(Double.parseDouble(end));
|
||||
|
||||
VehicleRoute.Builder routeBuilder = VehicleRoute.Builder.newInstance(vehicle, driver);
|
||||
routeBuilder.setDepartureTime(departureTime);
|
||||
routeBuilder.setRouteEndArrivalTime(Double.parseDouble(end));
|
||||
|
|
@ -313,8 +311,29 @@ public class VrpXMLReader{
|
|||
for(HierarchicalConfiguration shipmentConfig : shipmentConfigs){
|
||||
String id = shipmentConfig.getString("[@id]");
|
||||
if(id == null) throw new IllegalStateException("shipment[@id] is missing.");
|
||||
int cap = getCap(shipmentConfig);
|
||||
Shipment.Builder builder = Shipment.Builder.newInstance(id, cap);
|
||||
|
||||
String capacityString = shipmentConfig.getString("capacity-demand");
|
||||
boolean capacityDimensionsExist = shipmentConfig.containsKey("capacity-dimensions.dimension(0)");
|
||||
if(capacityString == null && !capacityDimensionsExist){
|
||||
throw new IllegalStateException("capacity of shipment is not set. use 'capacity-dimensions'");
|
||||
}
|
||||
if(capacityString != null && capacityDimensionsExist){
|
||||
throw new IllegalStateException("either use capacity or capacity-dimension, not both. prefer the use of 'capacity-dimensions' over 'capacity'.");
|
||||
}
|
||||
|
||||
Shipment.Builder builder;
|
||||
if(capacityString != null){
|
||||
builder = Shipment.Builder.newInstance(id, Integer.parseInt(capacityString));
|
||||
}
|
||||
else {
|
||||
builder = Shipment.Builder.newInstance(id);
|
||||
List<HierarchicalConfiguration> dimensionConfigs = shipmentConfig.configurationsAt("capacity-dimensions.dimension");
|
||||
for(HierarchicalConfiguration dimension : dimensionConfigs){
|
||||
Integer index = dimension.getInt("[@index]");
|
||||
Integer value = dimension.getInt("");
|
||||
builder.addSizeDimension(index, value);
|
||||
}
|
||||
}
|
||||
|
||||
//pickup-locationId
|
||||
String pickupLocationId = shipmentConfig.getString("pickup.locationId");
|
||||
|
|
@ -394,13 +413,6 @@ public class VrpXMLReader{
|
|||
return pickupCoord;
|
||||
}
|
||||
|
||||
private static int getCap(HierarchicalConfiguration serviceConfig) {
|
||||
String capacityDemand = serviceConfig.getString("capacity-demand");
|
||||
int cap = 0;
|
||||
if(capacityDemand != null) cap = Integer.parseInt(capacityDemand);
|
||||
return cap;
|
||||
}
|
||||
|
||||
private void readServices(XMLConfiguration vrpProblem) {
|
||||
List<HierarchicalConfiguration> serviceConfigs = vrpProblem.configurationsAt("services.service");
|
||||
for(HierarchicalConfiguration serviceConfig : serviceConfigs){
|
||||
|
|
@ -408,8 +420,29 @@ public class VrpXMLReader{
|
|||
if(id == null) throw new IllegalStateException("service[@id] is missing.");
|
||||
String type = serviceConfig.getString("[@type]");
|
||||
if(type == null) type = "service";
|
||||
int cap = getCap(serviceConfig);
|
||||
Service.Builder builder = serviceBuilderFactory.createBuilder(type, id, cap);
|
||||
|
||||
String capacityString = serviceConfig.getString("capacity-demand");
|
||||
boolean capacityDimensionsExist = serviceConfig.containsKey("capacity-dimensions.dimension(0)");
|
||||
if(capacityString == null && !capacityDimensionsExist){
|
||||
throw new IllegalStateException("capacity of service is not set. use 'capacity-dimensions'");
|
||||
}
|
||||
if(capacityString != null && capacityDimensionsExist){
|
||||
throw new IllegalStateException("either use capacity or capacity-dimension, not both. prefer the use of 'capacity-dimensions' over 'capacity'.");
|
||||
}
|
||||
|
||||
Service.Builder builder;
|
||||
if(capacityString != null){
|
||||
builder = serviceBuilderFactory.createBuilder(type, id, Integer.parseInt(capacityString));
|
||||
}
|
||||
else {
|
||||
builder = serviceBuilderFactory.createBuilder(type, id, null);
|
||||
List<HierarchicalConfiguration> dimensionConfigs = serviceConfig.configurationsAt("capacity-dimensions.dimension");
|
||||
for(HierarchicalConfiguration dimension : dimensionConfigs){
|
||||
Integer index = dimension.getInt("[@index]");
|
||||
Integer value = dimension.getInt("");
|
||||
builder.addSizeDimension(index, value);
|
||||
}
|
||||
}
|
||||
String serviceLocationId = serviceConfig.getString("locationId");
|
||||
if(serviceLocationId != null) builder.setLocationId(serviceLocationId);
|
||||
Coordinate serviceCoord = getCoord(serviceConfig,"");
|
||||
|
|
@ -446,13 +479,34 @@ public class VrpXMLReader{
|
|||
List<HierarchicalConfiguration> typeConfigs = vrpProblem.configurationsAt("vehicleTypes.type");
|
||||
for(HierarchicalConfiguration typeConfig : typeConfigs){
|
||||
String typeId = typeConfig.getString("id");
|
||||
Integer capacity = typeConfig.getInt("capacity");
|
||||
if(typeId == null) throw new IllegalStateException("typeId is missing.");
|
||||
|
||||
String capacityString = typeConfig.getString("capacity");
|
||||
boolean capacityDimensionsExist = typeConfig.containsKey("capacity-dimensions.dimension(0)");
|
||||
if(capacityString == null && !capacityDimensionsExist){
|
||||
throw new IllegalStateException("capacity of type is not set. use 'capacity-dimensions'");
|
||||
}
|
||||
if(capacityString != null && capacityDimensionsExist){
|
||||
throw new IllegalStateException("either use capacity or capacity-dimension, not both. prefer the use of 'capacity-dimensions' over 'capacity'.");
|
||||
}
|
||||
|
||||
VehicleTypeImpl.Builder typeBuilder;
|
||||
if(capacityString != null){
|
||||
typeBuilder = VehicleTypeImpl.Builder.newInstance(typeId, Integer.parseInt(capacityString));
|
||||
}
|
||||
else {
|
||||
typeBuilder = VehicleTypeImpl.Builder.newInstance(typeId);
|
||||
List<HierarchicalConfiguration> dimensionConfigs = typeConfig.configurationsAt("capacity-dimensions.dimension");
|
||||
for(HierarchicalConfiguration dimension : dimensionConfigs){
|
||||
Integer index = dimension.getInt("[@index]");
|
||||
Integer value = dimension.getInt("");
|
||||
typeBuilder.addCapacityDimension(index, value);
|
||||
}
|
||||
}
|
||||
Double fix = typeConfig.getDouble("costs.fixed");
|
||||
Double timeC = typeConfig.getDouble("costs.time");
|
||||
Double distC = typeConfig.getDouble("costs.distance");
|
||||
if(typeId == null) throw new IllegalStateException("typeId is missing.");
|
||||
if(capacity == null) throw new IllegalStateException("capacity is missing.");
|
||||
VehicleTypeImpl.Builder typeBuilder = VehicleTypeImpl.Builder.newInstance(typeId, capacity);
|
||||
|
||||
if(fix != null) typeBuilder.setFixedCost(fix);
|
||||
if(timeC != null) typeBuilder.setCostPerTime(timeC);
|
||||
if(distC != null) typeBuilder.setCostPerDistance(distC);
|
||||
|
|
|
|||
|
|
@ -174,7 +174,10 @@ public class VrpXMLWriter {
|
|||
xmlConfig.setProperty(shipmentPathString + "("+counter+").coord[@x]", service.getCoord().getX());
|
||||
xmlConfig.setProperty(shipmentPathString + "("+counter+").coord[@y]", service.getCoord().getY());
|
||||
}
|
||||
xmlConfig.setProperty(shipmentPathString + "("+counter+").capacity-demand", service.getCapacityDemand());
|
||||
for(int i=0;i<service.getSize().getNuOfDimensions();i++){
|
||||
xmlConfig.setProperty(shipmentPathString + "("+counter+").capacity-dimensions.dimension("+i+")[@index]", i);
|
||||
xmlConfig.setProperty(shipmentPathString + "("+counter+").capacity-dimensions.dimension("+i+")", service.getSize().get(i));
|
||||
}
|
||||
xmlConfig.setProperty(shipmentPathString + "("+counter+").duration", service.getServiceDuration());
|
||||
xmlConfig.setProperty(shipmentPathString + "("+counter+").timeWindows.timeWindow(0).start", service.getTimeWindow().getStart());
|
||||
xmlConfig.setProperty(shipmentPathString + "("+counter+").timeWindows.timeWindow(0).end", service.getTimeWindow().getEnd());
|
||||
|
|
@ -212,8 +215,10 @@ public class VrpXMLWriter {
|
|||
xmlConfig.setProperty(shipmentPathString + "("+counter+").delivery.timeWindows.timeWindow(0).start", shipment.getDeliveryTimeWindow().getStart());
|
||||
xmlConfig.setProperty(shipmentPathString + "("+counter+").delivery.timeWindows.timeWindow(0).end", shipment.getDeliveryTimeWindow().getEnd());
|
||||
|
||||
|
||||
xmlConfig.setProperty(shipmentPathString + "("+counter+").capacity-demand", shipment.getCapacityDemand());
|
||||
for(int i=0;i<shipment.getSize().getNuOfDimensions();i++){
|
||||
xmlConfig.setProperty(shipmentPathString + "("+counter+").capacity-dimensions.dimension("+i+")[@index]", i);
|
||||
xmlConfig.setProperty(shipmentPathString + "("+counter+").capacity-dimensions.dimension("+i+")", shipment.getSize().get(i));
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
|
@ -262,7 +267,12 @@ public class VrpXMLWriter {
|
|||
xmlConfig.setProperty(typePathString + "("+typeCounter+")[@penaltyFactor]", ((PenaltyVehicleType)type).getPenaltyFactor());
|
||||
}
|
||||
xmlConfig.setProperty(typePathString + "("+typeCounter+").id", type.getTypeId());
|
||||
xmlConfig.setProperty(typePathString + "("+typeCounter+").capacity", type.getCapacity());
|
||||
|
||||
for(int i=0;i<type.getCapacityDimensions().getNuOfDimensions();i++){
|
||||
xmlConfig.setProperty(typePathString + "("+typeCounter+").capacity-dimensions.dimension("+i+")[@index]", i);
|
||||
xmlConfig.setProperty(typePathString + "("+typeCounter+").capacity-dimensions.dimension("+i+")", type.getCapacityDimensions().get(i));
|
||||
}
|
||||
|
||||
xmlConfig.setProperty(typePathString + "("+typeCounter+").costs.fixed", type.getVehicleCostParams().fix);
|
||||
xmlConfig.setProperty(typePathString + "("+typeCounter+").costs.distance", type.getVehicleCostParams().perDistanceUnit);
|
||||
xmlConfig.setProperty(typePathString + "("+typeCounter+").costs.time", type.getVehicleCostParams().perTimeUnit);
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem.job;
|
||||
|
||||
|
||||
/**
|
||||
* Delivery extends Service and is intended to model a Service where smth is UNLOADED (i.e. delivered) from a transport unit.
|
||||
*
|
||||
|
|
@ -33,9 +34,24 @@ public class Delivery extends Service{
|
|||
* @param size
|
||||
* @return builder
|
||||
* @throws IllegalArgumentException if size < 0 or id is null
|
||||
* @deprecated use <code>.newInstance(String id)</code> instead, and add a capacity dimension
|
||||
* with dimensionIndex='your index' and and dimsionValue=size to the returned builder
|
||||
*/
|
||||
@Deprecated
|
||||
public static Builder newInstance(String id, int size){
|
||||
return new Builder(id,size);
|
||||
Builder builder = new Builder(id,size);
|
||||
builder.addSizeDimension(0, size);
|
||||
return builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new instance of builder that builds a delivery.
|
||||
*
|
||||
* @param id
|
||||
* @return the builder
|
||||
*/
|
||||
public static Builder newInstance(String id){
|
||||
return new Builder(id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -48,6 +64,11 @@ public class Delivery extends Service{
|
|||
Builder(String id, int size) {
|
||||
super(id, size);
|
||||
}
|
||||
|
||||
Builder(String id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds Delivery.
|
||||
*
|
||||
|
|
@ -60,6 +81,7 @@ public class Delivery extends Service{
|
|||
locationId = coord.toString();
|
||||
}
|
||||
this.setType("delivery");
|
||||
super.capacity = super.capacityBuilder.build();
|
||||
return new Delivery(this);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem.job;
|
||||
|
||||
|
||||
import jsprit.core.problem.Capacity;
|
||||
|
||||
/**
|
||||
* Basic interface for all jobs.
|
||||
*
|
||||
|
|
@ -36,9 +39,17 @@ public interface Job {
|
|||
*
|
||||
* <p>It determines how much capacity this job consumes of vehicle/transport unit.
|
||||
*
|
||||
* @deprecated use <code>.getCapacity()</code> instead
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
public int getCapacityDemand();
|
||||
|
||||
/**
|
||||
* Returns size, i.e. capacity-demand, of this job which can consist of an arbitrary number of capacity dimensions.
|
||||
*
|
||||
* @return Capacity
|
||||
*/
|
||||
public Capacity getSize();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem.job;
|
||||
|
||||
|
||||
/**
|
||||
* Pickup extends Service and is intended to model a Service where smth is LOADED (i.e. picked up) to a transport unit.
|
||||
*
|
||||
|
|
@ -33,9 +34,24 @@ public class Pickup extends Service {
|
|||
* @param size
|
||||
* @return builder
|
||||
* @throws IllegalArgumentException if size < 0 or id is null
|
||||
* @deprecated use <code>.newInstance(String id)</code> instead, and add a capacity dimension
|
||||
* with dimensionIndex='your index' and and dimsionValue=size to the returned builder
|
||||
*/
|
||||
@Deprecated
|
||||
public static Builder newInstance(String id, int size){
|
||||
return new Builder(id,size);
|
||||
Builder builder = new Builder(id,size);
|
||||
builder.addSizeDimension(0, size);
|
||||
return builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new instance of builder that builds a pickup.
|
||||
*
|
||||
* @param id
|
||||
* @return the builder
|
||||
*/
|
||||
public static Builder newInstance(String id){
|
||||
return new Builder(id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -49,6 +65,10 @@ public class Pickup extends Service {
|
|||
super(id, size);
|
||||
}
|
||||
|
||||
Builder(String id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds Pickup.
|
||||
*
|
||||
|
|
@ -63,6 +83,7 @@ public class Pickup extends Service {
|
|||
locationId = coord.toString();
|
||||
}
|
||||
this.setType("pickup");
|
||||
super.capacity = super.capacityBuilder.build();
|
||||
return new Pickup(this);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem.job;
|
||||
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||
import jsprit.core.util.Coordinate;
|
||||
|
||||
|
|
@ -43,13 +44,30 @@ public class Service implements Job {
|
|||
/**
|
||||
* Returns a new instance of service-builder.
|
||||
*
|
||||
* <p>Note that if you use this builder, size is assigned to capacity-dimension with index=0.
|
||||
*
|
||||
* @param id of service
|
||||
* @param size of capacity-demand
|
||||
* @return builder
|
||||
* @throws IllegalArgumentException if size < 0 or id is null
|
||||
* @deprecated use <code>.newInstance(String id)</code> instead, and add a capacity dimension
|
||||
* with dimensionIndex='your index' and and dimsionValue=size to the returned builder
|
||||
*/
|
||||
@Deprecated
|
||||
public static Builder newInstance(String id, int size){
|
||||
return new Builder(id,size);
|
||||
Builder builder = new Builder(id,size);
|
||||
builder.addSizeDimension(0, size);
|
||||
return builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new instance of builder that builds a service.
|
||||
*
|
||||
* @param id
|
||||
* @return the builder
|
||||
*/
|
||||
public static Builder newInstance(String id){
|
||||
return new Builder(id);
|
||||
}
|
||||
|
||||
private String id;
|
||||
|
|
@ -64,7 +82,9 @@ public class Service implements Job {
|
|||
|
||||
protected TimeWindow timeWindow = TimeWindow.newInstance(0.0, Double.MAX_VALUE);
|
||||
|
||||
protected int demand;
|
||||
protected Capacity.Builder capacityBuilder = Capacity.Builder.newInstance();
|
||||
|
||||
protected Capacity capacity;
|
||||
|
||||
/**
|
||||
* Constructs the builder.
|
||||
|
|
@ -77,7 +97,10 @@ public class Service implements Job {
|
|||
if(size < 0) throw new IllegalArgumentException("size must be greater than or equal to zero");
|
||||
if(id == null) throw new IllegalArgumentException("id must not be null");
|
||||
this.id = id;
|
||||
this.demand = size;
|
||||
}
|
||||
|
||||
Builder(String id){
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -131,6 +154,20 @@ public class Service implements Job {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds capacity dimension.
|
||||
*
|
||||
* @param dimensionIndex
|
||||
* @param dimensionValue
|
||||
* @return the builder
|
||||
* @throws IllegalArgumentException if dimensionValue < 0
|
||||
*/
|
||||
public Builder addSizeDimension(int dimensionIndex, int dimensionValue){
|
||||
if(dimensionValue<0) throw new IllegalArgumentException("capacity value cannot be negative");
|
||||
capacityBuilder.addDimension(dimensionIndex, dimensionValue);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the time-window of this service.
|
||||
*
|
||||
|
|
@ -158,6 +195,7 @@ public class Service implements Job {
|
|||
locationId = coord.toString();
|
||||
}
|
||||
this.setType("service");
|
||||
capacity = capacityBuilder.build();
|
||||
return new Service(this);
|
||||
}
|
||||
|
||||
|
|
@ -175,8 +213,8 @@ public class Service implements Job {
|
|||
private final double serviceTime;
|
||||
|
||||
private final TimeWindow timeWindow;
|
||||
|
||||
private final int demand;
|
||||
|
||||
private final Capacity size;
|
||||
|
||||
Service(Builder builder){
|
||||
id = builder.id;
|
||||
|
|
@ -184,8 +222,8 @@ public class Service implements Job {
|
|||
coord = builder.coord;
|
||||
serviceTime = builder.serviceTime;
|
||||
timeWindow = builder.timeWindow;
|
||||
demand = builder.demand;
|
||||
type = builder.type;
|
||||
size = builder.capacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -229,9 +267,15 @@ public class Service implements Job {
|
|||
return timeWindow;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Deprecated use <code>.getCapacity()</code> instead. if you still use this method, it returns the
|
||||
* capacity dimension with index=0.
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public int getCapacityDemand() {
|
||||
return demand;
|
||||
return size.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -248,7 +292,7 @@ public class Service implements Job {
|
|||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[id=" + id + "][type="+type+"][locationId=" + locationId + "][coord="+coord+"][size=" + demand + "][serviceTime=" + serviceTime + "][timeWindow=" + timeWindow + "]";
|
||||
return "[id=" + id + "][type="+type+"][locationId=" + locationId + "][coord="+coord+"][capacity=" + size + "][serviceTime=" + serviceTime + "][timeWindow=" + timeWindow + "]";
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -281,6 +325,9 @@ public class Service implements Job {
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Capacity getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package jsprit.core.problem.job;
|
||||
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||
import jsprit.core.util.Coordinate;
|
||||
|
||||
|
|
@ -30,8 +31,6 @@ public class Shipment implements Job{
|
|||
*/
|
||||
public static class Builder {
|
||||
|
||||
private int demand;
|
||||
|
||||
private String id;
|
||||
|
||||
private String pickupLocation;
|
||||
|
|
@ -48,18 +47,33 @@ public class Shipment implements Job{
|
|||
|
||||
private TimeWindow deliveryTimeWindow = TimeWindow.newInstance(0.0, Double.MAX_VALUE);
|
||||
|
||||
private TimeWindow pickupTimeWindow = TimeWindow.newInstance(0.0, Double.MAX_VALUE);;
|
||||
private TimeWindow pickupTimeWindow = TimeWindow.newInstance(0.0, Double.MAX_VALUE);
|
||||
|
||||
private Capacity.Builder capacityBuilder = Capacity.Builder.newInstance();
|
||||
|
||||
private Capacity capacity;
|
||||
|
||||
/**
|
||||
* Returns a new instance of this builder.
|
||||
*
|
||||
* <p>Note that if you use this builder, size is assigned to capacity-dimension with index=0.
|
||||
*
|
||||
* @param id
|
||||
* @param size
|
||||
* @return builder
|
||||
* @throws IllegalArgumentException if size < 0 or id is null
|
||||
* @deprecated use <code>.newInstance(String id)</code> instead, and add a capacity dimension
|
||||
* with dimensionIndex='your index' and and dimsionValue=size to the returned builder
|
||||
*/
|
||||
@Deprecated
|
||||
public static Builder newInstance(String id, int size){
|
||||
return new Builder(id,size);
|
||||
Builder builder = new Builder(id,size);
|
||||
builder.addSizeDimension(0, size);
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static Builder newInstance(String id){
|
||||
return new Builder(id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -73,7 +87,10 @@ public class Shipment implements Job{
|
|||
if(size < 0) throw new IllegalArgumentException("size must be greater than or equal to zero");
|
||||
if(id == null) throw new IllegalArgumentException("id must not be null");
|
||||
this.id = id;
|
||||
this.demand = size;
|
||||
}
|
||||
|
||||
Builder(String id){
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -190,6 +207,21 @@ public class Shipment implements Job{
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds capacity dimension.
|
||||
*
|
||||
* @param dimensionIndex
|
||||
* @param dimensionValue
|
||||
* @return builder
|
||||
* @throws IllegalArgumentException if dimVal < 0
|
||||
*/
|
||||
public Builder addSizeDimension(int dimensionIndex, int dimensionValue) {
|
||||
if(dimensionValue<0) throw new IllegalArgumentException("capacity value cannot be negative");
|
||||
capacityBuilder.addDimension(dimensionIndex, dimensionValue);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Builds the shipment.
|
||||
*
|
||||
|
|
@ -206,12 +238,13 @@ public class Shipment implements Job{
|
|||
if(deliveryCoord == null) throw new IllegalStateException("either locationId or a coordinate must be given. But is not.");
|
||||
deliveryLocation = deliveryCoord.toString();
|
||||
}
|
||||
capacity = capacityBuilder.build();
|
||||
return new Shipment(this);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private final int demand;
|
||||
|
||||
private final String id;
|
||||
|
||||
private final String pickupLocation;
|
||||
|
|
@ -230,6 +263,9 @@ public class Shipment implements Job{
|
|||
|
||||
private final TimeWindow pickupTimeWindow;
|
||||
|
||||
private final Capacity capacity;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs the shipment.
|
||||
*
|
||||
|
|
@ -237,7 +273,6 @@ public class Shipment implements Job{
|
|||
*/
|
||||
Shipment(Builder builder){
|
||||
this.id = builder.id;
|
||||
this.demand = builder.demand;
|
||||
this.pickupLocation = builder.pickupLocation;
|
||||
this.pickupCoord = builder.pickupCoord;
|
||||
this.pickupServiceTime = builder.pickupServiceTime;
|
||||
|
|
@ -246,6 +281,7 @@ public class Shipment implements Job{
|
|||
this.deliveryCoord = builder.deliveryCoord;
|
||||
this.deliveryServiceTime = builder.deliveryServiceTime;
|
||||
this.deliveryTimeWindow = builder.deliveryTimeWindow;
|
||||
this.capacity = builder.capacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -253,9 +289,14 @@ public class Shipment implements Job{
|
|||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Deprecated use <code>.getCapacity()</code> instead. if you still use this method, it returns the
|
||||
* capacity dimension with index=0.
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
public int getCapacityDemand() {
|
||||
return demand;
|
||||
return capacity.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -362,5 +403,10 @@ public class Shipment implements Job{
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Capacity getSize() {
|
||||
return capacity;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
package jsprit.core.problem.solution.route.activity;
|
||||
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.job.Delivery;
|
||||
|
||||
public final class DeliverService implements DeliveryActivity{
|
||||
|
||||
private Delivery delivery;
|
||||
|
||||
private Capacity capacity;
|
||||
|
||||
private double arrTime;
|
||||
|
||||
private double endTime;
|
||||
|
|
@ -13,14 +16,20 @@ public final class DeliverService implements DeliveryActivity{
|
|||
public DeliverService(Delivery delivery) {
|
||||
super();
|
||||
this.delivery = delivery;
|
||||
capacity = Capacity.invert(delivery.getSize());
|
||||
}
|
||||
|
||||
private DeliverService(DeliverService deliveryActivity){
|
||||
this.delivery=deliveryActivity.getJob();
|
||||
this.arrTime=deliveryActivity.getArrTime();
|
||||
this.endTime=deliveryActivity.getEndTime();
|
||||
capacity = deliveryActivity.getSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use <code>getCapacity()</code> instead
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
public int getCapacityDemand() {
|
||||
return delivery.getCapacityDemand()*-1;
|
||||
|
|
@ -85,4 +94,9 @@ public final class DeliverService implements DeliveryActivity{
|
|||
public String toString() {
|
||||
return "[act="+getName()+"][capDemand="+getCapacityDemand()+"][loc="+getLocationId()+"]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Capacity getSize() {
|
||||
return capacity;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,30 @@
|
|||
package jsprit.core.problem.solution.route.activity;
|
||||
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.job.Shipment;
|
||||
|
||||
public final class DeliverShipment implements DeliveryActivity{
|
||||
|
||||
private Shipment shipment;
|
||||
|
||||
private double endTime;
|
||||
|
||||
private double arrTime;
|
||||
|
||||
private Capacity capacity;
|
||||
|
||||
public DeliverShipment(Shipment shipment) {
|
||||
super();
|
||||
this.shipment = shipment;
|
||||
this.capacity = Capacity.invert(shipment.getSize());
|
||||
}
|
||||
|
||||
public DeliverShipment(DeliverShipment deliveryShipmentActivity) {
|
||||
this.shipment = (Shipment) deliveryShipmentActivity.getJob();
|
||||
this.arrTime = deliveryShipmentActivity.getArrTime();
|
||||
this.endTime = deliveryShipmentActivity.getEndTime();
|
||||
this.capacity = deliveryShipmentActivity.getSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -25,6 +32,10 @@ public final class DeliverShipment implements DeliveryActivity{
|
|||
return shipment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use <code>getCapacity()</code> instead
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
public int getCapacityDemand() {
|
||||
return shipment.getCapacityDemand()*-1;
|
||||
|
|
@ -84,4 +95,9 @@ public final class DeliverShipment implements DeliveryActivity{
|
|||
public String toString() {
|
||||
return "[act="+getName()+"][loc="+getLocationId()+"]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Capacity getSize() {
|
||||
return capacity;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem.solution.route.activity;
|
||||
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.util.Coordinate;
|
||||
|
||||
public final class End implements TourActivity {
|
||||
|
|
@ -31,6 +32,8 @@ public final class End implements TourActivity {
|
|||
return new End(end);
|
||||
}
|
||||
|
||||
private final static Capacity capacity = Capacity.Builder.newInstance().build();
|
||||
|
||||
private String locationId;
|
||||
|
||||
private Coordinate coordinate;
|
||||
|
|
@ -147,4 +150,9 @@ public final class End implements TourActivity {
|
|||
return new End(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Capacity getSize() {
|
||||
return capacity;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package jsprit.core.problem.solution.route.activity;
|
||||
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.job.Pickup;
|
||||
import jsprit.core.problem.job.Service;
|
||||
|
||||
|
|
@ -81,7 +82,12 @@ public final class PickupService implements PickupActivity{
|
|||
return pickup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use <code>getCapacity()</code> instead
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public int getCapacityDemand() {
|
||||
return pickup.getCapacityDemand();
|
||||
}
|
||||
|
|
@ -91,4 +97,9 @@ public final class PickupService implements PickupActivity{
|
|||
return "[act="+getName()+"][capDemand="+getCapacityDemand()+"][loc="+getLocationId()+"]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Capacity getSize() {
|
||||
return pickup.getSize();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,15 @@
|
|||
package jsprit.core.problem.solution.route.activity;
|
||||
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.job.Shipment;
|
||||
|
||||
public final class PickupShipment implements PickupActivity{
|
||||
|
||||
private Shipment shipment;
|
||||
|
||||
private double endTime;
|
||||
|
||||
private double arrTime;
|
||||
|
||||
public PickupShipment(Shipment shipment) {
|
||||
|
|
@ -25,6 +28,10 @@ public final class PickupShipment implements PickupActivity{
|
|||
return shipment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use <code>getCapacity()</code> instead
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
public int getCapacityDemand() {
|
||||
return shipment.getCapacityDemand();
|
||||
|
|
@ -85,4 +92,11 @@ public final class PickupShipment implements PickupActivity{
|
|||
return "[act="+getName()+"][loc="+getLocationId()+"]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Capacity getSize() {
|
||||
return shipment.getSize();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem.solution.route.activity;
|
||||
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity.JobActivity;
|
||||
|
||||
|
|
@ -27,8 +28,6 @@ public class ServiceActivity implements JobActivity{
|
|||
|
||||
public double endTime;
|
||||
|
||||
public int capacityDemand;
|
||||
|
||||
/**
|
||||
* @return the arrTime
|
||||
*/
|
||||
|
|
@ -64,24 +63,13 @@ public class ServiceActivity implements JobActivity{
|
|||
public static ServiceActivity newInstance(Service service){
|
||||
return new ServiceActivity(service);
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a new instance of {@link ServiceActivity} with a flag that indicates whether smthing is unloaded or loaded.
|
||||
*
|
||||
* @param service
|
||||
* @param capacityDemand
|
||||
* @return
|
||||
*/
|
||||
// public static ServiceActivity newInstance(Service service, boolean isPickup){
|
||||
// return new ServiceActivity(service, capacityDemand);
|
||||
// }
|
||||
|
||||
|
||||
private final Service service;
|
||||
|
||||
protected ServiceActivity(Service service) {
|
||||
counter++;
|
||||
this.service = service;
|
||||
this.capacityDemand = service.getCapacityDemand();
|
||||
}
|
||||
|
||||
protected ServiceActivity(ServiceActivity serviceActivity) {
|
||||
|
|
@ -89,7 +77,6 @@ public class ServiceActivity implements JobActivity{
|
|||
this.service = serviceActivity.getJob();
|
||||
this.arrTime = serviceActivity.getArrTime();
|
||||
this.endTime = serviceActivity.getEndTime();
|
||||
this.capacityDemand = serviceActivity.getCapacityDemand();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -132,9 +119,13 @@ public class ServiceActivity implements JobActivity{
|
|||
return service.getTimeWindow().getEnd();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use <code>getCapacity()</code> instead
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public int getCapacityDemand() {
|
||||
return this.capacityDemand;
|
||||
return service.getCapacityDemand();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -166,6 +157,11 @@ public class ServiceActivity implements JobActivity{
|
|||
public TourActivity duplicate() {
|
||||
return new ServiceActivity(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Capacity getSize() {
|
||||
return service.getSize();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem.solution.route.activity;
|
||||
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.util.Coordinate;
|
||||
|
||||
public final class Start implements TourActivity {
|
||||
|
|
@ -24,6 +25,8 @@ public final class Start implements TourActivity {
|
|||
|
||||
public static int creation;
|
||||
|
||||
private final static Capacity capacity = Capacity.Builder.newInstance().build();
|
||||
|
||||
public static Start newInstance(String locationId, double theoreticalStart, double theoreticalEnd){
|
||||
creation++;
|
||||
return new Start(locationId,theoreticalStart,theoreticalEnd);
|
||||
|
|
@ -35,8 +38,6 @@ public final class Start implements TourActivity {
|
|||
|
||||
private String locationId;
|
||||
|
||||
|
||||
|
||||
private Coordinate coordinate;
|
||||
|
||||
private double theoretical_earliestOperationStartTime;
|
||||
|
|
@ -45,7 +46,7 @@ public final class Start implements TourActivity {
|
|||
|
||||
private double endTime;
|
||||
|
||||
private double arrTime;
|
||||
private double arrTime;
|
||||
|
||||
public Start(String locationId, double theoreticalStart, double theoreticalEnd) {
|
||||
super();
|
||||
|
|
@ -62,13 +63,13 @@ public final class Start implements TourActivity {
|
|||
theoretical_latestOperationStartTime = start.getTheoreticalLatestOperationStartTime();
|
||||
endTime = start.getEndTime();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Deprecated
|
||||
Coordinate getCoordinate() {
|
||||
return coordinate;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
void setCoordinate(Coordinate coordinate) {
|
||||
this.coordinate = coordinate;
|
||||
}
|
||||
|
|
@ -153,6 +154,9 @@ public final class Start implements TourActivity {
|
|||
return new Start(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Capacity getSize() {
|
||||
return capacity;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,37 +16,130 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem.solution.route.activity;
|
||||
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.job.Job;
|
||||
|
||||
|
||||
/**
|
||||
* Basic interface for tour-activities.
|
||||
*
|
||||
* <p>A tour activity is the basic element of a tour, which is consequently a sequence of tour-activities.
|
||||
*
|
||||
* @author schroeder
|
||||
*
|
||||
*/
|
||||
public interface TourActivity {
|
||||
|
||||
/**
|
||||
* Basic interface of job-activies.
|
||||
*
|
||||
* <p>A job activity is related to a {@link Job}.
|
||||
*
|
||||
* @author schroeder
|
||||
*
|
||||
*/
|
||||
public interface JobActivity extends TourActivity {
|
||||
|
||||
/**
|
||||
* Returns the job that is involved with this activity.
|
||||
*
|
||||
* @return job
|
||||
*/
|
||||
public Job getJob();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the capacity-demand of that activity, in terms of what needs to be loaded or unloaded at
|
||||
* this activity.
|
||||
*
|
||||
* @return int
|
||||
* @deprecated use <code>getCapacity()</code> instead
|
||||
*/
|
||||
@Deprecated
|
||||
public int getCapacityDemand();
|
||||
|
||||
/**
|
||||
* Returns the name of this activity.
|
||||
*
|
||||
* @return name
|
||||
*/
|
||||
public abstract String getName();
|
||||
|
||||
/**
|
||||
* Returns the activity's locationId.
|
||||
*
|
||||
* @return locationId
|
||||
*/
|
||||
public abstract String getLocationId();
|
||||
|
||||
/**
|
||||
* Returns the theoretical earliest operation start time, which is the time that is just allowed
|
||||
* (not earlier) to start this activity, that is for example <code>service.getTimeWindow().getStart()</code>.
|
||||
*
|
||||
* @return earliest start time
|
||||
*/
|
||||
public abstract double getTheoreticalEarliestOperationStartTime();
|
||||
|
||||
/**
|
||||
* Returns the theoretical latest operation start time, which is the time that is just allowed
|
||||
* (not later) to start this activity, that is for example <code>service.getTimeWindow().getEnd()</code>.
|
||||
*
|
||||
*
|
||||
* @return latest start time
|
||||
*/
|
||||
public abstract double getTheoreticalLatestOperationStartTime();
|
||||
|
||||
/**
|
||||
* Returns the operation-time this activity takes.
|
||||
*
|
||||
* <p>Note that this is not necessarily the duration of this activity, but the
|
||||
* service time a pickup/delivery actually takes, that is for example <code>service.getServiceTime()</code>.
|
||||
*
|
||||
* @return operation time
|
||||
*/
|
||||
public abstract double getOperationTime();
|
||||
|
||||
/**
|
||||
* Returns the arrival-time of this activity.
|
||||
*
|
||||
* @return arrival time
|
||||
*/
|
||||
public abstract double getArrTime();
|
||||
|
||||
/**
|
||||
* Returns end-time of this activity.
|
||||
*
|
||||
* @return end time
|
||||
*/
|
||||
public abstract double getEndTime();
|
||||
|
||||
/**
|
||||
* Sets the arrival time of that activity.
|
||||
*
|
||||
* @param arrTime
|
||||
*/
|
||||
public abstract void setArrTime(double arrTime);
|
||||
|
||||
/**
|
||||
* Sets the end-time of this activity.
|
||||
*
|
||||
* @param endTime
|
||||
*/
|
||||
public abstract void setEndTime(double endTime);
|
||||
|
||||
public TourActivity duplicate();
|
||||
/**
|
||||
* Returns the capacity-demand of that activity, in terms of what needs to be loaded or unloaded at
|
||||
* this activity.
|
||||
*
|
||||
* @return capacity
|
||||
*/
|
||||
public abstract Capacity getSize();
|
||||
|
||||
/**
|
||||
* Makes a deep copy of this activity.
|
||||
*
|
||||
* @return copied activity
|
||||
*/
|
||||
public abstract TourActivity duplicate();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,9 +23,14 @@ import jsprit.core.problem.solution.route.state.StateFactory.StateId;
|
|||
|
||||
public interface RouteAndActivityStateGetter {
|
||||
|
||||
@Deprecated
|
||||
public State getActivityState(TourActivity act, StateId stateId);
|
||||
|
||||
@Deprecated
|
||||
public State getRouteState(VehicleRoute route, StateId stateId);
|
||||
|
||||
public <T> T getActivityState(TourActivity act, StateId stateId, Class<T> type);
|
||||
|
||||
public <T> T getRouteState(VehicleRoute route, StateId stateId, Class<T> type);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ public class StateFactory {
|
|||
|
||||
}
|
||||
|
||||
|
||||
static class StateImpl implements State{
|
||||
double state;
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem.vehicle;
|
||||
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.vehicle.VehicleTypeImpl.VehicleCostParams;
|
||||
|
||||
public class PenaltyVehicleType implements VehicleType{
|
||||
|
|
@ -44,6 +45,10 @@ public class PenaltyVehicleType implements VehicleType{
|
|||
return type.getTypeId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use <code>getCapacityDimensions()</code> instead
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
public int getCapacity() {
|
||||
return type.getCapacity();
|
||||
|
|
@ -59,6 +64,11 @@ public class PenaltyVehicleType implements VehicleType{
|
|||
return type.getMaxVelocity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Capacity getCapacityDimensions() {
|
||||
return type.getCapacityDimensions();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,7 +81,11 @@ public interface Vehicle {
|
|||
* Returns the capacity of this vehicle.
|
||||
*
|
||||
* @return capacity
|
||||
* @deprecated use .getType().getCapacityDimensions() - if you still use this method,
|
||||
* but set capacity-dimensions via <code>VehicleTypeImpl.Builder.newInstance(...).addCapacityDimension(...)</code> then this method returns the
|
||||
* dimension with index=0.
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract int getCapacity();
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ public class VehicleImpl implements Vehicle {
|
|||
|
||||
private boolean returnToDepot = true;
|
||||
|
||||
private VehicleType type = VehicleTypeImpl.Builder.newInstance("default", 0).build();
|
||||
private VehicleType type = VehicleTypeImpl.Builder.newInstance("default").build();
|
||||
|
||||
/**
|
||||
* Constructs the builder with the vehicleId.
|
||||
|
|
@ -372,6 +372,7 @@ public class VehicleImpl implements Vehicle {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public int getCapacity() {
|
||||
return type.getCapacity();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem.vehicle;
|
||||
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.vehicle.VehicleTypeImpl.VehicleCostParams;
|
||||
|
||||
/**
|
||||
|
|
@ -38,10 +39,21 @@ public interface VehicleType {
|
|||
*
|
||||
* <p>In future versions there will be a capacity-object with an arbitrary number of capacity dimensions. (stefan,11.01.14)
|
||||
*
|
||||
*
|
||||
* @deprecated use <code>.getCapacityDimensions()</code> - if you still use it, but set CapacityDimensions rather
|
||||
* than setCapacity(...) it will return the capacity.dimension with index=0
|
||||
* @return cap
|
||||
*/
|
||||
@Deprecated
|
||||
public int getCapacity();
|
||||
|
||||
/**
|
||||
* Returns capacity dimensions.
|
||||
*
|
||||
* @return {@link Capacity}
|
||||
*/
|
||||
public Capacity getCapacityDimensions();
|
||||
|
||||
/**
|
||||
* Returns maximum velocity of this vehicle-type.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem.vehicle;
|
||||
|
||||
|
||||
import jsprit.core.problem.Capacity;
|
||||
|
||||
/**
|
||||
* Implementation of {@link VehicleType}.
|
||||
*
|
||||
|
|
@ -73,15 +76,24 @@ public class VehicleTypeImpl implements VehicleType {
|
|||
* @param capacity
|
||||
* @return the vehicleType builder
|
||||
* @throws IllegalStateException if capacity is smaller than zero or id is null
|
||||
* @deprecated use <code>newInstance(String id)</code> instead
|
||||
*/
|
||||
@Deprecated
|
||||
public static VehicleTypeImpl.Builder newInstance(String id, int capacity){
|
||||
if(capacity < 0) throw new IllegalStateException("capacity cannot be smaller than zero");
|
||||
if(id == null) throw new IllegalStateException("typeId must be null");
|
||||
return new Builder(id,capacity);
|
||||
Builder builder = new Builder(id,capacity);
|
||||
builder.addCapacityDimension(0, capacity);
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static VehicleTypeImpl.Builder newInstance(String id) {
|
||||
return new Builder(id);
|
||||
}
|
||||
|
||||
|
||||
private String id;
|
||||
private int capacity;
|
||||
private int capacity = 0;
|
||||
private double maxVelo = Double.MAX_VALUE;
|
||||
/**
|
||||
* default cost values for default vehicle type
|
||||
|
|
@ -89,6 +101,12 @@ public class VehicleTypeImpl implements VehicleType {
|
|||
private double fixedCost = 0.0;
|
||||
private double perDistance = 1.0;
|
||||
private double perTime = 0.0;
|
||||
|
||||
private Capacity.Builder capacityBuilder = Capacity.Builder.newInstance();
|
||||
|
||||
private Capacity capacityDimensions = null;
|
||||
|
||||
private boolean dimensionAdded = false;
|
||||
|
||||
/**
|
||||
* Constructs the builder.
|
||||
|
|
@ -96,12 +114,17 @@ public class VehicleTypeImpl implements VehicleType {
|
|||
* @param id
|
||||
* @param capacity
|
||||
*/
|
||||
@Deprecated
|
||||
private Builder(String id, int capacity) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.capacity = capacity;
|
||||
}
|
||||
|
||||
public Builder(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the maximum velocity this vehicle-type can go [in meter per seconds].
|
||||
*
|
||||
|
|
@ -165,9 +188,49 @@ public class VehicleTypeImpl implements VehicleType {
|
|||
* @return VehicleTypeImpl
|
||||
*/
|
||||
public VehicleTypeImpl build(){
|
||||
if(capacityDimensions == null){
|
||||
capacityDimensions = capacityBuilder.build();
|
||||
}
|
||||
return new VehicleTypeImpl(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a capacity dimension.
|
||||
*
|
||||
* @param dimIndex
|
||||
* @param dimVal
|
||||
* @return the builder
|
||||
* @throws IllegalArgumentException if dimVal < 0
|
||||
* @throws IllegalStateException if capacity dimension is already set
|
||||
*/
|
||||
public Builder addCapacityDimension(int dimIndex, int dimVal) {
|
||||
if(dimVal<0) throw new IllegalArgumentException("capacity value cannot be negative");
|
||||
if(capacityDimensions != null) throw new IllegalStateException("either build your dimension with build your dimensions with " +
|
||||
"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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets capacity dimensions.
|
||||
*
|
||||
* <p>Note if you use this you cannot use <code>addCapacityDimension(int dimIndex, int dimVal)</code> anymore. Thus either build
|
||||
* your dimensions with <code>addCapacityDimension(int dimIndex, int dimVal)</code> or set the already built dimensions with
|
||||
* this method.
|
||||
*
|
||||
* @param capacity
|
||||
* @return this builder
|
||||
* @throws IllegalStateException if capacityDimension has already been added
|
||||
*/
|
||||
public Builder setCapacityDimensions(Capacity capacity){
|
||||
if(dimensionAdded) throw new IllegalStateException("either build your dimension with build your dimensions with " +
|
||||
"addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with .setCapacityDimensions(Capacity capacity)." +
|
||||
"You used both methods.");
|
||||
this.capacityDimensions = capacity;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -205,8 +268,11 @@ public class VehicleTypeImpl implements VehicleType {
|
|||
|
||||
private final VehicleTypeImpl.VehicleCostParams vehicleCostParams;
|
||||
|
||||
private final Capacity capacityDimensions;
|
||||
|
||||
private final double maxVelocity;
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated use builder instead
|
||||
*/
|
||||
|
|
@ -225,6 +291,7 @@ public class VehicleTypeImpl implements VehicleType {
|
|||
capacity = builder.capacity;
|
||||
maxVelocity = builder.maxVelo;
|
||||
vehicleCostParams = new VehicleCostParams(builder.fixedCost, builder.perTime, builder.perDistance);
|
||||
capacityDimensions = builder.capacityDimensions;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -240,6 +307,7 @@ public class VehicleTypeImpl implements VehicleType {
|
|||
this.typeId = typeId;
|
||||
this.capacity = capacity;
|
||||
this.vehicleCostParams = vehicleCostParams;
|
||||
this.capacityDimensions = Capacity.Builder.newInstance().addDimension(0, capacity).build();
|
||||
this.maxVelocity = Double.MAX_VALUE;
|
||||
}
|
||||
|
||||
|
|
@ -255,8 +323,9 @@ public class VehicleTypeImpl implements VehicleType {
|
|||
* @see basics.route.VehicleType#getCapacity()
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public int getCapacity() {
|
||||
return capacity;
|
||||
return capacityDimensions.get(0);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
@ -276,4 +345,9 @@ public class VehicleTypeImpl implements VehicleType {
|
|||
public double getMaxVelocity() {
|
||||
return maxVelocity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Capacity getCapacityDimensions() {
|
||||
return capacityDimensions;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,97 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2013 Stefan Schroeder
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package jsprit.core.util;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
|
||||
import jsprit.core.algorithm.listener.AlgorithmStartsListener;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
* Verifies whether vrp can be solved.
|
||||
*
|
||||
* <p>Checks<br>
|
||||
* - capacities, i.e. whether all job at least fit into the biggest vehicle
|
||||
*
|
||||
* @author stefan
|
||||
*
|
||||
*/
|
||||
public class VrpVerifier implements AlgorithmStartsListener{
|
||||
|
||||
private static Logger log = Logger.getLogger(VrpVerifier.class);
|
||||
|
||||
@Override
|
||||
public void informAlgorithmStarts(VehicleRoutingProblem problem, VehicleRoutingAlgorithm algorithm, Collection<VehicleRoutingProblemSolution> solutions) {
|
||||
//check capacity
|
||||
log.info("verifying vehicle-routing-problem ...");
|
||||
log.info("check vehicle capacities ...");
|
||||
Vehicle vehicleWithMaxCapacity = getMaxVehicle(problem);
|
||||
if(vehicleWithMaxCapacity == null) throw new IllegalStateException("vehicles are missing.");
|
||||
for(Job j : problem.getJobs().values()){
|
||||
if(vehicleWithMaxCapacity.getCapacity() < Math.abs(j.getCapacityDemand())){
|
||||
throw new IllegalStateException("maximal vehicle-capacity is "+vehicleWithMaxCapacity.getCapacity() + ", but there is a job bigger than this. [job=" + j + "]");
|
||||
}
|
||||
}
|
||||
log.info("ok");
|
||||
// log.info("check vehicles can manage shuttle tours ...");
|
||||
// for(Job j : problem.getJobs().values()){
|
||||
// Service s = (Service)j;
|
||||
// boolean jobCanBeRoutedWithinTimeWindow = false;
|
||||
// for(Vehicle v : problem.getVehicles()){
|
||||
// double transportTime = problem.getTransportCosts().getTransportTime(v.getStartLocationId(), s.getLocationId(), v.getEarliestDeparture(), DriverImpl.noDriver(), v);
|
||||
// if(transportTime+v.getEarliestDeparture() < s.getTimeWindow().getEnd()){
|
||||
// jobCanBeRoutedWithinTimeWindow = true;
|
||||
// break;
|
||||
// }
|
||||
// else{
|
||||
// log.warn("vehicle " + v + " needs " + transportTime + " time-units to get to " + s.getLocationId() + ". latestOperationStartTime however is " + s.getTimeWindow().getEnd());
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// if(!jobCanBeRoutedWithinTimeWindow){
|
||||
// throw new IllegalStateException("no vehicle is able to cover the distance from depot to " + s.getLocationId() + " to meet the time-window " + s.getTimeWindow() + ".");
|
||||
// }
|
||||
// }
|
||||
// log.info("ok");
|
||||
log.info("verifying done");
|
||||
}
|
||||
|
||||
public void verify(VehicleRoutingProblem pblm, VehicleRoutingAlgorithm vra){
|
||||
informAlgorithmStarts(pblm, vra, null);
|
||||
}
|
||||
|
||||
private Vehicle getMaxVehicle(VehicleRoutingProblem problem) {
|
||||
Vehicle maxVehicle = null;
|
||||
for(Vehicle v : problem.getVehicles()){
|
||||
if(maxVehicle == null) {
|
||||
maxVehicle = v;
|
||||
continue;
|
||||
}
|
||||
else if(v.getCapacity() > maxVehicle.getCapacity()){
|
||||
maxVehicle = v;
|
||||
}
|
||||
}
|
||||
return maxVehicle;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -82,6 +82,21 @@
|
|||
<xs:all>
|
||||
<xs:element name="id" type="xs:string" minOccurs="1" maxOccurs="1"/>
|
||||
<xs:element name="capacity" type="xs:integer" minOccurs="0" maxOccurs="1" default="0"/>
|
||||
<xs:element name="capacity-dimensions" minOccurs="0" maxOccurs="1">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="dimension" minOccurs="1" maxOccurs="unbounded">
|
||||
<xs:complexType>
|
||||
<xs:simpleContent>
|
||||
<xs:extension base="xs:integer">
|
||||
<xs:attribute name="index" type="xs:integer" use="required"/>
|
||||
</xs:extension>
|
||||
</xs:simpleContent>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="costs">
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
|
|
@ -109,6 +124,21 @@
|
|||
<xs:element name="locationId" type="xs:string" minOccurs="0" maxOccurs="1"/>
|
||||
<xs:element name="coord" type="coordType" minOccurs="0" maxOccurs="1"/>
|
||||
<xs:element name="capacity-demand" type="xs:integer" minOccurs="0" maxOccurs="1" default="0"/>
|
||||
<xs:element name="capacity-dimensions" minOccurs="0" maxOccurs="1">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="dimension" minOccurs="1" maxOccurs="unbounded">
|
||||
<xs:complexType>
|
||||
<xs:simpleContent>
|
||||
<xs:extension base="xs:integer">
|
||||
<xs:attribute name="index" type="xs:integer" use="required"/>
|
||||
</xs:extension>
|
||||
</xs:simpleContent>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="duration" type="xs:decimal" minOccurs="0" maxOccurs="1" default="0.0"/>
|
||||
<xs:element name="timeWindows" minOccurs="0" maxOccurs="1">
|
||||
<xs:complexType>
|
||||
|
|
@ -165,7 +195,22 @@
|
|||
</xs:all>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="capacity-demand" type="xs:integer" minOccurs="1" maxOccurs="1"/>
|
||||
<xs:element name="capacity-demand" type="xs:integer" minOccurs="0" maxOccurs="1"/>
|
||||
<xs:element name="capacity-dimensions" minOccurs="0" maxOccurs="1">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="dimension" minOccurs="1" maxOccurs="unbounded">
|
||||
<xs:complexType>
|
||||
<xs:simpleContent>
|
||||
<xs:extension base="xs:integer">
|
||||
<xs:attribute name="index" type="xs:integer" use="required"/>
|
||||
</xs:extension>
|
||||
</xs:simpleContent>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:sequence>
|
||||
<xs:attribute name="id" type="xs:string" use="required" />
|
||||
</xs:complexType>
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ public class BuildCVRPAlgoFromScratch_IT {
|
|||
new VrpXMLReader(builder).read("src/test/resources/vrpnc1-jsprit.xml");
|
||||
vrp = builder.build();
|
||||
|
||||
final StateManager stateManager = new StateManager(vrp);
|
||||
final StateManager stateManager = new StateManager(vrp.getTransportCosts());
|
||||
stateManager.updateLoadStates();
|
||||
stateManager.updateTimeWindowStates();
|
||||
stateManager.addStateUpdater(new UpdateVariableCosts(vrp.getActivityCosts(), vrp.getTransportCosts(), stateManager));
|
||||
|
|
@ -82,7 +82,7 @@ public class BuildCVRPAlgoFromScratch_IT {
|
|||
public double getCosts(VehicleRoutingProblemSolution solution) {
|
||||
double costs = 0.0;
|
||||
for(VehicleRoute route : solution.getRoutes()){
|
||||
costs += stateManager.getRouteState(route, StateFactory.COSTS).toDouble();
|
||||
costs += stateManager.getRouteState(route, StateFactory.COSTS,Double.class);
|
||||
}
|
||||
return costs;
|
||||
}
|
||||
|
|
@ -108,7 +108,7 @@ public class BuildCVRPAlgoFromScratch_IT {
|
|||
|
||||
vra.addInitialSolution(iniSolution);
|
||||
|
||||
vra.setNuOfIterations(2000);
|
||||
vra.setNuOfIterations(1000);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ public class BuildPDVRPAlgoFromScratch_IT {
|
|||
new VrpXMLReader(builder).read("src/test/resources/pd_solomon_r101.xml");
|
||||
vrp = builder.build();
|
||||
|
||||
final StateManager stateManager = new StateManager(vrp);
|
||||
final StateManager stateManager = new StateManager(vrp.getTransportCosts());
|
||||
|
||||
ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager);
|
||||
constraintManager.addTimeWindowConstraint();
|
||||
|
|
@ -81,7 +81,7 @@ public class BuildPDVRPAlgoFromScratch_IT {
|
|||
public double getCosts(VehicleRoutingProblemSolution solution) {
|
||||
double costs = 0.0;
|
||||
for(VehicleRoute route : solution.getRoutes()){
|
||||
costs += stateManager.getRouteState(route, StateFactory.COSTS).toDouble();
|
||||
costs += stateManager.getRouteState(route, StateFactory.COSTS, Double.class);
|
||||
}
|
||||
return costs;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ public class BuildPDVRPWithShipmentsAlgoFromScratch_IT {
|
|||
|
||||
vrp = builder.build();
|
||||
|
||||
final StateManager stateManager = new StateManager(vrp);
|
||||
final StateManager stateManager = new StateManager(vrp.getTransportCosts());
|
||||
stateManager.updateLoadStates();
|
||||
stateManager.updateTimeWindowStates();
|
||||
stateManager.addStateUpdater(new UpdateVariableCosts(vrp.getActivityCosts(), vrp.getTransportCosts(), stateManager));
|
||||
|
|
@ -87,7 +87,7 @@ public class BuildPDVRPWithShipmentsAlgoFromScratch_IT {
|
|||
public double getCosts(VehicleRoutingProblemSolution solution) {
|
||||
double costs = 0.0;
|
||||
for(VehicleRoute route : solution.getRoutes()){
|
||||
costs += stateManager.getRouteState(route, StateFactory.COSTS).toDouble();
|
||||
costs += stateManager.getRouteState(route, StateFactory.COSTS, Double.class);
|
||||
}
|
||||
return costs;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,30 +106,6 @@ public class RefuseCollectionWithCostsHigherThanTimesAndFiniteFleet_IT {
|
|||
}
|
||||
}
|
||||
|
||||
// static class RoutingCosts extends AbstractForwardVehicleRoutingTransportCosts {
|
||||
//
|
||||
// private Map<RelationKey,Integer> distances;
|
||||
//
|
||||
// public RoutingCosts(Map<RelationKey, Integer> distances) {
|
||||
// super();
|
||||
// this.distances = distances;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public double getTransportTime(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) {
|
||||
// return getTransportCost(fromId, toId, departureTime, driver, vehicle)/2.;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public double getTransportCost(String fromId, String toId,double departureTime, Driver driver, Vehicle vehicle) {
|
||||
// if(fromId.equals(toId)) return 0.0;
|
||||
// RelationKey key = RelationKey.newKey(fromId, toId);
|
||||
// return distances.get(key);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
@Test
|
||||
public void testAlgo(){
|
||||
|
||||
|
|
@ -137,7 +113,7 @@ public class RefuseCollectionWithCostsHigherThanTimesAndFiniteFleet_IT {
|
|||
/*
|
||||
* create vehicle-type and vehicle
|
||||
*/
|
||||
VehicleTypeImpl.Builder typeBuilder = VehicleTypeImpl.Builder.newInstance("vehicle-type", 23);
|
||||
VehicleTypeImpl.Builder typeBuilder = VehicleTypeImpl.Builder.newInstance("vehicle-type").addCapacityDimension(0, 23);
|
||||
typeBuilder.setCostPerDistance(1.0);
|
||||
VehicleTypeImpl bigType = typeBuilder.build();
|
||||
|
||||
|
|
@ -198,7 +174,7 @@ public class RefuseCollectionWithCostsHigherThanTimesAndFiniteFleet_IT {
|
|||
/*
|
||||
* build service
|
||||
*/
|
||||
Service service = Service.Builder.newInstance(lineTokens[0], Integer.parseInt(lineTokens[1])).setLocationId(lineTokens[0]).build();
|
||||
Service service = Service.Builder.newInstance(lineTokens[0]).addSizeDimension(0, Integer.parseInt(lineTokens[1])).setLocationId(lineTokens[0]).build();
|
||||
/*
|
||||
* and add it to problem
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ public class RefuseCollection_IT {
|
|||
/*
|
||||
* create vehicle-type and vehicle
|
||||
*/
|
||||
VehicleTypeImpl.Builder typeBuilder = VehicleTypeImpl.Builder.newInstance("vehicle-type", 23);
|
||||
VehicleTypeImpl.Builder typeBuilder = VehicleTypeImpl.Builder.newInstance("vehicle-type").addCapacityDimension(0, 23);
|
||||
typeBuilder.setCostPerDistance(1.0);
|
||||
VehicleTypeImpl bigType = typeBuilder.build();
|
||||
|
||||
|
|
@ -210,7 +210,7 @@ public class RefuseCollection_IT {
|
|||
/*
|
||||
* build service
|
||||
*/
|
||||
Service service = Service.Builder.newInstance(lineTokens[0], Integer.parseInt(lineTokens[1])).setLocationId(lineTokens[0]).build();
|
||||
Service service = Service.Builder.newInstance(lineTokens[0]).addSizeDimension(0, Integer.parseInt(lineTokens[1])).setLocationId(lineTokens[0]).build();
|
||||
/*
|
||||
* and add it to problem
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -23,22 +23,20 @@ import static org.mockito.Mockito.when;
|
|||
|
||||
import java.util.Arrays;
|
||||
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleFleetManager;
|
||||
import jsprit.core.problem.vehicle.VehicleImpl;
|
||||
import jsprit.core.problem.vehicle.VehicleType;
|
||||
import jsprit.core.problem.vehicle.VehicleTypeImpl;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class CalcVehicleTypeDependentServiceInsertionTest {
|
||||
|
||||
Vehicle veh1;
|
||||
|
|
@ -51,8 +49,8 @@ public class CalcVehicleTypeDependentServiceInsertionTest {
|
|||
public void doBefore(){
|
||||
veh1 = mock(Vehicle.class);
|
||||
veh2 = mock(Vehicle.class);
|
||||
when(veh1.getType()).thenReturn(VehicleTypeImpl.Builder.newInstance("type1", 0).build());
|
||||
when(veh2.getType()).thenReturn(VehicleTypeImpl.Builder.newInstance("type2", 0).build());
|
||||
when(veh1.getType()).thenReturn(VehicleTypeImpl.Builder.newInstance("type1").build());
|
||||
when(veh2.getType()).thenReturn(VehicleTypeImpl.Builder.newInstance("type2").build());
|
||||
when(veh1.getStartLocationId()).thenReturn("loc1");
|
||||
when(veh2.getStartLocationId()).thenReturn("loc2");
|
||||
fleetManager = mock(VehicleFleetManager.class);
|
||||
|
|
@ -61,10 +59,13 @@ public class CalcVehicleTypeDependentServiceInsertionTest {
|
|||
|
||||
when(fleetManager.getAvailableVehicles()).thenReturn(Arrays.asList(veh1,veh2));
|
||||
|
||||
when(veh1.getCapacity()).thenReturn(10);
|
||||
when(veh2.getCapacity()).thenReturn(10);
|
||||
VehicleType type = mock(VehicleType.class);
|
||||
when(type.getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10).build());
|
||||
when(veh1.getType()).thenReturn(type);
|
||||
|
||||
when(service.getCapacityDemand()).thenReturn(0);
|
||||
when(veh2.getType()).thenReturn(type);
|
||||
|
||||
when(service.getSize()).thenReturn(Capacity.Builder.newInstance().build());
|
||||
when(service.getTimeWindow()).thenReturn(TimeWindow.newInstance(0.0, Double.MAX_VALUE));
|
||||
|
||||
when(vehicleRoute.getDriver()).thenReturn(null);
|
||||
|
|
|
|||
|
|
@ -39,14 +39,14 @@ import jsprit.core.util.Solutions;
|
|||
|
||||
public class CalcWithTimeSchedulingTest {
|
||||
|
||||
|
||||
|
||||
public void timeScheduler(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("myVehicle").setEarliestStart(0.0).setLatestArrival(100.0).
|
||||
setStartLocationCoordinate(Coordinate.newInstance(0, 0)).setStartLocationId("0,0")
|
||||
.setType(VehicleTypeImpl.Builder.newInstance("myType", 20).setCostPerDistance(1.0).build()).build();
|
||||
.setType(VehicleTypeImpl.Builder.newInstance("myType").addCapacityDimension(0, 20).setCostPerDistance(1.0).build()).build();
|
||||
vrpBuilder.addVehicle(vehicle);
|
||||
vrpBuilder.addJob(Service.Builder.newInstance("myService", 2).setLocationId("0,20").setCoord(Coordinate.newInstance(0, 20)).build());
|
||||
vrpBuilder.addJob(Service.Builder.newInstance("myService").addSizeDimension(0, 2).setLocationId("0,20").setCoord(Coordinate.newInstance(0, 20)).build());
|
||||
vrpBuilder.setFleetSize(FleetSize.INFINITE);
|
||||
vrpBuilder.setRoutingCost(getTpCosts(new CrowFlyCosts(vrpBuilder.getLocations())));
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,258 @@
|
|||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleType;
|
||||
import jsprit.core.problem.vehicle.VehicleTypeImpl;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class JobInsertionConsideringFixCostsCalculatorTest {
|
||||
|
||||
private JobInsertionConsideringFixCostsCalculator calc;
|
||||
|
||||
private Vehicle oVehicle;
|
||||
|
||||
private Vehicle nVehicle;
|
||||
|
||||
private Job job;
|
||||
|
||||
private VehicleRoute route;
|
||||
|
||||
private RouteAndActivityStateGetter stateGetter;
|
||||
|
||||
@Before
|
||||
public void doBefore(){
|
||||
JobInsertionCostsCalculator jobInsertionCosts = mock(JobInsertionCostsCalculator.class);
|
||||
job = mock(Job.class);
|
||||
when(job.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 50).build());
|
||||
|
||||
oVehicle = mock(Vehicle.class);
|
||||
VehicleType oType = VehicleTypeImpl.Builder.newInstance("otype").addCapacityDimension(0, 50).setFixedCost(50.0).build();
|
||||
when(oVehicle.getType()).thenReturn(oType);
|
||||
|
||||
nVehicle = mock(Vehicle.class);
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, 100).setFixedCost(100.0).build();
|
||||
when(nVehicle.getType()).thenReturn(type);
|
||||
|
||||
InsertionData iData = new InsertionData(0.0, 1, 1, nVehicle, null);
|
||||
route = mock(VehicleRoute.class);
|
||||
|
||||
when(jobInsertionCosts.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE)).thenReturn(iData);
|
||||
|
||||
stateGetter = mock(RouteAndActivityStateGetter.class);
|
||||
when(stateGetter.getRouteState(route, StateFactory.MAXLOAD, Capacity.class)).thenReturn(Capacity.Builder.newInstance().build());
|
||||
|
||||
calc = new JobInsertionConsideringFixCostsCalculator(jobInsertionCosts, stateGetter);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNullAndSolutionComplete_itShouldReturnFixedCostsOfNewVehicle(){
|
||||
calc.setSolutionCompletenessRatio(1.0);
|
||||
calc.setWeightOfFixCost(1.0);
|
||||
//(1.*absFix + 0.*relFix) * completeness * weight = (1.*100. + 0.*50.) * 1. * 1. = 100.
|
||||
assertEquals(100.,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNullAndSolutionIs0PercentComplete_itShouldReturnNoFixedCosts(){
|
||||
calc.setSolutionCompletenessRatio(0.0);
|
||||
calc.setWeightOfFixCost(1.0);
|
||||
//(0.*absFix + 1.*relFix) * completeness * weight = 0.
|
||||
assertEquals(0.,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNullAndSolutionIs50PercentComplete_itShouldReturnAvgOfRelFixedAndAbsFixedCostOfNewVehicle(){
|
||||
calc.setSolutionCompletenessRatio(0.5);
|
||||
calc.setWeightOfFixCost(1.0);
|
||||
//(0.5*absFix + 0.5*relFix) * 0.5 * 1. = (0.5*100+0.5*50)*0.5*1. = 37.5
|
||||
assertEquals(37.5,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNullAndSolutionIs75PercentComplete_itShouldReturnAvgOfRelFixedAndAbsFixedCostOfNewVehicle(){
|
||||
calc.setSolutionCompletenessRatio(0.75);
|
||||
calc.setWeightOfFixCost(1.0);
|
||||
//(0.75*absFix + 0.25*relFix) * 0.75 * 1.= (0.75*100.+0.25*50.)*0.75*1. = 65.625
|
||||
assertEquals(65.625,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNullAndSolutionCompleteAndWeightIs05_itShouldReturnHalfOfFixedCostsOfNewVehicle(){
|
||||
calc.setSolutionCompletenessRatio(1.0);
|
||||
calc.setWeightOfFixCost(.5);
|
||||
//(1.*absFix + 0.*relFix) * 1. * 0.5 = (1.*100. + 0.*50.) * 1. * 0.5 = 5.
|
||||
assertEquals(50.,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNullAndSolutionIs0PercentCompleteAndWeightIs05_itShouldReturnHalfOfNoFixedCosts(){
|
||||
calc.setSolutionCompletenessRatio(0.0);
|
||||
calc.setWeightOfFixCost(.5);
|
||||
//(0.*absFix + 1.*relFix) * 0. * .5 = 0.
|
||||
assertEquals(0.,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNullAndSolutionIs50PercentCompleteAndWeightIs05_itShouldReturnHalfOfAvgOfRelFixedAndAbsFixedCostOfNewVehicle(){
|
||||
calc.setSolutionCompletenessRatio(0.5);
|
||||
calc.setWeightOfFixCost(.5);
|
||||
//(0.5*absFix + 0.5*relFix) * 0.5 * 0.= (0.5*100+0.5*50)*0.5*0.5 = 18.75
|
||||
assertEquals(18.75,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNullAndSolutionIs75PercentCompleteAndWeightIs05_itShouldReturnHalfOfAvgOfRelFixedAndAbsFixedCostOfNewVehicle(){
|
||||
calc.setSolutionCompletenessRatio(0.75);
|
||||
calc.setWeightOfFixCost(0.5);
|
||||
//(0.75*absFix + 0.25*relFix) * 0.75 * 0.5 = (0.75*100.+0.25*50.)*0.75*0.5 = 32.8125
|
||||
assertEquals(32.8125,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNotNullAndSolutionComplete_itShouldReturnHalfOfFixedCostsOfNewVehicle(){
|
||||
calc.setSolutionCompletenessRatio(1.0);
|
||||
calc.setWeightOfFixCost(1.0);
|
||||
when(route.getVehicle()).thenReturn(oVehicle);
|
||||
//(1.*absFix + 0.*relFix) * completeness * weight = (1.*(100.-50.) + 0.*(50.-0.)) * 1. * 1. = 50.
|
||||
assertEquals(50.,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNotNullAndSolutionIs0PercentComplete_itShouldReturnNoFixedCosts(){
|
||||
calc.setSolutionCompletenessRatio(0.0);
|
||||
calc.setWeightOfFixCost(1.0);
|
||||
when(route.getVehicle()).thenReturn(oVehicle);
|
||||
//(0.*absFix + 1.*relFix) * completeness * weight = 0.
|
||||
assertEquals(0.,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNotNullAndSolutionIs50PercentComplete_itShouldCorrectVal(){
|
||||
calc.setSolutionCompletenessRatio(0.5);
|
||||
calc.setWeightOfFixCost(1.0);
|
||||
when(route.getVehicle()).thenReturn(oVehicle);
|
||||
//(0.5*absFix + 0.5*relFix) * 0.5 * 1. = (0.5*(100-50)+0.5*(50-0))*0.5*1. = 25.
|
||||
assertEquals(25.,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNotNullAndSolutionIs75PercentComplete_itShouldReturnCorrectVal(){
|
||||
calc.setSolutionCompletenessRatio(0.75);
|
||||
calc.setWeightOfFixCost(1.0);
|
||||
when(route.getVehicle()).thenReturn(oVehicle);
|
||||
//(0.75*absFix + 0.25*relFix) * 0.75 * 1.= (0.75*(100.-50.)+0.25*(50.-0.))*0.75*1. = 37.5
|
||||
assertEquals(37.5,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNotNullAndSolutionCompleteAndWeightIs05_itShouldReturnCorrectVal(){
|
||||
calc.setSolutionCompletenessRatio(1.0);
|
||||
calc.setWeightOfFixCost(.5);
|
||||
when(route.getVehicle()).thenReturn(oVehicle);
|
||||
//(1.*absFix + 0.*relFix) * 1. * 0.5 = (1.*(100.-50.) + 0.*(50.-0.)) * 1. * 0.5 = 25.
|
||||
assertEquals(25.,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNotNullAndSolutionIs0PercentCompleteAndWeightIs05_itShouldReturnCorrectVal(){
|
||||
calc.setSolutionCompletenessRatio(0.0);
|
||||
calc.setWeightOfFixCost(.5);
|
||||
when(route.getVehicle()).thenReturn(oVehicle);
|
||||
//(0.*absFix + 1.*relFix) * 0. * .5 = 0.
|
||||
assertEquals(0.,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNotNullAndSolutionIs50PercentCompleteAndWeightIs05_itShouldReturnCorrectVal(){
|
||||
calc.setSolutionCompletenessRatio(0.5);
|
||||
calc.setWeightOfFixCost(.5);
|
||||
when(route.getVehicle()).thenReturn(oVehicle);
|
||||
//(0.5*absFix + 0.5*relFix) * 0.5 * 0.= (0.5*(100-50)+0.5*(50-0))*0.5*0.5 = 12.5
|
||||
assertEquals(12.5,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNotNullAndSolutionIs75PercentCompleteAndWeightIs05_itShouldReturnCorrectVal(){
|
||||
calc.setSolutionCompletenessRatio(0.75);
|
||||
calc.setWeightOfFixCost(0.5);
|
||||
when(route.getVehicle()).thenReturn(oVehicle);
|
||||
//(0.75*absFix + 0.25*relFix) * 0.75 * 0.5 = (0.75*(100.-50.)+0.25*(50.-0.))*0.75*0.5 = 18.75
|
||||
assertEquals(18.75,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNotNullAndCurrentLoadIs25AndSolutionIs50PercentCompleteAndWeightIs05_itShouldReturnCorrectVal(){
|
||||
calc.setSolutionCompletenessRatio(0.5);
|
||||
calc.setWeightOfFixCost(.5);
|
||||
when(route.getVehicle()).thenReturn(oVehicle);
|
||||
when(stateGetter.getRouteState(route, StateFactory.MAXLOAD, Capacity.class)).thenReturn(Capacity.Builder.newInstance().addDimension(0, 25).build());
|
||||
//(0.5*absFix + 0.5*relFix) * 0.5 * 0.= (0.5*(100-50)+0.5*(75-25))*0.5*0.5 = 12.5
|
||||
assertEquals(12.5,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNotNullAndCurrentLoadIs25AndSolutionIs75PercentCompleteAndWeightIs05_itShouldReturnCorrectVal(){
|
||||
calc.setSolutionCompletenessRatio(0.75);
|
||||
calc.setWeightOfFixCost(0.5);
|
||||
when(route.getVehicle()).thenReturn(oVehicle);
|
||||
//(0.75*absFix + 0.25*relFix) * 0.75 * 0.5 = (0.75*(100.-50.)+0.25*(75.-25.))*0.75*0.5 = 18.75
|
||||
assertEquals(18.75,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNotNullAndCurrentLoadIs25AndSolutionIs50PercentCompleteAndWeightIs05WithMultipleCapDims_itShouldReturnCorrectVal(){
|
||||
calc.setSolutionCompletenessRatio(.5);
|
||||
calc.setWeightOfFixCost(.5);
|
||||
|
||||
when(job.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 50).addDimension(1, 0).build());
|
||||
|
||||
VehicleType oType = VehicleTypeImpl.Builder.newInstance("otype").addCapacityDimension(0, 50).addCapacityDimension(1, 100).setFixedCost(50.0).build();
|
||||
when(oVehicle.getType()).thenReturn(oType);
|
||||
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, 100).addCapacityDimension(1, 400).setFixedCost(100.0).build();
|
||||
when(nVehicle.getType()).thenReturn(type);
|
||||
|
||||
when(route.getVehicle()).thenReturn(oVehicle);
|
||||
when(stateGetter.getRouteState(route, StateFactory.MAXLOAD, Capacity.class)).thenReturn(Capacity.Builder.newInstance().addDimension(0, 25).addDimension(1, 100).build());
|
||||
//(0.5*absFix + 0.5*relFix) * 0.5 * 0.= (0.5*(100-50)+0.5*(75-25))*0.5*0.5 = 12.5
|
||||
/*
|
||||
* (0.5*(100-50)+0.5*(
|
||||
* relFixNew - relFixOld = (75/100+100/400)/2.*100 - ((25/50+100/100)/2.*50.) =
|
||||
* )*0.5*0.5
|
||||
* = (0.5*(100-50)+0.5*((75/100+100/400)/2.*100 - ((25/50+100/100)/2.*50.)))*0.5*0.5
|
||||
* = (0.5*(100-50)+0.5*12.5)*0.5*0.5 = 7.8125
|
||||
*/
|
||||
assertEquals(7.8125,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOldVehicleIsNotNullAndCurrentLoadIs25AndSolutionIs75PercentCompleteAndWeightIs05WithMultipleCapDims_itShouldReturnCorrectVal(){
|
||||
calc.setSolutionCompletenessRatio(0.75);
|
||||
calc.setWeightOfFixCost(0.5);
|
||||
when(job.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 50).addDimension(1, 0).build());
|
||||
|
||||
VehicleType oType = VehicleTypeImpl.Builder.newInstance("otype").addCapacityDimension(0, 50).addCapacityDimension(1, 100).setFixedCost(50.0).build();
|
||||
when(oVehicle.getType()).thenReturn(oType);
|
||||
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, 100).addCapacityDimension(1, 400).setFixedCost(100.0).build();
|
||||
when(nVehicle.getType()).thenReturn(type);
|
||||
|
||||
when(route.getVehicle()).thenReturn(oVehicle);
|
||||
when(stateGetter.getRouteState(route, StateFactory.MAXLOAD, Capacity.class)).thenReturn(Capacity.Builder.newInstance().addDimension(0, 25).addDimension(1, 100).build());
|
||||
//(0.75*absFix + 0.25*relFix) * 0.75 * 0.5 = (0.75*(100.-50.)+0.25*12.5)*0.75*0.5 = 15.234375
|
||||
|
||||
assertEquals(15.234375,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -5,13 +5,6 @@ import static org.mockito.Mockito.mock;
|
|||
|
||||
import java.util.Arrays;
|
||||
|
||||
import jsprit.core.algorithm.recreate.ActivityInsertionCostsCalculator;
|
||||
import jsprit.core.algorithm.recreate.Inserter;
|
||||
import jsprit.core.algorithm.recreate.InsertionData;
|
||||
import jsprit.core.algorithm.recreate.JobCalculatorSwitcher;
|
||||
import jsprit.core.algorithm.recreate.LocalActivityInsertionCostsCalculator;
|
||||
import jsprit.core.algorithm.recreate.ServiceInsertionCalculator;
|
||||
import jsprit.core.algorithm.recreate.ShipmentInsertionCalculator;
|
||||
import jsprit.core.algorithm.recreate.listener.InsertionListeners;
|
||||
import jsprit.core.algorithm.state.StateManager;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
|
|
@ -33,9 +26,7 @@ import jsprit.core.problem.vehicle.Vehicle;
|
|||
import jsprit.core.problem.vehicle.VehicleImpl;
|
||||
import jsprit.core.problem.vehicle.VehicleType;
|
||||
import jsprit.core.problem.vehicle.VehicleTypeImpl;
|
||||
import jsprit.core.util.Coordinate;
|
||||
import jsprit.core.util.Locations;
|
||||
import jsprit.core.util.ManhattanCosts;
|
||||
import jsprit.core.util.CostFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
|
@ -79,19 +70,8 @@ public class ServiceInsertionAndLoadConstraintsTest {
|
|||
|
||||
@Before
|
||||
public void doBefore(){
|
||||
Locations locations = new Locations(){
|
||||
|
||||
@Override
|
||||
public Coordinate getCoord(String id) {
|
||||
//assume: locationId="x,y"
|
||||
String[] splitted = id.split(",");
|
||||
return Coordinate.newInstance(Double.parseDouble(splitted[0]),
|
||||
Double.parseDouble(splitted[1]));
|
||||
}
|
||||
|
||||
};
|
||||
routingCosts = new ManhattanCosts(locations);
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("t", 2).setCostPerDistance(1).build();
|
||||
routingCosts = CostFactory.createManhattanCosts();
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("t").addCapacityDimension(0, 2).setCostPerDistance(1).build();
|
||||
vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("0,0").setType(type).build();
|
||||
activityInsertionCostsCalculator = new LocalActivityInsertionCostsCalculator(routingCosts, activityCosts);
|
||||
createInsertionCalculator(hardRouteLevelConstraint);
|
||||
|
|
@ -105,10 +85,10 @@ public class ServiceInsertionAndLoadConstraintsTest {
|
|||
|
||||
@Test
|
||||
public void whenInsertingServiceWhileNoCapIsAvailable_itMustReturnTheCorrectInsertionIndex(){
|
||||
Delivery delivery = (Delivery) Delivery.Builder.newInstance("del", 41).setLocationId("10,10").build();
|
||||
Pickup pickup = (Pickup) Pickup.Builder.newInstance("pick", 15).setLocationId("0,10").build();
|
||||
Delivery delivery = (Delivery) Delivery.Builder.newInstance("del").addSizeDimension(0, 41).setLocationId("10,10").build();
|
||||
Pickup pickup = (Pickup) Pickup.Builder.newInstance("pick").addSizeDimension(0, 15).setLocationId("0,10").build();
|
||||
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("t", 50).setCostPerDistance(1).build();
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("t").addCapacityDimension(0, 50).setCostPerDistance(1).build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("0,0").setType(type).build();
|
||||
|
||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||
|
|
@ -117,18 +97,10 @@ public class ServiceInsertionAndLoadConstraintsTest {
|
|||
Inserter inserter = new Inserter(new InsertionListeners());
|
||||
|
||||
inserter.insertJob(delivery, new InsertionData(0,0,0,vehicle,null), route);
|
||||
// inserter.insertJob(shipment2, new InsertionData(0,1,2,vehicle,null), route);
|
||||
// inserter.insertJob(shipment2, new InsertionData(0,1,2,vehicle,null), route);
|
||||
|
||||
|
||||
|
||||
// RouteActivityVisitor routeActVisitor = new RouteActivityVisitor();
|
||||
// routeActVisitor.addActivityVisitor(new UpdateLoads(stateManager));
|
||||
// routeActVisitor.visit(route);
|
||||
|
||||
VehicleRoutingProblem vrp = mock(VehicleRoutingProblem.class);
|
||||
|
||||
StateManager stateManager = new StateManager(vrp);
|
||||
StateManager stateManager = new StateManager(vrp.getTransportCosts());
|
||||
stateManager.updateLoadStates();
|
||||
|
||||
ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager);
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
|||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.driver.DriverImpl;
|
||||
import jsprit.core.problem.job.Pickup;
|
||||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.problem.job.Shipment;
|
||||
import jsprit.core.problem.misc.JobInsertionContext;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
|
|
@ -29,9 +30,7 @@ import jsprit.core.problem.vehicle.Vehicle;
|
|||
import jsprit.core.problem.vehicle.VehicleImpl;
|
||||
import jsprit.core.problem.vehicle.VehicleType;
|
||||
import jsprit.core.problem.vehicle.VehicleTypeImpl;
|
||||
import jsprit.core.util.Coordinate;
|
||||
import jsprit.core.util.Locations;
|
||||
import jsprit.core.util.ManhattanCosts;
|
||||
import jsprit.core.util.CostFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
|
@ -75,19 +74,8 @@ public class ShipmentInsertionCalculatorTest {
|
|||
|
||||
@Before
|
||||
public void doBefore(){
|
||||
Locations locations = new Locations(){
|
||||
|
||||
@Override
|
||||
public Coordinate getCoord(String id) {
|
||||
//assume: locationId="x,y"
|
||||
String[] splitted = id.split(",");
|
||||
return Coordinate.newInstance(Double.parseDouble(splitted[0]),
|
||||
Double.parseDouble(splitted[1]));
|
||||
}
|
||||
|
||||
};
|
||||
routingCosts = new ManhattanCosts(locations);
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("t", 2).setCostPerDistance(1).build();
|
||||
routingCosts = CostFactory.createManhattanCosts();
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("t").addCapacityDimension(0, 2).setCostPerDistance(1).build();
|
||||
vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("0,0").setType(type).build();
|
||||
activityInsertionCostsCalculator = new LocalActivityInsertionCostsCalculator(routingCosts, activityCosts);
|
||||
createInsertionCalculator(hardRouteLevelConstraint);
|
||||
|
|
@ -101,7 +89,7 @@ public class ShipmentInsertionCalculatorTest {
|
|||
|
||||
@Test
|
||||
public void whenCalculatingInsertionCostsOfShipment_itShouldReturnCorrectCostValue(){
|
||||
Shipment shipment = Shipment.Builder.newInstance("s", 1).setPickupLocation("0,10").setDeliveryLocation("10,0").build();
|
||||
Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation("0,10").setDeliveryLocation("10,0").build();
|
||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||
|
||||
InsertionData iData = insertionCalculator.getInsertionData(route, shipment, vehicle, 0.0, null, Double.MAX_VALUE);
|
||||
|
|
@ -110,8 +98,8 @@ public class ShipmentInsertionCalculatorTest {
|
|||
|
||||
@Test
|
||||
public void whenCalculatingInsertionIntoExistingRoute_itShouldReturnCorrectCosts(){
|
||||
Shipment shipment = Shipment.Builder.newInstance("s", 1).setPickupLocation("0,10").setDeliveryLocation("10,0").build();
|
||||
Shipment shipment2 = Shipment.Builder.newInstance("s2", 1).setPickupLocation("10,10").setDeliveryLocation("0,0").build();
|
||||
Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation("0,10").setDeliveryLocation("10,0").build();
|
||||
Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation("10,10").setDeliveryLocation("0,0").build();
|
||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||
new Inserter(new InsertionListeners()).insertJob(shipment, new InsertionData(0,0,0,vehicle,null), route);
|
||||
|
||||
|
|
@ -123,8 +111,8 @@ public class ShipmentInsertionCalculatorTest {
|
|||
|
||||
@Test
|
||||
public void whenInsertingShipmentInRouteWithNotEnoughCapacity_itShouldReturnNoInsertion(){
|
||||
Shipment shipment = Shipment.Builder.newInstance("s", 1).setPickupLocation("0,10").setDeliveryLocation("10,0").build();
|
||||
Shipment shipment2 = Shipment.Builder.newInstance("s2", 1).setPickupLocation("10,10").setDeliveryLocation("0,0").build();
|
||||
Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation("0,10").setDeliveryLocation("10,0").build();
|
||||
Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation("10,10").setDeliveryLocation("0,0").build();
|
||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||
new Inserter(new InsertionListeners()).insertJob(shipment, new InsertionData(0,0,0,vehicle,null), route);
|
||||
createInsertionCalculator(new HardRouteStateLevelConstraint() {
|
||||
|
|
@ -143,9 +131,9 @@ public class ShipmentInsertionCalculatorTest {
|
|||
|
||||
@Test
|
||||
public void whenInsertingThirdShipment_itShouldCalcCorrectVal(){
|
||||
Shipment shipment = Shipment.Builder.newInstance("s", 1).setPickupLocation("0,10").setDeliveryLocation("10,0").build();
|
||||
Shipment shipment2 = Shipment.Builder.newInstance("s2", 1).setPickupLocation("10,10").setDeliveryLocation("0,0").build();
|
||||
Shipment shipment3 = Shipment.Builder.newInstance("s3", 1).setPickupLocation("0,0").setDeliveryLocation("9,10").build();
|
||||
Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation("0,10").setDeliveryLocation("10,0").build();
|
||||
Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation("10,10").setDeliveryLocation("0,0").build();
|
||||
Shipment shipment3 = Shipment.Builder.newInstance("s3").addSizeDimension(0, 1).setPickupLocation("0,0").setDeliveryLocation("9,10").build();
|
||||
|
||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||
Inserter inserter = new Inserter(new InsertionListeners());
|
||||
|
|
@ -160,9 +148,9 @@ public class ShipmentInsertionCalculatorTest {
|
|||
|
||||
@Test
|
||||
public void whenInsertingThirdShipment_itShouldCalcCorrectVal2(){
|
||||
Shipment shipment = Shipment.Builder.newInstance("s", 1).setPickupLocation("0,10").setDeliveryLocation("10,0").build();
|
||||
Shipment shipment2 = Shipment.Builder.newInstance("s2", 1).setPickupLocation("10,10").setDeliveryLocation("0,0").build();
|
||||
Shipment shipment3 = Shipment.Builder.newInstance("s3", 1).setPickupLocation("0,0").setDeliveryLocation("9,9").build();
|
||||
Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation("0,10").setDeliveryLocation("10,0").build();
|
||||
Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation("10,10").setDeliveryLocation("0,0").build();
|
||||
Shipment shipment3 = Shipment.Builder.newInstance("s3").addSizeDimension(0, 1).setPickupLocation("0,0").setDeliveryLocation("9,9").build();
|
||||
|
||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||
Inserter inserter = new Inserter(new InsertionListeners());
|
||||
|
|
@ -177,9 +165,9 @@ public class ShipmentInsertionCalculatorTest {
|
|||
|
||||
@Test
|
||||
public void whenInstertingShipmentWithLoadConstraintWhereCapIsNotSufficient_capConstraintsAreFulfilled(){
|
||||
Shipment shipment = Shipment.Builder.newInstance("s", 1).setPickupLocation("0,10").setDeliveryLocation("10,0").build();
|
||||
Shipment shipment2 = Shipment.Builder.newInstance("s2", 1).setPickupLocation("10,10").setDeliveryLocation("0,0").build();
|
||||
Shipment shipment3 = Shipment.Builder.newInstance("s3", 1).setPickupLocation("0,0").setDeliveryLocation("9,9").build();
|
||||
Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation("0,10").setDeliveryLocation("10,0").build();
|
||||
Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation("10,10").setDeliveryLocation("0,0").build();
|
||||
Shipment shipment3 = Shipment.Builder.newInstance("s3").addSizeDimension(0, 1).setPickupLocation("0,0").setDeliveryLocation("9,9").build();
|
||||
|
||||
|
||||
|
||||
|
|
@ -193,7 +181,7 @@ public class ShipmentInsertionCalculatorTest {
|
|||
|
||||
VehicleRoutingProblem vrp = mock(VehicleRoutingProblem.class);
|
||||
|
||||
StateManager stateManager = new StateManager(vrp);
|
||||
StateManager stateManager = new StateManager(vrp.getTransportCosts());
|
||||
stateManager.updateLoadStates();
|
||||
stateManager.informInsertionStarts(Arrays.asList(route), null);
|
||||
|
||||
|
|
@ -212,8 +200,8 @@ public class ShipmentInsertionCalculatorTest {
|
|||
|
||||
@Test
|
||||
public void whenInsertingServiceWhileNoCapIsAvailable_itMustReturnNoInsertionData(){
|
||||
Shipment shipment = Shipment.Builder.newInstance("s", 1).setPickupLocation("0,10").setDeliveryLocation("0,0").build();
|
||||
Shipment shipment2 = Shipment.Builder.newInstance("s2", 1).setPickupLocation("10,10").setDeliveryLocation("0,0").build();
|
||||
Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation("0,10").setDeliveryLocation("0,0").build();
|
||||
Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation("10,10").setDeliveryLocation("0,0").build();
|
||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||
route.setVehicleAndDepartureTime(vehicle, 0.0);
|
||||
|
||||
|
|
@ -225,16 +213,10 @@ public class ShipmentInsertionCalculatorTest {
|
|||
|
||||
VehicleRoutingProblem vrp = mock(VehicleRoutingProblem.class);
|
||||
|
||||
StateManager stateManager = new StateManager(vrp);
|
||||
StateManager stateManager = new StateManager(vrp.getTransportCosts());
|
||||
stateManager.updateLoadStates();
|
||||
stateManager.informInsertionStarts(Arrays.asList(route), null);
|
||||
|
||||
// RouteActivityVisitor routeActVisitor = new RouteActivityVisitor();
|
||||
// routeActVisitor.addActivityVisitor(new UpdateLoads(stateManager));
|
||||
// routeActVisitor.visit(route);
|
||||
|
||||
|
||||
|
||||
|
||||
ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager);
|
||||
constraintManager.addLoadConstraint();
|
||||
// constraintManager.addConstraint(new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager),Priority.CRITICAL);
|
||||
|
|
@ -246,9 +228,11 @@ public class ShipmentInsertionCalculatorTest {
|
|||
ServiceInsertionCalculator serviceInsertionCalc = new ServiceInsertionCalculator(routingCosts, activityInsertionCostsCalculator, constraintManager);
|
||||
ShipmentInsertionCalculator insertionCalculator = new ShipmentInsertionCalculator(routingCosts, activityInsertionCostsCalculator, constraintManager);
|
||||
switcher.put(Pickup.class, serviceInsertionCalc);
|
||||
switcher.put(Service.class, serviceInsertionCalc);
|
||||
switcher.put(Shipment.class, insertionCalculator);
|
||||
|
||||
Pickup service = (Pickup)Pickup.Builder.newInstance("pick", 1).setLocationId("5,5").build();
|
||||
// Service service = Service.Builder.newInstance("pick", 1).setLocationId("5,5").build();
|
||||
Pickup service = (Pickup)Pickup.Builder.newInstance("pick").addSizeDimension(0, 1).setLocationId("5,5").build();
|
||||
InsertionData iData = switcher.getInsertionData(route, service, vehicle, 0, DriverImpl.noDriver(), Double.MAX_VALUE);
|
||||
// routeActVisitor.visit(route);
|
||||
|
||||
|
|
|
|||
|
|
@ -84,10 +84,10 @@ public class TestCalculatesServiceInsertion {
|
|||
public void setup(){
|
||||
Logger.getRootLogger().setLevel(Level.DEBUG);
|
||||
|
||||
VehicleType t1 = VehicleTypeImpl.Builder.newInstance("t1", 1000).setCostPerDistance(1.0).build();
|
||||
VehicleType t1 = VehicleTypeImpl.Builder.newInstance("t1").addCapacityDimension(0, 1000).setCostPerDistance(1.0).build();
|
||||
vehicle = VehicleImpl.Builder.newInstance("vehicle").setLatestArrival(100.0).setStartLocationId("0,0").setType(t1).build();
|
||||
|
||||
VehicleType t2 = VehicleTypeImpl.Builder.newInstance("t2", 1000).setCostPerDistance(2.0).build();
|
||||
VehicleType t2 = VehicleTypeImpl.Builder.newInstance("t2").addCapacityDimension(0, 1000).setCostPerDistance(2.0).build();
|
||||
newVehicle = VehicleImpl.Builder.newInstance("newVehicle").setLatestArrival(100.0).setStartLocationId("0,0").setType(t2).build();
|
||||
|
||||
driver = DriverImpl.noDriver();
|
||||
|
|
@ -117,9 +117,9 @@ public class TestCalculatesServiceInsertion {
|
|||
};
|
||||
|
||||
|
||||
first = Service.Builder.newInstance("1", 0).setLocationId("0,10").setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build();
|
||||
second = Service.Builder.newInstance("2", 0).setLocationId("10,10").setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build();
|
||||
third = Service.Builder.newInstance("3", 0).setLocationId("10,0").setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build();
|
||||
first = Service.Builder.newInstance("1").addSizeDimension(0, 0).setLocationId("0,10").setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build();
|
||||
second = Service.Builder.newInstance("2").addSizeDimension(0, 0).setLocationId("10,10").setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build();
|
||||
third = Service.Builder.newInstance("3").addSizeDimension(0, 0).setLocationId("10,0").setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build();
|
||||
|
||||
Collection<Job> jobs = new ArrayList<Job>();
|
||||
jobs.add(first);
|
||||
|
|
@ -128,7 +128,7 @@ public class TestCalculatesServiceInsertion {
|
|||
|
||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addAllJobs(jobs).addVehicle(vehicle).setRoutingCost(costs).build();
|
||||
|
||||
states = new StateManager(vrp);
|
||||
states = new StateManager(vrp.getTransportCosts());
|
||||
states.updateLoadStates();
|
||||
states.updateTimeWindowStates();
|
||||
|
||||
|
|
@ -214,7 +214,7 @@ public class TestCalculatesServiceInsertion {
|
|||
public void whenInsertingJobAndCurrRouteIsEmpty_accessEggressCalcShouldReturnZero(){
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(VehicleImpl.createNoVehicle(), DriverImpl.noDriver()).build();
|
||||
AdditionalAccessEgressCalculator accessEgressCalc = new AdditionalAccessEgressCalculator(costs);
|
||||
Job job = Service.Builder.newInstance("1", 0).setLocationId("1").setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build();
|
||||
Job job = Service.Builder.newInstance("1").addSizeDimension(0, 0).setLocationId("1").setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build();
|
||||
JobInsertionContext iContex = new JobInsertionContext(route, job, newVehicle, mock(Driver.class), 0.0);
|
||||
assertEquals(0.0, accessEgressCalc.getCosts(iContex),0.01);
|
||||
}
|
||||
|
|
@ -252,13 +252,13 @@ public class TestCalculatesServiceInsertion {
|
|||
Vehicle oldVehicle = VehicleImpl.Builder.newInstance("oldV").setStartLocationId("oldV").build();
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(oldVehicle, DriverImpl.noDriver())
|
||||
.addService(Service.Builder.newInstance("service", 0).setLocationId("service").build())
|
||||
.addService(Service.Builder.newInstance("service").addSizeDimension(0, 0).setLocationId("service").build())
|
||||
.build();
|
||||
|
||||
Vehicle newVehicle = VehicleImpl.Builder.newInstance("newV").setStartLocationId("newV").build();
|
||||
|
||||
AdditionalAccessEgressCalculator accessEgressCalc = new AdditionalAccessEgressCalculator(routingCosts);
|
||||
Job job = Service.Builder.newInstance("service2", 0).setLocationId("service").build();
|
||||
Job job = Service.Builder.newInstance("service2").addSizeDimension(0, 0).setLocationId("service").build();
|
||||
JobInsertionContext iContex = new JobInsertionContext(route, job, newVehicle, mock(Driver.class), 0.0);
|
||||
assertEquals(8.0, accessEgressCalc.getCosts(iContex),0.01);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import java.util.Collection;
|
|||
import jsprit.core.algorithm.ExampleActivityCostFunction;
|
||||
import jsprit.core.algorithm.state.StateManager;
|
||||
import jsprit.core.algorithm.state.UpdateVariableCosts;
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.constraint.ConstraintManager;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
|
|
@ -41,6 +42,7 @@ import jsprit.core.problem.solution.route.activity.TimeWindow;
|
|||
import jsprit.core.problem.solution.route.activity.TourActivities;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleType;
|
||||
import jsprit.core.util.Coordinate;
|
||||
import jsprit.core.util.ManhattanDistanceCalculator;
|
||||
|
||||
|
|
@ -78,7 +80,11 @@ public class TestCalculatesServiceInsertionOnRouteLevel {
|
|||
|
||||
costs = mock(VehicleRoutingTransportCosts.class);
|
||||
vehicle = mock(Vehicle.class);
|
||||
when(vehicle.getCapacity()).thenReturn(1000);
|
||||
VehicleType type = mock(VehicleType.class);
|
||||
|
||||
when(type.getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1000).build());
|
||||
|
||||
when(vehicle.getType()).thenReturn(type);
|
||||
when(vehicle.getStartLocationId()).thenReturn("0,0");
|
||||
when(vehicle.getEndLocationId()).thenReturn("0,0");
|
||||
when(vehicle.getEarliestDeparture()).thenReturn(0.0);
|
||||
|
|
@ -86,7 +92,7 @@ public class TestCalculatesServiceInsertionOnRouteLevel {
|
|||
when(vehicle.isReturnToDepot()).thenReturn(true);
|
||||
|
||||
newVehicle = mock(Vehicle.class);
|
||||
when(newVehicle.getCapacity()).thenReturn(1000);
|
||||
when(newVehicle.getType()).thenReturn(type);
|
||||
when(newVehicle.getStartLocationId()).thenReturn("0,0");
|
||||
when(newVehicle.getEndLocationId()).thenReturn("0,0");
|
||||
when(newVehicle.getEarliestDeparture()).thenReturn(0.0);
|
||||
|
|
@ -140,9 +146,9 @@ public class TestCalculatesServiceInsertionOnRouteLevel {
|
|||
};
|
||||
|
||||
|
||||
first = Service.Builder.newInstance("1", 0).setLocationId("0,10").setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build();
|
||||
second = Service.Builder.newInstance("3", 0).setLocationId("10,0").setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build();
|
||||
third = Service.Builder.newInstance("2", 0).setLocationId("10,10").setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build();
|
||||
first = Service.Builder.newInstance("1").setLocationId("0,10").setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build();
|
||||
second = Service.Builder.newInstance("3").setLocationId("10,0").setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build();
|
||||
third = Service.Builder.newInstance("2").setLocationId("10,10").setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build();
|
||||
Collection<Job> jobs = new ArrayList<Job>();
|
||||
jobs.add(first);
|
||||
jobs.add(second);
|
||||
|
|
@ -150,7 +156,7 @@ public class TestCalculatesServiceInsertionOnRouteLevel {
|
|||
|
||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addAllJobs(jobs).addVehicle(vehicle).addVehicle(newVehicle).setRoutingCost(costs).build();
|
||||
|
||||
states = new StateManager(vrp);
|
||||
states = new StateManager(vrp.getTransportCosts());
|
||||
states.updateLoadStates();
|
||||
states.updateTimeWindowStates();
|
||||
states.addStateUpdater(new UpdateVariableCosts(vrp.getActivityCosts(), vrp.getTransportCosts(), states));
|
||||
|
|
|
|||
|
|
@ -44,9 +44,9 @@ public class TestDepartureTimeOpt {
|
|||
@Test
|
||||
public void whenSettingOneCustWithTWAnd_NO_DepTimeChoice_totalCostsShouldBe50(){
|
||||
TimeWindow timeWindow = TimeWindow.newInstance(40, 45);
|
||||
Service service = Service.Builder.newInstance("s", 0).setLocationId("servLoc").setCoord(Coordinate.newInstance(0, 10)).setTimeWindow(timeWindow).build();
|
||||
Service service = Service.Builder.newInstance("s").setLocationId("servLoc").setCoord(Coordinate.newInstance(0, 10)).setTimeWindow(timeWindow).build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("vehLoc").setStartLocationCoordinate(Coordinate.newInstance(0, 0))
|
||||
.setType(VehicleTypeImpl.Builder.newInstance("vType", 0).build()).build();
|
||||
.setType(VehicleTypeImpl.Builder.newInstance("vType").build()).build();
|
||||
|
||||
Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
vrpBuilder.setActivityCosts(new VehicleRoutingActivityCosts(){
|
||||
|
|
@ -71,9 +71,9 @@ public class TestDepartureTimeOpt {
|
|||
@Test
|
||||
public void whenSettingOneCustWithTWAnd_NO_DepTimeChoice_depTimeShouldBe0(){
|
||||
TimeWindow timeWindow = TimeWindow.newInstance(40, 45);
|
||||
Service service = Service.Builder.newInstance("s", 0).setLocationId("servLoc").setCoord(Coordinate.newInstance(0, 10)).setTimeWindow(timeWindow).build();
|
||||
Service service = Service.Builder.newInstance("s").setLocationId("servLoc").setCoord(Coordinate.newInstance(0, 10)).setTimeWindow(timeWindow).build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("vehLoc").setStartLocationCoordinate(Coordinate.newInstance(0, 0))
|
||||
.setType(VehicleTypeImpl.Builder.newInstance("vType", 0).build()).build();
|
||||
.setType(VehicleTypeImpl.Builder.newInstance("vType").build()).build();
|
||||
|
||||
Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
vrpBuilder.setActivityCosts(new VehicleRoutingActivityCosts(){
|
||||
|
|
@ -98,9 +98,9 @@ public class TestDepartureTimeOpt {
|
|||
@Test
|
||||
public void whenSettingOneCustWithTWAndDepTimeChoice_totalCostsShouldBe50(){
|
||||
TimeWindow timeWindow = TimeWindow.newInstance(40, 45);
|
||||
Service service = Service.Builder.newInstance("s", 0).setLocationId("servLoc").setCoord(Coordinate.newInstance(0, 10)).setTimeWindow(timeWindow).build();
|
||||
Service service = Service.Builder.newInstance("s").setLocationId("servLoc").setCoord(Coordinate.newInstance(0, 10)).setTimeWindow(timeWindow).build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("vehLoc").setStartLocationCoordinate(Coordinate.newInstance(0, 0))
|
||||
.setType(VehicleTypeImpl.Builder.newInstance("vType", 0).build()).build();
|
||||
.setType(VehicleTypeImpl.Builder.newInstance("vType").build()).build();
|
||||
|
||||
Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
vrpBuilder.setActivityCosts(new VehicleRoutingActivityCosts(){
|
||||
|
|
@ -126,9 +126,9 @@ public class TestDepartureTimeOpt {
|
|||
@Test
|
||||
public void whenSettingOneCustWithTWAndDepTimeChoice_depTimeShouldBe0(){
|
||||
TimeWindow timeWindow = TimeWindow.newInstance(40, 45);
|
||||
Service service = Service.Builder.newInstance("s", 0).setLocationId("servLoc").setCoord(Coordinate.newInstance(0, 10)).setTimeWindow(timeWindow).build();
|
||||
Service service = Service.Builder.newInstance("s").setLocationId("servLoc").setCoord(Coordinate.newInstance(0, 10)).setTimeWindow(timeWindow).build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("vehLoc").setStartLocationCoordinate(Coordinate.newInstance(0, 0))
|
||||
.setType(VehicleTypeImpl.Builder.newInstance("vType", 0).build()).build();
|
||||
.setType(VehicleTypeImpl.Builder.newInstance("vType").build()).build();
|
||||
|
||||
Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
vrpBuilder.setActivityCosts(new VehicleRoutingActivityCosts(){
|
||||
|
|
@ -154,13 +154,13 @@ public class TestDepartureTimeOpt {
|
|||
@Test
|
||||
public void whenSettingTwoCustWithTWAndDepTimeChoice_totalCostsShouldBe50(){
|
||||
TimeWindow timeWindow = TimeWindow.newInstance(40, 45);
|
||||
Service service = Service.Builder.newInstance("s", 0).setLocationId("servLoc").setCoord(Coordinate.newInstance(0, 10)).setTimeWindow(timeWindow).build();
|
||||
Service service = Service.Builder.newInstance("s").setLocationId("servLoc").setCoord(Coordinate.newInstance(0, 10)).setTimeWindow(timeWindow).build();
|
||||
|
||||
Service service2 = Service.Builder.newInstance("s2", 0).setLocationId("servLoc2").setCoord(Coordinate.newInstance(0, 20)).
|
||||
Service service2 = Service.Builder.newInstance("s2").setLocationId("servLoc2").setCoord(Coordinate.newInstance(0, 20)).
|
||||
setTimeWindow(TimeWindow.newInstance(30, 40)).build();
|
||||
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("vehLoc").setStartLocationCoordinate(Coordinate.newInstance(0, 0))
|
||||
.setType(VehicleTypeImpl.Builder.newInstance("vType", 0).build()).build();
|
||||
.setType(VehicleTypeImpl.Builder.newInstance("vType").build()).build();
|
||||
|
||||
Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
vrpBuilder.setActivityCosts(new VehicleRoutingActivityCosts(){
|
||||
|
|
@ -186,13 +186,13 @@ public class TestDepartureTimeOpt {
|
|||
@Test
|
||||
public void whenSettingTwoCustWithTWAndDepTimeChoice_depTimeShouldBe10(){
|
||||
TimeWindow timeWindow = TimeWindow.newInstance(40, 45);
|
||||
Service service = Service.Builder.newInstance("s", 0).setLocationId("servLoc").setCoord(Coordinate.newInstance(0, 10)).setTimeWindow(timeWindow).build();
|
||||
Service service = Service.Builder.newInstance("s").setLocationId("servLoc").setCoord(Coordinate.newInstance(0, 10)).setTimeWindow(timeWindow).build();
|
||||
|
||||
Service service2 = Service.Builder.newInstance("s2", 0).setLocationId("servLoc2").setCoord(Coordinate.newInstance(0, 20)).
|
||||
Service service2 = Service.Builder.newInstance("s2").setLocationId("servLoc2").setCoord(Coordinate.newInstance(0, 20)).
|
||||
setTimeWindow(TimeWindow.newInstance(30, 40)).build();
|
||||
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("vehLoc").setStartLocationCoordinate(Coordinate.newInstance(0, 0))
|
||||
.setType(VehicleTypeImpl.Builder.newInstance("vType", 0).build()).build();
|
||||
.setType(VehicleTypeImpl.Builder.newInstance("vType").build()).build();
|
||||
|
||||
Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
vrpBuilder.setActivityCosts(new VehicleRoutingActivityCosts(){
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import static org.mockito.Mockito.mock;
|
|||
import static org.mockito.Mockito.when;
|
||||
import jsprit.core.algorithm.recreate.listener.InsertionListeners;
|
||||
import jsprit.core.algorithm.state.UpdateEndLocationIfRouteIsOpen;
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.problem.job.Shipment;
|
||||
|
|
@ -73,6 +74,8 @@ public class TestInserter {
|
|||
@Test
|
||||
public void whenInsertingShipmentAndRouteIsClosed_itInsertsCorrectly(){
|
||||
Shipment shipment = mock(Shipment.class);
|
||||
Capacity capacity = Capacity.Builder.newInstance().build();
|
||||
when(shipment.getSize()).thenReturn(capacity);
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.getStartLocationId()).thenReturn("vehLoc");
|
||||
when(vehicle.getEndLocationId()).thenReturn("vehLoc");
|
||||
|
|
@ -82,6 +85,7 @@ public class TestInserter {
|
|||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build();
|
||||
//start - pick(shipment) - del(shipment) - end
|
||||
Shipment shipmentToInsert = mock(Shipment.class);
|
||||
when(shipmentToInsert.getSize()).thenReturn(capacity);
|
||||
when(shipmentToInsert.getDeliveryLocation()).thenReturn("delLoc");
|
||||
when(shipmentToInsert.getPickupLocation()).thenReturn("pickLoc");
|
||||
InsertionData iData = mock(InsertionData.class);
|
||||
|
|
@ -101,6 +105,8 @@ public class TestInserter {
|
|||
@Test
|
||||
public void whenInsertingShipmentAndRouteIsOpen_itInsertsCorrectlyAndSwitchesEndLocation(){
|
||||
Shipment shipment = mock(Shipment.class);
|
||||
Capacity capacity = Capacity.Builder.newInstance().build();
|
||||
when(shipment.getSize()).thenReturn(capacity);
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.isReturnToDepot()).thenReturn(false);
|
||||
when(vehicle.getId()).thenReturn("vehId");
|
||||
|
|
@ -108,6 +114,7 @@ public class TestInserter {
|
|||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build();
|
||||
//start - pick(shipment) - del(shipment) - end
|
||||
Shipment shipmentToInsert = mock(Shipment.class);
|
||||
when(shipmentToInsert.getSize()).thenReturn(capacity);
|
||||
when(shipmentToInsert.getDeliveryLocation()).thenReturn("delLoc");
|
||||
when(shipmentToInsert.getPickupLocation()).thenReturn("pickLoc");
|
||||
InsertionData iData = mock(InsertionData.class);
|
||||
|
|
@ -127,12 +134,15 @@ public class TestInserter {
|
|||
@Test
|
||||
public void whenSwitchingVehicleAndRouteIsClosed_newStartAndEndShouldBeTheLocationOfNewVehicle(){
|
||||
Shipment shipment = mock(Shipment.class);
|
||||
Capacity capacity = Capacity.Builder.newInstance().build();
|
||||
when(shipment.getSize()).thenReturn(capacity);
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("vehId").setStartLocationId("vehLoc").setType(mock(VehicleType.class)).build();
|
||||
Vehicle newVehicle = VehicleImpl.Builder.newInstance("newVehId").setStartLocationId("newVehLoc").setType(mock(VehicleType.class)).build();
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build();
|
||||
//start - pick(shipment) - del(shipment) - end
|
||||
Shipment shipmentToInsert = mock(Shipment.class);
|
||||
when(shipmentToInsert.getSize()).thenReturn(capacity);
|
||||
when(shipmentToInsert.getDeliveryLocation()).thenReturn("delLoc");
|
||||
when(shipmentToInsert.getPickupLocation()).thenReturn("pickLoc");
|
||||
|
||||
|
|
@ -150,12 +160,15 @@ public class TestInserter {
|
|||
@Test
|
||||
public void whenSwitchingVehicleAndRouteIsOpen_endLocationShouldBeTheLocationOfTheLastActivity(){
|
||||
Shipment shipment = mock(Shipment.class);
|
||||
Capacity capacity = Capacity.Builder.newInstance().build();
|
||||
when(shipment.getSize()).thenReturn(capacity);
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("vehId").setReturnToDepot(false).setStartLocationId("vehLoc").setType(mock(VehicleType.class)).build();
|
||||
Vehicle newVehicle = VehicleImpl.Builder.newInstance("newVehId").setReturnToDepot(false).setStartLocationId("newVehLoc").setType(mock(VehicleType.class)).build();
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build();
|
||||
//start - pick(shipment) - del(shipment) - end
|
||||
Shipment shipmentToInsert = mock(Shipment.class);
|
||||
when(shipmentToInsert.getSize()).thenReturn(capacity);
|
||||
when(shipmentToInsert.getDeliveryLocation()).thenReturn("delLoc");
|
||||
when(shipmentToInsert.getPickupLocation()).thenReturn("pickLoc");
|
||||
|
||||
|
|
@ -173,6 +186,8 @@ public class TestInserter {
|
|||
@Test
|
||||
public void whenInsertingShipmentAtBeginningAndSwitchingVehicleAndRouteIsOpen_endLocationShouldBeTheLocationOfTheLastActivity(){
|
||||
Shipment shipment = mock(Shipment.class);
|
||||
Capacity capacity = Capacity.Builder.newInstance().build();
|
||||
when(shipment.getSize()).thenReturn(capacity);
|
||||
when(shipment.getDeliveryLocation()).thenReturn("oldShipmentDelLoc");
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("vehId").setReturnToDepot(false).setStartLocationId("vehLoc").setType(mock(VehicleType.class)).build();
|
||||
Vehicle newVehicle = VehicleImpl.Builder.newInstance("newVehId").setReturnToDepot(false).setStartLocationId("newVehLoc").setType(mock(VehicleType.class)).build();
|
||||
|
|
@ -180,6 +195,7 @@ public class TestInserter {
|
|||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build();
|
||||
//start - pick(shipment) - del(shipment) - end
|
||||
Shipment shipmentToInsert = mock(Shipment.class);
|
||||
when(shipmentToInsert.getSize()).thenReturn(capacity);
|
||||
when(shipmentToInsert.getDeliveryLocation()).thenReturn("delLoc");
|
||||
when(shipmentToInsert.getPickupLocation()).thenReturn("pickLoc");
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ public class TestMixedServiceAndShipmentsProblemOnRouteLevel {
|
|||
public void whenHavingShipmentsAndServicesInOneProblem_andInsertionShouldBeMadeOnRouteLevel_throwException(){
|
||||
/* get a vehicle type-builder and build a type with the typeId "vehicleType" and a capacity of 2
|
||||
*/
|
||||
VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType", 2);
|
||||
VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType").addCapacityDimension(0, 2);
|
||||
VehicleType vehicleType = vehicleTypeBuilder.build();
|
||||
|
||||
/*
|
||||
|
|
@ -49,11 +49,11 @@ public class TestMixedServiceAndShipmentsProblemOnRouteLevel {
|
|||
* 4: (15,13)->(14,11)
|
||||
*/
|
||||
|
||||
Shipment shipment1 = Shipment.Builder.newInstance("1", 1).setPickupCoord(Coordinate.newInstance(5, 7)).setDeliveryCoord(Coordinate.newInstance(6, 9)).build();
|
||||
Shipment shipment2 = Shipment.Builder.newInstance("2", 1).setPickupCoord(Coordinate.newInstance(5, 13)).setDeliveryCoord(Coordinate.newInstance(6, 11)).build();
|
||||
Shipment shipment1 = Shipment.Builder.newInstance("1").addSizeDimension(0, 1).setPickupCoord(Coordinate.newInstance(5, 7)).setDeliveryCoord(Coordinate.newInstance(6, 9)).build();
|
||||
Shipment shipment2 = Shipment.Builder.newInstance("2").addSizeDimension(0, 1).setPickupCoord(Coordinate.newInstance(5, 13)).setDeliveryCoord(Coordinate.newInstance(6, 11)).build();
|
||||
|
||||
Shipment shipment3 = Shipment.Builder.newInstance("3", 1).setPickupCoord(Coordinate.newInstance(15, 7)).setDeliveryCoord(Coordinate.newInstance(14, 9)).build();
|
||||
Shipment shipment4 = Shipment.Builder.newInstance("4", 1).setPickupCoord(Coordinate.newInstance(15, 13)).setDeliveryCoord(Coordinate.newInstance(14, 11)).build();
|
||||
Shipment shipment3 = Shipment.Builder.newInstance("3").addSizeDimension(0, 1).setPickupCoord(Coordinate.newInstance(15, 7)).setDeliveryCoord(Coordinate.newInstance(14, 9)).build();
|
||||
Shipment shipment4 = Shipment.Builder.newInstance("4").addSizeDimension(0, 1).setPickupCoord(Coordinate.newInstance(15, 13)).setDeliveryCoord(Coordinate.newInstance(14, 11)).build();
|
||||
|
||||
/*
|
||||
* build deliveries, (implicitly picked up in the depot)
|
||||
|
|
@ -62,10 +62,10 @@ public class TestMixedServiceAndShipmentsProblemOnRouteLevel {
|
|||
* 3: (16,8)
|
||||
* 4: (16,12)
|
||||
*/
|
||||
Delivery delivery1 = (Delivery) Delivery.Builder.newInstance("5", 1).setCoord(Coordinate.newInstance(4, 8)).build();
|
||||
Delivery delivery2 = (Delivery) Delivery.Builder.newInstance("6", 1).setCoord(Coordinate.newInstance(4, 12)).build();
|
||||
Delivery delivery3 = (Delivery) Delivery.Builder.newInstance("7", 1).setCoord(Coordinate.newInstance(16, 8)).build();
|
||||
Delivery delivery4 = (Delivery) Delivery.Builder.newInstance("8", 1).setCoord(Coordinate.newInstance(16, 12)).build();
|
||||
Delivery delivery1 = (Delivery) Delivery.Builder.newInstance("5").addSizeDimension(0, 1).setCoord(Coordinate.newInstance(4, 8)).build();
|
||||
Delivery delivery2 = (Delivery) Delivery.Builder.newInstance("6").addSizeDimension(0, 1).setCoord(Coordinate.newInstance(4, 12)).build();
|
||||
Delivery delivery3 = (Delivery) Delivery.Builder.newInstance("7").addSizeDimension(0, 1).setCoord(Coordinate.newInstance(16, 8)).build();
|
||||
Delivery delivery4 = (Delivery) Delivery.Builder.newInstance("8").addSizeDimension(0, 1).setCoord(Coordinate.newInstance(16, 12)).build();
|
||||
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
vrpBuilder.addVehicle(vehicle);
|
||||
|
|
@ -74,7 +74,7 @@ public class TestMixedServiceAndShipmentsProblemOnRouteLevel {
|
|||
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
|
||||
final StateManager stateManager = new StateManager(vrp);
|
||||
final StateManager stateManager = new StateManager(vrp.getTransportCosts());
|
||||
|
||||
|
||||
ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager);
|
||||
|
|
@ -94,7 +94,7 @@ public class TestMixedServiceAndShipmentsProblemOnRouteLevel {
|
|||
public void whenHavingOnlyServicesInOneProblem_andInsertionShouldBeMadeOnRouteLevel_itShouldAssertTrue(){
|
||||
/* get a vehicle type-builder and build a type with the typeId "vehicleType" and a capacity of 2
|
||||
*/
|
||||
VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType", 2);
|
||||
VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType").addCapacityDimension(0, 2);
|
||||
VehicleType vehicleType = vehicleTypeBuilder.build();
|
||||
|
||||
/*
|
||||
|
|
@ -127,10 +127,10 @@ public class TestMixedServiceAndShipmentsProblemOnRouteLevel {
|
|||
* 3: (16,8)
|
||||
* 4: (16,12)
|
||||
*/
|
||||
Delivery delivery1 = (Delivery) Delivery.Builder.newInstance("5", 1).setCoord(Coordinate.newInstance(4, 8)).build();
|
||||
Delivery delivery2 = (Delivery) Delivery.Builder.newInstance("6", 1).setCoord(Coordinate.newInstance(4, 12)).build();
|
||||
Delivery delivery3 = (Delivery) Delivery.Builder.newInstance("7", 1).setCoord(Coordinate.newInstance(16, 8)).build();
|
||||
Delivery delivery4 = (Delivery) Delivery.Builder.newInstance("8", 1).setCoord(Coordinate.newInstance(16, 12)).build();
|
||||
Delivery delivery1 = (Delivery) Delivery.Builder.newInstance("5").addSizeDimension(0, 1).setCoord(Coordinate.newInstance(4, 8)).build();
|
||||
Delivery delivery2 = (Delivery) Delivery.Builder.newInstance("6").addSizeDimension(0, 1).setCoord(Coordinate.newInstance(4, 12)).build();
|
||||
Delivery delivery3 = (Delivery) Delivery.Builder.newInstance("7").addSizeDimension(0, 1).setCoord(Coordinate.newInstance(16, 8)).build();
|
||||
Delivery delivery4 = (Delivery) Delivery.Builder.newInstance("8").addSizeDimension(0, 1).setCoord(Coordinate.newInstance(16, 12)).build();
|
||||
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
vrpBuilder.addVehicle(vehicle)
|
||||
|
|
@ -139,7 +139,7 @@ public class TestMixedServiceAndShipmentsProblemOnRouteLevel {
|
|||
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
|
||||
final StateManager stateManager = new StateManager(vrp);
|
||||
final StateManager stateManager = new StateManager(vrp.getTransportCosts());
|
||||
|
||||
ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager);
|
||||
constraintManager.addLoadConstraint();
|
||||
|
|
|
|||
|
|
@ -36,14 +36,14 @@ public class JobNeighborhoodsImplTest {
|
|||
@Before
|
||||
public void doBefore(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
target = Service.Builder.newInstance("s1", 1).setCoord(Coordinate.newInstance(0, 5)).build();
|
||||
s2 = Service.Builder.newInstance("s2", 1).setCoord(Coordinate.newInstance(0, 4)).build();
|
||||
s3 = Service.Builder.newInstance("s3", 1).setCoord(Coordinate.newInstance(0, 3)).build();
|
||||
s4 = Service.Builder.newInstance("s4", 1).setCoord(Coordinate.newInstance(0, 2)).build();
|
||||
target = Service.Builder.newInstance("s1").addSizeDimension(0, 1).setCoord(Coordinate.newInstance(0, 5)).build();
|
||||
s2 = Service.Builder.newInstance("s2").addSizeDimension(0, 1).setCoord(Coordinate.newInstance(0, 4)).build();
|
||||
s3 = Service.Builder.newInstance("s3").addSizeDimension(0, 1).setCoord(Coordinate.newInstance(0, 3)).build();
|
||||
s4 = Service.Builder.newInstance("s4").addSizeDimension(0, 1).setCoord(Coordinate.newInstance(0, 2)).build();
|
||||
|
||||
s5 = Service.Builder.newInstance("s5", 1).setCoord(Coordinate.newInstance(0, 6)).build();
|
||||
s6 = Service.Builder.newInstance("s6", 1).setCoord(Coordinate.newInstance(0, 7)).build();
|
||||
s7 = Service.Builder.newInstance("s7", 1).setCoord(Coordinate.newInstance(0, 8)).build();
|
||||
s5 = Service.Builder.newInstance("s5").addSizeDimension(0, 1).setCoord(Coordinate.newInstance(0, 6)).build();
|
||||
s6 = Service.Builder.newInstance("s6").addSizeDimension(0, 1).setCoord(Coordinate.newInstance(0, 7)).build();
|
||||
s7 = Service.Builder.newInstance("s7").addSizeDimension(0, 1).setCoord(Coordinate.newInstance(0, 8)).build();
|
||||
|
||||
vrp = builder.addJob(target).addJob(s2).addJob(s3).addJob(s4).addJob(s5).addJob(s6).addJob(s7).build();
|
||||
|
||||
|
|
|
|||
|
|
@ -36,14 +36,14 @@ public class JobNeighborhoodsWithCapRestrictionImplTest {
|
|||
@Before
|
||||
public void doBefore(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
target = Service.Builder.newInstance("s1", 1).setCoord(Coordinate.newInstance(0, 5)).build();
|
||||
s2 = Service.Builder.newInstance("s2", 1).setCoord(Coordinate.newInstance(0, 4)).build();
|
||||
s3 = Service.Builder.newInstance("s3", 1).setCoord(Coordinate.newInstance(0, 3)).build();
|
||||
s4 = Service.Builder.newInstance("s4", 1).setCoord(Coordinate.newInstance(0, 2)).build();
|
||||
target = Service.Builder.newInstance("s1").addSizeDimension(0, 1).setCoord(Coordinate.newInstance(0, 5)).build();
|
||||
s2 = Service.Builder.newInstance("s2").addSizeDimension(0, 1).setCoord(Coordinate.newInstance(0, 4)).build();
|
||||
s3 = Service.Builder.newInstance("s3").addSizeDimension(0, 1).setCoord(Coordinate.newInstance(0, 3)).build();
|
||||
s4 = Service.Builder.newInstance("s4").addSizeDimension(0, 1).setCoord(Coordinate.newInstance(0, 2)).build();
|
||||
|
||||
s5 = Service.Builder.newInstance("s5", 1).setCoord(Coordinate.newInstance(0, 6)).build();
|
||||
s6 = Service.Builder.newInstance("s6", 1).setCoord(Coordinate.newInstance(0, 7)).build();
|
||||
s7 = Service.Builder.newInstance("s7", 1).setCoord(Coordinate.newInstance(0, 8)).build();
|
||||
s5 = Service.Builder.newInstance("s5").addSizeDimension(0, 1).setCoord(Coordinate.newInstance(0, 6)).build();
|
||||
s6 = Service.Builder.newInstance("s6").addSizeDimension(0, 1).setCoord(Coordinate.newInstance(0, 7)).build();
|
||||
s7 = Service.Builder.newInstance("s7").addSizeDimension(0, 1).setCoord(Coordinate.newInstance(0, 8)).build();
|
||||
|
||||
vrp = builder.addJob(target).addJob(s2).addJob(s3).addJob(s4).addJob(s5).addJob(s6).addJob(s7).build();
|
||||
|
||||
|
|
|
|||
|
|
@ -37,15 +37,15 @@ public class AverageJobDistanceTest {
|
|||
|
||||
@Test
|
||||
public void distanceOfTwoEqualShipmentsShouldBeSmallerThanAnyOtherDistance(){
|
||||
Shipment s1 = Shipment.Builder.newInstance("s1", 1).setPickupLocation("0,0").setDeliveryLocation("10,10").build();
|
||||
Shipment s2 = Shipment.Builder.newInstance("s2", 1).setPickupLocation("0,0").setDeliveryLocation("10,10").build();
|
||||
Shipment s1 = Shipment.Builder.newInstance("s1").addSizeDimension(0, 1).setPickupLocation("0,0").setDeliveryLocation("10,10").build();
|
||||
Shipment s2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation("0,0").setDeliveryLocation("10,10").build();
|
||||
|
||||
double dist = new AvgServiceAndShipmentDistance(routingCosts).getDistance(s1, s2);
|
||||
|
||||
for(int i=0;i<10;i++){
|
||||
for(int j=0;j<10;j++){
|
||||
Shipment other1 = Shipment.Builder.newInstance("s1", 1).setPickupLocation("0,0").setDeliveryLocation(i+","+j).build();
|
||||
Shipment other2 = Shipment.Builder.newInstance("s2", 1).setPickupLocation("0,0").setDeliveryLocation("10,10").build();
|
||||
Shipment other1 = Shipment.Builder.newInstance("s1").addSizeDimension(0, 1).setPickupLocation("0,0").setDeliveryLocation(i+","+j).build();
|
||||
Shipment other2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation("0,0").setDeliveryLocation("10,10").build();
|
||||
double dist2 = new AvgServiceAndShipmentDistance(routingCosts).getDistance(other1, other2);
|
||||
System.out.println("("+i+","+j+"), dist=" + dist + ", dist2=" + dist2);
|
||||
assertTrue(dist<=dist2+dist2*0.001);
|
||||
|
|
@ -57,8 +57,8 @@ public class AverageJobDistanceTest {
|
|||
|
||||
@Test
|
||||
public void whenServicesHaveSameLocation_distanceShouldBeZero(){
|
||||
Service s1 = Service.Builder.newInstance("s1", 1).setLocationId("10,0").build();
|
||||
Service s2 = Service.Builder.newInstance("s2", 1).setLocationId("10,0").build();
|
||||
Service s1 = Service.Builder.newInstance("s1").addSizeDimension(0, 1).setLocationId("10,0").build();
|
||||
Service s2 = Service.Builder.newInstance("s2").addSizeDimension(0, 1).setLocationId("10,0").build();
|
||||
|
||||
double dist = new AvgServiceAndShipmentDistance(routingCosts).getDistance(s1, s2);
|
||||
assertEquals(0.0,dist,0.01);
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ public class TestJobDistanceAvgCosts {
|
|||
}
|
||||
};
|
||||
AvgServiceDistance c = new AvgServiceDistance(costs);
|
||||
c.getDistance(Service.Builder.newInstance("1", 1).setLocationId("foo").build(), Service.Builder.newInstance("2", 2).setLocationId("foo").build());
|
||||
c.getDistance(Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocationId("foo").build(), Service.Builder.newInstance("2").addSizeDimension(0, 2).setLocationId("foo").build());
|
||||
}
|
||||
|
||||
@Test(expected=NullPointerException.class)
|
||||
|
|
@ -96,7 +96,7 @@ public class TestJobDistanceAvgCosts {
|
|||
}
|
||||
};
|
||||
AvgServiceDistance c = new AvgServiceDistance(costs);
|
||||
c.getDistance(Service.Builder.newInstance("1", 1).setLocationId("loc").build(), Service.Builder.newInstance("2", 2).setLocationId("loc").build());
|
||||
c.getDistance(Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocationId("loc").build(), Service.Builder.newInstance("2").addSizeDimension(0, 2).setLocationId("loc").build());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,65 @@
|
|||
package jsprit.core.algorithm.state;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory.State;
|
||||
|
||||
public class GenericsTest {
|
||||
|
||||
|
||||
|
||||
// static class State<T> {
|
||||
// Class<T> type;
|
||||
// T state;
|
||||
// public State(Class<T> type, T state) {
|
||||
// super();
|
||||
// this.type = type;
|
||||
// this.state = state;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
static class States {
|
||||
|
||||
private Map<String,Object> states = new HashMap<String,Object>();
|
||||
|
||||
public <T> void putState(String id, Class<T> type, T state){
|
||||
states.put(id, type.cast(state));
|
||||
}
|
||||
|
||||
public <T> T getState(String id, Class<T> type){
|
||||
T s = type.cast(states.get(id));
|
||||
return s;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
States states = new States();
|
||||
states.putState("load", Double.class, 0.1);
|
||||
states.putState("state", String.class, "foo");
|
||||
states.putState("job", Job.class, Service.Builder.newInstance("foo").setLocationId("loc").build());
|
||||
states.putState("cap", Capacity.class, Capacity.Builder.newInstance().addDimension(0, 1).build());
|
||||
|
||||
Double load = states.getState("load", Double.class);
|
||||
String state = states.getState("state", String.class);
|
||||
Job service = states.getState("job", Job.class);
|
||||
Capacity capacity = states.getState("cap", Capacity.class);
|
||||
|
||||
states.putState("st", State.class, StateFactory.createState(10.));
|
||||
|
||||
System.out.println(load);
|
||||
System.out.println(state);
|
||||
System.out.println(service);
|
||||
System.out.println(capacity);
|
||||
System.out.println(states.getState("st", State.class).toDouble());
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -3,10 +3,10 @@ package jsprit.core.algorithm.state;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import jsprit.core.algorithm.state.StateManager;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.constraint.PickupAndDeliverShipmentLoadActivityLevelConstraint;
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.constraint.HardActivityStateLevelConstraint.ConstraintsStatus;
|
||||
import jsprit.core.problem.constraint.PickupAndDeliverShipmentLoadActivityLevelConstraint;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.problem.job.Shipment;
|
||||
import jsprit.core.problem.misc.JobInsertionContext;
|
||||
|
|
@ -15,6 +15,7 @@ import jsprit.core.problem.solution.route.activity.PickupService;
|
|||
import jsprit.core.problem.solution.route.activity.PickupShipment;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleType;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
|
@ -35,10 +36,16 @@ public class HardPickupAndDeliveryShipmentActivityConstraintTest {
|
|||
@Before
|
||||
public void doBefore(){
|
||||
vehicle = mock(Vehicle.class);
|
||||
when(vehicle.getCapacity()).thenReturn(2);
|
||||
stateManager = new StateManager(mock(VehicleRoutingProblem.class));
|
||||
// when(vehicle.getCapacity()).thenReturn(2);
|
||||
VehicleType type = mock(VehicleType.class);
|
||||
when(type.getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).build());
|
||||
when(vehicle.getType()).thenReturn(type);
|
||||
// when(vehicle.getType().getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).build());
|
||||
stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
shipment = mock(Shipment.class);
|
||||
when(shipment.getCapacityDemand()).thenReturn(1);
|
||||
when(shipment.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1).build());
|
||||
// when(shipment.getCapacityDemand()).thenReturn(1);
|
||||
|
||||
iFacts = new JobInsertionContext(null, null, vehicle, null, 0.0);
|
||||
constraint = new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager);
|
||||
}
|
||||
|
|
@ -58,7 +65,7 @@ public class HardPickupAndDeliveryShipmentActivityConstraintTest {
|
|||
PickupService anotherService = new PickupService(mock(Service.class));
|
||||
PickupShipment pickupShipment = new PickupShipment(shipment);
|
||||
|
||||
stateManager.putInternalActivityState(pickupService, StateFactory.LOAD, StateFactory.createState(2));
|
||||
stateManager.putInternalTypedActivityState(pickupService, StateFactory.LOAD, Capacity.class, Capacity.Builder.newInstance().addDimension(0, 2).build());
|
||||
// when(stateManager.getActivityState(pickupService, StateFactory.LOAD)).thenReturn(StateFactory.createState(2.0));
|
||||
assertEquals(ConstraintsStatus.NOT_FULFILLED,constraint.fulfilled(iFacts, pickupService, pickupShipment, anotherService, 0.0));
|
||||
}
|
||||
|
|
@ -69,7 +76,7 @@ public class HardPickupAndDeliveryShipmentActivityConstraintTest {
|
|||
PickupService anotherService = new PickupService(mock(Service.class));
|
||||
DeliverShipment pickupShipment = new DeliverShipment(shipment);
|
||||
|
||||
stateManager.putInternalActivityState(pickupService, StateFactory.LOAD, StateFactory.createState(2));
|
||||
stateManager.putInternalTypedActivityState(pickupService, StateFactory.LOAD, Capacity.class, Capacity.Builder.newInstance().addDimension(0, 2).build());
|
||||
assertEquals(ConstraintsStatus.NOT_FULFILLED_BREAK,constraint.fulfilled(iFacts, pickupService, pickupShipment, anotherService, 0.0));
|
||||
}
|
||||
|
||||
|
|
@ -79,7 +86,8 @@ public class HardPickupAndDeliveryShipmentActivityConstraintTest {
|
|||
PickupService anotherService = new PickupService(mock(Service.class));
|
||||
DeliverShipment pickupShipment = new DeliverShipment(shipment);
|
||||
|
||||
stateManager.putInternalActivityState(pickupService, StateFactory.LOAD, StateFactory.createState(1));
|
||||
stateManager.putInternalTypedActivityState(pickupService, StateFactory.LOAD, Capacity.class, Capacity.Builder.newInstance().addDimension(0, 1).build());
|
||||
// stateManager.putInternalActivityState(pickupService, StateFactory.LOAD, StateFactory.createState(1));
|
||||
assertEquals(ConstraintsStatus.FULFILLED,constraint.fulfilled(iFacts, pickupService, pickupShipment, anotherService, 0.0));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,146 @@
|
|||
package jsprit.core.algorithm.state;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory.State;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory.StateId;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class StateManagerTest {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void whenInternalRouteStateIsSet_itMustBeSetCorrectly(){
|
||||
VehicleRoute route = mock(VehicleRoute.class);
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
StateId id = StateFactory.createId("myState");
|
||||
State state = StateFactory.createState(1.);
|
||||
stateManager.putInternalRouteState(route, id, state);
|
||||
assertEquals(1.,stateManager.getRouteState(route, id).toDouble(),0.01);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void whenRouteStateIsSet_itMustBeSetCorrectly(){
|
||||
VehicleRoute route = mock(VehicleRoute.class);
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
StateId id = StateFactory.createId("myState");
|
||||
State state = StateFactory.createState(1.);
|
||||
stateManager.putRouteState(route, id, state);
|
||||
assertEquals(1.,stateManager.getRouteState(route, id).toDouble(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRouteStateIsSetWithGenericMethod_itMustBeSetCorrectly(){
|
||||
VehicleRoute route = mock(VehicleRoute.class);
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
StateId id = StateFactory.createId("myState");
|
||||
State state = StateFactory.createState(1.);
|
||||
stateManager.putTypedRouteState(route, id, State.class, state);
|
||||
assertEquals(1.,stateManager.getRouteState(route, id, State.class).toDouble(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRouteStateIsSetWithGenericMethodAndBoolean_itMustBeSetCorrectly(){
|
||||
VehicleRoute route = mock(VehicleRoute.class);
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
StateId id = StateFactory.createId("myState");
|
||||
boolean routeIsRed = true;
|
||||
stateManager.putTypedRouteState(route, id, Boolean.class, routeIsRed);
|
||||
assertTrue(stateManager.getRouteState(route, id, Boolean.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRouteStateIsSetWithGenericMethodAndInteger_itMustBeSetCorrectly(){
|
||||
VehicleRoute route = mock(VehicleRoute.class);
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
StateId id = StateFactory.createId("myState");
|
||||
int load = 3;
|
||||
stateManager.putTypedRouteState(route, id, Integer.class, load);
|
||||
int getLoad = stateManager.getRouteState(route, id, Integer.class);
|
||||
assertEquals(3, getLoad);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRouteStateIsSetWithGenericMethodAndCapacity_itMustBeSetCorrectly(){
|
||||
VehicleRoute route = mock(VehicleRoute.class);
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
StateId id = StateFactory.createId("myState");
|
||||
Capacity capacity = Capacity.Builder.newInstance().addDimension(0, 500).build();
|
||||
stateManager.putTypedRouteState(route, id, Capacity.class, capacity);
|
||||
Capacity getCap = stateManager.getRouteState(route, id, Capacity.class);
|
||||
assertEquals(500, getCap.get(0));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void whenInternalActivityStateIsSet_itMustBeSetCorrectly(){
|
||||
TourActivity activity = mock(TourActivity.class);
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
StateId id = StateFactory.createId("myState");
|
||||
State state = StateFactory.createState(1.);
|
||||
stateManager.putInternalActivityState(activity, id, state);
|
||||
assertEquals(1.,stateManager.getActivityState(activity, id).toDouble(),0.01);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void whenActivityStateIsSet_itMustBeSetCorrectly(){
|
||||
TourActivity activity = mock(TourActivity.class);
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
StateId id = StateFactory.createId("myState");
|
||||
State state = StateFactory.createState(1.);
|
||||
stateManager.putActivityState(activity, id, state);
|
||||
assertEquals(1.,stateManager.getActivityState(activity, id).toDouble(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenActivityStateIsSetWithGenericMethod_itMustBeSetCorrectly(){
|
||||
TourActivity activity = mock(TourActivity.class);
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
StateId id = StateFactory.createId("myState");
|
||||
State state = StateFactory.createState(1.);
|
||||
stateManager.putTypedActivityState(activity, id, State.class, state);
|
||||
assertEquals(1.,stateManager.getActivityState(activity, id, State.class).toDouble(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenActivityStateIsSetWithGenericMethodAndBoolean_itMustBeSetCorrectly(){
|
||||
TourActivity activity = mock(TourActivity.class);
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
StateId id = StateFactory.createId("myState");
|
||||
boolean routeIsRed = true;
|
||||
stateManager.putTypedActivityState(activity, id, Boolean.class, routeIsRed);
|
||||
assertTrue(stateManager.getActivityState(activity, id, Boolean.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenActivityStateIsSetWithGenericMethodAndInteger_itMustBeSetCorrectly(){
|
||||
TourActivity activity = mock(TourActivity.class);
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
StateId id = StateFactory.createId("myState");
|
||||
int load = 3;
|
||||
stateManager.putTypedActivityState(activity, id, Integer.class, load);
|
||||
int getLoad = stateManager.getActivityState(activity, id, Integer.class);
|
||||
assertEquals(3, getLoad);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenActivityStateIsSetWithGenericMethodAndCapacity_itMustBeSetCorrectly(){
|
||||
TourActivity activity = mock(TourActivity.class);
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
StateId id = StateFactory.createId("myState");
|
||||
Capacity capacity = Capacity.Builder.newInstance().addDimension(0, 500).build();
|
||||
stateManager.putTypedActivityState(activity, id, Capacity.class, capacity);
|
||||
Capacity getCap = stateManager.getActivityState(activity, id, Capacity.class);
|
||||
assertEquals(500, getCap.get(0));
|
||||
}
|
||||
}
|
||||
|
|
@ -22,6 +22,7 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
|
|
@ -36,14 +37,11 @@ import jsprit.core.problem.solution.route.state.StateFactory;
|
|||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleImpl;
|
||||
import jsprit.core.problem.vehicle.VehicleTypeImpl;
|
||||
import jsprit.core.util.Coordinate;
|
||||
import jsprit.core.util.ManhattanDistanceCalculator;
|
||||
import jsprit.core.util.CostFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
|
||||
public class TestTourStateUpdaterWithService {
|
||||
|
||||
TourActivities tour;
|
||||
|
|
@ -66,54 +64,56 @@ public class TestTourStateUpdaterWithService {
|
|||
@Before
|
||||
public void setUp() {
|
||||
|
||||
VehicleRoutingTransportCosts cost = new VehicleRoutingTransportCosts() {
|
||||
VehicleRoutingTransportCosts cost = CostFactory.createManhattanCosts();
|
||||
|
||||
// VehicleRoutingTransportCosts cost = new VehicleRoutingTransportCosts() {
|
||||
//
|
||||
// @Override
|
||||
// public double getBackwardTransportTime(String fromId, String toId,
|
||||
// double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||
// return getTransportCost(fromId, toId, arrivalTime, driver, vehicle);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public double getBackwardTransportCost(String fromId, String toId,
|
||||
// double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||
// return getTransportCost(fromId, toId, arrivalTime, driver, vehicle);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public double getTransportCost(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) {
|
||||
// String[] fromTokens = fromId.split(",");
|
||||
// String[] toTokens = toId.split(",");
|
||||
// double fromX = Double.parseDouble(fromTokens[0]);
|
||||
// double fromY = Double.parseDouble(fromTokens[1]);
|
||||
//
|
||||
// double toX = Double.parseDouble(toTokens[0]);
|
||||
// double toY = Double.parseDouble(toTokens[1]);
|
||||
//
|
||||
// return ManhattanDistanceCalculator.calculateDistance(new Coordinate(fromX, fromY), new Coordinate(toX, toY));
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public double getTransportTime(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) {
|
||||
// return getTransportCost(fromId, toId, departureTime, driver, vehicle);
|
||||
// }
|
||||
// };
|
||||
|
||||
@Override
|
||||
public double getBackwardTransportTime(String fromId, String toId,
|
||||
double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||
return getTransportCost(fromId, toId, arrivalTime, driver, vehicle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBackwardTransportCost(String fromId, String toId,
|
||||
double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||
return getTransportCost(fromId, toId, arrivalTime, driver, vehicle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTransportCost(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) {
|
||||
String[] fromTokens = fromId.split(",");
|
||||
String[] toTokens = toId.split(",");
|
||||
double fromX = Double.parseDouble(fromTokens[0]);
|
||||
double fromY = Double.parseDouble(fromTokens[1]);
|
||||
|
||||
double toX = Double.parseDouble(toTokens[0]);
|
||||
double toY = Double.parseDouble(toTokens[1]);
|
||||
|
||||
return ManhattanDistanceCalculator.calculateDistance(new Coordinate(fromX, fromY), new Coordinate(toX, toY));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTransportTime(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) {
|
||||
return getTransportCost(fromId, toId, departureTime, driver, vehicle);
|
||||
}
|
||||
};
|
||||
|
||||
Service firstService = Service.Builder.newInstance("1", 5).setLocationId("10,0").setTimeWindow(TimeWindow.newInstance(0, 20)).build();
|
||||
Service secondService = Service.Builder.newInstance("2", 5).setLocationId("0,10").setTimeWindow(TimeWindow.newInstance(0, 50)).build();
|
||||
Service firstService = Service.Builder.newInstance("1").addSizeDimension(0, 5).setLocationId("10,0").setTimeWindow(TimeWindow.newInstance(0, 20)).build();
|
||||
Service secondService = Service.Builder.newInstance("2").addSizeDimension(0, 5).setLocationId("0,10").setTimeWindow(TimeWindow.newInstance(0, 50)).build();
|
||||
|
||||
Collection<Job> services = new ArrayList<Job>();
|
||||
services.add(firstService);
|
||||
services.add(secondService);
|
||||
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("test", 10).build();
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("test").addCapacityDimension(0, 10).build();
|
||||
vehicle = VehicleImpl.Builder.newInstance("testvehicle").setType(type).setStartLocationId("0,0")
|
||||
.setEarliestStart(0.0).setLatestArrival(50.0).build();
|
||||
|
||||
|
||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addAllJobs(services).addVehicle(vehicle).setRoutingCost(cost).build();
|
||||
|
||||
states = new StateManager(vrp);
|
||||
states = new StateManager(vrp.getTransportCosts());
|
||||
states.updateLoadStates();
|
||||
states.updateTimeWindowStates();
|
||||
states.addStateUpdater(new UpdateVariableCosts(vrp.getActivityCosts(), vrp.getTransportCosts(), states));
|
||||
|
|
@ -130,8 +130,8 @@ public class TestTourStateUpdaterWithService {
|
|||
@Test
|
||||
public void testCalculatedCost() {
|
||||
states.informInsertionStarts(Arrays.asList(vehicleRoute), null);
|
||||
assertEquals(40.0, states.getRouteState(vehicleRoute,StateFactory.COSTS).toDouble(), 0.05);
|
||||
assertEquals(10, states.getRouteState(vehicleRoute, StateFactory.LOAD_AT_END).toDouble(), 0.05);
|
||||
assertEquals(40., states.getRouteState(vehicleRoute,StateFactory.COSTS, Double.class), 0.05);
|
||||
assertEquals(10, states.getRouteState(vehicleRoute, StateFactory.LOAD_AT_END, Capacity.class).get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -147,23 +147,23 @@ public class TestTourStateUpdaterWithService {
|
|||
@Test
|
||||
public void testStatesOfAct1(){
|
||||
states.informInsertionStarts(Arrays.asList(vehicleRoute), null);
|
||||
assertEquals(10.0, states.getActivityState(act1, StateFactory.COSTS).toDouble(),0.05);
|
||||
assertEquals(5.0, states.getActivityState(act1, StateFactory.LOAD).toDouble(),0.05);
|
||||
assertEquals(20.0, states.getActivityState(act1, StateFactory.LATEST_OPERATION_START_TIME).toDouble(),0.05);
|
||||
assertEquals(10.0, states.getActivityState(act1, StateFactory.COSTS, Double.class),0.05);
|
||||
assertEquals(5, states.getActivityState(act1, StateFactory.LOAD, Capacity.class).get(0),0.05);
|
||||
assertEquals(20.0, states.getActivityState(act1, StateFactory.LATEST_OPERATION_START_TIME, Double.class),0.05);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStatesOfAct2(){
|
||||
states.informInsertionStarts(Arrays.asList(vehicleRoute), null);
|
||||
assertEquals(30.0, states.getActivityState(act2, StateFactory.COSTS).toDouble(),0.05);
|
||||
assertEquals(10.0, states.getActivityState(act2, StateFactory.LOAD).toDouble(),0.05);
|
||||
assertEquals(40.0, states.getActivityState(act2, StateFactory.LATEST_OPERATION_START_TIME).toDouble(),0.05);
|
||||
assertEquals(30.0, states.getActivityState(act2, StateFactory.COSTS, Double.class),0.05);
|
||||
assertEquals(10, states.getActivityState(act2, StateFactory.LOAD, Capacity.class).get(0),0.05);
|
||||
assertEquals(40.0, states.getActivityState(act2, StateFactory.LATEST_OPERATION_START_TIME, Double.class),0.05);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStatesOfAct3(){
|
||||
states.informInsertionStarts(Arrays.asList(vehicleRoute), null);
|
||||
assertEquals(40.0, states.getRouteState(vehicleRoute, StateFactory.COSTS).toDouble(), 0.05);
|
||||
assertEquals(40.0, states.getRouteState(vehicleRoute, StateFactory.COSTS, Double.class), 0.05);
|
||||
assertEquals(40.0, vehicleRoute.getEnd().getArrTime(),0.05);
|
||||
assertEquals(50.0, vehicleRoute.getEnd().getTheoreticalLatestOperationStartTime(),0.05);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,390 @@
|
|||
package jsprit.core.algorithm.state;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.job.Delivery;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.job.Pickup;
|
||||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.problem.solution.route.RouteActivityVisitor;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleType;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class UpdateLoadsTest {
|
||||
|
||||
private Vehicle vehicle;
|
||||
|
||||
@Before
|
||||
public void doBefore(){
|
||||
vehicle = mock(Vehicle.class);
|
||||
VehicleType type = mock(VehicleType.class);
|
||||
when(type.getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10000)
|
||||
.addDimension(1, 10000)
|
||||
.addDimension(2, 10000)
|
||||
.addDimension(3, 10000)
|
||||
.addDimension(4, 10000)
|
||||
.addDimension(5, 10000).build());
|
||||
when(vehicle.getType()).thenReturn(type);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenVehicleRouteIsEmpty_loadsAtBeginningAndEndShouldBeZero(){
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
|
||||
UpdateLoads updateLoads = new UpdateLoads(stateManager);
|
||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||
|
||||
updateLoads.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
Capacity loadAtBeginning = stateManager.getRouteState(route, StateFactory.LOAD_AT_BEGINNING, Capacity.class);
|
||||
assertEquals(0.,loadAtBeginning.get(0),0.1);
|
||||
assertEquals(0.,stateManager.getRouteState(route, StateFactory.LOAD_AT_END, Capacity.class).get(0),0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenVehcicleRouteIsNotEmpty_loadsAtBeginningAndEndShouldBeCalculatedCorrectly(){
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
UpdateLoads updateLoads = new UpdateLoads(stateManager);
|
||||
|
||||
Service service = mock(Service.class);
|
||||
Capacity capacity = Capacity.Builder.newInstance().addDimension(0, 1).build();
|
||||
when(service.getSize()).thenReturn(capacity);
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(service).build();
|
||||
|
||||
updateLoads.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
assertEquals(0.,stateManager.getRouteState(route, StateFactory.LOAD_AT_BEGINNING, Capacity.class).get(0),0.1);
|
||||
assertEquals(1.,stateManager.getRouteState(route, StateFactory.LOAD_AT_END, Capacity.class).get(0),0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenVehcicleRouteIsNotEmpty_multipleLoadsAtBeginningAndEndShouldBeCalculatedCorrectly(){
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
UpdateLoads updateLoads = new UpdateLoads(stateManager);
|
||||
|
||||
Service service = mock(Service.class);
|
||||
Capacity capacity = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1,2).build();
|
||||
when(service.getSize()).thenReturn(capacity);
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(service).build();
|
||||
|
||||
updateLoads.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
assertEquals(0.,stateManager.getRouteState(route, StateFactory.LOAD_AT_BEGINNING, Capacity.class).get(0),0.1);
|
||||
assertEquals(0.,stateManager.getRouteState(route, StateFactory.LOAD_AT_BEGINNING, Capacity.class).get(1),0.1);
|
||||
assertEquals(1.,stateManager.getRouteState(route, StateFactory.LOAD_AT_END, Capacity.class).get(0),0.1);
|
||||
assertEquals(2.,stateManager.getRouteState(route, StateFactory.LOAD_AT_END, Capacity.class).get(1),0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenVehcicleRouteHasTwoActivities_loadsAtBeginningAndEndShouldBeCalculatedCorrectly(){
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
UpdateLoads updateLoads = new UpdateLoads(stateManager);
|
||||
|
||||
Service service = mock(Service.class);
|
||||
when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1).build());
|
||||
|
||||
Service service2 = mock(Service.class);
|
||||
when(service2.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10).build());
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(service).addService(service2).build();
|
||||
|
||||
updateLoads.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
assertEquals(0.,stateManager.getRouteState(route, StateFactory.LOAD_AT_BEGINNING, Capacity.class).get(0),0.1);
|
||||
assertEquals(11.,stateManager.getRouteState(route, StateFactory.LOAD_AT_END, Capacity.class).get(0),0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenVehcicleRouteHasTwoActivitiesWithMultipleCapDims_loadsAtBeginningAndEndShouldBeCalculatedCorrectly(){
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
UpdateLoads updateLoads = new UpdateLoads(stateManager);
|
||||
|
||||
Service service = mock(Service.class);
|
||||
when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 3).build());
|
||||
|
||||
Service service2 = mock(Service.class);
|
||||
when(service2.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10).addDimension(1, 14).build());
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(service).addService(service2).build();
|
||||
|
||||
updateLoads.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
assertEquals(0.,stateManager.getRouteState(route, StateFactory.LOAD_AT_BEGINNING, Capacity.class).get(0),0.1);
|
||||
assertEquals(0.,stateManager.getRouteState(route, StateFactory.LOAD_AT_BEGINNING, Capacity.class).get(1),0.1);
|
||||
assertEquals(11.,stateManager.getRouteState(route, StateFactory.LOAD_AT_END, Capacity.class).get(0),0.1);
|
||||
assertEquals(17.,stateManager.getRouteState(route, StateFactory.LOAD_AT_END, Capacity.class).get(1),0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenVehicleRouteHasTwoActivities_loadsAtActivitiesShouldBeCalculatedCorrectly(){
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
UpdateLoads updateLoads = new UpdateLoads(stateManager);
|
||||
|
||||
RouteActivityVisitor routeActivityVisitor = new RouteActivityVisitor();
|
||||
routeActivityVisitor.addActivityVisitor(updateLoads);
|
||||
|
||||
Service service = mock(Service.class);
|
||||
when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1).build());
|
||||
|
||||
Service service2 = mock(Service.class);
|
||||
when(service2.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10).build());
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(service).addService(service2).build();
|
||||
|
||||
routeActivityVisitor.visit(route);
|
||||
|
||||
assertEquals(1.,stateManager.getActivityState(route.getActivities().get(0), StateFactory.LOAD, Capacity.class).get(0),0.1);
|
||||
assertEquals(11.,stateManager.getActivityState(route.getActivities().get(1), StateFactory.LOAD, Capacity.class).get(0),0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenVehicleRouteHasTwoActivitiesWithMultipleCapDims_loadsAtActivitiesShouldBeCalculatedCorrectly(){
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
UpdateLoads updateLoads = new UpdateLoads(stateManager);
|
||||
|
||||
RouteActivityVisitor routeActivityVisitor = new RouteActivityVisitor();
|
||||
routeActivityVisitor.addActivityVisitor(updateLoads);
|
||||
|
||||
Service service = mock(Service.class);
|
||||
when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 3).build());
|
||||
|
||||
Service service2 = mock(Service.class);
|
||||
when(service2.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10).addDimension(1, 13).build());
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(service).addService(service2).build();
|
||||
|
||||
routeActivityVisitor.visit(route);
|
||||
|
||||
assertEquals(1.,stateManager.getActivityState(route.getActivities().get(0), StateFactory.LOAD, Capacity.class).get(0),0.1);
|
||||
assertEquals(3.,stateManager.getActivityState(route.getActivities().get(0), StateFactory.LOAD, Capacity.class).get(1),0.1);
|
||||
assertEquals(11.,stateManager.getActivityState(route.getActivities().get(1), StateFactory.LOAD, Capacity.class).get(0),0.1);
|
||||
assertEquals(16.,stateManager.getActivityState(route.getActivities().get(1), StateFactory.LOAD, Capacity.class).get(1),0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenVehcicleRouteHasPickupAndDelivery_loadsAtBeginningAndEndShouldBeCalculatedCorrectly(){
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
UpdateLoads updateLoads = new UpdateLoads(stateManager);
|
||||
|
||||
Pickup pickup = mock(Pickup.class);
|
||||
when(pickup.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1).build());
|
||||
|
||||
Delivery delivery = mock(Delivery.class);
|
||||
when(delivery.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10).build());
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(pickup).addService(delivery).build();
|
||||
|
||||
updateLoads.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
assertEquals(10.,stateManager.getRouteState(route, StateFactory.LOAD_AT_BEGINNING, Capacity.class).get(0),0.1);
|
||||
assertEquals(1.,stateManager.getRouteState(route, StateFactory.LOAD_AT_END, Capacity.class).get(0),0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenVehcicleRouteHasPickupAndDeliveryWithMultipleCapDims_loadsAtBeginningAndEndShouldBeCalculatedCorrectly(){
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
UpdateLoads updateLoads = new UpdateLoads(stateManager);
|
||||
|
||||
Pickup pickup = mock(Pickup.class);
|
||||
when(pickup.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 4).build());
|
||||
|
||||
Delivery delivery = mock(Delivery.class);
|
||||
when(delivery.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10).addDimension(1, 13).build());
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(pickup).addService(delivery).build();
|
||||
|
||||
updateLoads.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
assertEquals(10.,stateManager.getRouteState(route, StateFactory.LOAD_AT_BEGINNING, Capacity.class).get(0),0.1);
|
||||
assertEquals(13.,stateManager.getRouteState(route, StateFactory.LOAD_AT_BEGINNING, Capacity.class).get(1),0.1);
|
||||
assertEquals(1.,stateManager.getRouteState(route, StateFactory.LOAD_AT_END, Capacity.class).get(0),0.1);
|
||||
assertEquals(4.,stateManager.getRouteState(route, StateFactory.LOAD_AT_END, Capacity.class).get(1),0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenVehcicleRouteHasPickupAndDelivery_loadsAtActivitiesShouldBeCalculatedCorrectly(){
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
UpdateLoads updateLoads = new UpdateLoads(stateManager);
|
||||
|
||||
RouteActivityVisitor routeActivityVisitor = new RouteActivityVisitor();
|
||||
routeActivityVisitor.addActivityVisitor(updateLoads);
|
||||
|
||||
Pickup pickup = mock(Pickup.class);
|
||||
when(pickup.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1).build());
|
||||
|
||||
Delivery delivery = mock(Delivery.class);
|
||||
Capacity capacity2 = Capacity.Builder.newInstance().addDimension(0, 10).build();
|
||||
when(delivery.getSize()).thenReturn(capacity2);
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(pickup).addService(delivery).build();
|
||||
|
||||
updateLoads.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
routeActivityVisitor.visit(route);
|
||||
|
||||
assertEquals(11.,stateManager.getActivityState(route.getActivities().get(0), StateFactory.LOAD, Capacity.class).get(0),0.1);
|
||||
assertEquals(1.,stateManager.getActivityState(route.getActivities().get(1), StateFactory.LOAD, Capacity.class).get(0),0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenVehcicleRouteHasPickupAndDeliveryWithMultipleCapDims_loadsAtActivitiesShouldBeCalculatedCorrectly(){
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
UpdateLoads updateLoads = new UpdateLoads(stateManager);
|
||||
|
||||
RouteActivityVisitor routeActivityVisitor = new RouteActivityVisitor();
|
||||
routeActivityVisitor.addActivityVisitor(updateLoads);
|
||||
|
||||
Pickup pickup = mock(Pickup.class);
|
||||
when(pickup.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 4).build());
|
||||
|
||||
Delivery delivery = mock(Delivery.class);
|
||||
Capacity capacity2 = Capacity.Builder.newInstance().addDimension(0, 10).addDimension(1, 14).build();
|
||||
when(delivery.getSize()).thenReturn(capacity2);
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(pickup).addService(delivery).build();
|
||||
|
||||
updateLoads.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
routeActivityVisitor.visit(route);
|
||||
|
||||
assertEquals(11.,stateManager.getActivityState(route.getActivities().get(0), StateFactory.LOAD, Capacity.class).get(0),0.1);
|
||||
assertEquals(18.,stateManager.getActivityState(route.getActivities().get(0), StateFactory.LOAD, Capacity.class).get(1),0.1);
|
||||
assertEquals(1.,stateManager.getActivityState(route.getActivities().get(1), StateFactory.LOAD, Capacity.class).get(0),0.1);
|
||||
assertEquals(4.,stateManager.getActivityState(route.getActivities().get(1), StateFactory.LOAD, Capacity.class).get(1),0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenPickupIsInsertedIntoVehcicleRouteWithPickupAndDelivery_loadsAtBeginningAndEndShouldBeCalculatedCorrectly(){
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
UpdateLoads updateLoads = new UpdateLoads(stateManager);
|
||||
|
||||
RouteActivityVisitor routeActivityVisitor = new RouteActivityVisitor();
|
||||
routeActivityVisitor.addActivityVisitor(updateLoads);
|
||||
|
||||
Pickup pickup = mock(Pickup.class);
|
||||
when(pickup.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1).build());
|
||||
|
||||
Delivery delivery = mock(Delivery.class);
|
||||
Capacity capacity2 = Capacity.Builder.newInstance().addDimension(0, 10).build();
|
||||
when(delivery.getSize()).thenReturn(capacity2);
|
||||
|
||||
Pickup pickup2insert = mock(Pickup.class);
|
||||
when(pickup2insert.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).build());
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(pickup).addService(delivery).build();
|
||||
|
||||
updateLoads.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
updateLoads.informJobInserted(pickup2insert, route, 0., 0.);
|
||||
|
||||
assertEquals(10.,stateManager.getRouteState(route, StateFactory.LOAD_AT_BEGINNING, Capacity.class).get(0),0.1);
|
||||
assertEquals(3.,stateManager.getRouteState(route, StateFactory.LOAD_AT_END, Capacity.class).get(0),0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenPickupIsInsertedIntoVehcicleRouteWithPickupAndDeliveryWithMultipleCapDims_loadsAtBeginningAndEndShouldBeCalculatedCorrectly(){
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
UpdateLoads updateLoads = new UpdateLoads(stateManager);
|
||||
|
||||
RouteActivityVisitor routeActivityVisitor = new RouteActivityVisitor();
|
||||
routeActivityVisitor.addActivityVisitor(updateLoads);
|
||||
|
||||
Pickup pickup = mock(Pickup.class);
|
||||
when(pickup.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 3).build());
|
||||
|
||||
Delivery delivery = mock(Delivery.class);
|
||||
Capacity capacity2 = Capacity.Builder.newInstance().addDimension(0, 10).addDimension(1, 15).build();
|
||||
when(delivery.getSize()).thenReturn(capacity2);
|
||||
|
||||
Pickup pickup2insert = mock(Pickup.class);
|
||||
when(pickup2insert.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 4).build());
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(pickup).addService(delivery).build();
|
||||
|
||||
updateLoads.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
updateLoads.informJobInserted(pickup2insert, route, 0., 0.);
|
||||
|
||||
assertEquals(10.,stateManager.getRouteState(route, StateFactory.LOAD_AT_BEGINNING, Capacity.class).get(0),0.1);
|
||||
assertEquals(15.,stateManager.getRouteState(route, StateFactory.LOAD_AT_BEGINNING, Capacity.class).get(1),0.1);
|
||||
assertEquals(3.,stateManager.getRouteState(route, StateFactory.LOAD_AT_END, Capacity.class).get(0),0.1);
|
||||
assertEquals(7.,stateManager.getRouteState(route, StateFactory.LOAD_AT_END, Capacity.class).get(1),0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenDeliveryIsInsertedIntoVehcicleRouteWithPickupAndDelivery_loadsAtBeginningAndEndShouldBeCalculatedCorrectly(){
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
UpdateLoads updateLoads = new UpdateLoads(stateManager);
|
||||
|
||||
RouteActivityVisitor routeActivityVisitor = new RouteActivityVisitor();
|
||||
routeActivityVisitor.addActivityVisitor(updateLoads);
|
||||
|
||||
Pickup pickup = mock(Pickup.class);
|
||||
when(pickup.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1).build());
|
||||
|
||||
Delivery delivery = mock(Delivery.class);
|
||||
Capacity size = Capacity.Builder.newInstance().addDimension(0, 10).build();
|
||||
when(delivery.getSize()).thenReturn(size);
|
||||
|
||||
Delivery delivery2insert = mock(Delivery.class);
|
||||
Capacity size2 = Capacity.Builder.newInstance().addDimension(0, 20).build();
|
||||
when(delivery2insert.getSize()).thenReturn(size2);
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(pickup).addService(delivery).build();
|
||||
|
||||
updateLoads.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
updateLoads.informJobInserted(delivery2insert, route, 0., 0.);
|
||||
|
||||
assertEquals(30.,stateManager.getRouteState(route, StateFactory.LOAD_AT_BEGINNING,Capacity.class).get(0),0.1);
|
||||
assertEquals(1.,stateManager.getRouteState(route, StateFactory.LOAD_AT_END,Capacity.class).get(0),0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenDeliveryIsInsertedIntoVehcicleRouteWithPickupAndDeliveryWithMultipleCapDims_loadsAtBeginningAndEndShouldBeCalculatedCorrectly(){
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
UpdateLoads updateLoads = new UpdateLoads(stateManager);
|
||||
|
||||
RouteActivityVisitor routeActivityVisitor = new RouteActivityVisitor();
|
||||
routeActivityVisitor.addActivityVisitor(updateLoads);
|
||||
|
||||
Pickup pickup = mock(Pickup.class);
|
||||
when(pickup.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 3).build());
|
||||
|
||||
Delivery delivery = mock(Delivery.class);
|
||||
Capacity size = Capacity.Builder.newInstance().addDimension(0, 10).addDimension(1, 14).build();
|
||||
when(delivery.getSize()).thenReturn(size);
|
||||
|
||||
Delivery delivery2insert = mock(Delivery.class);
|
||||
Capacity size2 = Capacity.Builder.newInstance().addDimension(0, 20).addDimension(1, 25).build();
|
||||
when(delivery2insert.getSize()).thenReturn(size2);
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(pickup).addService(delivery).build();
|
||||
|
||||
updateLoads.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
updateLoads.informJobInserted(delivery2insert, route, 0., 0.);
|
||||
|
||||
assertEquals(30.,stateManager.getRouteState(route, StateFactory.LOAD_AT_BEGINNING,Capacity.class).get(0),0.1);
|
||||
assertEquals(39.,stateManager.getRouteState(route, StateFactory.LOAD_AT_BEGINNING,Capacity.class).get(1),0.1);
|
||||
assertEquals(1.,stateManager.getRouteState(route, StateFactory.LOAD_AT_END,Capacity.class).get(0),0.1);
|
||||
assertEquals(3.,stateManager.getRouteState(route, StateFactory.LOAD_AT_END,Capacity.class).get(1),0.1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,184 @@
|
|||
package jsprit.core.algorithm.state;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.job.Delivery;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.job.Pickup;
|
||||
import jsprit.core.problem.solution.route.ReverseRouteActivityVisitor;
|
||||
import jsprit.core.problem.solution.route.RouteActivityVisitor;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleType;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class UpdateMaxCapacityUtilizationAtActivitiesByLookingBackwardInRouteTest {
|
||||
|
||||
private Vehicle vehicle;
|
||||
|
||||
@Before
|
||||
public void doBefore(){
|
||||
vehicle = mock(Vehicle.class);
|
||||
VehicleType type = mock(VehicleType.class);
|
||||
when(type.getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10000)
|
||||
.addDimension(1, 10000)
|
||||
.addDimension(2, 10000)
|
||||
.addDimension(3, 10000)
|
||||
.addDimension(4, 10000)
|
||||
.addDimension(5, 10000).build());
|
||||
when(vehicle.getType()).thenReturn(type);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenVehicleRouteHasPickupAndDelivery_maxLoadAtEachActivityShouldBeCalculatedCorrectly(){
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
UpdateLoads updateLoad = new UpdateLoads(stateManager);
|
||||
UpdateMaxCapacityUtilisationAtActivitiesByLookingBackwardInRoute updateMaxLoad = new UpdateMaxCapacityUtilisationAtActivitiesByLookingBackwardInRoute(stateManager);
|
||||
|
||||
RouteActivityVisitor routeActivityVisitor = new RouteActivityVisitor();
|
||||
routeActivityVisitor.addActivityVisitor(updateLoad);
|
||||
routeActivityVisitor.addActivityVisitor(updateMaxLoad);
|
||||
|
||||
Pickup pickup = mock(Pickup.class);
|
||||
when(pickup.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1).build());
|
||||
|
||||
Delivery delivery = mock(Delivery.class);
|
||||
when(delivery.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10).build());
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(pickup).addService(delivery).build();
|
||||
|
||||
updateLoad.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
routeActivityVisitor.visit(route);
|
||||
|
||||
assertEquals(11,stateManager.getActivityState(route.getActivities().get(0), StateFactory.PAST_MAXLOAD, Capacity.class).get(0));
|
||||
assertEquals(11,stateManager.getActivityState(route.getActivities().get(1), StateFactory.PAST_MAXLOAD, Capacity.class).get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenVehicleRouteHasPickupAndDeliveryWithMultipleCapDims_futureMaxLoadAtEachActivityShouldBeCalculatedCorrectly(){
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
UpdateLoads updateLoad = new UpdateLoads(stateManager);
|
||||
UpdateMaxCapacityUtilisationAtActivitiesByLookingBackwardInRoute updateMaxLoad = new UpdateMaxCapacityUtilisationAtActivitiesByLookingBackwardInRoute(stateManager);
|
||||
|
||||
RouteActivityVisitor routeActivityVisitor = new RouteActivityVisitor();
|
||||
routeActivityVisitor.addActivityVisitor(updateLoad);
|
||||
routeActivityVisitor.addActivityVisitor(updateMaxLoad);
|
||||
|
||||
Pickup pickup = mock(Pickup.class);
|
||||
when(pickup.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1)
|
||||
.addDimension(1, 5).build());
|
||||
|
||||
Delivery delivery = mock(Delivery.class);
|
||||
when(delivery.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10)
|
||||
.addDimension(1, 3).build());
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(pickup).addService(delivery).build();
|
||||
|
||||
updateLoad.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
routeActivityVisitor.visit(route);
|
||||
|
||||
assertEquals(11,stateManager.getActivityState(route.getActivities().get(0), StateFactory.PAST_MAXLOAD, Capacity.class).get(0),0.1);
|
||||
assertEquals(8,stateManager.getActivityState(route.getActivities().get(0), StateFactory.PAST_MAXLOAD, Capacity.class).get(1),0.1);
|
||||
|
||||
assertEquals(11,stateManager.getActivityState(route.getActivities().get(1), StateFactory.PAST_MAXLOAD, Capacity.class).get(0),0.1);
|
||||
assertEquals(8,stateManager.getActivityState(route.getActivities().get(1), StateFactory.PAST_MAXLOAD, Capacity.class).get(1),0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenVehicleRouteHasPickupAndDeliveryAndPickupWithMultipleCapDims_futureMaxLoadAtEachActivityShouldBeCalculatedCorrectly(){
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
UpdateLoads updateLoad = new UpdateLoads(stateManager);
|
||||
UpdateMaxCapacityUtilisationAtActivitiesByLookingBackwardInRoute updateMaxLoad = new UpdateMaxCapacityUtilisationAtActivitiesByLookingBackwardInRoute(stateManager);
|
||||
|
||||
RouteActivityVisitor routeActivityVisitor = new RouteActivityVisitor();
|
||||
routeActivityVisitor.addActivityVisitor(updateLoad);
|
||||
routeActivityVisitor.addActivityVisitor(updateMaxLoad);
|
||||
|
||||
Pickup pickup = mock(Pickup.class);
|
||||
when(pickup.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1)
|
||||
.addDimension(1, 5).build());
|
||||
|
||||
Delivery delivery = mock(Delivery.class);
|
||||
when(delivery.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10)
|
||||
.addDimension(1, 3).build());
|
||||
|
||||
Pickup pickup2 = mock(Pickup.class);
|
||||
when(pickup2.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 3)
|
||||
.addDimension(1, 8).build());
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(pickup).addService(delivery).addService(pickup2).build();
|
||||
|
||||
updateLoad.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
routeActivityVisitor.visit(route);
|
||||
|
||||
assertEquals(11,stateManager.getActivityState(route.getActivities().get(0), StateFactory.PAST_MAXLOAD, Capacity.class).get(0));
|
||||
assertEquals(8,stateManager.getActivityState(route.getActivities().get(0), StateFactory.PAST_MAXLOAD, Capacity.class).get(1));
|
||||
|
||||
assertEquals(11,stateManager.getActivityState(route.getActivities().get(1), StateFactory.PAST_MAXLOAD, Capacity.class).get(0));
|
||||
assertEquals(8,stateManager.getActivityState(route.getActivities().get(1), StateFactory.PAST_MAXLOAD, Capacity.class).get(1));
|
||||
|
||||
assertEquals(11,stateManager.getActivityState(route.getActivities().get(2), StateFactory.PAST_MAXLOAD, Capacity.class).get(0));
|
||||
assertEquals(13,stateManager.getActivityState(route.getActivities().get(2), StateFactory.PAST_MAXLOAD, Capacity.class).get(1));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenVehicleRouteHasPickupAndDeliveryAndPickupWithMultipleCapDims_futureMaxLoadAtEachActivityShouldBeCalculatedCorrectly_v2(){
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
UpdateLoads updateLoad = new UpdateLoads(stateManager);
|
||||
UpdateMaxCapacityUtilisationAtActivitiesByLookingForwardInRoute updateMaxLoad = new UpdateMaxCapacityUtilisationAtActivitiesByLookingForwardInRoute(stateManager);
|
||||
|
||||
RouteActivityVisitor routeActivityVisitor = new RouteActivityVisitor();
|
||||
routeActivityVisitor.addActivityVisitor(updateLoad);
|
||||
|
||||
ReverseRouteActivityVisitor revRouteActivityVisitor = new ReverseRouteActivityVisitor();
|
||||
revRouteActivityVisitor.addActivityVisitor(updateMaxLoad);
|
||||
|
||||
Pickup pickup = mock(Pickup.class);
|
||||
when(pickup.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1)
|
||||
.addDimension(1, 5).build());
|
||||
|
||||
Delivery delivery = mock(Delivery.class);
|
||||
when(delivery.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10)
|
||||
.addDimension(1, 3).build());
|
||||
|
||||
Pickup pickup2 = mock(Pickup.class);
|
||||
when(pickup2.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 3)
|
||||
.addDimension(1, 8).addDimension(4, 29).build());
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(pickup).addService(delivery).addService(pickup2).build();
|
||||
|
||||
updateLoad.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
routeActivityVisitor.visit(route);
|
||||
revRouteActivityVisitor.visit(route);
|
||||
|
||||
assertEquals(11,stateManager.getActivityState(route.getActivities().get(0), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(0));
|
||||
assertEquals(13,stateManager.getActivityState(route.getActivities().get(0), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(1));
|
||||
assertEquals(29,stateManager.getActivityState(route.getActivities().get(0), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(4));
|
||||
|
||||
assertEquals(4,stateManager.getActivityState(route.getActivities().get(1), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(0));
|
||||
assertEquals(13,stateManager.getActivityState(route.getActivities().get(1), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(1));
|
||||
assertEquals(29,stateManager.getActivityState(route.getActivities().get(1), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(4));
|
||||
|
||||
assertEquals(4,stateManager.getActivityState(route.getActivities().get(2), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(0));
|
||||
assertEquals(13,stateManager.getActivityState(route.getActivities().get(2), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(1));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,191 @@
|
|||
package jsprit.core.algorithm.state;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.job.Delivery;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.job.Pickup;
|
||||
import jsprit.core.problem.solution.route.ReverseRouteActivityVisitor;
|
||||
import jsprit.core.problem.solution.route.RouteActivityVisitor;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleType;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class UpdateMaxCapacityUtilizationAtActivitiesByLookingForwardInRouteTest {
|
||||
|
||||
private Vehicle vehicle;
|
||||
|
||||
@Before
|
||||
public void doBefore(){
|
||||
vehicle = mock(Vehicle.class);
|
||||
VehicleType type = mock(VehicleType.class);
|
||||
when(type.getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10000)
|
||||
.addDimension(1, 10000)
|
||||
.addDimension(2, 10000)
|
||||
.addDimension(3, 10000)
|
||||
.addDimension(4, 10000)
|
||||
.addDimension(5, 10000).build());
|
||||
when(vehicle.getType()).thenReturn(type);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenVehicleRouteHasPickupAndDelivery_futureMaxLoadAtEachActivityShouldBeCalculatedCorrectly(){
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
UpdateLoads updateLoad = new UpdateLoads(stateManager);
|
||||
UpdateMaxCapacityUtilisationAtActivitiesByLookingForwardInRoute updateMaxLoad = new UpdateMaxCapacityUtilisationAtActivitiesByLookingForwardInRoute(stateManager);
|
||||
|
||||
RouteActivityVisitor routeActivityVisitor = new RouteActivityVisitor();
|
||||
routeActivityVisitor.addActivityVisitor(updateLoad);
|
||||
|
||||
ReverseRouteActivityVisitor revRouteActivityVisitor = new ReverseRouteActivityVisitor();
|
||||
revRouteActivityVisitor.addActivityVisitor(updateMaxLoad);
|
||||
|
||||
Pickup pickup = mock(Pickup.class);
|
||||
when(pickup.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1).build());
|
||||
|
||||
Delivery delivery = mock(Delivery.class);
|
||||
when(delivery.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10).build());
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(pickup).addService(delivery).build();
|
||||
|
||||
updateLoad.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
routeActivityVisitor.visit(route);
|
||||
revRouteActivityVisitor.visit(route);
|
||||
|
||||
assertEquals(11,stateManager.getActivityState(route.getActivities().get(0), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(0),0.1);
|
||||
assertEquals(1,stateManager.getActivityState(route.getActivities().get(1), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(0),0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenVehicleRouteHasPickupAndDeliveryWithMultipleCapDims_futureMaxLoadAtEachActivityShouldBeCalculatedCorrectly(){
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
UpdateLoads updateLoad = new UpdateLoads(stateManager);
|
||||
UpdateMaxCapacityUtilisationAtActivitiesByLookingForwardInRoute updateMaxLoad = new UpdateMaxCapacityUtilisationAtActivitiesByLookingForwardInRoute(stateManager);
|
||||
|
||||
RouteActivityVisitor routeActivityVisitor = new RouteActivityVisitor();
|
||||
routeActivityVisitor.addActivityVisitor(updateLoad);
|
||||
|
||||
ReverseRouteActivityVisitor revRouteActivityVisitor = new ReverseRouteActivityVisitor();
|
||||
revRouteActivityVisitor.addActivityVisitor(updateMaxLoad);
|
||||
|
||||
Pickup pickup = mock(Pickup.class);
|
||||
when(pickup.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1)
|
||||
.addDimension(1, 5).build());
|
||||
|
||||
Delivery delivery = mock(Delivery.class);
|
||||
when(delivery.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10)
|
||||
.addDimension(1, 3).build());
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(pickup).addService(delivery).build();
|
||||
|
||||
updateLoad.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
routeActivityVisitor.visit(route);
|
||||
revRouteActivityVisitor.visit(route);
|
||||
|
||||
assertEquals(11,stateManager.getActivityState(route.getActivities().get(0), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(0),0.1);
|
||||
assertEquals(8,stateManager.getActivityState(route.getActivities().get(0), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(1),0.1);
|
||||
assertEquals(1,stateManager.getActivityState(route.getActivities().get(1), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(0),0.1);
|
||||
assertEquals(5,stateManager.getActivityState(route.getActivities().get(1), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(1),0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenVehicleRouteHasPickupAndDeliveryAndPickupWithMultipleCapDims_futureMaxLoadAtEachActivityShouldBeCalculatedCorrectly(){
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
UpdateLoads updateLoad = new UpdateLoads(stateManager);
|
||||
UpdateMaxCapacityUtilisationAtActivitiesByLookingForwardInRoute updateMaxLoad = new UpdateMaxCapacityUtilisationAtActivitiesByLookingForwardInRoute(stateManager);
|
||||
|
||||
RouteActivityVisitor routeActivityVisitor = new RouteActivityVisitor();
|
||||
routeActivityVisitor.addActivityVisitor(updateLoad);
|
||||
|
||||
ReverseRouteActivityVisitor revRouteActivityVisitor = new ReverseRouteActivityVisitor();
|
||||
revRouteActivityVisitor.addActivityVisitor(updateMaxLoad);
|
||||
|
||||
Pickup pickup = mock(Pickup.class);
|
||||
when(pickup.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1)
|
||||
.addDimension(1, 5).build());
|
||||
|
||||
Delivery delivery = mock(Delivery.class);
|
||||
when(delivery.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10)
|
||||
.addDimension(1, 3).build());
|
||||
|
||||
Pickup pickup2 = mock(Pickup.class);
|
||||
when(pickup2.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 3)
|
||||
.addDimension(1, 8).build());
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(pickup).addService(delivery).addService(pickup2).build();
|
||||
|
||||
updateLoad.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
routeActivityVisitor.visit(route);
|
||||
revRouteActivityVisitor.visit(route);
|
||||
|
||||
assertEquals(11,stateManager.getActivityState(route.getActivities().get(0), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(0));
|
||||
assertEquals(13,stateManager.getActivityState(route.getActivities().get(0), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(1));
|
||||
|
||||
assertEquals(4,stateManager.getActivityState(route.getActivities().get(1), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(0));
|
||||
assertEquals(13,stateManager.getActivityState(route.getActivities().get(1), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(1));
|
||||
|
||||
assertEquals(4,stateManager.getActivityState(route.getActivities().get(2), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(0));
|
||||
assertEquals(13,stateManager.getActivityState(route.getActivities().get(2), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(1));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenVehicleRouteHasPickupAndDeliveryAndPickupWithMultipleCapDims_futureMaxLoadAtEachActivityShouldBeCalculatedCorrectly_v2(){
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
UpdateLoads updateLoad = new UpdateLoads(stateManager);
|
||||
UpdateMaxCapacityUtilisationAtActivitiesByLookingForwardInRoute updateMaxLoad = new UpdateMaxCapacityUtilisationAtActivitiesByLookingForwardInRoute(stateManager);
|
||||
|
||||
RouteActivityVisitor routeActivityVisitor = new RouteActivityVisitor();
|
||||
routeActivityVisitor.addActivityVisitor(updateLoad);
|
||||
|
||||
ReverseRouteActivityVisitor revRouteActivityVisitor = new ReverseRouteActivityVisitor();
|
||||
revRouteActivityVisitor.addActivityVisitor(updateMaxLoad);
|
||||
|
||||
Pickup pickup = mock(Pickup.class);
|
||||
when(pickup.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1)
|
||||
.addDimension(1, 5).build());
|
||||
|
||||
Delivery delivery = mock(Delivery.class);
|
||||
when(delivery.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10)
|
||||
.addDimension(1, 3).build());
|
||||
|
||||
Pickup pickup2 = mock(Pickup.class);
|
||||
when(pickup2.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 3)
|
||||
.addDimension(1, 8).addDimension(4, 29).build());
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(pickup).addService(delivery).addService(pickup2).build();
|
||||
|
||||
updateLoad.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
routeActivityVisitor.visit(route);
|
||||
revRouteActivityVisitor.visit(route);
|
||||
|
||||
assertEquals(11,stateManager.getActivityState(route.getActivities().get(0), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(0));
|
||||
assertEquals(13,stateManager.getActivityState(route.getActivities().get(0), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(1));
|
||||
assertEquals(29,stateManager.getActivityState(route.getActivities().get(0), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(4));
|
||||
|
||||
assertEquals(4,stateManager.getActivityState(route.getActivities().get(1), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(0));
|
||||
assertEquals(13,stateManager.getActivityState(route.getActivities().get(1), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(1));
|
||||
assertEquals(29,stateManager.getActivityState(route.getActivities().get(1), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(4));
|
||||
|
||||
assertEquals(4,stateManager.getActivityState(route.getActivities().get(2), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(0));
|
||||
assertEquals(13,stateManager.getActivityState(route.getActivities().get(2), StateFactory.FUTURE_MAXLOAD, Capacity.class).get(1));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,166 @@
|
|||
package jsprit.core.algorithm.state;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.job.Delivery;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.job.Pickup;
|
||||
import jsprit.core.problem.solution.route.RouteActivityVisitor;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleType;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class UpdateMaxCapacityUtilizationAtRouteTest {
|
||||
|
||||
private Vehicle vehicle;
|
||||
|
||||
@Before
|
||||
public void doBefore(){
|
||||
vehicle = mock(Vehicle.class);
|
||||
VehicleType type = mock(VehicleType.class);
|
||||
when(type.getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10000)
|
||||
.addDimension(1, 10000)
|
||||
.addDimension(2, 10000)
|
||||
.addDimension(3, 10000)
|
||||
.addDimension(4, 10000)
|
||||
.addDimension(5, 10000).build());
|
||||
when(vehicle.getType()).thenReturn(type);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenVehicleRouteHasPickupAndDelivery_maxLoadAtEachActivityShouldBeCalculatedCorrectly(){
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
UpdateLoads updateLoad = new UpdateLoads(stateManager);
|
||||
UpdateMaxCapacityUtilisationAtRoute updateMaxLoad = new UpdateMaxCapacityUtilisationAtRoute(stateManager);
|
||||
|
||||
RouteActivityVisitor routeActivityVisitor = new RouteActivityVisitor();
|
||||
routeActivityVisitor.addActivityVisitor(updateLoad);
|
||||
routeActivityVisitor.addActivityVisitor(updateMaxLoad);
|
||||
|
||||
Pickup pickup = mock(Pickup.class);
|
||||
when(pickup.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1).build());
|
||||
|
||||
Delivery delivery = mock(Delivery.class);
|
||||
when(delivery.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10).build());
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(pickup).addService(delivery).build();
|
||||
|
||||
updateLoad.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
routeActivityVisitor.visit(route);
|
||||
|
||||
assertEquals(11,stateManager.getRouteState(route, StateFactory.MAXLOAD, Capacity.class).get(0));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenVehicleRouteHasPickupAndDeliveryWithMultipleCapDims_futureMaxLoadAtEachActivityShouldBeCalculatedCorrectly(){
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
UpdateLoads updateLoad = new UpdateLoads(stateManager);
|
||||
UpdateMaxCapacityUtilisationAtRoute updateMaxLoad = new UpdateMaxCapacityUtilisationAtRoute(stateManager);
|
||||
|
||||
RouteActivityVisitor routeActivityVisitor = new RouteActivityVisitor();
|
||||
routeActivityVisitor.addActivityVisitor(updateLoad);
|
||||
routeActivityVisitor.addActivityVisitor(updateMaxLoad);
|
||||
|
||||
Pickup pickup = mock(Pickup.class);
|
||||
when(pickup.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1)
|
||||
.addDimension(1, 5).build());
|
||||
|
||||
Delivery delivery = mock(Delivery.class);
|
||||
when(delivery.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10)
|
||||
.addDimension(1, 3).build());
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(pickup).addService(delivery).build();
|
||||
|
||||
updateLoad.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
routeActivityVisitor.visit(route);
|
||||
|
||||
assertEquals(11,stateManager.getRouteState(route, StateFactory.MAXLOAD, Capacity.class).get(0),0.1);
|
||||
assertEquals(8,stateManager.getRouteState(route, StateFactory.MAXLOAD, Capacity.class).get(1),0.1);
|
||||
|
||||
assertEquals(11,stateManager.getRouteState(route, StateFactory.MAXLOAD, Capacity.class).get(0),0.1);
|
||||
assertEquals(8,stateManager.getRouteState(route, StateFactory.MAXLOAD, Capacity.class).get(1),0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenVehicleRouteHasPickupAndDeliveryAndPickupWithMultipleCapDims_futureMaxLoadAtEachActivityShouldBeCalculatedCorrectly(){
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
UpdateLoads updateLoad = new UpdateLoads(stateManager);
|
||||
UpdateMaxCapacityUtilisationAtRoute updateMaxLoad = new UpdateMaxCapacityUtilisationAtRoute(stateManager);
|
||||
|
||||
RouteActivityVisitor routeActivityVisitor = new RouteActivityVisitor();
|
||||
routeActivityVisitor.addActivityVisitor(updateLoad);
|
||||
routeActivityVisitor.addActivityVisitor(updateMaxLoad);
|
||||
|
||||
Pickup pickup = mock(Pickup.class);
|
||||
when(pickup.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1)
|
||||
.addDimension(1, 5).build());
|
||||
|
||||
Delivery delivery = mock(Delivery.class);
|
||||
when(delivery.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10)
|
||||
.addDimension(1, 3).build());
|
||||
|
||||
Pickup pickup2 = mock(Pickup.class);
|
||||
when(pickup2.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 3)
|
||||
.addDimension(1, 8).build());
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(pickup).addService(delivery).addService(pickup2).build();
|
||||
|
||||
updateLoad.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
routeActivityVisitor.visit(route);
|
||||
|
||||
assertEquals(11,stateManager.getRouteState(route, StateFactory.MAXLOAD, Capacity.class).get(0));
|
||||
assertEquals(13,stateManager.getRouteState(route, StateFactory.MAXLOAD, Capacity.class).get(1));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenVehicleRouteHasPickupAndDeliveryAndPickupWithMultipleCapDims_futureMaxLoadAtEachActivityShouldBeCalculatedCorrectly_v2(){
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
UpdateLoads updateLoad = new UpdateLoads(stateManager);
|
||||
UpdateMaxCapacityUtilisationAtRoute updateMaxLoad = new UpdateMaxCapacityUtilisationAtRoute(stateManager);
|
||||
|
||||
RouteActivityVisitor routeActivityVisitor = new RouteActivityVisitor();
|
||||
routeActivityVisitor.addActivityVisitor(updateLoad);
|
||||
routeActivityVisitor.addActivityVisitor(updateMaxLoad);
|
||||
|
||||
Pickup pickup = mock(Pickup.class);
|
||||
when(pickup.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1)
|
||||
.addDimension(1, 5).build());
|
||||
|
||||
Delivery delivery = mock(Delivery.class);
|
||||
when(delivery.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10)
|
||||
.addDimension(1, 3).build());
|
||||
|
||||
Pickup pickup2 = mock(Pickup.class);
|
||||
when(pickup2.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 3)
|
||||
.addDimension(1, 8).addDimension(4, 29).build());
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(pickup).addService(delivery).addService(pickup2).build();
|
||||
|
||||
updateLoad.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
routeActivityVisitor.visit(route);
|
||||
|
||||
assertEquals(11,stateManager.getRouteState(route, StateFactory.MAXLOAD, Capacity.class).get(0));
|
||||
assertEquals(13,stateManager.getRouteState(route, StateFactory.MAXLOAD, Capacity.class).get(1));
|
||||
assertEquals(29,stateManager.getRouteState(route, StateFactory.MAXLOAD, Capacity.class).get(4));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
package jsprit.core.algorithm.state;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.job.Delivery;
|
||||
import jsprit.core.problem.job.Pickup;
|
||||
import jsprit.core.problem.solution.route.ReverseRouteActivityVisitor;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.util.CostFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class UpdatePracticalTimeWindowTest {
|
||||
|
||||
private VehicleRoutingTransportCosts routingCosts;
|
||||
|
||||
private ReverseRouteActivityVisitor reverseActivityVisitor;
|
||||
|
||||
private StateManager stateManager;
|
||||
|
||||
private VehicleRoute route;
|
||||
|
||||
@Before
|
||||
public void doBefore(){
|
||||
|
||||
routingCosts = CostFactory.createManhattanCosts();
|
||||
|
||||
stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
|
||||
reverseActivityVisitor = new ReverseRouteActivityVisitor();
|
||||
reverseActivityVisitor.addActivityVisitor(new UpdatePracticalTimeWindows(stateManager, routingCosts));
|
||||
|
||||
Pickup pickup = mock(Pickup.class);
|
||||
when(pickup.getTimeWindow()).thenReturn(TimeWindow.newInstance(0, 30));
|
||||
when(pickup.getLocationId()).thenReturn("0,20");
|
||||
|
||||
Delivery delivery = mock(Delivery.class);
|
||||
when(delivery.getTimeWindow()).thenReturn(TimeWindow.newInstance(10, 40));
|
||||
when(delivery.getLocationId()).thenReturn("20,20");
|
||||
when(delivery.getSize()).thenReturn(Capacity.Builder.newInstance().build());
|
||||
|
||||
Pickup pickup2 = mock(Pickup.class);
|
||||
when(pickup2.getTimeWindow()).thenReturn(TimeWindow.newInstance(20, 50));
|
||||
when(pickup2.getLocationId()).thenReturn("20,0");
|
||||
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.getStartLocationId()).thenReturn("0,0");
|
||||
when(vehicle.getLatestArrival()).thenReturn(Double.MAX_VALUE);
|
||||
|
||||
route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(pickup).addService(delivery).addService(pickup2).build();
|
||||
|
||||
reverseActivityVisitor.visit(route);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenVehicleRouteHasPickupAndDeliveryAndPickup_latestStartTimeOfAct3MustBeCorrect(){
|
||||
assertEquals(50.,route.getActivities().get(2).getTheoreticalLatestOperationStartTime(),0.01);
|
||||
assertEquals(50.,stateManager.getActivityState(route.getActivities().get(2), StateFactory.LATEST_OPERATION_START_TIME, Double.class),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenVehicleRouteHasPickupAndDeliveryAndPickup_latestStartTimeOfAct2MustBeCorrect(){
|
||||
assertEquals(40.,route.getActivities().get(1).getTheoreticalLatestOperationStartTime(),0.01);
|
||||
assertEquals(30.,stateManager.getActivityState(route.getActivities().get(1), StateFactory.LATEST_OPERATION_START_TIME, Double.class),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenVehicleRouteHasPickupAndDeliveryAndPickup_latestStartTimeOfAct1MustBeCorrect(){
|
||||
assertEquals(30.,route.getActivities().get(0).getTheoreticalLatestOperationStartTime(),0.01);
|
||||
assertEquals(10.,stateManager.getActivityState(route.getActivities().get(0), StateFactory.LATEST_OPERATION_START_TIME, Double.class),0.01);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package jsprit.core.algorithm.state;
|
||||
|
||||
public class UpdateVariableCostsTest {
|
||||
|
||||
}
|
||||
358
jsprit-core/src/test/java/jsprit/core/problem/CapacityTest.java
Normal file
358
jsprit-core/src/test/java/jsprit/core/problem/CapacityTest.java
Normal file
|
|
@ -0,0 +1,358 @@
|
|||
|
||||
package jsprit.core.problem;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class CapacityTest {
|
||||
|
||||
@Test
|
||||
public void whenSettingSimplyOneCapDimension_nuOfDimensionMustBeCorrect(){
|
||||
Capacity.Builder capBuilder = Capacity.Builder.newInstance();
|
||||
capBuilder.addDimension(0, 4);
|
||||
Capacity cap = capBuilder.build();
|
||||
assertEquals(1,cap.getNuOfDimensions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingTwoCapDimension_nuOfDimensionMustBeCorrect(){
|
||||
Capacity.Builder capBuilder = Capacity.Builder.newInstance();
|
||||
capBuilder.addDimension(0, 4);
|
||||
capBuilder.addDimension(1,10);
|
||||
Capacity cap = capBuilder.build();
|
||||
assertEquals(2,cap.getNuOfDimensions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingRandomNuOfCapDimension_nuOfDimensionMustBeCorrect(){
|
||||
Random rand = new Random();
|
||||
int nuOfCapDimensions = rand.nextInt(100);
|
||||
Capacity.Builder capBuilder = Capacity.Builder.newInstance();
|
||||
capBuilder.addDimension(nuOfCapDimensions-1, 4);
|
||||
Capacity cap = capBuilder.build();
|
||||
assertEquals(nuOfCapDimensions,cap.getNuOfDimensions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingOneDimValue_valueMustBeCorrect(){
|
||||
Capacity.Builder capBuilder = Capacity.Builder.newInstance();
|
||||
capBuilder.addDimension(0, 4);
|
||||
Capacity cap = capBuilder.build();
|
||||
assertEquals(4,cap.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGettingIndexWhichIsHigherThanNuOfCapDimensions_itShouldReturn0(){
|
||||
Capacity.Builder capBuilder = Capacity.Builder.newInstance();
|
||||
capBuilder.addDimension(0, 4);
|
||||
Capacity cap = capBuilder.build();
|
||||
assertEquals(0,cap.get(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingNoDim_DefaultIsOneDimWithDimValueOfZero(){
|
||||
Capacity.Builder capBuilder = Capacity.Builder.newInstance();
|
||||
Capacity cap = capBuilder.build();
|
||||
assertEquals(1, cap.getNuOfDimensions());
|
||||
assertEquals(0, cap.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCopyingCapacityWithTwoCapDim_copiedObjShouldHvSameNuOfDims(){
|
||||
Capacity.Builder capBuilder = Capacity.Builder.newInstance();
|
||||
capBuilder.addDimension(0, 4);
|
||||
capBuilder.addDimension(1,10);
|
||||
Capacity cap = capBuilder.build();
|
||||
|
||||
Capacity copiedCapacity = Capacity.copyOf(cap);
|
||||
assertEquals(2,copiedCapacity.getNuOfDimensions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCopyingCapacityWithTwoCapDim_copiedObjShouldHvSameValues(){
|
||||
Capacity.Builder capBuilder = Capacity.Builder.newInstance();
|
||||
capBuilder.addDimension(0, 4);
|
||||
capBuilder.addDimension(1,10);
|
||||
Capacity cap = capBuilder.build();
|
||||
|
||||
Capacity copiedCapacity = Capacity.copyOf(cap);
|
||||
assertEquals(4,copiedCapacity.get(0));
|
||||
assertEquals(10,copiedCapacity.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCopyingNull_itShouldReturnNull(){
|
||||
Capacity nullCap = Capacity.copyOf(null);
|
||||
assertTrue(nullCap==null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingUpTwoOneDimensionalCapacities_itShouldReturnCorrectCapacityValues(){
|
||||
Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).build();
|
||||
Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).build();
|
||||
Capacity result = Capacity.addup(cap1, cap2);
|
||||
assertEquals(3, result.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingUpTwoOneDimensionalCapacities_itShouldReturnCorrectNuOfDimensions(){
|
||||
Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).build();
|
||||
Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).build();
|
||||
Capacity result = Capacity.addup(cap1, cap2);
|
||||
assertEquals(1, result.getNuOfDimensions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingUpTwoThreeDimensionalCapacities_itShouldReturnCorrectNuOfDimensions(){
|
||||
Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).addDimension(2, 3).build();
|
||||
Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build();
|
||||
Capacity result = Capacity.addup(cap1, cap2);
|
||||
assertEquals(3, result.getNuOfDimensions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingUpTwoThreeDimensionalCapacities_itShouldReturnCorrectCapValues(){
|
||||
Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).addDimension(2, 3).build();
|
||||
Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build();
|
||||
Capacity result = Capacity.addup(cap1, cap2);
|
||||
assertEquals(3, result.get(0));
|
||||
assertEquals(5, result.get(1));
|
||||
assertEquals(7, result.get(2));
|
||||
}
|
||||
|
||||
public void whenAddingUpTwoCapacitiesWithDifferentNuOfDimensions_itShouldAddThemCorrectly(){
|
||||
Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).build();
|
||||
Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).build();
|
||||
Capacity result = Capacity.addup(cap1, cap2);
|
||||
assertEquals(3,result.get(0));
|
||||
assertEquals(2,result.get(1));
|
||||
}
|
||||
|
||||
@Test(expected=NullPointerException.class)
|
||||
public void whenOneOfArgsIsNullWhenAdding_itShouldThrowException(){
|
||||
Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).build();
|
||||
@SuppressWarnings("unused")
|
||||
Capacity result = Capacity.addup(cap1, null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void whenSubtractingTwoOneDimensionalCapacities_itShouldReturnCorrectCapacityValues(){
|
||||
Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).build();
|
||||
Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).build();
|
||||
Capacity result = Capacity.subtract(cap2, cap1);
|
||||
assertEquals(1, result.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSubtractingTwoOneDimensionalCapacities_itShouldReturnCorrectNuOfDimensions(){
|
||||
Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).build();
|
||||
Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).build();
|
||||
Capacity result = Capacity.subtract(cap2, cap1);
|
||||
assertEquals(1, result.getNuOfDimensions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSubtractingTwoThreeDimensionalCapacities_itShouldReturnCorrectNuOfDimensions(){
|
||||
Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).addDimension(2, 3).build();
|
||||
Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build();
|
||||
Capacity result = Capacity.subtract(cap2, cap1);
|
||||
assertEquals(3, result.getNuOfDimensions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSubtractingTwoThreeDimensionalCapacities_itShouldReturnCorrectCapValues(){
|
||||
Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).addDimension(2, 3).build();
|
||||
Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build();
|
||||
Capacity result = Capacity.subtract(cap2, cap1);
|
||||
assertEquals(1, result.get(0));
|
||||
assertEquals(1, result.get(1));
|
||||
assertEquals(1, result.get(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSubtractingTwoCapacitiesWithDifferentNuOfDimensions_itShouldSubtractCorrectly(){
|
||||
Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).build();
|
||||
Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).build();
|
||||
Capacity result = Capacity.subtract(cap2, cap1);
|
||||
assertEquals(1,result.get(0));
|
||||
assertEquals(-2,result.get(1));
|
||||
}
|
||||
|
||||
@Test(expected=NullPointerException.class)
|
||||
public void whenOneOfArgsIsNullWhenSubtracting_itShouldThrowException(){
|
||||
Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).build();
|
||||
@SuppressWarnings("unused")
|
||||
Capacity result = Capacity.subtract(cap1, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSubtractingBiggerFromLower_itShouldSubtractCorrectly(){
|
||||
Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).addDimension(2, 3).build();
|
||||
Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build();
|
||||
Capacity result = Capacity.subtract(cap1, cap2);
|
||||
assertEquals(-1,result.get(0));
|
||||
assertEquals(-1,result.get(1));
|
||||
assertEquals(-1,result.get(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOneCapIsLessThanAnother_itShouldReturnCorrectBoolean(){
|
||||
Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).addDimension(2, 3).build();
|
||||
Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build();
|
||||
assertTrue(cap1.isLessOrEqual(cap2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOneCapIsLessThanAnother_itShouldReturnCorrectBoolean_v2(){
|
||||
Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 2).addDimension(2, 4).build();
|
||||
Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build();
|
||||
assertTrue(cap1.isLessOrEqual(cap2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOneCapIsLessThanAnother_itShouldReturnCorrectBoolean_v3(){
|
||||
Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build();
|
||||
Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build();
|
||||
assertTrue(cap1.isLessOrEqual(cap2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOneCapIsBiggerThanAnother_itShouldReturnCorrectBoolean(){
|
||||
Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build();
|
||||
Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 4).addDimension(2, 4).build();
|
||||
assertFalse(cap2.isLessOrEqual(cap1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOneCapIsBiggerThanAnother_greaterOrEqualShouldReturnTrue(){
|
||||
Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build();
|
||||
Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 4).addDimension(2, 4).build();
|
||||
assertTrue(cap2.isGreaterOrEqual(cap1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOneCapIsBiggerThanAnother_greaterOrEqualShouldReturnTrue_v2(){
|
||||
Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build();
|
||||
//which is zero-cap
|
||||
Capacity cap2 = Capacity.Builder.newInstance().build();
|
||||
assertTrue(cap1.isGreaterOrEqual(cap2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOneCapIsEqualToAnother_greaterOrEqualShouldReturnTrue(){
|
||||
Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build();
|
||||
Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build();
|
||||
assertTrue(cap2.isGreaterOrEqual(cap1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingTwo_itShouldReturnCorrectCap(){
|
||||
int wheelChairSpace = 0;
|
||||
int passengerSeats = 1;
|
||||
Capacity cap1 = Capacity.Builder.newInstance().addDimension(wheelChairSpace, 2).addDimension(passengerSeats, 10).build();
|
||||
Capacity wheelChair = Capacity.Builder.newInstance().addDimension(wheelChairSpace, 1).build();
|
||||
Capacity passenger = Capacity.Builder.newInstance().addDimension(passengerSeats, 1).build();
|
||||
Capacity wheelChair_plus_passenger = Capacity.addup(wheelChair, passenger);
|
||||
assertEquals(1,wheelChair_plus_passenger.get(wheelChairSpace));
|
||||
assertEquals(1,wheelChair_plus_passenger.get(passengerSeats));
|
||||
assertTrue(wheelChair_plus_passenger.isLessOrEqual(cap1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingTwo_itShouldReturnCorrectCap_v2(){
|
||||
int wheelChairSpace = 0;
|
||||
int passengerSeats = 1;
|
||||
int weight = 2;
|
||||
Capacity cap1 = Capacity.Builder.newInstance().addDimension(wheelChairSpace, 2).addDimension(passengerSeats, 10).addDimension(2, 100).build();
|
||||
Capacity wheelChair = Capacity.Builder.newInstance().addDimension(wheelChairSpace, 1).addDimension(weight, 80).build();
|
||||
Capacity passenger = Capacity.Builder.newInstance().addDimension(passengerSeats, 1).addDimension(weight, 30).build();
|
||||
Capacity wheelChair_plus_passenger = Capacity.addup(wheelChair, passenger);
|
||||
assertEquals(1,wheelChair_plus_passenger.get(wheelChairSpace));
|
||||
assertEquals(1,wheelChair_plus_passenger.get(passengerSeats));
|
||||
assertEquals(110,wheelChair_plus_passenger.get(weight));
|
||||
assertFalse(wheelChair_plus_passenger.isLessOrEqual(cap1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInvertingCap_itShouldBeDoneCorrectly(){
|
||||
Capacity cap = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build();
|
||||
Capacity inverted = Capacity.invert(cap);
|
||||
assertEquals(-2,inverted.get(0));
|
||||
assertEquals(-3,inverted.get(1));
|
||||
assertEquals(-4,inverted.get(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenDeterminingTheMaximumOfTwoCapacities_itShouldReturnCapWithMaxOfEachDimension(){
|
||||
Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 3).addDimension(1, 3).build();
|
||||
Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 4).build();
|
||||
assertEquals(3,Capacity.max(cap1,cap2).get(0));
|
||||
assertEquals(4,Capacity.max(cap1,cap2).get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenDeterminingTheMaximumOfTwoCapacities_itShouldReturnCapWithMaxOfEachDimension_v2(){
|
||||
Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 3).build();
|
||||
Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 4).build();
|
||||
assertEquals(2,Capacity.max(cap1,cap2).get(0));
|
||||
assertEquals(4,Capacity.max(cap1,cap2).get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenDeterminingTheMaximumOfTwoCapacities_itShouldReturnCapWithMaxOfEachDimension_v3(){
|
||||
Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 3).addDimension(2, 3).build();
|
||||
Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 4).build();
|
||||
assertEquals(2,Capacity.max(cap1,cap2).get(0));
|
||||
assertEquals(4,Capacity.max(cap1,cap2).get(1));
|
||||
assertEquals(3,Capacity.max(cap1,cap2).get(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenDividingTwoCapacities_itShouldReturn05(){
|
||||
Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).build();
|
||||
Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 4).build();
|
||||
assertEquals(0.5,Capacity.divide(cap1, cap2),0.001);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenDividingTwoEqualCapacities_itShouldReturn10(){
|
||||
Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 4).build();
|
||||
Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 4).build();
|
||||
assertEquals(1.0,Capacity.divide(cap1, cap2),0.001);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenDividingTwoCapacities_itShouldReturn00(){
|
||||
Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 0).addDimension(1, 0).build();
|
||||
Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 4).build();
|
||||
assertEquals(0.0,Capacity.divide(cap1, cap2),0.001);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalStateException.class)
|
||||
public void whenDividingByAZeroDim_itShouldThrowException(){
|
||||
Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).build();
|
||||
Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 0).build();
|
||||
Capacity.divide(cap1, cap2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenBothDimOfNominatorAndDenominatorAreZero_divisionShouldIgnoreThisDim(){
|
||||
Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).addDimension(3, 0).build();
|
||||
Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 4).addDimension(3, 0).build();
|
||||
assertEquals(0.5,Capacity.divide(cap1, cap2),0.001);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenDividingZeroCaps_itShouldReturnZero(){
|
||||
Capacity cap1 = Capacity.Builder.newInstance().build();
|
||||
Capacity cap2 = Capacity.Builder.newInstance().build();
|
||||
assertEquals(0.0,Capacity.divide(cap1, cap2),0.001);
|
||||
}
|
||||
}
|
||||
|
|
@ -115,8 +115,8 @@ public class VehicleRoutingProblemTest {
|
|||
|
||||
@Test
|
||||
public void whenShipmentsAreAdded_vrpShouldContainThem(){
|
||||
Shipment s = Shipment.Builder.newInstance("s", 10).setPickupLocation("foofoo").setDeliveryLocation("foo").build();
|
||||
Shipment s2 = Shipment.Builder.newInstance("s2", 100).setPickupLocation("foofoo").setDeliveryLocation("foo").build();
|
||||
Shipment s = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation("foofoo").setDeliveryLocation("foo").build();
|
||||
Shipment s2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 100).setPickupLocation("foofoo").setDeliveryLocation("foo").build();
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
vrpBuilder.addJob(s);
|
||||
vrpBuilder.addJob(s2);
|
||||
|
|
@ -285,7 +285,7 @@ public class VehicleRoutingProblemTest {
|
|||
@Test
|
||||
public void whenAddingAVehicle_getAddedVehicleTypesShouldReturnItsType(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type", 0).build();
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").setType(type).build();
|
||||
builder.addVehicle(vehicle);
|
||||
|
||||
|
|
@ -297,7 +297,7 @@ public class VehicleRoutingProblemTest {
|
|||
@Test
|
||||
public void whenAddingTwoVehicleWithSameType_getAddedVehicleTypesShouldReturnOnlyOneType(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type", 0).build();
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").setType(type).build();
|
||||
Vehicle vehicle2 = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").setType(type).build();
|
||||
|
||||
|
|
@ -311,8 +311,8 @@ public class VehicleRoutingProblemTest {
|
|||
@Test
|
||||
public void whenAddingTwoVehicleWithDiffType_getAddedVehicleTypesShouldReturnTheseType(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type", 0).build();
|
||||
VehicleType type2 = VehicleTypeImpl.Builder.newInstance("type2", 0).build();
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||
VehicleType type2 = VehicleTypeImpl.Builder.newInstance("type2").build();
|
||||
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").setType(type).build();
|
||||
Vehicle vehicle2 = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").setType(type2).build();
|
||||
|
|
@ -327,7 +327,7 @@ public class VehicleRoutingProblemTest {
|
|||
@Test
|
||||
public void whenSettingAddPenaltyVehicleOptions_itShouldAddPenaltyVehicle(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type", 0).build();
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").setType(type).build();
|
||||
|
||||
builder.addVehicle(vehicle);
|
||||
|
|
@ -349,7 +349,7 @@ public class VehicleRoutingProblemTest {
|
|||
@Test
|
||||
public void whenSettingAddPenaltyVehicleOptionsAndFleetSizeIsInfinite_noPenaltyVehicleIsAdded(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type", 0).build();
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").setType(type).build();
|
||||
|
||||
builder.addVehicle(vehicle);
|
||||
|
|
@ -370,7 +370,7 @@ public class VehicleRoutingProblemTest {
|
|||
@Test
|
||||
public void whenSettingAddPenaltyVehicleOptionsAndTwoVehiclesWithSameLocationAndType_onlyOnePenaltyVehicleIsAdded(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type", 0).build();
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").setType(type).build();
|
||||
Vehicle vehicle2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("loc").setType(type).build();
|
||||
|
||||
|
|
@ -394,7 +394,7 @@ public class VehicleRoutingProblemTest {
|
|||
@Test
|
||||
public void whenSettingAddPenaltyVehicleOptionsWithAbsoluteFixedCostsAndTwoVehiclesWithSameLocationAndType_onePenaltyVehicleIsAddedWithTheCorrectPenaltyFixedCosts(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type", 0).build();
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").setType(type).build();
|
||||
Vehicle vehicle2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("loc").setType(type).build();
|
||||
|
||||
|
|
@ -420,7 +420,7 @@ public class VehicleRoutingProblemTest {
|
|||
@Test
|
||||
public void whenSettingAddPenaltyVehicleOptionsAndTwoVehiclesWithDiffLocationAndType_twoPenaltyVehicleIsAdded(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type", 0).build();
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").setType(type).build();
|
||||
Vehicle vehicle2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("loc2").setType(type).build();
|
||||
|
||||
|
|
@ -447,8 +447,8 @@ public class VehicleRoutingProblemTest {
|
|||
@Test
|
||||
public void whenSettingAddPenaltyVehicleOptionsAndTwoVehiclesWithSameLocationButDiffType_twoPenaltyVehicleIsAdded(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type", 0).build();
|
||||
VehicleType type2 = VehicleTypeImpl.Builder.newInstance("type2", 0).build();
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||
VehicleType type2 = VehicleTypeImpl.Builder.newInstance("type2").build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").setType(type).build();
|
||||
Vehicle vehicle2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("loc").setType(type2).build();
|
||||
|
||||
|
|
|
|||
|
|
@ -59,10 +59,11 @@ public class VrpReaderV2Test {
|
|||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(builder, null).read(inFileName);
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
assertEquals(4,vrp.getVehicles().size());
|
||||
assertEquals(5,vrp.getVehicles().size());
|
||||
assertTrue(idsInCollection(Arrays.asList("v1","v2"),vrp.getVehicles()));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void whenReadingVrp_vehiclesAreReadCorrectly2(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
|
@ -70,6 +71,7 @@ public class VrpReaderV2Test {
|
|||
VehicleRoutingProblem vrp = builder.build();
|
||||
Vehicle v1 = getVehicle("v1",vrp.getVehicles());
|
||||
assertEquals(20,v1.getCapacity());
|
||||
assertEquals(20,v1.getType().getCapacityDimensions().get(0));
|
||||
assertEquals(100.0,v1.getStartLocationCoordinate().getX(),0.01);
|
||||
assertEquals(0.0,v1.getEarliestDeparture(),0.01);
|
||||
assertEquals("depotLoc2",v1.getStartLocationId());
|
||||
|
|
@ -96,7 +98,7 @@ public class VrpReaderV2Test {
|
|||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(builder, null).read(inFileName);
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
assertEquals(2,vrp.getTypes().size());
|
||||
assertEquals(3,vrp.getTypes().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -139,6 +141,7 @@ public class VrpReaderV2Test {
|
|||
assertEquals(2,shipCounter);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void whenReadingServices_capOfService1IsReadCorrectly(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
|
@ -146,6 +149,7 @@ public class VrpReaderV2Test {
|
|||
VehicleRoutingProblem vrp = builder.build();
|
||||
Service s1 = (Service) vrp.getJobs().get("1");
|
||||
assertEquals(1,s1.getCapacityDemand());
|
||||
assertEquals(1,s1.getSize().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -299,6 +303,7 @@ public class VrpReaderV2Test {
|
|||
assertEquals("startLoc",v.getStartLocationId());
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void whenReadingJobs_capOfShipment3IsReadCorrectly(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
|
@ -306,6 +311,7 @@ public class VrpReaderV2Test {
|
|||
VehicleRoutingProblem vrp = builder.build();
|
||||
Shipment s = (Shipment) vrp.getJobs().get("3");
|
||||
assertEquals(10,s.getCapacityDemand());
|
||||
assertEquals(10,s.getSize().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -419,5 +425,20 @@ public class VrpReaderV2Test {
|
|||
Shipment s = (Shipment) vrp.getJobs().get("4");
|
||||
assertEquals(100.0,s.getDeliveryServiceTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenReadingFile_v5AndItsTypeHasTheCorrectCapacityDimensionValues(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(builder, null).read(inFileName);
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
Vehicle v = getVehicle("v5",vrp.getVehicles());
|
||||
assertEquals(100, v.getType().getCapacityDimensions().get(0));
|
||||
assertEquals(1000, v.getType().getCapacityDimensions().get(1));
|
||||
assertEquals(10000, v.getType().getCapacityDimensions().get(2));
|
||||
assertEquals(0, v.getType().getCapacityDimensions().get(3));
|
||||
assertEquals(0, v.getType().getCapacityDimensions().get(5));
|
||||
assertEquals(100000, v.getType().getCapacityDimensions().get(10));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ import jsprit.core.util.Coordinate;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class VrpWriterV2Test {
|
||||
|
||||
private String infileName;
|
||||
|
|
@ -100,6 +100,7 @@ public class VrpWriterV2Test {
|
|||
builder.addVehicle(v1);
|
||||
builder.addVehicle(v2);
|
||||
|
||||
|
||||
Service s1 = Service.Builder.newInstance("1", 1).setLocationId("loc").setServiceTime(2.0).build();
|
||||
Service s2 = Service.Builder.newInstance("2", 1).setLocationId("loc2").setServiceTime(4.0).build();
|
||||
|
||||
|
|
@ -118,6 +119,32 @@ public class VrpWriterV2Test {
|
|||
assertEquals(2.0,s1_read.getServiceDuration(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenWritingServicesWithSeveralCapacityDimensions_itWritesThemCorrectly(){
|
||||
Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
||||
Service s1 = Service.Builder.newInstance("1")
|
||||
.addSizeDimension(0, 20)
|
||||
.addSizeDimension(1, 200)
|
||||
.setLocationId("loc").setServiceTime(2.0).build();
|
||||
Service s2 = Service.Builder.newInstance("2", 1).setLocationId("loc2").setServiceTime(4.0).build();
|
||||
|
||||
VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build();
|
||||
new VrpXMLWriter(vrp, null).write(infileName);
|
||||
|
||||
VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(vrpToReadBuilder, null).read(infileName);
|
||||
VehicleRoutingProblem readVrp = vrpToReadBuilder.build();
|
||||
assertEquals(2,readVrp.getJobs().size());
|
||||
|
||||
Service s1_read = (Service) vrp.getJobs().get("1");
|
||||
|
||||
assertEquals(2, s1_read.getSize().getNuOfDimensions());
|
||||
assertEquals(20, s1_read.getSize().get(0));
|
||||
assertEquals(200, s1_read.getSize().get(1));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenWritingShipments_readingThemAgainMustReturnTheWrittenLocationIdsOfS1(){
|
||||
Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
|
@ -305,6 +332,36 @@ public class VrpWriterV2Test {
|
|||
assertEquals(6.0,((Shipment)readVrp.getJobs().get("1")).getDeliveryCoord().getY(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenWritingShipmentWithSeveralCapacityDimension_itShouldWriteAndReadItCorrectly(){
|
||||
Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
||||
Shipment s1 = Shipment.Builder.newInstance("1")
|
||||
.setPickupCoord(Coordinate.newInstance(1, 2)).setDeliveryCoord(Coordinate.newInstance(5, 6)).setDeliveryLocation("delLoc").setPickupTimeWindow(TimeWindow.newInstance(1, 2))
|
||||
.setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).setPickupServiceTime(100).setDeliveryServiceTime(50)
|
||||
.addSizeDimension(0, 10)
|
||||
.addSizeDimension(2, 100)
|
||||
.build();
|
||||
|
||||
Shipment s2 = Shipment.Builder.newInstance("2", 20).setPickupLocation("pickLocation").setDeliveryLocation("delLocation").setPickupTimeWindow(TimeWindow.newInstance(5, 6))
|
||||
.setDeliveryTimeWindow(TimeWindow.newInstance(7, 8)).build();
|
||||
|
||||
VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build();
|
||||
new VrpXMLWriter(vrp, null).write(infileName);
|
||||
|
||||
VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(vrpToReadBuilder, null).read(infileName);
|
||||
VehicleRoutingProblem readVrp = vrpToReadBuilder.build();
|
||||
|
||||
assertEquals(3,((Shipment)readVrp.getJobs().get("1")).getSize().getNuOfDimensions());
|
||||
assertEquals(10,((Shipment)readVrp.getJobs().get("1")).getSize().get(0));
|
||||
assertEquals(0,((Shipment)readVrp.getJobs().get("1")).getSize().get(1));
|
||||
assertEquals(100,((Shipment)readVrp.getJobs().get("1")).getSize().get(2));
|
||||
|
||||
assertEquals(1,((Shipment)readVrp.getJobs().get("2")).getSize().getNuOfDimensions());
|
||||
assertEquals(20,((Shipment)readVrp.getJobs().get("2")).getSize().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenWritingVehicleV1_itsStartLocationMustBeWrittenCorrectly(){
|
||||
Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
|
@ -472,6 +529,61 @@ public class VrpWriterV2Test {
|
|||
assertEquals(5.0,v.getEndLocationCoordinate().getY(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenWritingVehicleWithSeveralCapacityDimensions_itShouldBeWrittenAndRereadCorrectly(){
|
||||
Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
||||
VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("type", 200)
|
||||
.addCapacityDimension(0, 100)
|
||||
.addCapacityDimension(1, 1000)
|
||||
.addCapacityDimension(2, 10000)
|
||||
.build();
|
||||
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v").setStartLocationId("startLoc").setStartLocationCoordinate(Coordinate.newInstance(1, 2))
|
||||
.setEndLocationId("endLoc").setEndLocationCoordinate(Coordinate.newInstance(4, 5)).setType(type2).build();
|
||||
builder.addVehicle(v2);
|
||||
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
new VrpXMLWriter(vrp, null).write(infileName);
|
||||
|
||||
VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(vrpToReadBuilder, null).read(infileName);
|
||||
VehicleRoutingProblem readVrp = vrpToReadBuilder.build();
|
||||
|
||||
Vehicle v = getVehicle("v",readVrp.getVehicles());
|
||||
assertEquals(3,v.getType().getCapacityDimensions().getNuOfDimensions());
|
||||
assertEquals(100,v.getType().getCapacityDimensions().get(0));
|
||||
assertEquals(1000,v.getType().getCapacityDimensions().get(1));
|
||||
assertEquals(10000,v.getType().getCapacityDimensions().get(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenWritingVehicleWithSeveralCapacityDimensions_itShouldBeWrittenAndRereadCorrectlyV2(){
|
||||
Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
||||
VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("type", 200)
|
||||
.addCapacityDimension(0, 100)
|
||||
.addCapacityDimension(1, 1000)
|
||||
.addCapacityDimension(10, 10000)
|
||||
.build();
|
||||
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v").setStartLocationId("startLoc").setStartLocationCoordinate(Coordinate.newInstance(1, 2))
|
||||
.setEndLocationId("endLoc").setEndLocationCoordinate(Coordinate.newInstance(4, 5)).setType(type2).build();
|
||||
builder.addVehicle(v2);
|
||||
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
new VrpXMLWriter(vrp, null).write(infileName);
|
||||
|
||||
VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(vrpToReadBuilder, null).read(infileName);
|
||||
VehicleRoutingProblem readVrp = vrpToReadBuilder.build();
|
||||
|
||||
Vehicle v = getVehicle("v",readVrp.getVehicles());
|
||||
assertEquals(11,v.getType().getCapacityDimensions().getNuOfDimensions());
|
||||
assertEquals(0,v.getType().getCapacityDimensions().get(9));
|
||||
assertEquals(10000,v.getType().getCapacityDimensions().get(10));
|
||||
}
|
||||
|
||||
private Vehicle getVehicle(String string, Collection<Vehicle> vehicles) {
|
||||
for(Vehicle v : vehicles) if(string.equals(v.getId())) return v;
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,46 @@
|
|||
package jsprit.core.problem.job;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class DeliveryTest {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test(expected=IllegalStateException.class)
|
||||
public void whenNeitherLocationIdNorCoordIsSet_itThrowsException(){
|
||||
Delivery.Builder.newInstance("p", 0).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo(){
|
||||
Delivery one = (Delivery)Delivery.Builder.newInstance("s").setLocationId("foofoo")
|
||||
.addSizeDimension(0,2)
|
||||
.addSizeDimension(1,4)
|
||||
.build();
|
||||
assertEquals(2,one.getSize().getNuOfDimensions());
|
||||
assertEquals(2,one.getSize().get(0));
|
||||
assertEquals(4,one.getSize().get(1));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenPickupIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero(){
|
||||
Delivery one = (Delivery)Delivery.Builder.newInstance("s").setLocationId("foofoo")
|
||||
.build();
|
||||
assertEquals(1,one.getSize().getNuOfDimensions());
|
||||
assertEquals(0,one.getSize().get(0));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void whenPickupIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly(){
|
||||
Delivery one = (Delivery)Delivery.Builder.newInstance("s",1).setLocationId("foofoo")
|
||||
.build();
|
||||
assertEquals(1,one.getCapacityDemand());
|
||||
assertEquals(1,one.getSize().getNuOfDimensions());
|
||||
assertEquals(1,one.getSize().get(0));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,46 @@
|
|||
package jsprit.core.problem.job;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class PickupTest {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test(expected=IllegalStateException.class)
|
||||
public void whenNeitherLocationIdNorCoordIsSet_itThrowsException(){
|
||||
Pickup.Builder.newInstance("p", 0).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo(){
|
||||
Pickup one = (Pickup)Pickup.Builder.newInstance("s").setLocationId("foofoo")
|
||||
.addSizeDimension(0,2)
|
||||
.addSizeDimension(1,4)
|
||||
.build();
|
||||
assertEquals(2,one.getSize().getNuOfDimensions());
|
||||
assertEquals(2,one.getSize().get(0));
|
||||
assertEquals(4,one.getSize().get(1));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenPickupIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero(){
|
||||
Pickup one = (Pickup)Pickup.Builder.newInstance("s").setLocationId("foofoo")
|
||||
.build();
|
||||
assertEquals(1,one.getSize().getNuOfDimensions());
|
||||
assertEquals(0,one.getSize().get(0));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void whenPickupIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly(){
|
||||
Pickup one = (Pickup)Pickup.Builder.newInstance("s",1).setLocationId("foofoo")
|
||||
.build();
|
||||
assertEquals(1,one.getCapacityDemand());
|
||||
assertEquals(1,one.getSize().getNuOfDimensions());
|
||||
assertEquals(1,one.getSize().get(0));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,9 @@
|
|||
package jsprit.core.problem.job;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
|
@ -28,11 +30,11 @@ import jsprit.core.util.Coordinate;
|
|||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ServiceTest {
|
||||
|
||||
@Test
|
||||
public void whenTwoServicesHaveTheSameId_theyReferencesShouldBeUnEqual(){
|
||||
public void whenTwoServicesHaveTheSameId_theirReferencesShouldBeUnEqual(){
|
||||
Service one = Service.Builder.newInstance("service", 10).setLocationId("foo").build();
|
||||
Service two = Service.Builder.newInstance("service", 10).setLocationId("fo").build();
|
||||
|
||||
|
|
@ -56,9 +58,40 @@ public class ServiceTest {
|
|||
// assertTrue(serviceSet.contains(two));
|
||||
serviceSet.remove(two);
|
||||
assertTrue(serviceSet.isEmpty());
|
||||
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void whenCapacityDimValueIsNegative_throwIllegalStateExpception(){
|
||||
@SuppressWarnings("unused")
|
||||
Service s = Service.Builder.newInstance("s").setLocationId("foo").addSizeDimension(0, -10).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo(){
|
||||
Service one = Service.Builder.newInstance("s").setLocationId("foofoo")
|
||||
.addSizeDimension(0,2)
|
||||
.addSizeDimension(1,4)
|
||||
.build();
|
||||
assertEquals(2,one.getSize().getNuOfDimensions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenShipmentIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero(){
|
||||
Service one = Service.Builder.newInstance("s").setLocationId("foofoo")
|
||||
.build();
|
||||
assertEquals(1,one.getSize().getNuOfDimensions());
|
||||
assertEquals(0,one.getSize().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenShipmentIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly(){
|
||||
Service one = Service.Builder.newInstance("s",1).setLocationId("foofoo")
|
||||
.build();
|
||||
assertEquals(1,one.getCapacityDemand());
|
||||
assertEquals(1,one.getSize().getNuOfDimensions());
|
||||
assertEquals(1,one.getSize().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallingForNewInstanceOfBuilder_itShouldReturnBuilderCorrectly(){
|
||||
Service.Builder builder = Service.Builder.newInstance("s", 0);
|
||||
|
|
@ -115,4 +148,5 @@ public class ServiceTest {
|
|||
assertEquals(1.0,s.getTimeWindow().getStart(),0.01);
|
||||
assertEquals(2.0,s.getTimeWindow().getEnd(),0.01);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import jsprit.core.util.Coordinate;
|
|||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ShipmentTest {
|
||||
|
||||
@Test
|
||||
|
|
@ -44,6 +44,12 @@ public class ShipmentTest {
|
|||
Shipment one = Shipment.Builder.newInstance("s", -10).setPickupLocation("foo").setDeliveryLocation("foofoo").build();
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void whenShipmentIsBuiltWithNegativeDemand_itShouldThrowException_v2(){
|
||||
@SuppressWarnings("unused")
|
||||
Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, -10).setPickupLocation("foo").setDeliveryLocation("foofoo").build();
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void whenIdIsNull_itShouldThrowException(){
|
||||
@SuppressWarnings("unused")
|
||||
|
|
@ -193,4 +199,38 @@ public class ShipmentTest {
|
|||
assertEquals(1.0,s.getDeliveryTimeWindow().getStart(),0.01);
|
||||
assertEquals(2.0,s.getDeliveryTimeWindow().getEnd(),0.01);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void whenShipmentHasNegativeCapacityVal_throwIllegalStateExpception(){
|
||||
@SuppressWarnings("unused")
|
||||
Shipment one = Shipment.Builder.newInstance("s").setPickupLocation("foo").setDeliveryLocation("foofoo")
|
||||
.addSizeDimension(0, -2)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo(){
|
||||
Shipment one = Shipment.Builder.newInstance("s").setPickupLocation("foo").setDeliveryLocation("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("foo").setPickupCoord(Coordinate.newInstance(0, 0))
|
||||
.setDeliveryLocation("foofoo").build();
|
||||
assertEquals(1,one.getSize().getNuOfDimensions());
|
||||
assertEquals(0,one.getSize().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenShipmentIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly(){
|
||||
Shipment one = Shipment.Builder.newInstance("s",1).setPickupLocation("foo").setPickupCoord(Coordinate.newInstance(0, 0))
|
||||
.setDeliveryLocation("foofoo").build();
|
||||
assertEquals(1,one.getCapacityDemand());
|
||||
assertEquals(1,one.getSize().getNuOfDimensions());
|
||||
assertEquals(1,one.getSize().get(0));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ public class TestVehicleRoute {
|
|||
|
||||
@Before
|
||||
public void doBefore(){
|
||||
vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").setType(VehicleTypeImpl.Builder.newInstance("yo", 0).build()).build();
|
||||
vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").setType(VehicleTypeImpl.Builder.newInstance("yo").build()).build();
|
||||
driver = DriverImpl.noDriver();
|
||||
}
|
||||
|
||||
|
|
@ -78,7 +78,7 @@ public class TestVehicleRoute {
|
|||
@Test
|
||||
public void whenBuildingANonEmptyTour2Times_tourIterIteratesOverActivitiesCorrectly(){
|
||||
VehicleRoute.Builder routeBuilder = VehicleRoute.Builder.newInstance(vehicle, driver);
|
||||
routeBuilder.addService(Service.Builder.newInstance("2", 30).setLocationId("1").build());
|
||||
routeBuilder.addService(Service.Builder.newInstance("2").addSizeDimension(0, 30).setLocationId("1").build());
|
||||
VehicleRoute route = routeBuilder.build();
|
||||
|
||||
{
|
||||
|
|
@ -92,7 +92,7 @@ public class TestVehicleRoute {
|
|||
assertEquals(1,count);
|
||||
}
|
||||
{
|
||||
route.getTourActivities().addActivity(ServiceActivity.newInstance(Service.Builder.newInstance("3", 30).setLocationId("1").build()));
|
||||
route.getTourActivities().addActivity(ServiceActivity.newInstance(Service.Builder.newInstance("3").addSizeDimension(0, 30).setLocationId("1").build()));
|
||||
Iterator<TourActivity> iter = route.getTourActivities().iterator();
|
||||
int count = 0;
|
||||
while(iter.hasNext()){
|
||||
|
|
@ -120,7 +120,7 @@ public class TestVehicleRoute {
|
|||
@Test
|
||||
public void whenBuildingANonEmptyTourV2_tourReverseIterIteratesOverActivitiesCorrectly(){
|
||||
VehicleRoute.Builder routeBuilder = VehicleRoute.Builder.newInstance(vehicle, driver);
|
||||
routeBuilder.addService(Service.Builder.newInstance("2", 30).setLocationId("1").build());
|
||||
routeBuilder.addService(Service.Builder.newInstance("2").addSizeDimension(0, 30).setLocationId("1").build());
|
||||
VehicleRoute route = routeBuilder.build();
|
||||
Iterator<TourActivity> iter = route.getTourActivities().reverseActivityIterator();
|
||||
int count = 0;
|
||||
|
|
@ -135,8 +135,8 @@ public class TestVehicleRoute {
|
|||
@Test
|
||||
public void whenBuildingANonEmptyTour2Times_tourReverseIterIteratesOverActivitiesCorrectly(){
|
||||
VehicleRoute.Builder routeBuilder = VehicleRoute.Builder.newInstance(vehicle, driver);
|
||||
routeBuilder.addService(Service.Builder.newInstance("2", 30).setLocationId("1").build());
|
||||
routeBuilder.addService(Service.Builder.newInstance("3", 30).setLocationId("2").build());
|
||||
routeBuilder.addService(Service.Builder.newInstance("2").addSizeDimension(0, 30).setLocationId("1").build());
|
||||
routeBuilder.addService(Service.Builder.newInstance("3").addSizeDimension(0, 30).setLocationId("2").build());
|
||||
VehicleRoute route = routeBuilder.build();
|
||||
{
|
||||
Iterator<TourActivity> iter = route.getTourActivities().reverseActivityIterator();
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package jsprit.core.problem.solution.route;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.job.Shipment;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
|
|
@ -30,6 +31,8 @@ public class VehicleRouteBuilderTest {
|
|||
@Test(expected=IllegalStateException.class)
|
||||
public void whenShipmentIsPickedDeliveredAndDeliveredAgain_throwsException(){
|
||||
Shipment s = mock(Shipment.class);
|
||||
Capacity capacity = Capacity.Builder.newInstance().build();
|
||||
when(s.getSize()).thenReturn(capacity);
|
||||
VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class));
|
||||
builder.addPickup(s);
|
||||
builder.addDelivery(s);
|
||||
|
|
@ -39,6 +42,8 @@ public class VehicleRouteBuilderTest {
|
|||
@Test(expected=IllegalStateException.class)
|
||||
public void whenShipmentIsPickedUpThoughButHasNotBeenDeliveredAndRouteIsBuilt_throwsException(){
|
||||
Shipment s = mock(Shipment.class);
|
||||
Capacity capacity = Capacity.Builder.newInstance().build();
|
||||
when(s.getSize()).thenReturn(capacity);
|
||||
VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class));
|
||||
builder.addPickup(s);
|
||||
builder.addPickup(mock(Shipment.class));
|
||||
|
|
@ -50,6 +55,9 @@ public class VehicleRouteBuilderTest {
|
|||
public void whenTwoShipmentsHaveBeenAdded_nuOfActivitiesMustEqualFour(){
|
||||
Shipment s = mock(Shipment.class);
|
||||
Shipment s2 = mock(Shipment.class);
|
||||
Capacity capacity = Capacity.Builder.newInstance().build();
|
||||
when(s.getSize()).thenReturn(capacity);
|
||||
when(s2.getSize()).thenReturn(capacity);
|
||||
VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class));
|
||||
builder.addPickup(s);
|
||||
builder.addPickup(s2);
|
||||
|
|
@ -63,6 +71,9 @@ public class VehicleRouteBuilderTest {
|
|||
public void whenBuildingClosedRoute_routeEndShouldHaveLocationOfVehicle(){
|
||||
Shipment s = mock(Shipment.class);
|
||||
Shipment s2 = mock(Shipment.class);
|
||||
Capacity capacity = Capacity.Builder.newInstance().build();
|
||||
when(s.getSize()).thenReturn(capacity);
|
||||
when(s2.getSize()).thenReturn(capacity);
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.isReturnToDepot()).thenReturn(true);
|
||||
when(vehicle.getStartLocationId()).thenReturn("vehLoc");
|
||||
|
|
@ -80,6 +91,9 @@ public class VehicleRouteBuilderTest {
|
|||
public void whenBuildingOpenRoute_routeEndShouldHaveLocationOfLastActivity(){
|
||||
Shipment s = mock(Shipment.class);
|
||||
Shipment s2 = mock(Shipment.class);
|
||||
Capacity capacity = Capacity.Builder.newInstance().build();
|
||||
when(s.getSize()).thenReturn(capacity);
|
||||
when(s2.getSize()).thenReturn(capacity);
|
||||
when(s2.getDeliveryLocation()).thenReturn("delLoc");
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.isReturnToDepot()).thenReturn(false);
|
||||
|
|
@ -97,6 +111,9 @@ public class VehicleRouteBuilderTest {
|
|||
public void whenSettingDepartureTime(){
|
||||
Shipment s = mock(Shipment.class);
|
||||
Shipment s2 = mock(Shipment.class);
|
||||
Capacity capacity = Capacity.Builder.newInstance().build();
|
||||
when(s.getSize()).thenReturn(capacity);
|
||||
when(s2.getSize()).thenReturn(capacity);
|
||||
when(s2.getDeliveryLocation()).thenReturn("delLoc");
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.isReturnToDepot()).thenReturn(false);
|
||||
|
|
@ -117,6 +134,9 @@ public class VehicleRouteBuilderTest {
|
|||
public void whenSettingEndTime(){
|
||||
Shipment s = mock(Shipment.class);
|
||||
Shipment s2 = mock(Shipment.class);
|
||||
Capacity capacity = Capacity.Builder.newInstance().build();
|
||||
when(s.getSize()).thenReturn(capacity);
|
||||
when(s2.getSize()).thenReturn(capacity);
|
||||
when(s2.getDeliveryLocation()).thenReturn("delLoc");
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.isReturnToDepot()).thenReturn(false);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
package jsprit.core.problem.solution.route.activity;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import jsprit.core.problem.job.Shipment;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class DefaultShipmentActivityFactoryTest {
|
||||
|
||||
@Test
|
||||
public void whenCreatingPickupActivityWithShipment_itShouldReturnPickupShipment(){
|
||||
DefaultShipmentActivityFactory factory = new DefaultShipmentActivityFactory();
|
||||
Shipment shipment = Shipment.Builder.newInstance("s")
|
||||
.setPickupLocation("pLoc").setDeliveryLocation("dLoc").build();
|
||||
TourActivity act = factory.createPickup(shipment);
|
||||
assertNotNull(act);
|
||||
assertTrue(act instanceof PickupShipment);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCreatingDeliverActivityWithShipment_itShouldReturnDeliverShipment(){
|
||||
DefaultShipmentActivityFactory factory = new DefaultShipmentActivityFactory();
|
||||
Shipment shipment = Shipment.Builder.newInstance("s")
|
||||
.setPickupLocation("pLoc").setDeliveryLocation("dLoc").build();
|
||||
TourActivity act = factory.createDelivery(shipment);
|
||||
assertNotNull(act);
|
||||
assertTrue(act instanceof DeliverShipment);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
package jsprit.core.problem.solution.route.activity;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import jsprit.core.problem.job.Delivery;
|
||||
import jsprit.core.problem.job.Pickup;
|
||||
import jsprit.core.problem.job.Service;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class DefaultTourActivityFactoryTest {
|
||||
|
||||
@Test
|
||||
public void whenCreatingActivityWithService_itShouldReturnPickupService(){
|
||||
DefaultTourActivityFactory factory = new DefaultTourActivityFactory();
|
||||
Service service = Service.Builder.newInstance("service").setLocationId("loc").build();
|
||||
TourActivity act = factory.createActivity(service);
|
||||
assertNotNull(act);
|
||||
assertTrue(act instanceof PickupService);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCreatingActivityWithPickup_itShouldReturnPickupService(){
|
||||
DefaultTourActivityFactory factory = new DefaultTourActivityFactory();
|
||||
Pickup service = (Pickup) Pickup.Builder.newInstance("service").setLocationId("loc").build();
|
||||
TourActivity act = factory.createActivity(service);
|
||||
assertNotNull(act);
|
||||
assertTrue(act instanceof PickupService);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCreatingActivityWithDelivery_itShouldReturnDeliverService(){
|
||||
DefaultTourActivityFactory factory = new DefaultTourActivityFactory();
|
||||
Delivery service = (Delivery) Delivery.Builder.newInstance("service").setLocationId("loc").build();
|
||||
TourActivity act = factory.createActivity(service);
|
||||
assertNotNull(act);
|
||||
assertTrue(act instanceof DeliverService);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
package jsprit.core.problem.solution.route.activity;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import jsprit.core.problem.job.Delivery;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DeliverServiceTest {
|
||||
|
||||
private Delivery service;
|
||||
|
||||
private DeliverService deliver;
|
||||
|
||||
@Before
|
||||
public void doBefore(){
|
||||
service = (Delivery) Delivery.Builder.newInstance("service").setLocationId("loc").
|
||||
setTimeWindow(TimeWindow.newInstance(1., 2.)).
|
||||
addSizeDimension(0, 10).addSizeDimension(1, 100).addSizeDimension(2, 1000).build();
|
||||
deliver = new DeliverService(service);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallingCapacity_itShouldReturnCorrectCapacity(){
|
||||
assertEquals(-10,deliver.getSize().get(0));
|
||||
assertEquals(-100,deliver.getSize().get(1));
|
||||
assertEquals(-1000,deliver.getSize().get(2));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void whenCallingCapacityDemand_itShouldReturnCapDimWithIndex0(){
|
||||
assertEquals(-10,deliver.getCapacityDemand());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenStartIsIniWithEarliestStart_itShouldBeSetCorrectly(){
|
||||
assertEquals(1.,deliver.getTheoreticalEarliestOperationStartTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenStartIsIniWithLatestStart_itShouldBeSetCorrectly(){
|
||||
assertEquals(2.,deliver.getTheoreticalLatestOperationStartTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingArrTime_itShouldBeSetCorrectly(){
|
||||
deliver.setArrTime(4.0);
|
||||
assertEquals(4.,deliver.getArrTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingEndTime_itShouldBeSetCorrectly(){
|
||||
deliver.setEndTime(5.0);
|
||||
assertEquals(5.,deliver.getEndTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenIniLocationId_itShouldBeSetCorrectly(){
|
||||
assertEquals("loc",deliver.getLocationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCopyingStart_itShouldBeDoneCorrectly(){
|
||||
DeliverService copy = (DeliverService) deliver.duplicate();
|
||||
assertEquals(1.,copy.getTheoreticalEarliestOperationStartTime(),0.01);
|
||||
assertEquals(2.,copy.getTheoreticalLatestOperationStartTime(),0.01);
|
||||
assertEquals("loc",copy.getLocationId());
|
||||
assertEquals(-10,copy.getSize().get(0));
|
||||
assertEquals(-100,copy.getSize().get(1));
|
||||
assertEquals(-1000,copy.getSize().get(2));
|
||||
assertTrue(copy!=deliver);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
package jsprit.core.problem.solution.route.activity;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import jsprit.core.problem.job.Shipment;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DeliverShipmentTest {
|
||||
|
||||
private Shipment shipment;
|
||||
|
||||
private DeliverShipment deliver;
|
||||
|
||||
@Before
|
||||
public void doBefore(){
|
||||
shipment = Shipment.Builder.newInstance("shipment").setPickupLocation("pickupLoc")
|
||||
.setDeliveryLocation("deliveryLoc")
|
||||
.setPickupTimeWindow(TimeWindow.newInstance(1., 2.))
|
||||
.setDeliveryTimeWindow(TimeWindow.newInstance(3., 4.))
|
||||
.addSizeDimension(0, 10).addSizeDimension(1, 100).addSizeDimension(2, 1000).build();
|
||||
deliver = new DeliverShipment(shipment);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallingCapacity_itShouldReturnCorrectCapacity(){
|
||||
assertEquals(-10,deliver.getSize().get(0));
|
||||
assertEquals(-100,deliver.getSize().get(1));
|
||||
assertEquals(-1000,deliver.getSize().get(2));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void whenCallingCapacityDemand_itShouldReturnCapDimWithIndex0(){
|
||||
assertEquals(-10,deliver.getCapacityDemand());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenStartIsIniWithEarliestStart_itShouldBeSetCorrectly(){
|
||||
assertEquals(3.,deliver.getTheoreticalEarliestOperationStartTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenStartIsIniWithLatestStart_itShouldBeSetCorrectly(){
|
||||
assertEquals(4.,deliver.getTheoreticalLatestOperationStartTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingArrTime_itShouldBeSetCorrectly(){
|
||||
deliver.setArrTime(4.0);
|
||||
assertEquals(4.,deliver.getArrTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingEndTime_itShouldBeSetCorrectly(){
|
||||
deliver.setEndTime(5.0);
|
||||
assertEquals(5.,deliver.getEndTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenIniLocationId_itShouldBeSetCorrectly(){
|
||||
assertEquals("deliveryLoc",deliver.getLocationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCopyingStart_itShouldBeDoneCorrectly(){
|
||||
DeliverShipment copy = (DeliverShipment) deliver.duplicate();
|
||||
assertEquals(3.,copy.getTheoreticalEarliestOperationStartTime(),0.01);
|
||||
assertEquals(4.,copy.getTheoreticalLatestOperationStartTime(),0.01);
|
||||
assertEquals("deliveryLoc",copy.getLocationId());
|
||||
assertEquals(-10,copy.getSize().get(0));
|
||||
assertEquals(-100,copy.getSize().get(1));
|
||||
assertEquals(-1000,copy.getSize().get(2));
|
||||
assertTrue(copy!=deliver);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenGettingCapacity_itShouldReturnItCorrectly(){
|
||||
Shipment shipment = Shipment.Builder.newInstance("s").setPickupLocation("pickLoc").setDeliveryLocation("delLoc")
|
||||
.addSizeDimension(0, 10).addSizeDimension(1, 100).build();
|
||||
PickupShipment pick = new PickupShipment(shipment);
|
||||
assertEquals(10,pick.getSize().get(0));
|
||||
assertEquals(100,pick.getSize().get(1));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
package jsprit.core.problem.solution.route.activity;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class EndTest {
|
||||
|
||||
@Test
|
||||
public void whenCallingCapacity_itShouldReturnEmptyCapacity(){
|
||||
End end = End.newInstance("loc", 0., 0.);
|
||||
assertEquals(0,end.getSize().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallingCapacityDemand_itShouldReturnEmptyCapacity(){
|
||||
End end = End.newInstance("loc", 0., 0.);
|
||||
assertEquals(0,end.getCapacityDemand());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenStartIsIniWithEarliestStart_itShouldBeSetCorrectly(){
|
||||
End end = End.newInstance("loc", 1., 2.);
|
||||
assertEquals(1.,end.getTheoreticalEarliestOperationStartTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenStartIsIniWithLatestStart_itShouldBeSetCorrectly(){
|
||||
End end = End.newInstance("loc", 1., 2.);
|
||||
assertEquals(2.,end.getTheoreticalLatestOperationStartTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingEndTime_itShouldBeSetCorrectly(){
|
||||
End end = End.newInstance("loc", 1., 2.);
|
||||
end.setEndTime(4.0);
|
||||
assertEquals(4.,end.getEndTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingLocationId_itShouldBeSetCorrectly(){
|
||||
End end = End.newInstance("loc", 1., 2.);
|
||||
end.setLocationId("newLoc");
|
||||
assertEquals("newLoc",end.getLocationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingEarliestStart_itShouldBeSetCorrectly(){
|
||||
End end = End.newInstance("loc", 1., 2.);
|
||||
end.setTheoreticalEarliestOperationStartTime(5.);
|
||||
assertEquals(5.,end.getTheoreticalEarliestOperationStartTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingLatestStart_itShouldBeSetCorrectly(){
|
||||
End end = End.newInstance("loc", 1., 2.);
|
||||
end.setTheoreticalLatestOperationStartTime(5.);
|
||||
assertEquals(5.,end.getTheoreticalLatestOperationStartTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCopyingEnd_itShouldBeDoneCorrectly(){
|
||||
End end = End.newInstance("loc", 1., 2.);
|
||||
end.setTheoreticalEarliestOperationStartTime(3.);
|
||||
end.setTheoreticalLatestOperationStartTime(5.);
|
||||
|
||||
End copy = End.copyOf(end);
|
||||
assertEquals(3.,copy.getTheoreticalEarliestOperationStartTime(),0.01);
|
||||
assertEquals(5.,copy.getTheoreticalLatestOperationStartTime(),0.01);
|
||||
assertEquals("loc",copy.getLocationId());
|
||||
assertTrue(copy!=end);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
package jsprit.core.problem.solution.route.activity;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import jsprit.core.problem.job.Service;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class PickupServiceTest {
|
||||
|
||||
private Service service;
|
||||
|
||||
private PickupService pickup;
|
||||
|
||||
@Before
|
||||
public void doBefore(){
|
||||
service = Service.Builder.newInstance("service").setLocationId("loc").
|
||||
setTimeWindow(TimeWindow.newInstance(1., 2.)).
|
||||
addSizeDimension(0, 10).addSizeDimension(1, 100).addSizeDimension(2, 1000).build();
|
||||
pickup = new PickupService(service);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallingCapacity_itShouldReturnCorrectCapacity(){
|
||||
assertEquals(10,pickup.getSize().get(0));
|
||||
assertEquals(100,pickup.getSize().get(1));
|
||||
assertEquals(1000,pickup.getSize().get(2));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void whenCallingCapacityDemand_itShouldReturnCapDimWithIndex0(){
|
||||
assertEquals(10,pickup.getCapacityDemand());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenStartIsIniWithEarliestStart_itShouldBeSetCorrectly(){
|
||||
assertEquals(1.,pickup.getTheoreticalEarliestOperationStartTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenStartIsIniWithLatestStart_itShouldBeSetCorrectly(){
|
||||
assertEquals(2.,pickup.getTheoreticalLatestOperationStartTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingArrTime_itShouldBeSetCorrectly(){
|
||||
pickup.setArrTime(4.0);
|
||||
assertEquals(4.,pickup.getArrTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingEndTime_itShouldBeSetCorrectly(){
|
||||
pickup.setEndTime(5.0);
|
||||
assertEquals(5.,pickup.getEndTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenIniLocationId_itShouldBeSetCorrectly(){
|
||||
assertEquals("loc",pickup.getLocationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCopyingStart_itShouldBeDoneCorrectly(){
|
||||
PickupService copy = (PickupService) pickup.duplicate();
|
||||
assertEquals(1.,copy.getTheoreticalEarliestOperationStartTime(),0.01);
|
||||
assertEquals(2.,copy.getTheoreticalLatestOperationStartTime(),0.01);
|
||||
assertEquals("loc",copy.getLocationId());
|
||||
assertEquals(10,copy.getSize().get(0));
|
||||
assertEquals(100,copy.getSize().get(1));
|
||||
assertEquals(1000,copy.getSize().get(2));
|
||||
assertTrue(copy!=pickup);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
package jsprit.core.problem.solution.route.activity;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import jsprit.core.problem.job.Shipment;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class PickupShipmentTest {
|
||||
|
||||
private Shipment shipment;
|
||||
|
||||
private PickupShipment pickup;
|
||||
|
||||
@Before
|
||||
public void doBefore(){
|
||||
shipment = Shipment.Builder.newInstance("shipment").setPickupLocation("pickupLoc")
|
||||
.setDeliveryLocation("deliveryLoc")
|
||||
.setPickupTimeWindow(TimeWindow.newInstance(1., 2.))
|
||||
.setDeliveryTimeWindow(TimeWindow.newInstance(3., 4.))
|
||||
.addSizeDimension(0, 10).addSizeDimension(1, 100).addSizeDimension(2, 1000).build();
|
||||
pickup = new PickupShipment(shipment);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallingCapacity_itShouldReturnCorrectCapacity(){
|
||||
assertEquals(10,pickup.getSize().get(0));
|
||||
assertEquals(100,pickup.getSize().get(1));
|
||||
assertEquals(1000,pickup.getSize().get(2));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void whenCallingCapacityDemand_itShouldReturnCapDimWithIndex0(){
|
||||
assertEquals(10,pickup.getCapacityDemand());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenStartIsIniWithEarliestStart_itShouldBeSetCorrectly(){
|
||||
assertEquals(1.,pickup.getTheoreticalEarliestOperationStartTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenStartIsIniWithLatestStart_itShouldBeSetCorrectly(){
|
||||
assertEquals(2.,pickup.getTheoreticalLatestOperationStartTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingArrTime_itShouldBeSetCorrectly(){
|
||||
pickup.setArrTime(4.0);
|
||||
assertEquals(4.,pickup.getArrTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingEndTime_itShouldBeSetCorrectly(){
|
||||
pickup.setEndTime(5.0);
|
||||
assertEquals(5.,pickup.getEndTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenIniLocationId_itShouldBeSetCorrectly(){
|
||||
assertEquals("pickupLoc",pickup.getLocationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCopyingStart_itShouldBeDoneCorrectly(){
|
||||
PickupShipment copy = (PickupShipment) pickup.duplicate();
|
||||
assertEquals(1.,copy.getTheoreticalEarliestOperationStartTime(),0.01);
|
||||
assertEquals(2.,copy.getTheoreticalLatestOperationStartTime(),0.01);
|
||||
assertEquals("pickupLoc",copy.getLocationId());
|
||||
assertEquals(10,copy.getSize().get(0));
|
||||
assertEquals(100,copy.getSize().get(1));
|
||||
assertEquals(1000,copy.getSize().get(2));
|
||||
assertTrue(copy!=pickup);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenGettingCapacity_itShouldReturnItCorrectly(){
|
||||
Shipment shipment = Shipment.Builder.newInstance("s").setPickupLocation("pickLoc").setDeliveryLocation("delLoc")
|
||||
.addSizeDimension(0, 10).addSizeDimension(1, 100).build();
|
||||
PickupShipment pick = new PickupShipment(shipment);
|
||||
assertEquals(10,pick.getSize().get(0));
|
||||
assertEquals(100,pick.getSize().get(1));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2013 Stefan Schroeder
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package jsprit.core.problem.solution.route.activity;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.problem.solution.route.activity.ServiceActivity;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class ServiceActTest {
|
||||
|
||||
@Test
|
||||
public void whenTwoDeliveriesHaveTheSameUnderlyingJob_theyAreEqual(){
|
||||
Service s1 = Service.Builder.newInstance("s", 10).setLocationId("loc").build();
|
||||
Service s2 = Service.Builder.newInstance("s", 10).setLocationId("loc").build();
|
||||
|
||||
ServiceActivity d1 = ServiceActivity.newInstance(s1);
|
||||
ServiceActivity d2 = ServiceActivity.newInstance(s2);
|
||||
|
||||
assertTrue(d1.equals(d2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenTwoDeliveriesHaveTheDifferentUnderlyingJob_theyAreNotEqual(){
|
||||
Service s1 = Service.Builder.newInstance("s", 10).setLocationId("loc").build();
|
||||
Service s2 = Service.Builder.newInstance("s1", 10).setLocationId("loc").build();
|
||||
|
||||
ServiceActivity d1 = ServiceActivity.newInstance(s1);
|
||||
ServiceActivity d2 = ServiceActivity.newInstance(s2);
|
||||
|
||||
assertFalse(d1.equals(d2));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,115 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2013 Stefan Schroeder
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package jsprit.core.problem.solution.route.activity;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.problem.solution.route.activity.ServiceActivity;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class ServiceActivityTest {
|
||||
|
||||
private Service service;
|
||||
|
||||
private ServiceActivity serviceActivity;
|
||||
|
||||
@Before
|
||||
public void doBefore(){
|
||||
service = Service.Builder.newInstance("service").setLocationId("loc").
|
||||
setTimeWindow(TimeWindow.newInstance(1., 2.)).
|
||||
addSizeDimension(0, 10).addSizeDimension(1, 100).addSizeDimension(2, 1000).build();
|
||||
serviceActivity = ServiceActivity.newInstance(service);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallingCapacity_itShouldReturnCorrectCapacity(){
|
||||
assertEquals(10,serviceActivity.getSize().get(0));
|
||||
assertEquals(100,serviceActivity.getSize().get(1));
|
||||
assertEquals(1000,serviceActivity.getSize().get(2));
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void whenCallingCapacityDemand_itShouldReturnCapDimWithIndex0(){
|
||||
assertEquals(10,serviceActivity.getCapacityDemand());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenStartIsIniWithEarliestStart_itShouldBeSetCorrectly(){
|
||||
assertEquals(1.,serviceActivity.getTheoreticalEarliestOperationStartTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenStartIsIniWithLatestStart_itShouldBeSetCorrectly(){
|
||||
assertEquals(2.,serviceActivity.getTheoreticalLatestOperationStartTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingArrTime_itShouldBeSetCorrectly(){
|
||||
serviceActivity.setArrTime(4.0);
|
||||
assertEquals(4.,serviceActivity.getArrTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingEndTime_itShouldBeSetCorrectly(){
|
||||
serviceActivity.setEndTime(5.0);
|
||||
assertEquals(5.,serviceActivity.getEndTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenIniLocationId_itShouldBeSetCorrectly(){
|
||||
assertEquals("loc",serviceActivity.getLocationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCopyingStart_itShouldBeDoneCorrectly(){
|
||||
ServiceActivity copy = (ServiceActivity) serviceActivity.duplicate();
|
||||
assertEquals(1.,copy.getTheoreticalEarliestOperationStartTime(),0.01);
|
||||
assertEquals(2.,copy.getTheoreticalLatestOperationStartTime(),0.01);
|
||||
assertEquals("loc",copy.getLocationId());
|
||||
assertTrue(copy!=serviceActivity);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenTwoDeliveriesHaveTheSameUnderlyingJob_theyAreEqual(){
|
||||
Service s1 = Service.Builder.newInstance("s").setLocationId("loc").build();
|
||||
Service s2 = Service.Builder.newInstance("s").setLocationId("loc").build();
|
||||
|
||||
ServiceActivity d1 = ServiceActivity.newInstance(s1);
|
||||
ServiceActivity d2 = ServiceActivity.newInstance(s2);
|
||||
|
||||
assertTrue(d1.equals(d2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenTwoDeliveriesHaveTheDifferentUnderlyingJob_theyAreNotEqual(){
|
||||
Service s1 = Service.Builder.newInstance("s").setLocationId("loc").build();
|
||||
Service s2 = Service.Builder.newInstance("s1").setLocationId("loc").build();
|
||||
|
||||
ServiceActivity d1 = ServiceActivity.newInstance(s1);
|
||||
ServiceActivity d2 = ServiceActivity.newInstance(s2);
|
||||
|
||||
assertFalse(d1.equals(d2));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
package jsprit.core.problem.solution.route.activity;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class StartTest {
|
||||
|
||||
@Test
|
||||
public void whenCallingCapacity_itShouldReturnEmptyCapacity(){
|
||||
Start start = Start.newInstance("loc", 0., 0.);
|
||||
assertEquals(0,start.getSize().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallingCapacityDemand_itShouldReturnEmptyCapacity(){
|
||||
Start start = Start.newInstance("loc", 0., 0.);
|
||||
assertEquals(0,start.getCapacityDemand());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenStartIsIniWithEarliestStart_itShouldBeSetCorrectly(){
|
||||
Start start = Start.newInstance("loc", 1., 2.);
|
||||
assertEquals(1.,start.getTheoreticalEarliestOperationStartTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenStartIsIniWithLatestStart_itShouldBeSetCorrectly(){
|
||||
Start start = Start.newInstance("loc", 1., 2.);
|
||||
assertEquals(2.,start.getTheoreticalLatestOperationStartTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingStartEndTime_itShouldBeSetCorrectly(){
|
||||
Start start = Start.newInstance("loc", 1., 2.);
|
||||
start.setEndTime(4.0);
|
||||
assertEquals(4.,start.getEndTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingLocationId_itShouldBeSetCorrectly(){
|
||||
Start start = Start.newInstance("loc", 1., 2.);
|
||||
start.setLocationId("newLoc");
|
||||
assertEquals("newLoc",start.getLocationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingEarliestStart_itShouldBeSetCorrectly(){
|
||||
Start start = Start.newInstance("loc", 1., 2.);
|
||||
start.setTheoreticalEarliestOperationStartTime(5.);
|
||||
assertEquals(5.,start.getTheoreticalEarliestOperationStartTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingLatestStart_itShouldBeSetCorrectly(){
|
||||
Start start = Start.newInstance("loc", 1., 2.);
|
||||
start.setTheoreticalLatestOperationStartTime(5.);
|
||||
assertEquals(5.,start.getTheoreticalLatestOperationStartTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCopyingStart_itShouldBeDoneCorrectly(){
|
||||
Start start = Start.newInstance("loc", 1., 2.);
|
||||
start.setTheoreticalEarliestOperationStartTime(3.);
|
||||
start.setTheoreticalLatestOperationStartTime(5.);
|
||||
|
||||
Start copy = Start.copyOf(start);
|
||||
assertEquals(3.,copy.getTheoreticalEarliestOperationStartTime(),0.01);
|
||||
assertEquals(5.,copy.getTheoreticalLatestOperationStartTime(),0.01);
|
||||
assertEquals("loc",copy.getLocationId());
|
||||
assertTrue(copy!=start);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -40,7 +40,7 @@ public class TestTour {
|
|||
|
||||
@Before
|
||||
public void doBefore(){
|
||||
service = Service.Builder.newInstance("yo", 10).setLocationId("loc").build();
|
||||
service = Service.Builder.newInstance("yo").addSizeDimension(0, 10).setLocationId("loc").build();
|
||||
act = ServiceActivity.newInstance(service);
|
||||
tour = new TourActivities();
|
||||
}
|
||||
|
|
@ -73,7 +73,7 @@ public class TestTour {
|
|||
assertEquals(0, tour.getActivities().size());
|
||||
tour.addActivity(act);
|
||||
assertEquals(1, tour.getActivities().size());
|
||||
Service anotherServiceInstance = Service.Builder.newInstance("yo", 10).setLocationId("loc").build();
|
||||
Service anotherServiceInstance = Service.Builder.newInstance("yo").addSizeDimension(0, 10).setLocationId("loc").build();
|
||||
assertTrue(service.equals(anotherServiceInstance));
|
||||
boolean removed = tour.removeJob(anotherServiceInstance);
|
||||
assertTrue(removed);
|
||||
|
|
@ -82,7 +82,7 @@ public class TestTour {
|
|||
|
||||
@Test
|
||||
public void whenAddingAShipmentActivity_tourShouldServeShipment(){
|
||||
Shipment s = Shipment.Builder.newInstance("s", 1).setDeliveryLocation("delLoc").setPickupLocation("pickLoc").build();
|
||||
Shipment s = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setDeliveryLocation("delLoc").setPickupLocation("pickLoc").build();
|
||||
TourShipmentActivityFactory fac = new DefaultShipmentActivityFactory();
|
||||
TourActivity pickupShipment = fac.createPickup(s);
|
||||
TourActivity deliverShipment = fac.createDelivery(s);
|
||||
|
|
@ -96,7 +96,7 @@ public class TestTour {
|
|||
|
||||
@Test
|
||||
public void whenRemovingShipment_tourShouldNotServiceItAnymore(){
|
||||
Shipment s = Shipment.Builder.newInstance("s", 1).setDeliveryLocation("delLoc").setPickupLocation("pickLoc").build();
|
||||
Shipment s = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setDeliveryLocation("delLoc").setPickupLocation("pickLoc").build();
|
||||
TourShipmentActivityFactory fac = new DefaultShipmentActivityFactory();
|
||||
TourActivity pickupShipment = fac.createPickup(s);
|
||||
TourActivity deliverShipment = fac.createDelivery(s);
|
||||
|
|
@ -110,7 +110,7 @@ public class TestTour {
|
|||
|
||||
@Test
|
||||
public void whenRemovingShipment_theirCorrespondingActivitiesShouldBeRemoved(){
|
||||
Shipment s = Shipment.Builder.newInstance("s", 1).setDeliveryLocation("delLoc").setPickupLocation("pickLoc").build();
|
||||
Shipment s = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setDeliveryLocation("delLoc").setPickupLocation("pickLoc").build();
|
||||
TourShipmentActivityFactory fac = new DefaultShipmentActivityFactory();
|
||||
TourActivity pickupShipment = fac.createPickup(s);
|
||||
TourActivity deliverShipment = fac.createDelivery(s);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
package jsprit.core.problem.solution.route.activity;
|
||||
|
||||
public class TimeWindowTest {
|
||||
|
||||
}
|
||||
|
|
@ -39,8 +39,8 @@ public class TestVehicleFleetManagerImpl extends TestCase{
|
|||
public void setUp(){
|
||||
List<Vehicle> vehicles = new ArrayList<Vehicle>();
|
||||
|
||||
v1 = VehicleImpl.Builder.newInstance("standard").setStartLocationId("loc").setType(VehicleTypeImpl.Builder.newInstance("standard", 0).build()).build();
|
||||
v2 = VehicleImpl.Builder.newInstance("foo").setStartLocationId("fooLoc").setType(VehicleTypeImpl.Builder.newInstance("foo", 0).build()).build();
|
||||
v1 = VehicleImpl.Builder.newInstance("standard").setStartLocationId("loc").setType(VehicleTypeImpl.Builder.newInstance("standard").build()).build();
|
||||
v2 = VehicleImpl.Builder.newInstance("foo").setStartLocationId("fooLoc").setType(VehicleTypeImpl.Builder.newInstance("foo").build()).build();
|
||||
|
||||
// v1.
|
||||
vehicles.add(v1);
|
||||
|
|
@ -92,7 +92,7 @@ public class TestVehicleFleetManagerImpl extends TestCase{
|
|||
|
||||
public void testWithPenalty_whenHavingOneRegularVehicleAvailable_noPenaltyVehicleIsReturn(){
|
||||
Vehicle penalty4standard = VehicleImpl.Builder.newInstance("standard_penalty").setStartLocationId("loc").
|
||||
setType(VehicleTypeImpl.Builder.newInstance("standard", 0).build()).build();
|
||||
setType(VehicleTypeImpl.Builder.newInstance("standard").build()).build();
|
||||
|
||||
List<Vehicle> vehicles = new ArrayList<Vehicle>();
|
||||
vehicles.add(v1);
|
||||
|
|
@ -105,7 +105,7 @@ public class TestVehicleFleetManagerImpl extends TestCase{
|
|||
}
|
||||
|
||||
public void testWithPenalty_whenHavingTwoRegularVehicleAvailablePlusOnePenaltyVehicle_andOneIsLocked_returnTheOtherRegularVehicle(){
|
||||
VehicleTypeImpl penaltyType = VehicleTypeImpl.Builder.newInstance("standard", 0).build();
|
||||
VehicleTypeImpl penaltyType = VehicleTypeImpl.Builder.newInstance("standard").build();
|
||||
PenaltyVehicleType penaltyVehicleType = new PenaltyVehicleType(penaltyType);
|
||||
|
||||
Vehicle penalty4standard = VehicleImpl.Builder.newInstance("standard_penalty").setStartLocationId("loc").
|
||||
|
|
@ -128,7 +128,7 @@ public class TestVehicleFleetManagerImpl extends TestCase{
|
|||
}
|
||||
|
||||
public void testWithPenalty_whenHavingNoRegularVehicleAvailable_penaltyVehicleIsReturned(){
|
||||
VehicleTypeImpl penaltyType = VehicleTypeImpl.Builder.newInstance("standard", 0).build();
|
||||
VehicleTypeImpl penaltyType = VehicleTypeImpl.Builder.newInstance("standard").build();
|
||||
|
||||
Vehicle penalty4standard = VehicleImpl.Builder.newInstance("standard_penalty").setStartLocationId("loc").
|
||||
setType(penaltyType).build();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package jsprit.core.problem.vehicle;
|
||||
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import jsprit.core.problem.vehicle.VehicleImpl.NoVehicle;
|
||||
|
|
@ -197,4 +198,5 @@ public class VehicleImplTest {
|
|||
assertTrue(true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,78 +6,131 @@ import org.junit.Test;
|
|||
|
||||
public class VehicleTypeImplTest {
|
||||
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void whenTypeHasNegativeCapacityVal_throwIllegalStateExpception(){
|
||||
@SuppressWarnings("unused")
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").addCapacityDimension(0,-10).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo(){
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t")
|
||||
.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();
|
||||
assertEquals(2,type.getCapacityDimensions().get(0));
|
||||
assertEquals(4,type.getCapacityDimensions().get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenTypeIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDim(){
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").build();
|
||||
assertEquals(1,type.getCapacityDimensions().getNuOfDimensions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenTypeIsBuiltWithoutSpecifyingCapacity_itShouldHvCapDimValOfZero(){
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").build();
|
||||
assertEquals(0,type.getCapacityDimensions().get(0));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void whenTypeIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly(){
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t",20).build();
|
||||
assertEquals(20,type.getCapacity());
|
||||
assertEquals(20,type.getCapacityDimensions().get(0));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void whenCallingStaticNewBuilderInstance_itShouldReturnNewBuilderInstance(){
|
||||
VehicleTypeImpl.Builder builder = VehicleTypeImpl.Builder.newInstance("foo", 0);
|
||||
assertNotNull(builder);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void whenBuildingTypeJustByCallingNewInstance_typeIdMustBeCorrect(){
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("foo", 0).build();
|
||||
assertEquals("foo",type.getTypeId());
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void whenBuildingTypeJustByCallingNewInstance_capMustBeCorrect(){
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("foo", 0).build();
|
||||
assertEquals(0,type.getCapacity());
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test(expected=IllegalStateException.class)
|
||||
public void whenBuildingTypeWithCapSmallerThanZero_throwIllegalStateException(){
|
||||
@SuppressWarnings("unused")
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("foo", -10).build();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test(expected=IllegalStateException.class)
|
||||
public void whenBuildingTypeWithNullId_throwIllegalStateException(){
|
||||
@SuppressWarnings("unused")
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance(null, 10).build();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenSettingMaxVelocity_itShouldBeSetCorrectly(){
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type", 10).setMaxVelocity(10).build();
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setMaxVelocity(10).build();
|
||||
assertEquals(10,type.getMaxVelocity(),0.0);
|
||||
}
|
||||
|
||||
|
||||
@Test(expected=IllegalStateException.class)
|
||||
public void whenMaxVelocitySmallerThanZero_itShouldThrowException(){
|
||||
@SuppressWarnings("unused")
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type", 10).setMaxVelocity(-10).build();
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setMaxVelocity(-10).build();
|
||||
}
|
||||
|
||||
@Test(expected=IllegalStateException.class)
|
||||
public void whenFixedCostsSmallerThanZero_itShouldThrowException(){
|
||||
@SuppressWarnings("unused")
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type", 10).setFixedCost(-10).build();
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setFixedCost(-10).build();
|
||||
}
|
||||
|
||||
public void whenSettingFixedCosts_itShouldBeSetCorrectly(){
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type", 10).setFixedCost(10).build();
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setFixedCost(10).build();
|
||||
assertEquals(10.0, type.getVehicleCostParams().fix,0.0);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalStateException.class)
|
||||
public void whenPerDistanceCostsSmallerThanZero_itShouldThrowException(){
|
||||
@SuppressWarnings("unused")
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type", 10).setCostPerDistance(-10).build();
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setCostPerDistance(-10).build();
|
||||
}
|
||||
|
||||
public void whenSettingPerDistanceCosts_itShouldBeSetCorrectly(){
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type", 10).setCostPerDistance(10).build();
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setCostPerDistance(10).build();
|
||||
assertEquals(10.0, type.getVehicleCostParams().perDistanceUnit,0.0);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalStateException.class)
|
||||
public void whenPerTimeCostsSmallerThanZero_itShouldThrowException(){
|
||||
@SuppressWarnings("unused")
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type", 10).setCostPerTime(-10).build();
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setCostPerTime(-10).build();
|
||||
}
|
||||
|
||||
public void whenSettingPerTimeCosts_itShouldBeSetCorrectly(){
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type", 10).setCostPerTime(10).build();
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setCostPerTime(10).build();
|
||||
assertEquals(10.0, type.getVehicleCostParams().perDistanceUnit,0.0);
|
||||
}
|
||||
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue