mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
relax api
This commit is contained in:
parent
ee94ac2e21
commit
1e520f3269
42 changed files with 382 additions and 948 deletions
|
|
@ -32,30 +32,39 @@ public class BestInsertionBuilder implements InsertionStrategyBuilder{
|
||||||
this.stateManager = stateManager;
|
this.stateManager = stateManager;
|
||||||
this.constraintManager = new ConstraintManager();
|
this.constraintManager = new ConstraintManager();
|
||||||
this.fleetManager = vehicleFleetManager;
|
this.fleetManager = vehicleFleetManager;
|
||||||
|
addCoreStateUpdaters();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private void addCoreStateUpdaters(){
|
||||||
* Adds core constraints, i.e.
|
stateManager.addListener(new UpdateLoadsAtStartAndEndOfRouteWhenInsertionStarts(stateManager));
|
||||||
*
|
stateManager.addListener(new UpdateLoadsAtStartAndEndOfRouteWhenJobHasBeenInserted(stateManager));
|
||||||
* <p>HardPickupAndDeliveryLoadRouteLevelConstraint<br>
|
|
||||||
* HardTimeWindowActivityLevelConstraint<br>
|
stateManager.addActivityVisitor(new UpdateMaxLoad(stateManager));
|
||||||
* if(Constraint.DELIVERIES_FIRST) HardPickupAndDeliveryBackhaulActivityLevelConstraint<br>
|
stateManager.addActivityVisitor(new UpdateActivityTimes(vrp.getTransportCosts()));
|
||||||
* else HardPickupAndDeliveryActivityLevelConstraint
|
stateManager.addActivityVisitor(new UpdateCostsAtAllLevels(vrp.getActivityCosts(), vrp.getTransportCosts(), stateManager));
|
||||||
* @return
|
}
|
||||||
*/
|
|
||||||
public BestInsertionBuilder addCoreConstraints(){
|
public BestInsertionBuilder addHardLoadConstraints(){
|
||||||
constraintManager.addConstraint(new HardPickupAndDeliveryLoadRouteLevelConstraint(stateManager));
|
constraintManager.addConstraint(new HardPickupAndDeliveryLoadRouteLevelConstraint(stateManager));
|
||||||
constraintManager.addConstraint(new HardTimeWindowActivityLevelConstraint(stateManager, vrp.getTransportCosts()));
|
|
||||||
if(vrp.getProblemConstraints().contains(Constraint.DELIVERIES_FIRST)){
|
if(vrp.getProblemConstraints().contains(Constraint.DELIVERIES_FIRST)){
|
||||||
constraintManager.addConstraint(new HardPickupAndDeliveryBackhaulActivityLevelConstraint(stateManager));
|
constraintManager.addConstraint(new HardPickupAndDeliveryBackhaulActivityLevelConstraint(stateManager));
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
constraintManager.addConstraint(new HardPickupAndDeliveryActivityLevelConstraint(stateManager));
|
constraintManager.addConstraint(new HardPickupAndDeliveryActivityLevelConstraint(stateManager));
|
||||||
}
|
}
|
||||||
StateUtils.addCoreStateUpdaters(vrp, stateManager);
|
stateManager.addActivityVisitor(new UpdateOccuredDeliveriesAtActivityLevel(stateManager));
|
||||||
|
stateManager.addActivityVisitor(new UpdateFuturePickupsAtActivityLevel(stateManager));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BestInsertionBuilder addHardTimeWindowConstraint(){
|
||||||
|
constraintManager.addConstraint(new HardTimeWindowActivityLevelConstraint(stateManager, vrp.getTransportCosts()));
|
||||||
|
stateManager.addActivityVisitor(new UpdateEarliestStartTimeWindowAtActLocations(stateManager, vrp.getTransportCosts()));
|
||||||
|
stateManager.addActivityVisitor(new UpdateLatestOperationStartTimeAtActLocations(stateManager, vrp.getTransportCosts()));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public BestInsertionBuilder addConstraint(HardActivityLevelConstraint hardActvitiyLevelConstraint){
|
public BestInsertionBuilder addConstraint(HardActivityLevelConstraint hardActvitiyLevelConstraint){
|
||||||
constraintManager.addConstraint(hardActvitiyLevelConstraint);
|
constraintManager.addConstraint(hardActvitiyLevelConstraint);
|
||||||
return this;
|
return this;
|
||||||
|
|
@ -115,7 +124,7 @@ public class BestInsertionBuilder implements InsertionStrategyBuilder{
|
||||||
|
|
||||||
private void addCoreUpdater() {
|
private void addCoreUpdater() {
|
||||||
if(!hasActivityTimeUpdater()){
|
if(!hasActivityTimeUpdater()){
|
||||||
stateManager.addActivityVisitor(new UpdateActivityTimes(vrp.getTransportCosts()));
|
|
||||||
}
|
}
|
||||||
// if(!hasLoadUpdater()){
|
// if(!hasLoadUpdater()){
|
||||||
// stateManager.addActivityVisitor(new UpdateLoadAtActivityLevel(stateManager));
|
// stateManager.addActivityVisitor(new UpdateLoadAtActivityLevel(stateManager));
|
||||||
|
|
|
||||||
|
|
@ -236,7 +236,7 @@ class CalculatorBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
private CalculatorPlusListeners createCalculatorConsideringFixedCosts(VehicleRoutingProblem vrp, JobInsertionCalculator baseCalculator, StateGetter activityStates2, double weightOfFixedCosts){
|
private CalculatorPlusListeners createCalculatorConsideringFixedCosts(VehicleRoutingProblem vrp, JobInsertionCalculator baseCalculator, StateGetter activityStates2, double weightOfFixedCosts){
|
||||||
final CalculatesServiceInsertionConsideringFixCost withFixCost = new CalculatesServiceInsertionConsideringFixCost(baseCalculator, activityStates2);
|
final JobInsertionConsideringFixCostsCalculator withFixCost = new JobInsertionConsideringFixCostsCalculator(baseCalculator, activityStates2);
|
||||||
withFixCost.setWeightOfFixCost(weightOfFixedCosts);
|
withFixCost.setWeightOfFixCost(weightOfFixedCosts);
|
||||||
CalculatorPlusListeners calcPlusListeners = new CalculatorPlusListeners(withFixCost);
|
CalculatorPlusListeners calcPlusListeners = new CalculatorPlusListeners(withFixCost);
|
||||||
calcPlusListeners.getInsertionListener().add(new ConfigureFixCostCalculator(vrp, withFixCost));
|
calcPlusListeners.getInsertionListener().add(new ConfigureFixCostCalculator(vrp, withFixCost));
|
||||||
|
|
@ -262,7 +262,7 @@ class CalculatorBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
private JobInsertionCalculator createFinalInsertion(VehicleFleetManager fleetManager, JobInsertionCalculator baseCalc, StateGetter activityStates2){
|
private JobInsertionCalculator createFinalInsertion(VehicleFleetManager fleetManager, JobInsertionCalculator baseCalc, StateGetter activityStates2){
|
||||||
return new CalculatesVehTypeDepServiceInsertion(fleetManager, baseCalc);
|
return new VehicleTypeDependentJobInsertionCalculator(fleetManager, baseCalc);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConstraintManager(ConstraintManager constraintManager) {
|
public void setConstraintManager(ConstraintManager constraintManager) {
|
||||||
|
|
|
||||||
|
|
@ -37,11 +37,11 @@ final class ConfigureFixCostCalculator implements InsertionStartsListener, JobIn
|
||||||
|
|
||||||
VehicleRoutingProblem vrp;
|
VehicleRoutingProblem vrp;
|
||||||
|
|
||||||
CalculatesServiceInsertionConsideringFixCost calcConsideringFix;
|
JobInsertionConsideringFixCostsCalculator calcConsideringFix;
|
||||||
|
|
||||||
private int nuOfJobsToRecreate;
|
private int nuOfJobsToRecreate;
|
||||||
|
|
||||||
public ConfigureFixCostCalculator(VehicleRoutingProblem vrp, CalculatesServiceInsertionConsideringFixCost calcConsideringFix) {
|
public ConfigureFixCostCalculator(VehicleRoutingProblem vrp, JobInsertionConsideringFixCostsCalculator calcConsideringFix) {
|
||||||
super();
|
super();
|
||||||
this.vrp = vrp;
|
this.vrp = vrp;
|
||||||
this.calcConsideringFix = calcConsideringFix;
|
this.calcConsideringFix = calcConsideringFix;
|
||||||
|
|
|
||||||
|
|
@ -79,11 +79,11 @@ final class FindCheaperVehicleAlgo {
|
||||||
if(vehicle.getType().getTypeId().equals(vehicleRoute.getVehicle().getType().getTypeId())){
|
if(vehicle.getType().getTypeId().equals(vehicleRoute.getVehicle().getType().getTypeId())){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(states.getRouteState(vehicleRoute,StateIdFactory.LOAD).toDouble() <= vehicle.getCapacity()){
|
if(states.getRouteState(vehicleRoute,StateFactory.LOAD).toDouble() <= vehicle.getCapacity()){
|
||||||
double fixCostSaving = vehicleRoute.getVehicle().getType().getVehicleCostParams().fix - vehicle.getType().getVehicleCostParams().fix;
|
double fixCostSaving = vehicleRoute.getVehicle().getType().getVehicleCostParams().fix - vehicle.getType().getVehicleCostParams().fix;
|
||||||
double departureTime = vehicleRoute.getStart().getEndTime();
|
double departureTime = vehicleRoute.getStart().getEndTime();
|
||||||
double newCost = auxilliaryCostCalculator.costOfPath(path, departureTime, vehicleRoute.getDriver(), vehicle);
|
double newCost = auxilliaryCostCalculator.costOfPath(path, departureTime, vehicleRoute.getDriver(), vehicle);
|
||||||
double varCostSaving = states.getRouteState(vehicleRoute, StateIdFactory.COSTS).toDouble() - newCost;
|
double varCostSaving = states.getRouteState(vehicleRoute, StateFactory.COSTS).toDouble() - newCost;
|
||||||
double totalCostSaving = varCostSaving + weightFixCosts*fixCostSaving;
|
double totalCostSaving = varCostSaving + weightFixCosts*fixCostSaving;
|
||||||
if(totalCostSaving > bestSaving){
|
if(totalCostSaving > bestSaving){
|
||||||
bestSaving = totalCostSaving;
|
bestSaving = totalCostSaving;
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ class HardLoadConstraint implements HardRouteLevelConstraint{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean fulfilled(InsertionContext insertionContext) {
|
public boolean fulfilled(InsertionContext insertionContext) {
|
||||||
int currentLoad = (int) states.getRouteState(insertionContext.getRoute(), StateIdFactory.LOAD).toDouble();
|
int currentLoad = (int) states.getRouteState(insertionContext.getRoute(), StateFactory.LOAD).toDouble();
|
||||||
Service service = (Service) insertionContext.getJob();
|
Service service = (Service) insertionContext.getJob();
|
||||||
if(currentLoad + service.getCapacityDemand() > insertionContext.getNewVehicle().getCapacity()){
|
if(currentLoad + service.getCapacityDemand() > insertionContext.getNewVehicle().getCapacity()){
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -21,14 +21,14 @@ class HardPickupAndDeliveryActivityLevelConstraint implements HardActivityLevelC
|
||||||
int futurePicks;
|
int futurePicks;
|
||||||
int pastDeliveries;
|
int pastDeliveries;
|
||||||
if(prevAct instanceof Start){
|
if(prevAct instanceof Start){
|
||||||
loadAtPrevAct = (int)stateManager.getRouteState(iFacts.getRoute(), StateIdFactory.LOAD_AT_BEGINNING).toDouble();
|
loadAtPrevAct = (int)stateManager.getRouteState(iFacts.getRoute(), StateFactory.LOAD_AT_BEGINNING).toDouble();
|
||||||
futurePicks = (int)stateManager.getRouteState(iFacts.getRoute(), StateIdFactory.LOAD).toDouble();
|
futurePicks = (int)stateManager.getRouteState(iFacts.getRoute(), StateFactory.LOAD_AT_END).toDouble();
|
||||||
pastDeliveries = 0;
|
pastDeliveries = 0;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
loadAtPrevAct = (int) stateManager.getActivityState(prevAct, StateIdFactory.LOAD).toDouble();
|
loadAtPrevAct = (int) stateManager.getActivityState(prevAct, StateFactory.LOAD).toDouble();
|
||||||
futurePicks = (int) stateManager.getActivityState(prevAct, StateIdFactory.FUTURE_PICKS).toDouble();
|
futurePicks = (int) stateManager.getActivityState(prevAct, StateFactory.FUTURE_PICKS).toDouble();
|
||||||
pastDeliveries = (int) stateManager.getActivityState(prevAct, StateIdFactory.PAST_DELIVERIES).toDouble();
|
pastDeliveries = (int) stateManager.getActivityState(prevAct, StateFactory.PAST_DELIVERIES).toDouble();
|
||||||
}
|
}
|
||||||
if(newAct instanceof PickupActivity || newAct instanceof ServiceActivity){
|
if(newAct instanceof PickupActivity || newAct instanceof ServiceActivity){
|
||||||
if(loadAtPrevAct + newAct.getCapacityDemand() + futurePicks > iFacts.getNewVehicle().getCapacity()){
|
if(loadAtPrevAct + newAct.getCapacityDemand() + futurePicks > iFacts.getNewVehicle().getCapacity()){
|
||||||
|
|
|
||||||
|
|
@ -25,14 +25,14 @@ class HardPickupAndDeliveryBackhaulActivityLevelConstraint implements HardActivi
|
||||||
int futurePicks;
|
int futurePicks;
|
||||||
int pastDeliveries;
|
int pastDeliveries;
|
||||||
if(prevAct instanceof Start){
|
if(prevAct instanceof Start){
|
||||||
loadAtPrevAct = (int)stateManager.getRouteState(iFacts.getRoute(), StateIdFactory.LOAD_AT_BEGINNING).toDouble();
|
loadAtPrevAct = (int)stateManager.getRouteState(iFacts.getRoute(), StateFactory.LOAD_AT_BEGINNING).toDouble();
|
||||||
futurePicks = (int)stateManager.getRouteState(iFacts.getRoute(), StateIdFactory.LOAD).toDouble();
|
futurePicks = (int)stateManager.getRouteState(iFacts.getRoute(), StateFactory.LOAD_AT_END).toDouble();
|
||||||
pastDeliveries = 0;
|
pastDeliveries = 0;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
loadAtPrevAct = (int) stateManager.getActivityState(prevAct, StateIdFactory.LOAD).toDouble();
|
loadAtPrevAct = (int) stateManager.getActivityState(prevAct, StateFactory.LOAD).toDouble();
|
||||||
futurePicks = (int) stateManager.getActivityState(prevAct, StateIdFactory.FUTURE_PICKS).toDouble();
|
futurePicks = (int) stateManager.getActivityState(prevAct, StateFactory.FUTURE_PICKS).toDouble();
|
||||||
pastDeliveries = (int) stateManager.getActivityState(prevAct, StateIdFactory.PAST_DELIVERIES).toDouble();
|
pastDeliveries = (int) stateManager.getActivityState(prevAct, StateFactory.PAST_DELIVERIES).toDouble();
|
||||||
}
|
}
|
||||||
if(newAct instanceof PickupActivity || newAct instanceof ServiceActivity){
|
if(newAct instanceof PickupActivity || newAct instanceof ServiceActivity){
|
||||||
if(loadAtPrevAct + newAct.getCapacityDemand() + futurePicks > iFacts.getNewVehicle().getCapacity()){
|
if(loadAtPrevAct + newAct.getCapacityDemand() + futurePicks > iFacts.getNewVehicle().getCapacity()){
|
||||||
|
|
|
||||||
|
|
@ -22,13 +22,13 @@ class HardPickupAndDeliveryLoadRouteLevelConstraint implements HardRouteLevelCon
|
||||||
@Override
|
@Override
|
||||||
public boolean fulfilled(InsertionContext insertionContext) {
|
public boolean fulfilled(InsertionContext insertionContext) {
|
||||||
if(insertionContext.getJob() instanceof Delivery){
|
if(insertionContext.getJob() instanceof Delivery){
|
||||||
int loadAtDepot = (int) stateManager.getRouteState(insertionContext.getRoute(), StateIdFactory.LOAD_AT_BEGINNING).toDouble();
|
int loadAtDepot = (int) stateManager.getRouteState(insertionContext.getRoute(), StateFactory.LOAD_AT_BEGINNING).toDouble();
|
||||||
if(loadAtDepot + insertionContext.getJob().getCapacityDemand() > insertionContext.getNewVehicle().getCapacity()){
|
if(loadAtDepot + insertionContext.getJob().getCapacityDemand() > insertionContext.getNewVehicle().getCapacity()){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(insertionContext.getJob() instanceof Pickup || insertionContext.getJob() instanceof Service){
|
else if(insertionContext.getJob() instanceof Pickup || insertionContext.getJob() instanceof Service){
|
||||||
int loadAtEnd = (int) stateManager.getRouteState(insertionContext.getRoute(), StateIdFactory.LOAD).toDouble();
|
int loadAtEnd = (int) stateManager.getRouteState(insertionContext.getRoute(), StateFactory.LOAD_AT_END).toDouble();
|
||||||
if(loadAtEnd + insertionContext.getJob().getCapacityDemand() > insertionContext.getNewVehicle().getCapacity()){
|
if(loadAtEnd + insertionContext.getJob().getCapacityDemand() > insertionContext.getNewVehicle().getCapacity()){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,14 +28,14 @@ import basics.route.TourActivity;
|
||||||
public boolean fulfilled(InsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) {
|
public boolean fulfilled(InsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) {
|
||||||
// log.info("check insertion of " + newAct + " between " + prevAct + " and " + nextAct + ". prevActDepTime=" + prevActDepTime);
|
// 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 arrTimeAtNewAct = prevActDepTime + routingCosts.getTransportTime(prevAct.getLocationId(), newAct.getLocationId(), prevActDepTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||||
double latestArrTimeAtNewAct = states.getActivityState(newAct, StateIdFactory.LATEST_OPERATION_START_TIME).toDouble();
|
double latestArrTimeAtNewAct = states.getActivityState(newAct, StateFactory.LATEST_OPERATION_START_TIME).toDouble();
|
||||||
if(arrTimeAtNewAct > latestArrTimeAtNewAct){
|
if(arrTimeAtNewAct > latestArrTimeAtNewAct){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// log.info(newAct + " arrTime=" + arrTimeAtNewAct);
|
// log.info(newAct + " arrTime=" + arrTimeAtNewAct);
|
||||||
double endTimeAtNewAct = CalculationUtils.getActivityEndTime(arrTimeAtNewAct, newAct);
|
double endTimeAtNewAct = CalculationUtils.getActivityEndTime(arrTimeAtNewAct, newAct);
|
||||||
double arrTimeAtNextAct = endTimeAtNewAct + routingCosts.getTransportTime(newAct.getLocationId(), nextAct.getLocationId(), endTimeAtNewAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
double arrTimeAtNextAct = endTimeAtNewAct + routingCosts.getTransportTime(newAct.getLocationId(), nextAct.getLocationId(), endTimeAtNewAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||||
double latestArrTimeAtNextAct = states.getActivityState(nextAct, StateIdFactory.LATEST_OPERATION_START_TIME).toDouble();
|
double latestArrTimeAtNextAct = states.getActivityState(nextAct, StateFactory.LATEST_OPERATION_START_TIME).toDouble();
|
||||||
if(arrTimeAtNextAct > latestArrTimeAtNextAct){
|
if(arrTimeAtNextAct > latestArrTimeAtNextAct){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,9 @@ import basics.route.VehicleRoute;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
final class CalculatesServiceInsertionConsideringFixCost implements JobInsertionCalculator{
|
final class JobInsertionConsideringFixCostsCalculator implements JobInsertionCalculator{
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(CalculatesServiceInsertionConsideringFixCost.class);
|
private static final Logger logger = Logger.getLogger(JobInsertionConsideringFixCostsCalculator.class);
|
||||||
|
|
||||||
private final JobInsertionCalculator standardServiceInsertion;
|
private final JobInsertionCalculator standardServiceInsertion;
|
||||||
|
|
||||||
|
|
@ -37,12 +37,12 @@ final class CalculatesServiceInsertionConsideringFixCost implements JobInsertion
|
||||||
|
|
||||||
private double solution_completeness_ratio = 0.5;
|
private double solution_completeness_ratio = 0.5;
|
||||||
|
|
||||||
private StateGetter states;
|
private StateGetter stateGetter;
|
||||||
|
|
||||||
public CalculatesServiceInsertionConsideringFixCost(final JobInsertionCalculator standardInsertionCalculator, StateGetter activityStates2) {
|
public JobInsertionConsideringFixCostsCalculator(final JobInsertionCalculator standardInsertionCalculator, StateGetter stateGetter) {
|
||||||
super();
|
super();
|
||||||
this.standardServiceInsertion = standardInsertionCalculator;
|
this.standardServiceInsertion = standardInsertionCalculator;
|
||||||
this.states = activityStates2;
|
this.stateGetter = stateGetter;
|
||||||
logger.info("inialise " + this);
|
logger.info("inialise " + this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -80,7 +80,7 @@ final class CalculatesServiceInsertionConsideringFixCost implements JobInsertion
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getDeltaAbsoluteFixCost(VehicleRoute route, Vehicle newVehicle, Job job) {
|
private double getDeltaAbsoluteFixCost(VehicleRoute route, Vehicle newVehicle, Job job) {
|
||||||
double load = getCurrentLoad(route) + job.getCapacityDemand();
|
double load = getCurrentMaxLoadInRoute(route) + job.getCapacityDemand();
|
||||||
double currentFix = 0.0;
|
double currentFix = 0.0;
|
||||||
if(route.getVehicle() != null){
|
if(route.getVehicle() != null){
|
||||||
if(!(route.getVehicle() instanceof NoVehicle)){
|
if(!(route.getVehicle() instanceof NoVehicle)){
|
||||||
|
|
@ -94,7 +94,7 @@ final class CalculatesServiceInsertionConsideringFixCost implements JobInsertion
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getDeltaRelativeFixCost(VehicleRoute route, Vehicle newVehicle, Job job) {
|
private double getDeltaRelativeFixCost(VehicleRoute route, Vehicle newVehicle, Job job) {
|
||||||
int currentLoad = getCurrentLoad(route);
|
int currentLoad = getCurrentMaxLoadInRoute(route);
|
||||||
double load = currentLoad + job.getCapacityDemand();
|
double load = currentLoad + job.getCapacityDemand();
|
||||||
double currentRelFix = 0.0;
|
double currentRelFix = 0.0;
|
||||||
if(route.getVehicle() != null){
|
if(route.getVehicle() != null){
|
||||||
|
|
@ -109,8 +109,8 @@ final class CalculatesServiceInsertionConsideringFixCost implements JobInsertion
|
||||||
return relativeFixCost;
|
return relativeFixCost;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getCurrentLoad(VehicleRoute route) {
|
private int getCurrentMaxLoadInRoute(VehicleRoute route) {
|
||||||
return (int) states.getRouteState(route, StateIdFactory.LOAD).toDouble();
|
return (int) stateGetter.getRouteState(route, StateFactory.MAXLOAD).toDouble();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -69,9 +69,9 @@ class RouteLevelActivityInsertionCostsEstimator implements ActivityInsertionCost
|
||||||
|
|
||||||
private double actCostsOld(VehicleRoute vehicleRoute, TourActivity act) {
|
private double actCostsOld(VehicleRoute vehicleRoute, TourActivity act) {
|
||||||
if(act instanceof End){
|
if(act instanceof End){
|
||||||
return stateManager.getRouteState(vehicleRoute,StateIdFactory.COSTS).toDouble();
|
return stateManager.getRouteState(vehicleRoute,StateFactory.COSTS).toDouble();
|
||||||
}
|
}
|
||||||
return stateManager.getActivityState(act,StateIdFactory.COSTS).toDouble();
|
return stateManager.getActivityState(act,StateFactory.COSTS).toDouble();
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<TourActivity> getForwardLookingPath(VehicleRoute route, int actIndex) {
|
private List<TourActivity> getForwardLookingPath(VehicleRoute route, int actIndex) {
|
||||||
|
|
|
||||||
|
|
@ -276,7 +276,7 @@ final class ServiceInsertionOnRouteLevelCalculator implements JobInsertionCalcul
|
||||||
/**
|
/**
|
||||||
* compute cost-diff of tour with and without new activity --> insertion_costs
|
* 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,StateIdFactory.COSTS).toDouble();
|
double insertion_costs = auxilliaryPathCostCalculator.costOfPath(wholeTour, start.getEndTime(), newDriver, newVehicle) - stateManager.getRouteState(currentRoute,StateFactory.COSTS).toDouble();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* if better than best known, make it the best known
|
* if better than best known, make it the best known
|
||||||
|
|
@ -321,9 +321,9 @@ final class ServiceInsertionOnRouteLevelCalculator implements JobInsertionCalcul
|
||||||
|
|
||||||
private double sumOf_prevCosts_oldVehicle(VehicleRoute vehicleRoute, TourActivity act) {
|
private double sumOf_prevCosts_oldVehicle(VehicleRoute vehicleRoute, TourActivity act) {
|
||||||
if(act instanceof End){
|
if(act instanceof End){
|
||||||
return stateManager.getRouteState(vehicleRoute,StateIdFactory.COSTS).toDouble();
|
return stateManager.getRouteState(vehicleRoute,StateFactory.COSTS).toDouble();
|
||||||
}
|
}
|
||||||
return stateManager.getActivityState(act,StateIdFactory.COSTS).toDouble();
|
return stateManager.getActivityState(act,StateFactory.COSTS).toDouble();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
package algorithms;
|
||||||
|
|
||||||
|
import basics.VehicleRoutingProblemSolution;
|
||||||
|
import basics.algo.SolutionCostCalculator;
|
||||||
|
import basics.route.VehicleRoute;
|
||||||
|
|
||||||
|
public class SolutionCostCalculatorFactory {
|
||||||
|
|
||||||
|
private StateManager stateManager;
|
||||||
|
|
||||||
|
public SolutionCostCalculatorFactory(StateManager stateManager) {
|
||||||
|
super();
|
||||||
|
this.stateManager = stateManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SolutionCostCalculator createCalculator(){
|
||||||
|
return new SolutionCostCalculator() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void calculateCosts(VehicleRoutingProblemSolution solution) {
|
||||||
|
double c = 0.0;
|
||||||
|
for(VehicleRoute r : solution.getRoutes()){
|
||||||
|
c += stateManager.getRouteState(r, StateFactory.COSTS).toDouble();
|
||||||
|
c += r.getVehicle().getType().getVehicleCostParams().fix;
|
||||||
|
}
|
||||||
|
solution.setCost(c);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -23,9 +23,13 @@ package algorithms;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import algorithms.StateGetter.State;
|
||||||
import algorithms.StateGetter.StateId;
|
import algorithms.StateGetter.StateId;
|
||||||
|
import algorithms.StateManager.StateImpl;
|
||||||
|
|
||||||
public class StateIdFactory {
|
public class StateFactory {
|
||||||
|
|
||||||
|
final static StateId MAXLOAD = new StateIdImpl("maxload");
|
||||||
|
|
||||||
final static StateId LOAD = new StateIdImpl("load");
|
final static StateId LOAD = new StateIdImpl("load");
|
||||||
|
|
||||||
|
|
@ -45,7 +49,7 @@ public class StateIdFactory {
|
||||||
|
|
||||||
final static StateId PAST_DELIVERIES = new StateIdImpl("pastDeliveries");
|
final static StateId PAST_DELIVERIES = new StateIdImpl("pastDeliveries");
|
||||||
|
|
||||||
final static List<String> reservedIds = Arrays.asList("load","costs","loadAtBeginning","loadAtEnd","duration","latestOST","earliestOST"
|
final static List<String> reservedIds = Arrays.asList("maxload","load","costs","loadAtBeginning","loadAtEnd","duration","latestOST","earliestOST"
|
||||||
,"futurePicks","pastDeliveries");
|
,"futurePicks","pastDeliveries");
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -54,6 +58,10 @@ public class StateIdFactory {
|
||||||
return new StateIdImpl(name);
|
return new StateIdImpl(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static State createState(double value){
|
||||||
|
return new StateImpl(value);
|
||||||
|
}
|
||||||
|
|
||||||
private static void throwException(String name) {
|
private static void throwException(String name) {
|
||||||
throw new IllegalStateException("state-id with name '" + name + "' cannot be created. it is already reserved internally.");
|
throw new IllegalStateException("state-id with name '" + name + "' cannot be created. it is already reserved internally.");
|
||||||
}
|
}
|
||||||
|
|
@ -46,7 +46,7 @@ public class StateManager implements StateGetter, IterationStartsListener, RuinL
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class StateImpl implements State{
|
static class StateImpl implements State{
|
||||||
double state;
|
double state;
|
||||||
|
|
||||||
public StateImpl(double state) {
|
public StateImpl(double state) {
|
||||||
|
|
@ -92,6 +92,18 @@ public class StateManager implements StateGetter, IterationStartsListener, RuinL
|
||||||
|
|
||||||
private Collection<StateUpdater> updaters = new ArrayList<StateUpdater>();
|
private Collection<StateUpdater> updaters = new ArrayList<StateUpdater>();
|
||||||
|
|
||||||
|
private Map<StateId,State> defaultRouteStates = new HashMap<StateGetter.StateId, StateGetter.State>();
|
||||||
|
|
||||||
|
private Map<StateId,State> defaultActivityStates = new HashMap<StateId, State>();
|
||||||
|
|
||||||
|
public void addDefaultRouteState(StateId stateId, State defaultState){
|
||||||
|
defaultRouteStates.put(stateId, defaultState);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addDefaultActivityState(StateId stateId, State defaultState){
|
||||||
|
defaultActivityStates.put(stateId, defaultState);
|
||||||
|
}
|
||||||
|
|
||||||
public void clear(){
|
public void clear(){
|
||||||
vehicleRouteStates.clear();
|
vehicleRouteStates.clear();
|
||||||
activityStates.clear();
|
activityStates.clear();
|
||||||
|
|
@ -208,21 +220,23 @@ public class StateManager implements StateGetter, IterationStartsListener, RuinL
|
||||||
}
|
}
|
||||||
|
|
||||||
private State getDefaultActState(StateId stateId, TourActivity act){
|
private State getDefaultActState(StateId stateId, TourActivity act){
|
||||||
if(stateId.equals(StateIdFactory.LOAD)) return new StateImpl(0);
|
if(stateId.equals(StateFactory.LOAD)) return new StateImpl(0);
|
||||||
if(stateId.equals(StateIdFactory.COSTS)) return new StateImpl(0);
|
if(stateId.equals(StateFactory.COSTS)) return new StateImpl(0);
|
||||||
if(stateId.equals(StateIdFactory.DURATION)) return new StateImpl(0);
|
if(stateId.equals(StateFactory.DURATION)) return new StateImpl(0);
|
||||||
if(stateId.equals(StateIdFactory.EARLIEST_OPERATION_START_TIME)) return new StateImpl(act.getTheoreticalEarliestOperationStartTime());
|
if(stateId.equals(StateFactory.EARLIEST_OPERATION_START_TIME)) return new StateImpl(act.getTheoreticalEarliestOperationStartTime());
|
||||||
if(stateId.equals(StateIdFactory.LATEST_OPERATION_START_TIME)) return new StateImpl(act.getTheoreticalLatestOperationStartTime());
|
if(stateId.equals(StateFactory.LATEST_OPERATION_START_TIME)) return new StateImpl(act.getTheoreticalLatestOperationStartTime());
|
||||||
if(stateId.equals(StateIdFactory.FUTURE_PICKS)) return new StateImpl(0);
|
if(stateId.equals(StateFactory.FUTURE_PICKS)) return new StateImpl(0);
|
||||||
if(stateId.equals(StateIdFactory.PAST_DELIVERIES)) return new StateImpl(0);
|
if(stateId.equals(StateFactory.PAST_DELIVERIES)) return new StateImpl(0);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private State getDefaultRouteState(StateId stateId, VehicleRoute route){
|
private State getDefaultRouteState(StateId stateId, VehicleRoute route){
|
||||||
if(stateId.equals(StateIdFactory.LOAD)) return new StateImpl(0);
|
if(stateId.equals(StateFactory.MAXLOAD)) return new StateImpl(0);
|
||||||
if(stateId.equals(StateIdFactory.LOAD_AT_BEGINNING)) return new StateImpl(0);
|
if(stateId.equals(StateFactory.LOAD)) return new StateImpl(0);
|
||||||
if(stateId.equals(StateIdFactory.COSTS)) return new StateImpl(0);
|
if(stateId.equals(StateFactory.LOAD_AT_END)) return new StateImpl(0);
|
||||||
if(stateId.equals(StateIdFactory.DURATION)) return new StateImpl(0);
|
if(stateId.equals(StateFactory.LOAD_AT_BEGINNING)) return new StateImpl(0);
|
||||||
|
if(stateId.equals(StateFactory.COSTS)) return new StateImpl(0);
|
||||||
|
if(stateId.equals(StateFactory.DURATION)) return new StateImpl(0);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,811 +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 algorithms;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import basics.Job;
|
|
||||||
import basics.algo.JobInsertedListener;
|
|
||||||
import basics.algo.RuinListener;
|
|
||||||
import basics.costs.VehicleRoutingActivityCosts;
|
|
||||||
import basics.costs.VehicleRoutingTransportCosts;
|
|
||||||
import basics.route.VehicleRoute;
|
|
||||||
|
|
||||||
|
|
||||||
class StateUpdates {
|
|
||||||
|
|
||||||
// static class UpdateCostsAtRouteLevel implements JobInsertedListener, InsertionStartsListener, InsertionEndsListener{
|
|
||||||
//
|
|
||||||
// private StateManagerImpl states;
|
|
||||||
//
|
|
||||||
// private VehicleRoutingTransportCosts tpCosts;
|
|
||||||
//
|
|
||||||
// private VehicleRoutingActivityCosts actCosts;
|
|
||||||
//
|
|
||||||
// public UpdateCostsAtRouteLevel(StateManagerImpl states, VehicleRoutingTransportCosts tpCosts, VehicleRoutingActivityCosts actCosts) {
|
|
||||||
// super();
|
|
||||||
// this.states = states;
|
|
||||||
// this.tpCosts = tpCosts;
|
|
||||||
// this.actCosts = actCosts;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) {
|
|
||||||
//// inRoute.getVehicleRouteCostCalculator().addTransportCost(additionalCosts);
|
|
||||||
// double oldCosts = states.getRouteState(inRoute, StateTypes.COSTS).toDouble();
|
|
||||||
// oldCosts += additionalCosts;
|
|
||||||
// states.putRouteState(inRoute, StateTypes.COSTS, new StateImpl(oldCosts));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void informInsertionStarts(Collection<VehicleRoute> vehicleRoutes, Collection<Job> unassignedJobs) {
|
|
||||||
// RouteActivityVisitor forwardInTime = new RouteActivityVisitor();
|
|
||||||
// forwardInTime.addActivityVisitor(new UpdateCostsAtAllLevels(actCosts, tpCosts, states));
|
|
||||||
// for(VehicleRoute route : vehicleRoutes){
|
|
||||||
// forwardInTime.visit(route);
|
|
||||||
// }
|
|
||||||
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void informInsertionEnds(Collection<VehicleRoute> vehicleRoutes) {
|
|
||||||
//
|
|
||||||
//// IterateRouteForwardInTime forwardInTime = new IterateRouteForwardInTime(tpCosts);
|
|
||||||
//// forwardInTime.addListener(new UpdateCostsAtAllLevels(actCosts, tpCosts, states));
|
|
||||||
//// for(VehicleRoute route : vehicleRoutes){
|
|
||||||
//// if(route.isEmpty()) continue;
|
|
||||||
//// route.getVehicleRouteCostCalculator().reset();
|
|
||||||
//// route.getVehicleRouteCostCalculator().addOtherCost(states.getRouteState(route, StateTypes.COSTS).toDouble());
|
|
||||||
//// route.getVehicleRouteCostCalculator().price(route.getVehicle());
|
|
||||||
//// forwardInTime.iterate(route);
|
|
||||||
//// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// static class UpdateActivityTimes implements ActivityVisitor{
|
|
||||||
//
|
|
||||||
// private Logger log = Logger.getLogger(UpdateActivityTimes.class);
|
|
||||||
//
|
|
||||||
// private ActivityTimeTracker timeTracker;
|
|
||||||
//
|
|
||||||
// private VehicleRoute route;
|
|
||||||
//
|
|
||||||
// public UpdateActivityTimes(ForwardTransportTime transportTime) {
|
|
||||||
// super();
|
|
||||||
// timeTracker = new ActivityTimeTracker(transportTime);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void begin(VehicleRoute route) {
|
|
||||||
// timeTracker.begin(route);
|
|
||||||
// this.route = route;
|
|
||||||
// route.getStart().setEndTime(timeTracker.getActEndTime());
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void visit(TourActivity activity) {
|
|
||||||
// timeTracker.visit(activity);
|
|
||||||
// activity.setArrTime(timeTracker.getActArrTime());
|
|
||||||
// activity.setEndTime(timeTracker.getActEndTime());
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void finish() {
|
|
||||||
// timeTracker.finish();
|
|
||||||
// route.getEnd().setArrTime(timeTracker.getActArrTime());
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// static class UpdateCostsAtAllLevels implements ActivityVisitor{
|
|
||||||
//
|
|
||||||
// private static Logger log = Logger.getLogger(UpdateCostsAtAllLevels.class);
|
|
||||||
//
|
|
||||||
// private VehicleRoutingActivityCosts activityCost;
|
|
||||||
//
|
|
||||||
// private ForwardTransportCost transportCost;
|
|
||||||
//
|
|
||||||
// private StateManagerImpl states;
|
|
||||||
//
|
|
||||||
// private double totalOperationCost = 0.0;
|
|
||||||
//
|
|
||||||
// private VehicleRoute vehicleRoute = null;
|
|
||||||
//
|
|
||||||
// private TourActivity prevAct = null;
|
|
||||||
//
|
|
||||||
// private double startTimeAtPrevAct = 0.0;
|
|
||||||
//
|
|
||||||
// private ActivityTimeTracker timeTracker;
|
|
||||||
//
|
|
||||||
// public UpdateCostsAtAllLevels(VehicleRoutingActivityCosts activityCost, VehicleRoutingTransportCosts transportCost, StateManagerImpl states) {
|
|
||||||
// super();
|
|
||||||
// this.activityCost = activityCost;
|
|
||||||
// this.transportCost = transportCost;
|
|
||||||
// this.states = states;
|
|
||||||
// timeTracker = new ActivityTimeTracker(transportCost);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void begin(VehicleRoute route) {
|
|
||||||
// vehicleRoute = route;
|
|
||||||
// vehicleRoute.getVehicleRouteCostCalculator().reset();
|
|
||||||
// timeTracker.begin(route);
|
|
||||||
// prevAct = route.getStart();
|
|
||||||
// startTimeAtPrevAct = timeTracker.getActEndTime();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void visit(TourActivity act) {
|
|
||||||
// timeTracker.visit(act);
|
|
||||||
//
|
|
||||||
// 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.putActivityState(act, StateTypes.COSTS, new StateImpl(totalOperationCost));
|
|
||||||
//
|
|
||||||
// prevAct = act;
|
|
||||||
// startTimeAtPrevAct = timeTracker.getActEndTime();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void finish() {
|
|
||||||
// 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();
|
|
||||||
//
|
|
||||||
// states.putRouteState(vehicleRoute, StateTypes.COSTS, new StateImpl(totalOperationCost));
|
|
||||||
//
|
|
||||||
// //this is rather strange and likely to change
|
|
||||||
//// vehicleRoute.getVehicleRouteCostCalculator().price(vehicleRoute.getDriver());
|
|
||||||
//// vehicleRoute.getVehicleRouteCostCalculator().price(vehicleRoute.getVehicle());
|
|
||||||
//// vehicleRoute.getVehicleRouteCostCalculator().finish();
|
|
||||||
//
|
|
||||||
// startTimeAtPrevAct = 0.0;
|
|
||||||
// prevAct = null;
|
|
||||||
// vehicleRoute = null;
|
|
||||||
// totalOperationCost = 0.0;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private double getFixCosts() {
|
|
||||||
// Vehicle vehicle = vehicleRoute.getVehicle();
|
|
||||||
// if(vehicle == null) return 0.0;
|
|
||||||
// VehicleType type = vehicle.getType();
|
|
||||||
// if(type == null) return 0.0;
|
|
||||||
// return type.getVehicleCostParams().fix;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// static class UpdateEarliestStartTimeWindowAtActLocations implements ActivityVisitor{
|
|
||||||
//
|
|
||||||
// private StateManagerImpl states;
|
|
||||||
//
|
|
||||||
// private ActivityTimeTracker timeTracker;
|
|
||||||
//
|
|
||||||
// public UpdateEarliestStartTimeWindowAtActLocations(StateManagerImpl 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.putActivityState(activity, StateTypes.EARLIEST_OPERATION_START_TIME, new StateImpl(Math.max(timeTracker.getActArrTime(), activity.getTheoreticalEarliestOperationStartTime())));
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void finish() {}
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// static class UpdateLatestOperationStartTimeAtActLocations implements ReverseActivityVisitor{
|
|
||||||
//
|
|
||||||
// private static Logger log = Logger.getLogger(UpdateLatestOperationStartTimeAtActLocations.class);
|
|
||||||
//
|
|
||||||
// private StateManagerImpl states;
|
|
||||||
//
|
|
||||||
// private VehicleRoute route;
|
|
||||||
//
|
|
||||||
// private VehicleRoutingTransportCosts transportCosts;
|
|
||||||
//
|
|
||||||
// private double latestArrTimeAtPrevAct;
|
|
||||||
//
|
|
||||||
// private TourActivity prevAct;
|
|
||||||
//
|
|
||||||
// public UpdateLatestOperationStartTimeAtActLocations(StateManagerImpl states, VehicleRoutingTransportCosts tpCosts) {
|
|
||||||
// super();
|
|
||||||
// this.states = states;
|
|
||||||
// this.transportCosts = tpCosts;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void begin(VehicleRoute route) {
|
|
||||||
// this.route = route;
|
|
||||||
// latestArrTimeAtPrevAct = route.getEnd().getTheoreticalLatestOperationStartTime();
|
|
||||||
// prevAct = route.getEnd();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void visit(TourActivity activity) {
|
|
||||||
// double potentialLatestArrivalTimeAtCurrAct = latestArrTimeAtPrevAct - transportCosts.getBackwardTransportTime(activity.getLocationId(), prevAct.getLocationId(), latestArrTimeAtPrevAct, route.getDriver(),route.getVehicle()) - activity.getOperationTime();
|
|
||||||
// double latestArrivalTime = Math.min(activity.getTheoreticalLatestOperationStartTime(), potentialLatestArrivalTimeAtCurrAct);
|
|
||||||
//
|
|
||||||
// states.putActivityState(activity, StateTypes.LATEST_OPERATION_START_TIME, new StateImpl(latestArrivalTime));
|
|
||||||
//
|
|
||||||
// latestArrTimeAtPrevAct = latestArrivalTime;
|
|
||||||
// prevAct = activity;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void finish() {}
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// static class UpdateLoadAtAllLevels implements ActivityVisitor{
|
|
||||||
//
|
|
||||||
// private double load = 0.0;
|
|
||||||
//
|
|
||||||
// private StateManagerImpl states;
|
|
||||||
//
|
|
||||||
// private VehicleRoute vehicleRoute;
|
|
||||||
//
|
|
||||||
// public UpdateLoadAtAllLevels(StateManagerImpl states) {
|
|
||||||
// super();
|
|
||||||
// this.states = states;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void begin(VehicleRoute route) {
|
|
||||||
// vehicleRoute = route;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void visit(TourActivity activity) {
|
|
||||||
// load += (double)activity.getCapacityDemand();
|
|
||||||
// states.putActivityState(activity, StateTypes.LOAD, new StateImpl(load));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void finish() {
|
|
||||||
// states.putRouteState(vehicleRoute, StateTypes.LOAD, new StateImpl(load));
|
|
||||||
// load=0;
|
|
||||||
// vehicleRoute = null;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// static class UpdateLoadAtRouteLevel implements JobInsertedListener, InsertionStartsListener{
|
|
||||||
//
|
|
||||||
// private StateManagerImpl states;
|
|
||||||
//
|
|
||||||
// public UpdateLoadAtRouteLevel(StateManagerImpl states) {
|
|
||||||
// super();
|
|
||||||
// this.states = states;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) {
|
|
||||||
// if(!(job2insert instanceof Service)){
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// double oldLoad = states.getRouteState(inRoute, StateTypes.LOAD).toDouble();
|
|
||||||
// states.putRouteState(inRoute, StateTypes.LOAD, new StateImpl(oldLoad + job2insert.getCapacityDemand()));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void informInsertionStarts(Collection<VehicleRoute> vehicleRoutes, Collection<Job> unassignedJobs) {
|
|
||||||
// for(VehicleRoute route : vehicleRoutes){
|
|
||||||
// int load = 0;
|
|
||||||
// for(Job j : route.getTourActivities().getJobs()){
|
|
||||||
// load += j.getCapacityDemand();
|
|
||||||
// }
|
|
||||||
// states.putRouteState(route, StateTypes.LOAD, new StateImpl(load));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//=======
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// static class UpdateActivityTimes implements ActivityVisitor{
|
|
||||||
//
|
|
||||||
// private Logger log = Logger.getLogger(UpdateActivityTimes.class);
|
|
||||||
//
|
|
||||||
// private ActivityTimeTracker timeTracker;
|
|
||||||
//
|
|
||||||
// private VehicleRoute route;
|
|
||||||
//
|
|
||||||
// public UpdateActivityTimes(ForwardTransportTime transportTime) {
|
|
||||||
// super();
|
|
||||||
// timeTracker = new ActivityTimeTracker(transportTime);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void begin(VehicleRoute route) {
|
|
||||||
// timeTracker.begin(route);
|
|
||||||
// this.route = route;
|
|
||||||
// route.getStart().setEndTime(timeTracker.getActEndTime());
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void visit(TourActivity activity) {
|
|
||||||
// timeTracker.visit(activity);
|
|
||||||
// activity.setArrTime(timeTracker.getActArrTime());
|
|
||||||
// activity.setEndTime(timeTracker.getActEndTime());
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void finish() {
|
|
||||||
// timeTracker.finish();
|
|
||||||
// route.getEnd().setArrTime(timeTracker.getActArrTime());
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// static class UpdateCostsAtAllLevels implements ActivityVisitor{
|
|
||||||
//
|
|
||||||
// private static Logger log = Logger.getLogger(UpdateCostsAtAllLevels.class);
|
|
||||||
//
|
|
||||||
// private VehicleRoutingActivityCosts activityCost;
|
|
||||||
//
|
|
||||||
// private ForwardTransportCost transportCost;
|
|
||||||
//
|
|
||||||
// private StateManagerImpl states;
|
|
||||||
//
|
|
||||||
// private double totalOperationCost = 0.0;
|
|
||||||
//
|
|
||||||
// private VehicleRoute vehicleRoute = null;
|
|
||||||
//
|
|
||||||
// private TourActivity prevAct = null;
|
|
||||||
//
|
|
||||||
// private double startTimeAtPrevAct = 0.0;
|
|
||||||
//
|
|
||||||
// private ActivityTimeTracker timeTracker;
|
|
||||||
//
|
|
||||||
// public UpdateCostsAtAllLevels(VehicleRoutingActivityCosts activityCost, VehicleRoutingTransportCosts transportCost, StateManagerImpl states) {
|
|
||||||
// super();
|
|
||||||
// this.activityCost = activityCost;
|
|
||||||
// this.transportCost = transportCost;
|
|
||||||
// this.states = states;
|
|
||||||
// timeTracker = new ActivityTimeTracker(transportCost);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void begin(VehicleRoute route) {
|
|
||||||
// vehicleRoute = route;
|
|
||||||
// vehicleRoute.getVehicleRouteCostCalculator().reset();
|
|
||||||
// timeTracker.begin(route);
|
|
||||||
// prevAct = route.getStart();
|
|
||||||
// startTimeAtPrevAct = timeTracker.getActEndTime();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void visit(TourActivity act) {
|
|
||||||
// timeTracker.visit(act);
|
|
||||||
//
|
|
||||||
// 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.putActivityState(act, StateTypes.COSTS, new StateImpl(totalOperationCost));
|
|
||||||
//
|
|
||||||
// prevAct = act;
|
|
||||||
// startTimeAtPrevAct = timeTracker.getActEndTime();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void finish() {
|
|
||||||
// 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();
|
|
||||||
//
|
|
||||||
// states.putRouteState(vehicleRoute, StateTypes.COSTS, new StateImpl(totalOperationCost));
|
|
||||||
//
|
|
||||||
//// this is rather strange and likely to change
|
|
||||||
// vehicleRoute.getVehicleRouteCostCalculator().price(vehicleRoute.getDriver());
|
|
||||||
// vehicleRoute.getVehicleRouteCostCalculator().price(vehicleRoute.getVehicle());
|
|
||||||
// vehicleRoute.getVehicleRouteCostCalculator().finish();
|
|
||||||
//
|
|
||||||
// startTimeAtPrevAct = 0.0;
|
|
||||||
// prevAct = null;
|
|
||||||
// vehicleRoute = null;
|
|
||||||
// totalOperationCost = 0.0;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private double getFixCosts() {
|
|
||||||
// Vehicle vehicle = vehicleRoute.getVehicle();
|
|
||||||
// if(vehicle == null) return 0.0;
|
|
||||||
// VehicleType type = vehicle.getType();
|
|
||||||
// if(type == null) return 0.0;
|
|
||||||
// return type.getVehicleCostParams().fix;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// static class UpdateEarliestStartTimeWindowAtActLocations implements ActivityVisitor{
|
|
||||||
//
|
|
||||||
// private StateManagerImpl states;
|
|
||||||
//
|
|
||||||
// private ActivityTimeTracker timeTracker;
|
|
||||||
//
|
|
||||||
// public UpdateEarliestStartTimeWindowAtActLocations(StateManagerImpl 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.putActivityState(activity, StateTypes.EARLIEST_OPERATION_START_TIME, new StateImpl(Math.max(timeTracker.getActArrTime(), activity.getTheoreticalEarliestOperationStartTime())));
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void finish() {}
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// static class UpdateLatestOperationStartTimeAtActLocations implements ReverseActivityVisitor{
|
|
||||||
//
|
|
||||||
// private static Logger log = Logger.getLogger(UpdateLatestOperationStartTimeAtActLocations.class);
|
|
||||||
//
|
|
||||||
// private StateManagerImpl states;
|
|
||||||
//
|
|
||||||
// private VehicleRoute route;
|
|
||||||
//
|
|
||||||
// private VehicleRoutingTransportCosts transportCosts;
|
|
||||||
//
|
|
||||||
// private double latestArrTimeAtPrevAct;
|
|
||||||
//
|
|
||||||
// private TourActivity prevAct;
|
|
||||||
//
|
|
||||||
// public UpdateLatestOperationStartTimeAtActLocations(StateManagerImpl states, VehicleRoutingTransportCosts tpCosts) {
|
|
||||||
// super();
|
|
||||||
// this.states = states;
|
|
||||||
// this.transportCosts = tpCosts;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void begin(VehicleRoute route) {
|
|
||||||
// this.route = route;
|
|
||||||
// latestArrTimeAtPrevAct = route.getEnd().getTheoreticalLatestOperationStartTime();
|
|
||||||
// prevAct = route.getEnd();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void visit(TourActivity activity) {
|
|
||||||
// double potentialLatestArrivalTimeAtCurrAct = latestArrTimeAtPrevAct - transportCosts.getBackwardTransportTime(activity.getLocationId(), prevAct.getLocationId(), latestArrTimeAtPrevAct, route.getDriver(),route.getVehicle()) - activity.getOperationTime();
|
|
||||||
// double latestArrivalTime = Math.min(activity.getTheoreticalLatestOperationStartTime(), potentialLatestArrivalTimeAtCurrAct);
|
|
||||||
//
|
|
||||||
// states.putActivityState(activity, StateTypes.LATEST_OPERATION_START_TIME, new StateImpl(latestArrivalTime));
|
|
||||||
//
|
|
||||||
// latestArrTimeAtPrevAct = latestArrivalTime;
|
|
||||||
// prevAct = activity;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void finish() {}
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// static class UpdateLoadAtAllLevels implements ActivityVisitor{
|
|
||||||
//
|
|
||||||
// private double load = 0.0;
|
|
||||||
//
|
|
||||||
// private StateManagerImpl states;
|
|
||||||
//
|
|
||||||
// private VehicleRoute vehicleRoute;
|
|
||||||
//
|
|
||||||
// public UpdateLoadAtAllLevels(StateManagerImpl states) {
|
|
||||||
// super();
|
|
||||||
// this.states = states;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void begin(VehicleRoute route) {
|
|
||||||
// vehicleRoute = route;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void visit(TourActivity activity) {
|
|
||||||
// load += (double)activity.getCapacityDemand();
|
|
||||||
// states.putActivityState(activity, StateTypes.LOAD, new StateImpl(load));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void finish() {
|
|
||||||
// states.putRouteState(vehicleRoute, StateTypes.LOAD, new StateImpl(load));
|
|
||||||
// load=0;
|
|
||||||
// vehicleRoute = null;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// static class UpdateLoadAtRouteLevel implements JobInsertedListener, InsertionStartsListener{
|
|
||||||
//
|
|
||||||
// private StateManagerImpl states;
|
|
||||||
//
|
|
||||||
// public UpdateLoadAtRouteLevel(StateManagerImpl states) {
|
|
||||||
// super();
|
|
||||||
// this.states = states;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) {
|
|
||||||
// if(!(job2insert instanceof Service)){
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// double oldLoad = states.getRouteState(inRoute, StateTypes.LOAD).toDouble();
|
|
||||||
// states.putRouteState(inRoute, StateTypes.LOAD, new StateImpl(oldLoad + job2insert.getCapacityDemand()));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void informInsertionStarts(Collection<VehicleRoute> vehicleRoutes, Collection<Job> unassignedJobs) {
|
|
||||||
// for(VehicleRoute route : vehicleRoutes){
|
|
||||||
// int load = 0;
|
|
||||||
// for(Job j : route.getTourActivities().getJobs()){
|
|
||||||
// load += j.getCapacityDemand();
|
|
||||||
// }
|
|
||||||
// states.putRouteState(route, StateTypes.LOAD, new StateImpl(load));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//>>>>>>> refs/heads/master
|
|
||||||
static class UpdateStates implements JobInsertedListener, RuinListener{
|
|
||||||
|
|
||||||
private RouteActivityVisitor routeActivityVisitor;
|
|
||||||
|
|
||||||
private ReverseRouteActivityVisitor revRouteActivityVisitor;
|
|
||||||
|
|
||||||
public UpdateStates(StateManager states, VehicleRoutingTransportCosts routingCosts, VehicleRoutingActivityCosts activityCosts) {
|
|
||||||
routeActivityVisitor = new RouteActivityVisitor();
|
|
||||||
routeActivityVisitor.addActivityVisitor(new UpdateActivityTimes(routingCosts));
|
|
||||||
routeActivityVisitor.addActivityVisitor(new UpdateCostsAtAllLevels(activityCosts, routingCosts, states));
|
|
||||||
routeActivityVisitor.addActivityVisitor(new UpdateLoadAtAllLevels(states));
|
|
||||||
|
|
||||||
revRouteActivityVisitor = new ReverseRouteActivityVisitor();
|
|
||||||
revRouteActivityVisitor.addActivityVisitor(new UpdateLatestOperationStartTimeAtActLocations(states, routingCosts));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void update(VehicleRoute route){
|
|
||||||
routeActivityVisitor.visit(route);
|
|
||||||
revRouteActivityVisitor.visit(route);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) {
|
|
||||||
routeActivityVisitor.visit(inRoute);
|
|
||||||
revRouteActivityVisitor.visit(inRoute);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void ruinStarts(Collection<VehicleRoute> routes) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void ruinEnds(Collection<VehicleRoute> routes,Collection<Job> unassignedJobs) {
|
|
||||||
for(VehicleRoute route : routes) {
|
|
||||||
routeActivityVisitor.visit(route);
|
|
||||||
revRouteActivityVisitor.visit(route);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removed(Job job, VehicleRoute fromRoute) {}
|
|
||||||
|
|
||||||
}
|
|
||||||
//
|
|
||||||
// static class UpdateFuturePickupsAtActivityLevel implements ReverseActivityVisitor {
|
|
||||||
// private StateManagerImpl stateManager;
|
|
||||||
// private int futurePicks = 0;
|
|
||||||
// private VehicleRoute route;
|
|
||||||
//
|
|
||||||
// public UpdateFuturePickupsAtActivityLevel(StateManagerImpl stateManager) {
|
|
||||||
// super();
|
|
||||||
// this.stateManager = stateManager;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void begin(VehicleRoute route) {
|
|
||||||
// this.route = route;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void visit(TourActivity act) {
|
|
||||||
// stateManager.putActivityState(act, StateTypes.FUTURE_PICKS, new StateImpl(futurePicks));
|
|
||||||
// if(act instanceof PickupActivity || act instanceof ServiceActivity){
|
|
||||||
// futurePicks += act.getCapacityDemand();
|
|
||||||
// }
|
|
||||||
// assert futurePicks <= route.getVehicle().getCapacity() : "sum of pickups must not be > vehicleCap";
|
|
||||||
// assert futurePicks >= 0 : "sum of pickups must not < 0";
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void finish() {
|
|
||||||
// futurePicks = 0;
|
|
||||||
// route = null;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// static class UpdateOccuredDeliveriesAtActivityLevel implements ActivityVisitor {
|
|
||||||
// private StateManagerImpl stateManager;
|
|
||||||
// private int deliveries = 0;
|
|
||||||
// private VehicleRoute route;
|
|
||||||
//
|
|
||||||
// public UpdateOccuredDeliveriesAtActivityLevel(StateManagerImpl stateManager) {
|
|
||||||
// super();
|
|
||||||
// this.stateManager = stateManager;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void begin(VehicleRoute route) {
|
|
||||||
// this.route = route;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void visit(TourActivity act) {
|
|
||||||
// if(act instanceof DeliveryActivity){
|
|
||||||
// deliveries += Math.abs(act.getCapacityDemand());
|
|
||||||
// }
|
|
||||||
// stateManager.putActivityState(act, StateTypes.PAST_DELIVERIES, new StateImpl(deliveries));
|
|
||||||
// assert deliveries >= 0 : "deliveries < 0";
|
|
||||||
// assert deliveries <= route.getVehicle().getCapacity() : "deliveries > vehicleCap";
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void finish() {
|
|
||||||
// deliveries = 0;
|
|
||||||
// route = null;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * Updates load at activity level. Note that this assumed that StateTypes.LOAD_AT_DEPOT is already updated, i.e. it starts by setting loadAtDepot to StateTypes.LOAD_AT_DEPOT.
|
|
||||||
// * If StateTypes.LOAD_AT_DEPOT is not set, it starts with 0 load at depot.
|
|
||||||
// *
|
|
||||||
// * @author stefan
|
|
||||||
// *
|
|
||||||
// */
|
|
||||||
// static class UpdateLoadAtActivityLevel implements ActivityVisitor {
|
|
||||||
// private StateManagerImpl stateManager;
|
|
||||||
// private int currentLoad = 0;
|
|
||||||
// private VehicleRoute route;
|
|
||||||
//
|
|
||||||
// public UpdateLoadAtActivityLevel(StateManagerImpl stateManager) {
|
|
||||||
// super();
|
|
||||||
// this.stateManager = stateManager;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void begin(VehicleRoute route) {
|
|
||||||
// currentLoad = (int) stateManager.getRouteState(route, StateTypes.LOAD_AT_DEPOT).toDouble();
|
|
||||||
// this.route = route;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void visit(TourActivity act) {
|
|
||||||
// currentLoad += act.getCapacityDemand();
|
|
||||||
// stateManager.putActivityState(act, StateTypes.LOAD, new StateImpl(currentLoad));
|
|
||||||
// assert currentLoad <= route.getVehicle().getCapacity() : "currentLoad at activity must not be > vehicleCapacity";
|
|
||||||
// assert currentLoad >= 0 : "currentLoad at act must not be < 0";
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void finish() {
|
|
||||||
// currentLoad = 0;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// static class ResetStateManager implements IterationStartsListener {
|
|
||||||
//
|
|
||||||
// private StateManagerImpl stateManager;
|
|
||||||
//
|
|
||||||
// public ResetStateManager(StateManagerImpl stateManager) {
|
|
||||||
// super();
|
|
||||||
// this.stateManager = stateManager;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void informIterationStarts(int i, VehicleRoutingProblem problem, Collection<VehicleRoutingProblemSolution> solutions) {
|
|
||||||
// stateManager.clear();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// static interface InsertionStarts {
|
|
||||||
//
|
|
||||||
// void insertionStarts(VehicleRoute route);
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// static class UpdateLoadsAtStartAndEndOfRouteWhenInsertionStarts implements InsertionStarts {
|
|
||||||
//
|
|
||||||
// private StateManagerImpl stateManager;
|
|
||||||
//
|
|
||||||
// public UpdateLoadsAtStartAndEndOfRouteWhenInsertionStarts(StateManagerImpl stateManager) {
|
|
||||||
// super();
|
|
||||||
// this.stateManager = stateManager;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void insertionStarts(VehicleRoute route) {
|
|
||||||
// int loadAtDepot = 0;
|
|
||||||
// int loadAtEnd = 0;
|
|
||||||
// for(Job j : route.getTourActivities().getJobs()){
|
|
||||||
// if(j instanceof Delivery){
|
|
||||||
// loadAtDepot += j.getCapacityDemand();
|
|
||||||
// }
|
|
||||||
// else if(j instanceof Pickup || j instanceof Service){
|
|
||||||
// loadAtEnd += j.getCapacityDemand();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// stateManager.putRouteState(route, StateTypes.LOAD_AT_DEPOT, new StateImpl(loadAtDepot));
|
|
||||||
// stateManager.putRouteState(route, StateTypes.LOAD, new StateImpl(loadAtEnd));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -2,10 +2,10 @@ package algorithms;
|
||||||
|
|
||||||
import basics.VehicleRoutingProblem;
|
import basics.VehicleRoutingProblem;
|
||||||
|
|
||||||
public class StateUtils {
|
class StateUtils {
|
||||||
|
|
||||||
public static void addCoreStateUpdaters(VehicleRoutingProblem vrp, StateManager stateManager){
|
public static void addCoreStateUpdaters(VehicleRoutingProblem vrp, StateManager stateManager){
|
||||||
stateManager.addListener(new InitializeLoadsAtStartAndEndOfRouteWhenInsertionStarts(stateManager));
|
stateManager.addListener(new UpdateLoadsAtStartAndEndOfRouteWhenInsertionStarts(stateManager));
|
||||||
stateManager.addListener(new UpdateLoadsAtStartAndEndOfRouteWhenJobHasBeenInserted(stateManager));
|
stateManager.addListener(new UpdateLoadsAtStartAndEndOfRouteWhenJobHasBeenInserted(stateManager));
|
||||||
|
|
||||||
stateManager.addActivityVisitor(new UpdateActivityTimes(vrp.getTransportCosts()));
|
stateManager.addActivityVisitor(new UpdateActivityTimes(vrp.getTransportCosts()));
|
||||||
|
|
@ -14,7 +14,9 @@ public class StateUtils {
|
||||||
stateManager.addActivityVisitor(new UpdateCostsAtAllLevels(vrp.getActivityCosts(), vrp.getTransportCosts(), stateManager));
|
stateManager.addActivityVisitor(new UpdateCostsAtAllLevels(vrp.getActivityCosts(), vrp.getTransportCosts(), stateManager));
|
||||||
|
|
||||||
stateManager.addActivityVisitor(new UpdateOccuredDeliveriesAtActivityLevel(stateManager));
|
stateManager.addActivityVisitor(new UpdateOccuredDeliveriesAtActivityLevel(stateManager));
|
||||||
|
|
||||||
stateManager.addActivityVisitor(new UpdateLatestOperationStartTimeAtActLocations(stateManager, vrp.getTransportCosts()));
|
stateManager.addActivityVisitor(new UpdateLatestOperationStartTimeAtActLocations(stateManager, vrp.getTransportCosts()));
|
||||||
|
|
||||||
stateManager.addActivityVisitor(new UpdateFuturePickupsAtActivityLevel(stateManager));
|
stateManager.addActivityVisitor(new UpdateFuturePickupsAtActivityLevel(stateManager));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ class UpdateCostsAtAllLevels implements ActivityVisitor,StateUpdater{
|
||||||
totalOperationCost += transportCost;
|
totalOperationCost += transportCost;
|
||||||
totalOperationCost += actCost;
|
totalOperationCost += actCost;
|
||||||
|
|
||||||
states.putActivityState(act, StateIdFactory.COSTS, new StateImpl(totalOperationCost));
|
states.putActivityState(act, StateFactory.COSTS, new StateImpl(totalOperationCost));
|
||||||
|
|
||||||
prevAct = act;
|
prevAct = act;
|
||||||
startTimeAtPrevAct = timeTracker.getActEndTime();
|
startTimeAtPrevAct = timeTracker.getActEndTime();
|
||||||
|
|
@ -101,7 +101,7 @@ class UpdateCostsAtAllLevels implements ActivityVisitor,StateUpdater{
|
||||||
totalOperationCost += actCost;
|
totalOperationCost += actCost;
|
||||||
// totalOperationCost += getFixCosts(vehicleRoute.getVehicle());
|
// totalOperationCost += getFixCosts(vehicleRoute.getVehicle());
|
||||||
|
|
||||||
states.putRouteState(vehicleRoute, StateIdFactory.COSTS, new StateImpl(totalOperationCost));
|
states.putRouteState(vehicleRoute, StateFactory.COSTS, new StateImpl(totalOperationCost));
|
||||||
|
|
||||||
//this is rather strange and likely to change
|
//this is rather strange and likely to change
|
||||||
vehicleRoute.getVehicleRouteCostCalculator().price(vehicleRoute.getDriver());
|
vehicleRoute.getVehicleRouteCostCalculator().price(vehicleRoute.getDriver());
|
||||||
|
|
|
||||||
|
|
@ -29,9 +29,9 @@ class UpdateCostsAtRouteLevel implements StateUpdater,JobInsertedListener, Inser
|
||||||
@Override
|
@Override
|
||||||
public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) {
|
public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) {
|
||||||
// inRoute.getVehicleRouteCostCalculator().addTransportCost(additionalCosts);
|
// inRoute.getVehicleRouteCostCalculator().addTransportCost(additionalCosts);
|
||||||
double oldCosts = states.getRouteState(inRoute, StateIdFactory.COSTS).toDouble();
|
double oldCosts = states.getRouteState(inRoute, StateFactory.COSTS).toDouble();
|
||||||
oldCosts += additionalCosts;
|
oldCosts += additionalCosts;
|
||||||
states.putRouteState(inRoute, StateIdFactory.COSTS, new StateImpl(oldCosts));
|
states.putRouteState(inRoute, StateFactory.COSTS, new StateImpl(oldCosts));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -52,7 +52,7 @@ class UpdateCostsAtRouteLevel implements StateUpdater,JobInsertedListener, Inser
|
||||||
for(VehicleRoute route : vehicleRoutes){
|
for(VehicleRoute route : vehicleRoutes){
|
||||||
if(route.isEmpty()) continue;
|
if(route.isEmpty()) continue;
|
||||||
route.getVehicleRouteCostCalculator().reset();
|
route.getVehicleRouteCostCalculator().reset();
|
||||||
route.getVehicleRouteCostCalculator().addOtherCost(states.getRouteState(route, StateIdFactory.COSTS).toDouble());
|
route.getVehicleRouteCostCalculator().addOtherCost(states.getRouteState(route, StateFactory.COSTS).toDouble());
|
||||||
route.getVehicleRouteCostCalculator().price(route.getVehicle());
|
route.getVehicleRouteCostCalculator().price(route.getVehicle());
|
||||||
// forwardInTime.iterate(route);
|
// forwardInTime.iterate(route);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ class UpdateEarliestStartTimeWindowAtActLocations implements ActivityVisitor,Sta
|
||||||
@Override
|
@Override
|
||||||
public void visit(TourActivity activity) {
|
public void visit(TourActivity activity) {
|
||||||
timeTracker.visit(activity);
|
timeTracker.visit(activity);
|
||||||
states.putActivityState(activity, StateIdFactory.EARLIEST_OPERATION_START_TIME, new StateImpl(Math.max(timeTracker.getActArrTime(), activity.getTheoreticalEarliestOperationStartTime())));
|
states.putActivityState(activity, StateFactory.EARLIEST_OPERATION_START_TIME, new StateImpl(Math.max(timeTracker.getActArrTime(), activity.getTheoreticalEarliestOperationStartTime())));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package algorithms;
|
package algorithms;
|
||||||
|
|
||||||
import algorithms.StateManager.StateImpl;
|
|
||||||
import basics.route.PickupActivity;
|
import basics.route.PickupActivity;
|
||||||
import basics.route.ServiceActivity;
|
import basics.route.ServiceActivity;
|
||||||
import basics.route.TourActivity;
|
import basics.route.TourActivity;
|
||||||
|
|
@ -23,7 +22,7 @@ class UpdateFuturePickupsAtActivityLevel implements ReverseActivityVisitor, Stat
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(TourActivity act) {
|
public void visit(TourActivity act) {
|
||||||
stateManager.putActivityState(act, StateIdFactory.FUTURE_PICKS, new StateImpl(futurePicks));
|
stateManager.putActivityState(act, StateFactory.FUTURE_PICKS, StateFactory.createState(futurePicks));
|
||||||
if(act instanceof PickupActivity || act instanceof ServiceActivity){
|
if(act instanceof PickupActivity || act instanceof ServiceActivity){
|
||||||
futurePicks += act.getCapacityDemand();
|
futurePicks += act.getCapacityDemand();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ class UpdateLatestOperationStartTimeAtActLocations implements ReverseActivityVis
|
||||||
double potentialLatestArrivalTimeAtCurrAct = latestArrTimeAtPrevAct - transportCosts.getBackwardTransportTime(activity.getLocationId(), prevAct.getLocationId(), latestArrTimeAtPrevAct, route.getDriver(),route.getVehicle()) - activity.getOperationTime();
|
double potentialLatestArrivalTimeAtCurrAct = latestArrTimeAtPrevAct - transportCosts.getBackwardTransportTime(activity.getLocationId(), prevAct.getLocationId(), latestArrTimeAtPrevAct, route.getDriver(),route.getVehicle()) - activity.getOperationTime();
|
||||||
double latestArrivalTime = Math.min(activity.getTheoreticalLatestOperationStartTime(), potentialLatestArrivalTimeAtCurrAct);
|
double latestArrivalTime = Math.min(activity.getTheoreticalLatestOperationStartTime(), potentialLatestArrivalTimeAtCurrAct);
|
||||||
|
|
||||||
states.putActivityState(activity, StateIdFactory.LATEST_OPERATION_START_TIME, new StateImpl(latestArrivalTime));
|
states.putActivityState(activity, StateFactory.LATEST_OPERATION_START_TIME, new StateImpl(latestArrivalTime));
|
||||||
|
|
||||||
latestArrTimeAtPrevAct = latestArrivalTime;
|
latestArrTimeAtPrevAct = latestArrivalTime;
|
||||||
prevAct = activity;
|
prevAct = activity;
|
||||||
|
|
|
||||||
|
|
@ -28,14 +28,14 @@ class UpdateLoadAtActivityLevel implements ActivityVisitor, StateUpdater {
|
||||||
*
|
*
|
||||||
* <p>Thus it DEPENDS on StateTypes.LOAD_AT_DEPOT
|
* <p>Thus it DEPENDS on StateTypes.LOAD_AT_DEPOT
|
||||||
*
|
*
|
||||||
* <p>If you want to update StateTypes.LOAD_AT_DEPOT see {@link InitializeLoadsAtStartAndEndOfRouteWhenInsertionStarts}, {@link UpdateLoadsAtStartAndEndOfRouteWhenJobHasBeenInserted}
|
* <p>If you want to update StateTypes.LOAD_AT_DEPOT see {@link UpdateLoadsAtStartAndEndOfRouteWhenInsertionStarts}, {@link UpdateLoadsAtStartAndEndOfRouteWhenJobHasBeenInserted}
|
||||||
*
|
*
|
||||||
* <p>The loads can be retrieved by <br>
|
* <p>The loads can be retrieved by <br>
|
||||||
* <code>stateManager.getActivityState(activity,StateTypes.LOAD);</code>
|
* <code>stateManager.getActivityState(activity,StateTypes.LOAD);</code>
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @see {@link InitializeLoadsAtStartAndEndOfRouteWhenInsertionStarts}, {@link UpdateLoadsAtStartAndEndOfRouteWhenJobHasBeenInserted}
|
* @see {@link UpdateLoadsAtStartAndEndOfRouteWhenInsertionStarts}, {@link UpdateLoadsAtStartAndEndOfRouteWhenJobHasBeenInserted}
|
||||||
* @author stefan
|
* @author stefan
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
@ -46,20 +46,21 @@ class UpdateLoadAtActivityLevel implements ActivityVisitor, StateUpdater {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void begin(VehicleRoute route) {
|
public void begin(VehicleRoute route) {
|
||||||
currentLoad = (int) stateManager.getRouteState(route, StateIdFactory.LOAD_AT_BEGINNING).toDouble();
|
currentLoad = (int) stateManager.getRouteState(route, StateFactory.LOAD_AT_BEGINNING).toDouble();
|
||||||
this.route = route;
|
this.route = route;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(TourActivity act) {
|
public void visit(TourActivity act) {
|
||||||
currentLoad += act.getCapacityDemand();
|
currentLoad += act.getCapacityDemand();
|
||||||
stateManager.putActivityState(act, StateIdFactory.LOAD, new StateImpl(currentLoad));
|
stateManager.putActivityState(act, StateFactory.LOAD, StateFactory.createState(currentLoad));
|
||||||
assert currentLoad <= route.getVehicle().getCapacity() : "currentLoad at activity must not be > vehicleCapacity";
|
assert currentLoad <= route.getVehicle().getCapacity() : "currentLoad at activity must not be > vehicleCapacity";
|
||||||
assert currentLoad >= 0 : "currentLoad at act must not be < 0";
|
assert currentLoad >= 0 : "currentLoad at act must not be < 0";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void finish() {
|
public void finish() {
|
||||||
|
// stateManager.putRouteState(route, StateFactory., state)
|
||||||
currentLoad = 0;
|
currentLoad = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -25,12 +25,12 @@ class UpdateLoadAtAllLevels implements ActivityVisitor,StateUpdater{
|
||||||
@Override
|
@Override
|
||||||
public void visit(TourActivity activity) {
|
public void visit(TourActivity activity) {
|
||||||
load += (double)activity.getCapacityDemand();
|
load += (double)activity.getCapacityDemand();
|
||||||
states.putActivityState(activity, StateIdFactory.LOAD, new StateImpl(load));
|
states.putActivityState(activity, StateFactory.LOAD, new StateImpl(load));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void finish() {
|
public void finish() {
|
||||||
states.putRouteState(vehicleRoute, StateIdFactory.LOAD, new StateImpl(load));
|
states.putRouteState(vehicleRoute, StateFactory.LOAD, new StateImpl(load));
|
||||||
load=0;
|
load=0;
|
||||||
vehicleRoute = null;
|
vehicleRoute = null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,8 @@ class UpdateLoadAtRouteLevel implements JobInsertedListener, InsertionStartsList
|
||||||
if(!(job2insert instanceof Service)){
|
if(!(job2insert instanceof Service)){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
double oldLoad = states.getRouteState(inRoute, StateIdFactory.LOAD).toDouble();
|
double oldLoad = states.getRouteState(inRoute, StateFactory.LOAD).toDouble();
|
||||||
states.putRouteState(inRoute, StateIdFactory.LOAD, new StateImpl(oldLoad + job2insert.getCapacityDemand()));
|
states.putRouteState(inRoute, StateFactory.LOAD, StateFactory.createState(oldLoad + job2insert.getCapacityDemand()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -46,7 +46,7 @@ class UpdateLoadAtRouteLevel implements JobInsertedListener, InsertionStartsList
|
||||||
for(Job j : route.getTourActivities().getJobs()){
|
for(Job j : route.getTourActivities().getJobs()){
|
||||||
load += j.getCapacityDemand();
|
load += j.getCapacityDemand();
|
||||||
}
|
}
|
||||||
states.putRouteState(route, StateIdFactory.LOAD, new StateImpl(load));
|
states.putRouteState(route, StateFactory.LOAD, new StateImpl(load));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ import basics.route.VehicleRoute;
|
||||||
*
|
*
|
||||||
* @param stateManager
|
* @param stateManager
|
||||||
*/
|
*/
|
||||||
class InitializeLoadsAtStartAndEndOfRouteWhenInsertionStarts implements InsertionStartsListener {
|
class UpdateLoadsAtStartAndEndOfRouteWhenInsertionStarts implements InsertionStartsListener {
|
||||||
|
|
||||||
private StateManager stateManager;
|
private StateManager stateManager;
|
||||||
|
|
||||||
|
|
@ -34,7 +34,7 @@ class InitializeLoadsAtStartAndEndOfRouteWhenInsertionStarts implements Insertio
|
||||||
*
|
*
|
||||||
* @param stateManager
|
* @param stateManager
|
||||||
*/
|
*/
|
||||||
public InitializeLoadsAtStartAndEndOfRouteWhenInsertionStarts(StateManager stateManager) {
|
public UpdateLoadsAtStartAndEndOfRouteWhenInsertionStarts(StateManager stateManager) {
|
||||||
super();
|
super();
|
||||||
this.stateManager = stateManager;
|
this.stateManager = stateManager;
|
||||||
}
|
}
|
||||||
|
|
@ -50,8 +50,8 @@ class InitializeLoadsAtStartAndEndOfRouteWhenInsertionStarts implements Insertio
|
||||||
loadAtEnd += j.getCapacityDemand();
|
loadAtEnd += j.getCapacityDemand();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stateManager.putRouteState(route, StateIdFactory.LOAD_AT_BEGINNING, new StateImpl(loadAtDepot));
|
stateManager.putRouteState(route, StateFactory.LOAD_AT_BEGINNING, StateFactory.createState(loadAtDepot));
|
||||||
stateManager.putRouteState(route, StateIdFactory.LOAD, new StateImpl(loadAtEnd));
|
stateManager.putRouteState(route, StateFactory.LOAD_AT_END, StateFactory.createState(loadAtEnd));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -38,14 +38,14 @@ class UpdateLoadsAtStartAndEndOfRouteWhenJobHasBeenInserted implements JobInsert
|
||||||
@Override
|
@Override
|
||||||
public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) {
|
public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) {
|
||||||
if(job2insert instanceof Delivery){
|
if(job2insert instanceof Delivery){
|
||||||
int loadAtDepot = (int) stateManager.getRouteState(inRoute, StateIdFactory.LOAD_AT_BEGINNING).toDouble();
|
int loadAtDepot = (int) stateManager.getRouteState(inRoute, StateFactory.LOAD_AT_BEGINNING).toDouble();
|
||||||
// log.info("loadAtDepot="+loadAtDepot);
|
// log.info("loadAtDepot="+loadAtDepot);
|
||||||
stateManager.putRouteState(inRoute, StateIdFactory.LOAD_AT_BEGINNING, new StateImpl(loadAtDepot + job2insert.getCapacityDemand()));
|
stateManager.putRouteState(inRoute, StateFactory.LOAD_AT_BEGINNING, StateFactory.createState(loadAtDepot + job2insert.getCapacityDemand()));
|
||||||
}
|
}
|
||||||
else if(job2insert instanceof Pickup || job2insert instanceof Service){
|
else if(job2insert instanceof Pickup || job2insert instanceof Service){
|
||||||
int loadAtEnd = (int) stateManager.getRouteState(inRoute, StateIdFactory.LOAD).toDouble();
|
int loadAtEnd = (int) stateManager.getRouteState(inRoute, StateFactory.LOAD_AT_END).toDouble();
|
||||||
// log.info("loadAtEnd="+loadAtEnd);
|
// log.info("loadAtEnd="+loadAtEnd);
|
||||||
stateManager.putRouteState(inRoute, StateIdFactory.LOAD, new StateImpl(loadAtEnd + job2insert.getCapacityDemand()));
|
stateManager.putRouteState(inRoute, StateFactory.LOAD_AT_END, StateFactory.createState(loadAtEnd + job2insert.getCapacityDemand()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
68
jsprit-core/src/main/java/algorithms/UpdateMaxLoad.java
Normal file
68
jsprit-core/src/main/java/algorithms/UpdateMaxLoad.java
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
package algorithms;
|
||||||
|
|
||||||
|
import basics.route.TourActivity;
|
||||||
|
import basics.route.VehicleRoute;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates load at activity level.
|
||||||
|
*
|
||||||
|
* <p>Note that this assumes that StateTypes.LOAD_AT_DEPOT is already updated, i.e. it starts by setting loadAtDepot to StateTypes.LOAD_AT_DEPOT.
|
||||||
|
* If StateTypes.LOAD_AT_DEPOT is not set, it starts with 0 load at depot.
|
||||||
|
*
|
||||||
|
* <p>Thus it DEPENDS on StateTypes.LOAD_AT_DEPOT
|
||||||
|
*
|
||||||
|
* @author stefan
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class UpdateMaxLoad implements ActivityVisitor, StateUpdater {
|
||||||
|
private StateManager stateManager;
|
||||||
|
private int currentLoad = 0;
|
||||||
|
private VehicleRoute route;
|
||||||
|
private int maxLoad = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates load at activity level.
|
||||||
|
*
|
||||||
|
* <p>Note that this assumes that StateTypes.LOAD_AT_DEPOT is already updated, i.e. it starts by setting loadAtDepot to StateTypes.LOAD_AT_DEPOT.
|
||||||
|
* If StateTypes.LOAD_AT_DEPOT is not set, it starts with 0 load at depot.
|
||||||
|
*
|
||||||
|
* <p>Thus it DEPENDS on StateTypes.LOAD_AT_DEPOT
|
||||||
|
*
|
||||||
|
* <p>If you want to update StateTypes.LOAD_AT_DEPOT see {@link UpdateLoadsAtStartAndEndOfRouteWhenInsertionStarts}, {@link UpdateLoadsAtStartAndEndOfRouteWhenJobHasBeenInserted}
|
||||||
|
*
|
||||||
|
* <p>The loads can be retrieved by <br>
|
||||||
|
* <code>stateManager.getActivityState(activity,StateTypes.LOAD);</code>
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @see {@link UpdateLoadsAtStartAndEndOfRouteWhenInsertionStarts}, {@link UpdateLoadsAtStartAndEndOfRouteWhenJobHasBeenInserted}
|
||||||
|
* @author stefan
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public UpdateMaxLoad(StateManager stateManager) {
|
||||||
|
super();
|
||||||
|
this.stateManager = stateManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void begin(VehicleRoute route) {
|
||||||
|
currentLoad = (int) stateManager.getRouteState(route, StateFactory.LOAD_AT_BEGINNING).toDouble();
|
||||||
|
maxLoad = currentLoad;
|
||||||
|
this.route = route;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(TourActivity act) {
|
||||||
|
currentLoad += act.getCapacityDemand();
|
||||||
|
maxLoad = Math.max(maxLoad, currentLoad);
|
||||||
|
assert currentLoad <= route.getVehicle().getCapacity() : "currentLoad at activity must not be > vehicleCapacity";
|
||||||
|
assert currentLoad >= 0 : "currentLoad at act must not be < 0";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void finish() {
|
||||||
|
stateManager.putRouteState(route, StateFactory.MAXLOAD, StateFactory.createState(maxLoad));
|
||||||
|
currentLoad = 0;
|
||||||
|
maxLoad = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -25,7 +25,7 @@ class UpdateOccuredDeliveriesAtActivityLevel implements ActivityVisitor, StateUp
|
||||||
if(act instanceof DeliveryActivity){
|
if(act instanceof DeliveryActivity){
|
||||||
deliveries += Math.abs(act.getCapacityDemand());
|
deliveries += Math.abs(act.getCapacityDemand());
|
||||||
}
|
}
|
||||||
stateManager.putActivityState(act, StateIdFactory.PAST_DELIVERIES, new StateImpl(deliveries));
|
stateManager.putActivityState(act, StateFactory.PAST_DELIVERIES, StateFactory.createState(deliveries));
|
||||||
assert deliveries >= 0 : "deliveries < 0";
|
assert deliveries >= 0 : "deliveries < 0";
|
||||||
assert deliveries <= route.getVehicle().getCapacity() : "deliveries > vehicleCap";
|
assert deliveries <= route.getVehicle().getCapacity() : "deliveries > vehicleCap";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
package algorithms;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import basics.VehicleRoutingAlgorithm;
|
||||||
|
import basics.VehicleRoutingProblem;
|
||||||
|
import basics.algo.SearchStrategyManager;
|
||||||
|
import basics.algo.VehicleRoutingAlgorithmListener;
|
||||||
|
|
||||||
|
public class VehicleRoutingAlgorithmBuilder {
|
||||||
|
|
||||||
|
private VehicleRoutingProblem vrp;
|
||||||
|
|
||||||
|
private SearchStrategyManager searchStrategyManager;
|
||||||
|
|
||||||
|
private StateManager stateManager;
|
||||||
|
|
||||||
|
private Collection<VehicleRoutingAlgorithmListener> listeners = new ArrayList<VehicleRoutingAlgorithmListener>();
|
||||||
|
|
||||||
|
public VehicleRoutingAlgorithmBuilder(VehicleRoutingProblem vrp, SearchStrategyManager searchStrategyManager, StateManager stateManager) {
|
||||||
|
super();
|
||||||
|
this.vrp = vrp;
|
||||||
|
this.searchStrategyManager = searchStrategyManager;
|
||||||
|
this.stateManager = stateManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addListener(VehicleRoutingAlgorithmListener listener){
|
||||||
|
listeners.add(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public VehicleRoutingAlgorithm build(){
|
||||||
|
VehicleRoutingAlgorithm algorithm = new VehicleRoutingAlgorithm(vrp, searchStrategyManager);
|
||||||
|
algorithm.getAlgorithmListeners().addListener(stateManager);
|
||||||
|
algorithm.getSearchStrategyManager().addSearchStrategyModuleListener(stateManager);
|
||||||
|
return algorithm;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -509,7 +509,7 @@ public class VehicleRoutingAlgorithms {
|
||||||
// routeChangedListener.addVisitor(new StateUpdates.UpdateLatestOperationStartTimeAtActLocations(stateManager, vrp.getTransportCosts()));
|
// routeChangedListener.addVisitor(new StateUpdates.UpdateLatestOperationStartTimeAtActLocations(stateManager, vrp.getTransportCosts()));
|
||||||
// routeChangedListener.addVisitor(new StateUpdates.UpdateFuturePickupsAtActivityLevel(stateManager));
|
// routeChangedListener.addVisitor(new StateUpdates.UpdateFuturePickupsAtActivityLevel(stateManager));
|
||||||
|
|
||||||
stateManager.addListener(new InitializeLoadsAtStartAndEndOfRouteWhenInsertionStarts(stateManager));
|
stateManager.addListener(new UpdateLoadsAtStartAndEndOfRouteWhenInsertionStarts(stateManager));
|
||||||
stateManager.addListener(new UpdateLoadsAtStartAndEndOfRouteWhenJobHasBeenInserted(stateManager));
|
stateManager.addListener(new UpdateLoadsAtStartAndEndOfRouteWhenJobHasBeenInserted(stateManager));
|
||||||
|
|
||||||
stateManager.addActivityVisitor(new UpdateActivityTimes(vrp.getTransportCosts()));
|
stateManager.addActivityVisitor(new UpdateActivityTimes(vrp.getTransportCosts()));
|
||||||
|
|
@ -550,7 +550,7 @@ public class VehicleRoutingAlgorithms {
|
||||||
double costs = 0.0;
|
double costs = 0.0;
|
||||||
for(VehicleRoute route : solution.getRoutes()){
|
for(VehicleRoute route : solution.getRoutes()){
|
||||||
|
|
||||||
costs += stateManager.getRouteState(route, StateIdFactory.COSTS).toDouble() + getFixedCosts(route.getVehicle());
|
costs += stateManager.getRouteState(route, StateFactory.COSTS).toDouble() + getFixedCosts(route.getVehicle());
|
||||||
|
|
||||||
}
|
}
|
||||||
solution.setCost(costs);
|
solution.setCost(costs);
|
||||||
|
|
|
||||||
|
|
@ -30,15 +30,15 @@ import basics.route.VehicleRoute;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
final class CalculatesVehTypeDepServiceInsertion implements JobInsertionCalculator{
|
final class VehicleTypeDependentJobInsertionCalculator implements JobInsertionCalculator{
|
||||||
|
|
||||||
private Logger logger = Logger.getLogger(CalculatesVehTypeDepServiceInsertion.class);
|
private Logger logger = Logger.getLogger(VehicleTypeDependentJobInsertionCalculator.class);
|
||||||
|
|
||||||
private final VehicleFleetManager fleetManager;
|
private final VehicleFleetManager fleetManager;
|
||||||
|
|
||||||
private final JobInsertionCalculator insertionCalculator;
|
private final JobInsertionCalculator insertionCalculator;
|
||||||
|
|
||||||
public CalculatesVehTypeDepServiceInsertion(final VehicleFleetManager fleetManager, final JobInsertionCalculator jobInsertionCalc) {
|
public VehicleTypeDependentJobInsertionCalculator(final VehicleFleetManager fleetManager, final JobInsertionCalculator jobInsertionCalc) {
|
||||||
this.fleetManager = fleetManager;
|
this.fleetManager = fleetManager;
|
||||||
this.insertionCalculator = jobInsertionCalc;
|
this.insertionCalculator = jobInsertionCalc;
|
||||||
logger.info("inialise " + this);
|
logger.info("inialise " + this);
|
||||||
|
|
@ -63,7 +63,7 @@ public class BuildCVRPAlgoFromScratchTest {
|
||||||
|
|
||||||
|
|
||||||
VehicleFleetManager fleetManager = new InfiniteVehicles(vrp.getVehicles());
|
VehicleFleetManager fleetManager = new InfiniteVehicles(vrp.getVehicles());
|
||||||
JobInsertionCalculator finalServiceInsertion = new CalculatesVehTypeDepServiceInsertion(fleetManager, serviceInsertion);
|
JobInsertionCalculator finalServiceInsertion = new VehicleTypeDependentJobInsertionCalculator(fleetManager, serviceInsertion);
|
||||||
|
|
||||||
BestInsertion bestInsertion = new BestInsertion(finalServiceInsertion);
|
BestInsertion bestInsertion = new BestInsertion(finalServiceInsertion);
|
||||||
|
|
||||||
|
|
@ -76,7 +76,7 @@ public class BuildCVRPAlgoFromScratchTest {
|
||||||
public void calculateCosts(VehicleRoutingProblemSolution solution) {
|
public void calculateCosts(VehicleRoutingProblemSolution solution) {
|
||||||
double costs = 0.0;
|
double costs = 0.0;
|
||||||
for(VehicleRoute route : solution.getRoutes()){
|
for(VehicleRoute route : solution.getRoutes()){
|
||||||
costs += stateManager.getRouteState(route, StateIdFactory.COSTS).toDouble();
|
costs += stateManager.getRouteState(route, StateFactory.COSTS).toDouble();
|
||||||
}
|
}
|
||||||
solution.setCost(costs);
|
solution.setCost(costs);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ public class BuildPDVRPAlgoFromScratchTest {
|
||||||
// CalculatesServiceInsertion serviceInsertion = new CalculatesServiceInsertion(vrp.getTransportCosts(), marginalCalculus, new HardConstraints.HardLoadConstraint(stateManager));
|
// CalculatesServiceInsertion serviceInsertion = new CalculatesServiceInsertion(vrp.getTransportCosts(), marginalCalculus, new HardConstraints.HardLoadConstraint(stateManager));
|
||||||
|
|
||||||
VehicleFleetManager fleetManager = new InfiniteVehicles(vrp.getVehicles());
|
VehicleFleetManager fleetManager = new InfiniteVehicles(vrp.getVehicles());
|
||||||
JobInsertionCalculator finalServiceInsertion = new CalculatesVehTypeDepServiceInsertion(fleetManager, serviceInsertion);
|
JobInsertionCalculator finalServiceInsertion = new VehicleTypeDependentJobInsertionCalculator(fleetManager, serviceInsertion);
|
||||||
|
|
||||||
BestInsertion bestInsertion = new BestInsertion(finalServiceInsertion);
|
BestInsertion bestInsertion = new BestInsertion(finalServiceInsertion);
|
||||||
|
|
||||||
|
|
@ -80,7 +80,7 @@ public class BuildPDVRPAlgoFromScratchTest {
|
||||||
public void calculateCosts(VehicleRoutingProblemSolution solution) {
|
public void calculateCosts(VehicleRoutingProblemSolution solution) {
|
||||||
double costs = 0.0;
|
double costs = 0.0;
|
||||||
for(VehicleRoute route : solution.getRoutes()){
|
for(VehicleRoute route : solution.getRoutes()){
|
||||||
costs += stateManager.getRouteState(route, StateIdFactory.COSTS).toDouble();
|
costs += stateManager.getRouteState(route, StateFactory.COSTS).toDouble();
|
||||||
}
|
}
|
||||||
solution.setCost(costs);
|
solution.setCost(costs);
|
||||||
}
|
}
|
||||||
|
|
@ -131,8 +131,8 @@ public class BuildPDVRPAlgoFromScratchTest {
|
||||||
loadAtEnd += j.getCapacityDemand();
|
loadAtEnd += j.getCapacityDemand();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stateManager.putRouteState(route, StateIdFactory.LOAD_AT_BEGINNING, new StateImpl(loadAtDepot));
|
stateManager.putRouteState(route, StateFactory.LOAD_AT_BEGINNING, new StateImpl(loadAtDepot));
|
||||||
stateManager.putRouteState(route, StateIdFactory.LOAD, new StateImpl(loadAtEnd));
|
stateManager.putRouteState(route, StateFactory.LOAD, new StateImpl(loadAtEnd));
|
||||||
iterateForward.visit(route);
|
iterateForward.visit(route);
|
||||||
iterateBackward.visit(route);
|
iterateBackward.visit(route);
|
||||||
}
|
}
|
||||||
|
|
@ -149,14 +149,14 @@ public class BuildPDVRPAlgoFromScratchTest {
|
||||||
// log.info("insert job " + job2insert.getClass().toString() + " job " + job2insert + "" + job2insert.getCapacityDemand() + " in route " + inRoute.getTourActivities());
|
// log.info("insert job " + job2insert.getClass().toString() + " job " + job2insert + "" + job2insert.getCapacityDemand() + " in route " + inRoute.getTourActivities());
|
||||||
|
|
||||||
if(job2insert instanceof Delivery){
|
if(job2insert instanceof Delivery){
|
||||||
int loadAtDepot = (int) stateManager.getRouteState(inRoute, StateIdFactory.LOAD_AT_BEGINNING).toDouble();
|
int loadAtDepot = (int) stateManager.getRouteState(inRoute, StateFactory.LOAD_AT_BEGINNING).toDouble();
|
||||||
// log.info("loadAtDepot="+loadAtDepot);
|
// log.info("loadAtDepot="+loadAtDepot);
|
||||||
stateManager.putRouteState(inRoute, StateIdFactory.LOAD_AT_BEGINNING, new StateImpl(loadAtDepot + job2insert.getCapacityDemand()));
|
stateManager.putRouteState(inRoute, StateFactory.LOAD_AT_BEGINNING, StateFactory.createState(loadAtDepot + job2insert.getCapacityDemand()));
|
||||||
}
|
}
|
||||||
if(job2insert instanceof Pickup){
|
if(job2insert instanceof Pickup){
|
||||||
int loadAtEnd = (int) stateManager.getRouteState(inRoute, StateIdFactory.LOAD).toDouble();
|
int loadAtEnd = (int) stateManager.getRouteState(inRoute, StateFactory.LOAD_AT_END).toDouble();
|
||||||
// log.info("loadAtEnd="+loadAtEnd);
|
// log.info("loadAtEnd="+loadAtEnd);
|
||||||
stateManager.putRouteState(inRoute, StateIdFactory.LOAD, new StateImpl(loadAtEnd + job2insert.getCapacityDemand()));
|
stateManager.putRouteState(inRoute, StateFactory.LOAD_AT_END, StateFactory.createState(loadAtEnd + job2insert.getCapacityDemand()));
|
||||||
}
|
}
|
||||||
iterateForward.visit(inRoute);
|
iterateForward.visit(inRoute);
|
||||||
iterateBackward.visit(inRoute);
|
iterateBackward.visit(inRoute);
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ public class CalcVehicleTypeDependentServiceInsertionTest {
|
||||||
when(calc.calculate(vehicleRoute, service, veh1, veh1.getEarliestDeparture(), null, Double.MAX_VALUE)).thenReturn(iDataVeh1);
|
when(calc.calculate(vehicleRoute, service, veh1, veh1.getEarliestDeparture(), null, Double.MAX_VALUE)).thenReturn(iDataVeh1);
|
||||||
when(calc.calculate(vehicleRoute, service, veh2, veh2.getEarliestDeparture(), null, Double.MAX_VALUE)).thenReturn(iDataVeh2);
|
when(calc.calculate(vehicleRoute, service, veh2, veh2.getEarliestDeparture(), null, Double.MAX_VALUE)).thenReturn(iDataVeh2);
|
||||||
when(calc.calculate(vehicleRoute, service, veh2, veh2.getEarliestDeparture(), null, 10.0)).thenReturn(iDataVeh2);
|
when(calc.calculate(vehicleRoute, service, veh2, veh2.getEarliestDeparture(), null, 10.0)).thenReturn(iDataVeh2);
|
||||||
CalculatesVehTypeDepServiceInsertion insertion = new CalculatesVehTypeDepServiceInsertion(fleetManager,calc);
|
VehicleTypeDependentJobInsertionCalculator insertion = new VehicleTypeDependentJobInsertionCalculator(fleetManager,calc);
|
||||||
InsertionData iData = insertion.calculate(vehicleRoute, service, null, 0.0, null, Double.MAX_VALUE);
|
InsertionData iData = insertion.calculate(vehicleRoute, service, null, 0.0, null, Double.MAX_VALUE);
|
||||||
assertThat(iData.getSelectedVehicle(), is(veh1));
|
assertThat(iData.getSelectedVehicle(), is(veh1));
|
||||||
|
|
||||||
|
|
@ -91,7 +91,7 @@ public class CalcVehicleTypeDependentServiceInsertionTest {
|
||||||
when(calc.calculate(vehicleRoute, service, veh1, veh1.getEarliestDeparture(), null, Double.MAX_VALUE)).thenReturn(iDataVeh1);
|
when(calc.calculate(vehicleRoute, service, veh1, veh1.getEarliestDeparture(), null, Double.MAX_VALUE)).thenReturn(iDataVeh1);
|
||||||
when(calc.calculate(vehicleRoute, service, veh2, veh2.getEarliestDeparture(), null, Double.MAX_VALUE)).thenReturn(iDataVeh2);
|
when(calc.calculate(vehicleRoute, service, veh2, veh2.getEarliestDeparture(), null, Double.MAX_VALUE)).thenReturn(iDataVeh2);
|
||||||
when(calc.calculate(vehicleRoute, service, veh2, veh2.getEarliestDeparture(), null, 20.0)).thenReturn(iDataVeh2);
|
when(calc.calculate(vehicleRoute, service, veh2, veh2.getEarliestDeparture(), null, 20.0)).thenReturn(iDataVeh2);
|
||||||
CalculatesVehTypeDepServiceInsertion insertion = new CalculatesVehTypeDepServiceInsertion(fleetManager,calc);
|
VehicleTypeDependentJobInsertionCalculator insertion = new VehicleTypeDependentJobInsertionCalculator(fleetManager,calc);
|
||||||
InsertionData iData = insertion.calculate(vehicleRoute, service, null, 0.0, null, Double.MAX_VALUE);
|
InsertionData iData = insertion.calculate(vehicleRoute, service, null, 0.0, null, Double.MAX_VALUE);
|
||||||
assertThat(iData.getSelectedVehicle(), is(veh2));
|
assertThat(iData.getSelectedVehicle(), is(veh2));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,6 @@ import org.junit.Test;
|
||||||
import util.Coordinate;
|
import util.Coordinate;
|
||||||
import util.ManhattanDistanceCalculator;
|
import util.ManhattanDistanceCalculator;
|
||||||
import util.RouteUtils;
|
import util.RouteUtils;
|
||||||
import algorithms.StateUpdates.UpdateStates;
|
|
||||||
import basics.Job;
|
import basics.Job;
|
||||||
import basics.Service;
|
import basics.Service;
|
||||||
import basics.VehicleRoutingProblem;
|
import basics.VehicleRoutingProblem;
|
||||||
|
|
@ -151,10 +150,10 @@ public class GendreauPostOptTest {
|
||||||
ServiceInsertionCalculator standardServiceInsertion = new ServiceInsertionCalculator(cost, new LocalActivityInsertionCostsCalculator(cost, activityCosts), new HardLoadConstraint(states), new HardTimeWindowActivityLevelConstraint(states, cost));
|
ServiceInsertionCalculator standardServiceInsertion = new ServiceInsertionCalculator(cost, new LocalActivityInsertionCostsCalculator(cost, activityCosts), new HardLoadConstraint(states), new HardTimeWindowActivityLevelConstraint(states, cost));
|
||||||
|
|
||||||
|
|
||||||
CalculatesServiceInsertionConsideringFixCost withFixCost = new CalculatesServiceInsertionConsideringFixCost(standardServiceInsertion, states);
|
JobInsertionConsideringFixCostsCalculator withFixCost = new JobInsertionConsideringFixCostsCalculator(standardServiceInsertion, states);
|
||||||
withFixCost.setWeightOfFixCost(1.2);
|
withFixCost.setWeightOfFixCost(1.2);
|
||||||
|
|
||||||
insertionCalc = new CalculatesVehTypeDepServiceInsertion(fleetManager, withFixCost);
|
insertionCalc = new VehicleTypeDependentJobInsertionCalculator(fleetManager, withFixCost);
|
||||||
|
|
||||||
// updater = new TourStateUpdater(states, cost, activityCosts);
|
// updater = new TourStateUpdater(states, cost, activityCosts);
|
||||||
|
|
||||||
|
|
@ -185,14 +184,14 @@ public class GendreauPostOptTest {
|
||||||
// routes.add(new VehicleRoute(getEmptyTour(),getDriver(),getNoVehicle()));
|
// routes.add(new VehicleRoute(getEmptyTour(),getDriver(),getNoVehicle()));
|
||||||
|
|
||||||
|
|
||||||
VehicleRoutingProblemSolution sol = new VehicleRoutingProblemSolution(routes, states.getRouteState(route, StateIdFactory.COSTS).toDouble() + getFixedCosts(routes));
|
VehicleRoutingProblemSolution sol = new VehicleRoutingProblemSolution(routes, states.getRouteState(route, StateFactory.COSTS).toDouble() + getFixedCosts(routes));
|
||||||
|
|
||||||
|
|
||||||
assertEquals(110.0, sol.getCost(), 0.5);
|
assertEquals(110.0, sol.getCost(), 0.5);
|
||||||
|
|
||||||
|
|
||||||
RuinRadial radialRuin = new RuinRadial(vrp, 0.2, new JobDistanceAvgCosts(vrp.getTransportCosts()));
|
RuinRadial radialRuin = new RuinRadial(vrp, 0.2, new JobDistanceAvgCosts(vrp.getTransportCosts()));
|
||||||
radialRuin.addListener(stateUpdater);
|
// radialRuin.addListener(stateUpdater);
|
||||||
|
|
||||||
InsertionStrategy insertionStrategy = new BestInsertion(insertionCalc);
|
InsertionStrategy insertionStrategy = new BestInsertion(insertionCalc);
|
||||||
insertionStrategy.addListener(stateUpdater);
|
insertionStrategy.addListener(stateUpdater);
|
||||||
|
|
@ -218,7 +217,7 @@ public class GendreauPostOptTest {
|
||||||
double c = 0.0;
|
double c = 0.0;
|
||||||
for(VehicleRoute r : newSolution.getRoutes()){
|
for(VehicleRoute r : newSolution.getRoutes()){
|
||||||
|
|
||||||
c += states.getRouteState(r, StateIdFactory.COSTS).toDouble() + r.getVehicle().getType().getVehicleCostParams().fix;
|
c += states.getRouteState(r, StateFactory.COSTS).toDouble() + r.getVehicle().getType().getVehicleCostParams().fix;
|
||||||
|
|
||||||
}
|
}
|
||||||
return c;
|
return c;
|
||||||
|
|
|
||||||
78
jsprit-core/src/test/java/algorithms/StateUpdates.java
Normal file
78
jsprit-core/src/test/java/algorithms/StateUpdates.java
Normal file
|
|
@ -0,0 +1,78 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* 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 algorithms;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import basics.Job;
|
||||||
|
import basics.algo.InsertionStartsListener;
|
||||||
|
import basics.algo.JobInsertedListener;
|
||||||
|
import basics.costs.VehicleRoutingActivityCosts;
|
||||||
|
import basics.costs.VehicleRoutingTransportCosts;
|
||||||
|
import basics.route.VehicleRoute;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class UpdateStates implements JobInsertedListener, InsertionStartsListener{
|
||||||
|
|
||||||
|
private RouteActivityVisitor routeActivityVisitor;
|
||||||
|
|
||||||
|
private ReverseRouteActivityVisitor revRouteActivityVisitor;
|
||||||
|
|
||||||
|
private InsertionListeners insertionListeners = new InsertionListeners();
|
||||||
|
|
||||||
|
public UpdateStates(StateManager states, VehicleRoutingTransportCosts routingCosts, VehicleRoutingActivityCosts activityCosts) {
|
||||||
|
routeActivityVisitor = new RouteActivityVisitor();
|
||||||
|
routeActivityVisitor.addActivityVisitor(new UpdateActivityTimes(routingCosts));
|
||||||
|
routeActivityVisitor.addActivityVisitor(new UpdateCostsAtAllLevels(activityCosts, routingCosts, states));
|
||||||
|
routeActivityVisitor.addActivityVisitor(new UpdateLoadAtAllLevels(states));
|
||||||
|
routeActivityVisitor.addActivityVisitor(new UpdateMaxLoad(states));
|
||||||
|
revRouteActivityVisitor = new ReverseRouteActivityVisitor();
|
||||||
|
revRouteActivityVisitor.addActivityVisitor(new UpdateLatestOperationStartTimeAtActLocations(states, routingCosts));
|
||||||
|
insertionListeners.addListener(new UpdateLoadsAtStartAndEndOfRouteWhenInsertionStarts(states));
|
||||||
|
insertionListeners.addListener(new UpdateLoadsAtStartAndEndOfRouteWhenJobHasBeenInserted(states));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(VehicleRoute route){
|
||||||
|
List<VehicleRoute> routes = Arrays.asList(route);
|
||||||
|
insertionListeners.informInsertionStarts(routes, Collections.EMPTY_LIST);
|
||||||
|
routeActivityVisitor.visit(route);
|
||||||
|
revRouteActivityVisitor.visit(route);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) {
|
||||||
|
insertionListeners.informJobInserted(job2insert, inRoute, additionalCosts, additionalTime);
|
||||||
|
routeActivityVisitor.visit(inRoute);
|
||||||
|
revRouteActivityVisitor.visit(inRoute);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void informInsertionStarts(Collection<VehicleRoute> vehicleRoutes,Collection<Job> unassignedJobs) {
|
||||||
|
insertionListeners.informInsertionStarts(vehicleRoutes, unassignedJobs);
|
||||||
|
for(VehicleRoute route : vehicleRoutes) {
|
||||||
|
routeActivityVisitor.visit(route);
|
||||||
|
revRouteActivityVisitor.visit(route);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -28,7 +28,6 @@ import org.apache.log4j.Logger;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import algorithms.StateUpdates.UpdateStates;
|
|
||||||
import basics.Job;
|
import basics.Job;
|
||||||
import basics.Service;
|
import basics.Service;
|
||||||
import basics.costs.VehicleRoutingTransportCosts;
|
import basics.costs.VehicleRoutingTransportCosts;
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,6 @@ import org.junit.Test;
|
||||||
|
|
||||||
import util.Coordinate;
|
import util.Coordinate;
|
||||||
import util.ManhattanDistanceCalculator;
|
import util.ManhattanDistanceCalculator;
|
||||||
import algorithms.StateUpdates.UpdateStates;
|
|
||||||
import basics.Job;
|
import basics.Job;
|
||||||
import basics.Service;
|
import basics.Service;
|
||||||
import basics.costs.VehicleRoutingTransportCosts;
|
import basics.costs.VehicleRoutingTransportCosts;
|
||||||
|
|
|
||||||
|
|
@ -148,8 +148,8 @@ public class TestIterateRouteForwardInTime {
|
||||||
forwardInTime.addActivityVisitor(new UpdateLoadAtAllLevels(stateManager));
|
forwardInTime.addActivityVisitor(new UpdateLoadAtAllLevels(stateManager));
|
||||||
forwardInTime.visit(vehicleRoute);
|
forwardInTime.visit(vehicleRoute);
|
||||||
|
|
||||||
assertEquals(5.0, stateManager.getActivityState(firstAct,StateIdFactory.LOAD).toDouble(), 0.01);
|
assertEquals(5.0, stateManager.getActivityState(firstAct,StateFactory.LOAD).toDouble(), 0.01);
|
||||||
assertEquals(10.0, stateManager.getActivityState(secondAct,StateIdFactory.LOAD).toDouble(), 0.01);
|
assertEquals(10.0, stateManager.getActivityState(secondAct,StateFactory.LOAD).toDouble(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -173,9 +173,9 @@ public class TestIterateRouteForwardInTime {
|
||||||
forwardInTime.addActivityVisitor(new UpdateCostsAtAllLevels(new DefaultVehicleRoutingActivityCosts(), cost, stateManager));
|
forwardInTime.addActivityVisitor(new UpdateCostsAtAllLevels(new DefaultVehicleRoutingActivityCosts(), cost, stateManager));
|
||||||
forwardInTime.visit(vehicleRoute);
|
forwardInTime.visit(vehicleRoute);
|
||||||
|
|
||||||
assertEquals(10.0, stateManager.getActivityState(firstAct, StateIdFactory.COSTS).toDouble(),0.05);
|
assertEquals(10.0, stateManager.getActivityState(firstAct, StateFactory.COSTS).toDouble(),0.05);
|
||||||
assertEquals(5.0, stateManager.getActivityState(firstAct, StateIdFactory.LOAD).toDouble(),0.05);
|
assertEquals(5.0, stateManager.getActivityState(firstAct, StateFactory.LOAD).toDouble(),0.05);
|
||||||
assertEquals(10.0, stateManager.getActivityState(firstAct, StateIdFactory.EARLIEST_OPERATION_START_TIME).toDouble(),0.05);
|
assertEquals(10.0, stateManager.getActivityState(firstAct, StateFactory.EARLIEST_OPERATION_START_TIME).toDouble(),0.05);
|
||||||
// assertEquals(20.0, states.getState(tour.getActivities().get(0)).getLatestOperationStart(),0.05);
|
// assertEquals(20.0, states.getState(tour.getActivities().get(0)).getLatestOperationStart(),0.05);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -188,9 +188,9 @@ public class TestIterateRouteForwardInTime {
|
||||||
forwardInTime.addActivityVisitor(new UpdateCostsAtAllLevels(new DefaultVehicleRoutingActivityCosts(), cost, stateManager));
|
forwardInTime.addActivityVisitor(new UpdateCostsAtAllLevels(new DefaultVehicleRoutingActivityCosts(), cost, stateManager));
|
||||||
forwardInTime.visit(vehicleRoute);
|
forwardInTime.visit(vehicleRoute);
|
||||||
|
|
||||||
assertEquals(30.0, stateManager.getActivityState(secondAct, StateIdFactory.COSTS).toDouble(),0.05);
|
assertEquals(30.0, stateManager.getActivityState(secondAct, StateFactory.COSTS).toDouble(),0.05);
|
||||||
assertEquals(10.0, stateManager.getActivityState(secondAct, StateIdFactory.LOAD).toDouble(),0.05);
|
assertEquals(10.0, stateManager.getActivityState(secondAct, StateFactory.LOAD).toDouble(),0.05);
|
||||||
assertEquals(30.0, stateManager.getActivityState(secondAct, StateIdFactory.EARLIEST_OPERATION_START_TIME).toDouble(),0.05);
|
assertEquals(30.0, stateManager.getActivityState(secondAct, StateFactory.EARLIEST_OPERATION_START_TIME).toDouble(),0.05);
|
||||||
// assertEquals(40.0, states.getState(tour.getActivities().get(1)).getLatestOperationStart(),0.05);
|
// assertEquals(40.0, states.getState(tour.getActivities().get(1)).getLatestOperationStart(),0.05);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -202,7 +202,7 @@ public class TestIterateRouteForwardInTime {
|
||||||
forwardInTime.addActivityVisitor(new UpdateCostsAtAllLevels(new DefaultVehicleRoutingActivityCosts(), cost, stateManager));
|
forwardInTime.addActivityVisitor(new UpdateCostsAtAllLevels(new DefaultVehicleRoutingActivityCosts(), cost, stateManager));
|
||||||
forwardInTime.visit(vehicleRoute);
|
forwardInTime.visit(vehicleRoute);
|
||||||
|
|
||||||
assertEquals(40.0, stateManager.getRouteState(vehicleRoute,StateIdFactory.COSTS).toDouble(), 0.05);
|
assertEquals(40.0, stateManager.getRouteState(vehicleRoute,StateFactory.COSTS).toDouble(), 0.05);
|
||||||
assertEquals(40.0, vehicleRoute.getEnd().getArrTime(),0.05);
|
assertEquals(40.0, vehicleRoute.getEnd().getArrTime(),0.05);
|
||||||
assertEquals(50.0, vehicleRoute.getEnd().getTheoreticalLatestOperationStartTime(),0.05);
|
assertEquals(50.0, vehicleRoute.getEnd().getTheoreticalLatestOperationStartTime(),0.05);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,6 @@ import org.junit.Test;
|
||||||
|
|
||||||
import util.Coordinate;
|
import util.Coordinate;
|
||||||
import util.ManhattanDistanceCalculator;
|
import util.ManhattanDistanceCalculator;
|
||||||
import algorithms.StateUpdates.UpdateStates;
|
|
||||||
import basics.Job;
|
import basics.Job;
|
||||||
import basics.Service;
|
import basics.Service;
|
||||||
import basics.costs.VehicleRoutingTransportCosts;
|
import basics.costs.VehicleRoutingTransportCosts;
|
||||||
|
|
@ -102,7 +101,7 @@ public class TestTourStateUpdaterWithService {
|
||||||
|
|
||||||
states = new StateManager();
|
states = new StateManager();
|
||||||
|
|
||||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("test", 0).build();
|
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("test", 10).build();
|
||||||
vehicle = VehicleImpl.Builder.newInstance("testvehicle").setType(type).setLocationId("0,0")
|
vehicle = VehicleImpl.Builder.newInstance("testvehicle").setType(type).setLocationId("0,0")
|
||||||
.setEarliestStart(0.0).setLatestArrival(50.0).build();
|
.setEarliestStart(0.0).setLatestArrival(50.0).build();
|
||||||
|
|
||||||
|
|
@ -119,8 +118,8 @@ public class TestTourStateUpdaterWithService {
|
||||||
@Test
|
@Test
|
||||||
public void testCalculatedCost() {
|
public void testCalculatedCost() {
|
||||||
updateStates.update(vehicleRoute);
|
updateStates.update(vehicleRoute);
|
||||||
assertEquals(40.0, states.getRouteState(vehicleRoute,StateIdFactory.COSTS).toDouble(), 0.05);
|
assertEquals(40.0, states.getRouteState(vehicleRoute,StateFactory.COSTS).toDouble(), 0.05);
|
||||||
assertEquals(10, states.getRouteState(vehicleRoute, StateIdFactory.LOAD).toDouble(), 0.05);
|
assertEquals(10, states.getRouteState(vehicleRoute, StateFactory.LOAD).toDouble(), 0.05);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -136,27 +135,27 @@ public class TestTourStateUpdaterWithService {
|
||||||
@Test
|
@Test
|
||||||
public void testStatesOfAct1(){
|
public void testStatesOfAct1(){
|
||||||
updateStates.update(vehicleRoute);
|
updateStates.update(vehicleRoute);
|
||||||
assertEquals(10.0, states.getActivityState(tour.getActivities().get(0), StateIdFactory.COSTS).toDouble(),0.05);
|
assertEquals(10.0, states.getActivityState(tour.getActivities().get(0), StateFactory.COSTS).toDouble(),0.05);
|
||||||
assertEquals(5.0, states.getActivityState(tour.getActivities().get(0), StateIdFactory.LOAD).toDouble(),0.05);
|
assertEquals(5.0, states.getActivityState(tour.getActivities().get(0), StateFactory.LOAD).toDouble(),0.05);
|
||||||
// assertEquals(10.0, states.getActivityState(tour.getActivities().get(0), StateTypes.EARLIEST_OPERATION_START_TIME).toDouble(),0.05);
|
// assertEquals(10.0, states.getActivityState(tour.getActivities().get(0), StateTypes.EARLIEST_OPERATION_START_TIME).toDouble(),0.05);
|
||||||
assertEquals(20.0, states.getActivityState(tour.getActivities().get(0), StateIdFactory.LATEST_OPERATION_START_TIME).toDouble(),0.05);
|
assertEquals(20.0, states.getActivityState(tour.getActivities().get(0), StateFactory.LATEST_OPERATION_START_TIME).toDouble(),0.05);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStatesOfAct2(){
|
public void testStatesOfAct2(){
|
||||||
updateStates.update(vehicleRoute);
|
updateStates.update(vehicleRoute);
|
||||||
|
|
||||||
assertEquals(30.0, states.getActivityState(tour.getActivities().get(1), StateIdFactory.COSTS).toDouble(),0.05);
|
assertEquals(30.0, states.getActivityState(tour.getActivities().get(1), StateFactory.COSTS).toDouble(),0.05);
|
||||||
assertEquals(10.0, states.getActivityState(tour.getActivities().get(1), StateIdFactory.LOAD).toDouble(),0.05);
|
assertEquals(10.0, states.getActivityState(tour.getActivities().get(1), StateFactory.LOAD).toDouble(),0.05);
|
||||||
// assertEquals(10.0, states.getActivityState(tour.getActivities().get(0), StateTypes.EARLIEST_OPERATION_START_TIME).toDouble(),0.05);
|
// assertEquals(10.0, states.getActivityState(tour.getActivities().get(0), StateTypes.EARLIEST_OPERATION_START_TIME).toDouble(),0.05);
|
||||||
assertEquals(40.0, states.getActivityState(tour.getActivities().get(1), StateIdFactory.LATEST_OPERATION_START_TIME).toDouble(),0.05);
|
assertEquals(40.0, states.getActivityState(tour.getActivities().get(1), StateFactory.LATEST_OPERATION_START_TIME).toDouble(),0.05);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStatesOfAct3(){
|
public void testStatesOfAct3(){
|
||||||
updateStates.update(vehicleRoute);
|
updateStates.update(vehicleRoute);
|
||||||
|
|
||||||
assertEquals(40.0, states.getRouteState(vehicleRoute, StateIdFactory.COSTS).toDouble(), 0.05);
|
assertEquals(40.0, states.getRouteState(vehicleRoute, StateFactory.COSTS).toDouble(), 0.05);
|
||||||
assertEquals(40.0, vehicleRoute.getEnd().getArrTime(),0.05);
|
assertEquals(40.0, vehicleRoute.getEnd().getArrTime(),0.05);
|
||||||
assertEquals(50.0, vehicleRoute.getEnd().getTheoreticalLatestOperationStartTime(),0.05);
|
assertEquals(50.0, vehicleRoute.getEnd().getTheoreticalLatestOperationStartTime(),0.05);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ public class SolomonExample {
|
||||||
*/
|
*/
|
||||||
// VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
|
// VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
|
||||||
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig_solomon.xml");
|
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig_solomon.xml");
|
||||||
vra.setPrematureBreak(100);
|
// vra.setPrematureBreak(100);
|
||||||
// vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/sol_progress.png"));
|
// vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/sol_progress.png"));
|
||||||
/*
|
/*
|
||||||
* Solve the problem.
|
* Solve the problem.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue