mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
tested and modified according to multiple capacities
This commit is contained in:
parent
217c824506
commit
09486fadec
49 changed files with 878 additions and 490 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;
|
||||
|
|
|
|||
|
|
@ -540,7 +540,7 @@ public class VehicleRoutingAlgorithms {
|
|||
stateManager = stateMan;
|
||||
}
|
||||
else{
|
||||
stateManager = new StateManager(vrp);
|
||||
stateManager = new StateManager(vrp.getTransportCosts());
|
||||
}
|
||||
stateManager.updateLoadStates();
|
||||
stateManager.updateTimeWindowStates();
|
||||
|
|
@ -621,7 +621,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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -117,19 +117,19 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
|
|||
defaultActivityStates_.put(StateFactory.LOAD, Capacity.Builder.newInstance().build());
|
||||
|
||||
|
||||
defaultActivityStates_.put(StateFactory.COSTS, StateFactory.createState(0));
|
||||
defaultActivityStates_.put(StateFactory.DURATION, StateFactory.createState(0));
|
||||
defaultActivityStates_.put(StateFactory.FUTURE_MAXLOAD, StateFactory.createState(0));
|
||||
defaultActivityStates_.put(StateFactory.PAST_MAXLOAD, StateFactory.createState(0));
|
||||
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, StateFactory.createState(0));
|
||||
defaultRouteStates_.put(StateFactory.DURATION, StateFactory.createState(0));
|
||||
defaultRouteStates_.put(StateFactory.FUTURE_MAXLOAD, StateFactory.createState(0));
|
||||
defaultRouteStates_.put(StateFactory.PAST_MAXLOAD, StateFactory.createState(0));
|
||||
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, StateFactory.createState(0));
|
||||
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());
|
||||
|
|
@ -223,10 +223,10 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
|
|||
return type.cast(defaultActivityStates_.get(stateId));
|
||||
}
|
||||
if(stateId.equals(StateFactory.EARLIEST_OPERATION_START_TIME)){
|
||||
return type.cast(StateFactory.createState(act.getTheoreticalEarliestOperationStartTime()));
|
||||
return type.cast(act.getTheoreticalEarliestOperationStartTime());
|
||||
}
|
||||
if(stateId.equals(StateFactory.LATEST_OPERATION_START_TIME)){
|
||||
return type.cast(StateFactory.createState(act.getTheoreticalLatestOperationStartTime()));
|
||||
return type.cast(act.getTheoreticalLatestOperationStartTime());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
@ -437,7 +437,7 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
|
|||
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() {}
|
||||
|
||||
}
|
||||
|
|
@ -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.putInternalActivityState_(activity, StateFactory.LATEST_OPERATION_START_TIME, Double.class, latestArrivalTime);
|
||||
|
||||
latestArrTimeAtPrevAct = latestArrivalTime;
|
||||
prevAct = activity;
|
||||
|
|
@ -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.putInternalActivityState_(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.putInternalRouteState_(vehicleRoute, StateFactory.COSTS, Double.class, totalOperationCost);
|
||||
|
||||
startTimeAtPrevAct = 0.0;
|
||||
prevAct = null;
|
||||
|
|
|
|||
|
|
@ -190,12 +190,9 @@ public class Capacity {
|
|||
* @param toCompare
|
||||
* @return
|
||||
* @throws NullPointerException if one of the args is null
|
||||
* @throws IllegalStateException if number of capacityDimensions of this capacity and toCompare are different.
|
||||
*/
|
||||
public boolean isLessOrEqual(Capacity toCompare){
|
||||
if(toCompare == null) throw new NullPointerException();
|
||||
if(this.getNuOfDimensions() != toCompare.getNuOfDimensions()) throw new IllegalStateException("cap1.getNuOfDimension()="+this.getNuOfDimensions()+
|
||||
"!= cap2.getNuOfDimension()="+toCompare.getNuOfDimensions()+ ". cannot add up capacities with different dimension.");
|
||||
for(int i=0;i<this.getNuOfDimensions();i++){
|
||||
if(this.get(i) > toCompare.get(i)) return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -45,22 +46,29 @@ public class PickupAndDeliverShipmentLoadActivityLevelConstraint implements Hard
|
|||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem.job;
|
||||
|
||||
import jsprit.core.problem.job.Pickup.Builder;
|
||||
|
||||
/**
|
||||
* Delivery extends Service and is intended to model a Service where smth is UNLOADED (i.e. delivered) from a transport unit.
|
||||
|
|
|
|||
|
|
@ -45,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();
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -76,7 +76,9 @@ 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");
|
||||
|
|
@ -102,7 +104,9 @@ public class VehicleTypeImpl implements VehicleType {
|
|||
|
||||
private Capacity.Builder capacityBuilder = Capacity.Builder.newInstance();
|
||||
|
||||
private Capacity capacityDimensions;
|
||||
private Capacity capacityDimensions = null;
|
||||
|
||||
private boolean dimensionAdded = false;
|
||||
|
||||
/**
|
||||
* Constructs the builder.
|
||||
|
|
@ -110,6 +114,7 @@ public class VehicleTypeImpl implements VehicleType {
|
|||
* @param id
|
||||
* @param capacity
|
||||
*/
|
||||
@Deprecated
|
||||
private Builder(String id, int capacity) {
|
||||
super();
|
||||
this.id = id;
|
||||
|
|
@ -183,7 +188,9 @@ public class VehicleTypeImpl implements VehicleType {
|
|||
* @return VehicleTypeImpl
|
||||
*/
|
||||
public VehicleTypeImpl build(){
|
||||
capacityDimensions = capacityBuilder.build();
|
||||
if(capacityDimensions == null){
|
||||
capacityDimensions = capacityBuilder.build();
|
||||
}
|
||||
return new VehicleTypeImpl(this);
|
||||
}
|
||||
|
||||
|
|
@ -194,14 +201,36 @@ public class VehicleTypeImpl implements VehicleType {
|
|||
* @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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
@ -120,7 +100,7 @@ public class ServiceInsertionAndLoadConstraintsTest {
|
|||
|
||||
VehicleRoutingProblem vrp = mock(VehicleRoutingProblem.class);
|
||||
|
||||
StateManager stateManager = new StateManager(vrp);
|
||||
StateManager stateManager = new StateManager(vrp.getTransportCosts());
|
||||
stateManager.updateLoadStates();
|
||||
|
||||
ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager);
|
||||
|
|
|
|||
|
|
@ -30,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;
|
||||
|
|
@ -76,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);
|
||||
|
|
@ -102,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);
|
||||
|
|
@ -111,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);
|
||||
|
||||
|
|
@ -124,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() {
|
||||
|
|
@ -144,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());
|
||||
|
|
@ -161,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());
|
||||
|
|
@ -178,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();
|
||||
|
||||
|
||||
|
||||
|
|
@ -194,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);
|
||||
|
||||
|
|
@ -213,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);
|
||||
|
||||
|
|
@ -226,7 +213,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);
|
||||
|
||||
|
|
@ -245,7 +232,7 @@ public class ShipmentInsertionCalculatorTest {
|
|||
switcher.put(Shipment.class, insertionCalculator);
|
||||
|
||||
// Service service = Service.Builder.newInstance("pick", 1).setLocationId("5,5").build();
|
||||
Pickup service = (Pickup)Pickup.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(){
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,11 +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.Capacity;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.constraint.PickupAndDeliverShipmentLoadActivityLevelConstraint;
|
||||
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;
|
||||
|
|
@ -16,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;
|
||||
|
|
@ -36,12 +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);
|
||||
Capacity capacity = Capacity.Builder.newInstance().addDimension(0, 1).build();
|
||||
when(shipment.getSize()).thenReturn(capacity);
|
||||
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);
|
||||
}
|
||||
|
|
@ -61,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.putInternalActivityState_(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));
|
||||
}
|
||||
|
|
@ -72,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.putInternalActivityState_(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));
|
||||
}
|
||||
|
||||
|
|
@ -82,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.putInternalActivityState_(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));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,11 +18,28 @@ 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));
|
||||
|
|
@ -45,7 +62,7 @@ public class UpdateLoadsTest {
|
|||
Capacity capacity = Capacity.Builder.newInstance().addDimension(0, 1).build();
|
||||
when(service.getSize()).thenReturn(capacity);
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class))
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(service).build();
|
||||
|
||||
updateLoads.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
|
|
@ -62,7 +79,7 @@ public class UpdateLoadsTest {
|
|||
Capacity capacity = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1,2).build();
|
||||
when(service.getSize()).thenReturn(capacity);
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class))
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(service).build();
|
||||
|
||||
updateLoads.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
|
|
@ -83,7 +100,7 @@ public class UpdateLoadsTest {
|
|||
Service service2 = mock(Service.class);
|
||||
when(service2.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10).build());
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class))
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(service).addService(service2).build();
|
||||
|
||||
updateLoads.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
|
|
@ -102,7 +119,7 @@ public class UpdateLoadsTest {
|
|||
Service service2 = mock(Service.class);
|
||||
when(service2.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10).addDimension(1, 14).build());
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class))
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(service).addService(service2).build();
|
||||
|
||||
updateLoads.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
|
|
@ -126,7 +143,7 @@ public class UpdateLoadsTest {
|
|||
Service service2 = mock(Service.class);
|
||||
when(service2.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10).build());
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class))
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(service).addService(service2).build();
|
||||
|
||||
routeActivityVisitor.visit(route);
|
||||
|
|
@ -149,7 +166,7 @@ public class UpdateLoadsTest {
|
|||
Service service2 = mock(Service.class);
|
||||
when(service2.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10).addDimension(1, 13).build());
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class))
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(service).addService(service2).build();
|
||||
|
||||
routeActivityVisitor.visit(route);
|
||||
|
|
@ -171,7 +188,7 @@ public class UpdateLoadsTest {
|
|||
Delivery delivery = mock(Delivery.class);
|
||||
when(delivery.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10).build());
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class))
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(pickup).addService(delivery).build();
|
||||
|
||||
updateLoads.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
|
|
@ -190,7 +207,7 @@ public class UpdateLoadsTest {
|
|||
Delivery delivery = mock(Delivery.class);
|
||||
when(delivery.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10).addDimension(1, 13).build());
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class))
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(pickup).addService(delivery).build();
|
||||
|
||||
updateLoads.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
|
|
@ -215,7 +232,7 @@ public class UpdateLoadsTest {
|
|||
Capacity capacity2 = Capacity.Builder.newInstance().addDimension(0, 10).build();
|
||||
when(delivery.getSize()).thenReturn(capacity2);
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class))
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(pickup).addService(delivery).build();
|
||||
|
||||
updateLoads.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
|
|
@ -240,7 +257,7 @@ public class UpdateLoadsTest {
|
|||
Capacity capacity2 = Capacity.Builder.newInstance().addDimension(0, 10).addDimension(1, 14).build();
|
||||
when(delivery.getSize()).thenReturn(capacity2);
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class))
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(pickup).addService(delivery).build();
|
||||
|
||||
updateLoads.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
|
|
@ -270,7 +287,7 @@ public class UpdateLoadsTest {
|
|||
Pickup pickup2insert = mock(Pickup.class);
|
||||
when(pickup2insert.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).build());
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class))
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(pickup).addService(delivery).build();
|
||||
|
||||
updateLoads.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
|
|
@ -298,7 +315,7 @@ public class UpdateLoadsTest {
|
|||
Pickup pickup2insert = mock(Pickup.class);
|
||||
when(pickup2insert.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 4).build());
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class))
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(pickup).addService(delivery).build();
|
||||
|
||||
updateLoads.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
|
|
@ -329,7 +346,7 @@ public class UpdateLoadsTest {
|
|||
Capacity size2 = Capacity.Builder.newInstance().addDimension(0, 20).build();
|
||||
when(delivery2insert.getSize()).thenReturn(size2);
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class))
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(pickup).addService(delivery).build();
|
||||
|
||||
updateLoads.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
|
|
@ -358,7 +375,7 @@ public class UpdateLoadsTest {
|
|||
Capacity size2 = Capacity.Builder.newInstance().addDimension(0, 20).addDimension(1, 25).build();
|
||||
when(delivery2insert.getSize()).thenReturn(size2);
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class))
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(pickup).addService(delivery).build();
|
||||
|
||||
updateLoads.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -18,10 +18,27 @@ 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 UpdateCapacityUtilizationForwardLookingTest {
|
||||
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(){
|
||||
|
|
@ -41,7 +58,7 @@ public class UpdateCapacityUtilizationForwardLookingTest {
|
|||
Delivery delivery = mock(Delivery.class);
|
||||
when(delivery.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10).build());
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class))
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(pickup).addService(delivery).build();
|
||||
|
||||
updateLoad.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
|
|
@ -72,7 +89,7 @@ public class UpdateCapacityUtilizationForwardLookingTest {
|
|||
when(delivery.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10)
|
||||
.addDimension(1, 3).build());
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class))
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(pickup).addService(delivery).build();
|
||||
|
||||
updateLoad.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
|
|
@ -109,7 +126,7 @@ public class UpdateCapacityUtilizationForwardLookingTest {
|
|||
when(pickup2.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 3)
|
||||
.addDimension(1, 8).build());
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class))
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(pickup).addService(delivery).addService(pickup2).build();
|
||||
|
||||
updateLoad.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
|
|
@ -151,7 +168,7 @@ public class UpdateCapacityUtilizationForwardLookingTest {
|
|||
when(pickup2.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 3)
|
||||
.addDimension(1, 8).addDimension(4, 29).build());
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class))
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class))
|
||||
.addService(pickup).addService(delivery).addService(pickup2).build();
|
||||
|
||||
updateLoad.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
|
|
@ -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 {
|
||||
|
||||
}
|
||||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ public class VehicleTypeImplTest {
|
|||
assertEquals(0,type.getCapacityDimensions().get(0));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void whenTypeIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly(){
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t",20).build();
|
||||
|
|
@ -51,78 +52,85 @@ public class VehicleTypeImplTest {
|
|||
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);
|
||||
}
|
||||
|
||||
|
|
|
|||
36
jsprit-core/src/test/java/jsprit/core/util/CostFactory.java
Normal file
36
jsprit-core/src/test/java/jsprit/core/util/CostFactory.java
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
package jsprit.core.util;
|
||||
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
|
||||
public class CostFactory {
|
||||
|
||||
public static VehicleRoutingTransportCosts createManhattanCosts(){
|
||||
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]));
|
||||
}
|
||||
|
||||
};
|
||||
return new ManhattanCosts(locations);
|
||||
}
|
||||
|
||||
public static VehicleRoutingTransportCosts createEuclideanCosts(){
|
||||
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]));
|
||||
}
|
||||
|
||||
};
|
||||
return new CrowFlyCosts(locations);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue