1
0
Fork 0
mirror of https://github.com/graphhopper/jsprit.git synced 2020-01-24 07:45:05 +01:00

refine contraint

This commit is contained in:
oblonski 2013-11-07 08:27:38 +01:00
parent d63abea764
commit dfe25738bf

View file

@ -0,0 +1,62 @@
package algorithms;
import basics.route.DeliverShipment;
import basics.route.PickupShipment;
import basics.route.Start;
import basics.route.TourActivity;
class HardPickupAndDeliveryShipmentActivityLevelConstraint implements HardActivityLevelConstraint {
private StateManager stateManager;
private boolean backhaul = false;
public HardPickupAndDeliveryShipmentActivityLevelConstraint(StateManager stateManager) {
super();
this.stateManager = stateManager;
}
public HardPickupAndDeliveryShipmentActivityLevelConstraint(StateManager stateManager, boolean backhaul) {
super();
this.stateManager = stateManager;
this.backhaul = backhaul;
}
@Override
public ConstraintsStatus fulfilled(InsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) {
if(!(newAct instanceof PickupShipment) && !(newAct instanceof DeliverShipment)){
return ConstraintsStatus.FULFILLED;
}
if(backhaul){
// if(newAct instanceof PickupShipment && nextAct instanceof DeliverShipment){ return false; }
if(newAct instanceof DeliverShipment && prevAct instanceof PickupShipment){ return ConstraintsStatus.NOT_FULFILLED; }
}
int loadAtPrevAct;
// int futurePicks;
// int pastDeliveries;
if(prevAct instanceof Start){
loadAtPrevAct = (int)stateManager.getRouteState(iFacts.getRoute(), StateFactory.LOAD_AT_BEGINNING).toDouble();
// futurePicks = (int)stateManager.getRouteState(iFacts.getRoute(), StateTypes.LOAD).toDouble();
// pastDeliveries = 0;
}
else{
loadAtPrevAct = (int) stateManager.getActivityState(prevAct, StateFactory.LOAD).toDouble();
// futurePicks = (int) stateManager.getActivityState(prevAct, StateTypes.FUTURE_PICKS).toDouble();
// pastDeliveries = (int) stateManager.getActivityState(prevAct, StateTypes.PAST_DELIVERIES).toDouble();
}
if(newAct instanceof PickupShipment){
if(loadAtPrevAct + newAct.getCapacityDemand() > iFacts.getNewVehicle().getCapacity()){
return ConstraintsStatus.NOT_FULFILLED;
}
}
if(newAct instanceof DeliverShipment){
if(loadAtPrevAct + Math.abs(newAct.getCapacityDemand()) > iFacts.getNewVehicle().getCapacity()){
return ConstraintsStatus.NOT_FULFILLED_BREAK;
}
}
return ConstraintsStatus.FULFILLED;
}
}