mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
Merge branch 'pickupAndDelivery' into PickupMergeRelaxAPI
Conflicts: jsprit-core/src/main/java/algorithms/BestInsertionBuilder.java jsprit-core/src/main/java/algorithms/VehicleRoutingAlgorithmFactoryImpl.java jsprit-core/src/test/java/algorithms/BuildPDVRPWithShipmentsAlgoFromScratchTest.java jsprit-core/src/test/resources/pdp_sol.xml
This commit is contained in:
commit
a9da587f6a
35 changed files with 609 additions and 36828 deletions
|
|
@ -107,4 +107,5 @@ public class BestInsertionBuilder {
|
|||
return bestInsertion;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ package algorithms;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import basics.Delivery;
|
||||
import basics.Pickup;
|
||||
import basics.Service;
|
||||
import basics.Shipment;
|
||||
import basics.VehicleRoutingProblem;
|
||||
|
|
@ -238,6 +240,8 @@ class CalculatorBuilder {
|
|||
JobCalculatorSwitcher switcher = new JobCalculatorSwitcher();
|
||||
switcher.put(Shipment.class, shipmentInsertion);
|
||||
switcher.put(Service.class, serviceInsertion);
|
||||
switcher.put(Pickup.class, serviceInsertion);
|
||||
switcher.put(Delivery.class, serviceInsertion);
|
||||
|
||||
// JobInsertionCostsCalculator standardServiceInsertion = new ServiceInsertionCalculator(vrp.getTransportCosts(), actInsertionCalc, constraintManager, constraintManager);
|
||||
// ((ServiceInsertionCalculator) standardServiceInsertion).setNeighborhood(vrp.getNeighborhood());
|
||||
|
|
|
|||
|
|
@ -1,10 +1,15 @@
|
|||
package algorithms;
|
||||
|
||||
import basics.VehicleRoutingProblem;
|
||||
import basics.VehicleRoutingProblem.Constraint;
|
||||
import basics.route.TourActivity;
|
||||
|
||||
public class ConstraintManager implements HardActivityStateLevelConstraint, HardRouteStateLevelConstraint{
|
||||
|
||||
public static enum Priority {
|
||||
CRITICAL, HIGH, LOW
|
||||
}
|
||||
|
||||
private HardActivityLevelConstraintManager actLevelConstraintManager = new HardActivityLevelConstraintManager();
|
||||
|
||||
private HardRouteLevelConstraintManager routeLevelConstraintManager = new HardRouteLevelConstraintManager();
|
||||
|
|
@ -24,7 +29,7 @@ public class ConstraintManager implements HardActivityStateLevelConstraint, Hard
|
|||
|
||||
public void addTimeWindowConstraint(){
|
||||
if(!timeWindowConstraintsSet){
|
||||
addConstraint(new TimeWindowConstraint(stateManager, vrp.getTransportCosts()));
|
||||
addConstraint(new TimeWindowConstraint(stateManager, vrp.getTransportCosts()),Priority.HIGH);
|
||||
stateManager.addActivityVisitor(new TimeWindowUpdater(stateManager, vrp.getTransportCosts()));
|
||||
timeWindowConstraintsSet = true;
|
||||
}
|
||||
|
|
@ -32,19 +37,24 @@ public class ConstraintManager implements HardActivityStateLevelConstraint, Hard
|
|||
|
||||
public void addLoadConstraint(){
|
||||
if(!loadConstraintsSet){
|
||||
if(vrp.getProblemConstraints().contains(Constraint.DELIVERIES_FIRST)){
|
||||
addConstraint(new ServiceBackhaulConstraint(),Priority.HIGH);
|
||||
}
|
||||
addConstraint(new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager),Priority.CRITICAL);
|
||||
addConstraint(new ServiceLoadRouteLevelConstraint(stateManager));
|
||||
addConstraint(new ServiceLoadActivityLevelConstraint(stateManager));
|
||||
addConstraint(new ServiceLoadActivityLevelConstraint(stateManager),Priority.LOW);
|
||||
UpdateLoads updateLoads = new UpdateLoads(stateManager);
|
||||
stateManager.addActivityVisitor(updateLoads);
|
||||
stateManager.addListener(updateLoads);
|
||||
stateManager.addActivityVisitor(new UpdateFuturePickups(stateManager));
|
||||
stateManager.addActivityVisitor(new UpdateOccuredDeliveries(stateManager));
|
||||
stateManager.addActivityVisitor(new UpdateMaxLoad(stateManager));
|
||||
stateManager.addActivityVisitor(new UpdateMaxLoad_(stateManager));
|
||||
stateManager.addActivityVisitor(new UpdatePrevMaxLoad(stateManager));
|
||||
loadConstraintsSet=true;
|
||||
}
|
||||
}
|
||||
|
||||
public void addConstraint(HardActivityStateLevelConstraint actLevelConstraint){
|
||||
actLevelConstraintManager.addConstraint(actLevelConstraint);
|
||||
public void addConstraint(HardActivityStateLevelConstraint actLevelConstraint, Priority priority){
|
||||
actLevelConstraintManager.addConstraint(actLevelConstraint,priority);
|
||||
}
|
||||
|
||||
public void addConstraint(HardRouteStateLevelConstraint routeLevelConstraint){
|
||||
|
|
|
|||
|
|
@ -36,8 +36,8 @@ import basics.algo.RuinListener;
|
|||
import basics.algo.SearchStrategyModule;
|
||||
import basics.algo.SearchStrategyModuleListener;
|
||||
import basics.route.TourActivity;
|
||||
import basics.route.VehicleFleetManager;
|
||||
import basics.route.TourActivity.JobActivity;
|
||||
import basics.route.VehicleFleetManager;
|
||||
import basics.route.VehicleRoute;
|
||||
|
||||
public final class Gendreau implements SearchStrategyModule{
|
||||
|
|
|
|||
|
|
@ -3,24 +3,65 @@ package algorithms;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import algorithms.ConstraintManager.Priority;
|
||||
import basics.route.TourActivity;
|
||||
|
||||
class HardActivityLevelConstraintManager implements HardActivityStateLevelConstraint {
|
||||
|
||||
private Collection<HardActivityStateLevelConstraint> hardConstraints = new ArrayList<HardActivityStateLevelConstraint>();
|
||||
private Collection<HardActivityStateLevelConstraint> criticalConstraints = new ArrayList<HardActivityStateLevelConstraint>();
|
||||
|
||||
public void addConstraint(HardActivityStateLevelConstraint constraint){
|
||||
hardConstraints.add(constraint);
|
||||
private Collection<HardActivityStateLevelConstraint> highPrioConstraints = new ArrayList<HardActivityStateLevelConstraint>();
|
||||
|
||||
private Collection<HardActivityStateLevelConstraint> lowPrioConstraints = new ArrayList<HardActivityStateLevelConstraint>();
|
||||
|
||||
public void addConstraint(HardActivityStateLevelConstraint constraint, Priority priority){
|
||||
if(priority.equals(Priority.CRITICAL)){
|
||||
criticalConstraints.add(constraint);
|
||||
}
|
||||
else if(priority.equals(Priority.HIGH)){
|
||||
highPrioConstraints.add(constraint);
|
||||
}
|
||||
else{
|
||||
lowPrioConstraints.add(constraint);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConstraintsStatus fulfilled(InsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) {
|
||||
for(HardActivityStateLevelConstraint constraint : hardConstraints){
|
||||
ConstraintsStatus notFulfilled = null;
|
||||
for(HardActivityStateLevelConstraint c : criticalConstraints){
|
||||
ConstraintsStatus status = c.fulfilled(iFacts, prevAct, newAct, nextAct, prevActDepTime);
|
||||
if(status.equals(ConstraintsStatus.NOT_FULFILLED_BREAK)){
|
||||
return status;
|
||||
}
|
||||
else{
|
||||
if(status.equals(ConstraintsStatus.NOT_FULFILLED)){
|
||||
notFulfilled = status;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(notFulfilled != null) return notFulfilled;
|
||||
|
||||
for(HardActivityStateLevelConstraint c : highPrioConstraints){
|
||||
ConstraintsStatus status = c.fulfilled(iFacts, prevAct, newAct, nextAct, prevActDepTime);
|
||||
if(status.equals(ConstraintsStatus.NOT_FULFILLED_BREAK)){
|
||||
return status;
|
||||
}
|
||||
else{
|
||||
if(status.equals(ConstraintsStatus.NOT_FULFILLED)){
|
||||
notFulfilled = status;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(notFulfilled != null) return notFulfilled;
|
||||
|
||||
for(HardActivityStateLevelConstraint constraint : lowPrioConstraints){
|
||||
ConstraintsStatus status = constraint.fulfilled(iFacts, prevAct, newAct, nextAct, prevActDepTime);
|
||||
if(status.equals(ConstraintsStatus.NOT_FULFILLED_BREAK) || status.equals(ConstraintsStatus.NOT_FULFILLED)){
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
return ConstraintsStatus.FULFILLED;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,76 +0,0 @@
|
|||
package algorithms;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import algorithms.HardActivityStateLevelConstraint.ConstraintsStatus;
|
||||
import basics.route.DeliverShipment;
|
||||
import basics.route.PickupShipment;
|
||||
import basics.route.Start;
|
||||
import basics.route.TourActivity;
|
||||
|
||||
public class HardPickupAndDeliveryShipmentActivityLevelConstraint implements HardActivityStateLevelConstraint {
|
||||
|
||||
private static Logger logger = Logger.getLogger(HardPickupAndDeliveryShipmentActivityLevelConstraint.class);
|
||||
|
||||
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) {
|
||||
// logger.info(prevAct + " - " + newAct + " - " + nextAct);
|
||||
if(!(newAct instanceof PickupShipment) && !(newAct instanceof DeliverShipment)){
|
||||
return ConstraintsStatus.FULFILLED;
|
||||
}
|
||||
if(backhaul){
|
||||
if(newAct instanceof PickupShipment && prevAct instanceof DeliverShipment){
|
||||
// logger.info("NOT_FULFILLED_BREAK");
|
||||
return ConstraintsStatus.NOT_FULFILLED_BREAK; }
|
||||
if(newAct instanceof DeliverShipment && nextAct instanceof PickupShipment){
|
||||
// logger.info("NOT_FULFILLED");
|
||||
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()){
|
||||
// logger.info("NOT_FULFILLED");
|
||||
return ConstraintsStatus.NOT_FULFILLED;
|
||||
}
|
||||
}
|
||||
if(newAct instanceof DeliverShipment){
|
||||
if(loadAtPrevAct + Math.abs(newAct.getCapacityDemand()) > iFacts.getNewVehicle().getCapacity()){
|
||||
// logger.info("NOT_FULFILLED_BREAK");
|
||||
return ConstraintsStatus.NOT_FULFILLED_BREAK;
|
||||
}
|
||||
|
||||
}
|
||||
// logger.info("FULFILLED");
|
||||
return ConstraintsStatus.FULFILLED;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -16,8 +16,6 @@
|
|||
******************************************************************************/
|
||||
package algorithms;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import algorithms.InsertionData.NoInsertionFound;
|
||||
import basics.Job;
|
||||
import basics.Service;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,65 @@
|
|||
package algorithms;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import basics.route.DeliverShipment;
|
||||
import basics.route.PickupShipment;
|
||||
import basics.route.Start;
|
||||
import basics.route.TourActivity;
|
||||
|
||||
/**
|
||||
* Constraint that ensures capacity constraint at each activity.
|
||||
*
|
||||
* <p>This is critical to consistently calculate pd-problems with capacity constraints. Critical means
|
||||
* that is MUST be visited. It also assumes that pd-activities are visited in the order they occur in a tour.
|
||||
*
|
||||
* @author schroeder
|
||||
*
|
||||
*/
|
||||
public class PickupAndDeliverShipmentLoadActivityLevelConstraint implements HardActivityStateLevelConstraint {
|
||||
|
||||
private static Logger logger = Logger.getLogger(PickupAndDeliverShipmentLoadActivityLevelConstraint.class);
|
||||
|
||||
private StateManager stateManager;
|
||||
|
||||
/**
|
||||
* Constructs the constraint ensuring capacity constraint at each activity.
|
||||
*
|
||||
* <p>This is critical to consistently calculate pd-problems with capacity constraints. Critical means
|
||||
* that is MUST be visited. It also assumes that pd-activities are visited in the order they occur in a tour.
|
||||
*
|
||||
*
|
||||
* @param stateManager
|
||||
*/
|
||||
public PickupAndDeliverShipmentLoadActivityLevelConstraint(StateManager stateManager) {
|
||||
super();
|
||||
this.stateManager = stateManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConstraintsStatus fulfilled(InsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) {
|
||||
if(!(newAct instanceof PickupShipment) && !(newAct instanceof DeliverShipment)){
|
||||
return ConstraintsStatus.FULFILLED;
|
||||
}
|
||||
int loadAtPrevAct;
|
||||
if(prevAct instanceof Start){
|
||||
loadAtPrevAct = (int)stateManager.getRouteState(iFacts.getRoute(), StateFactory.LOAD_AT_BEGINNING).toDouble();
|
||||
}
|
||||
else{
|
||||
loadAtPrevAct = (int) stateManager.getActivityState(prevAct, StateFactory.LOAD).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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,19 +1,18 @@
|
|||
package algorithms;
|
||||
|
||||
import basics.route.DeliveryActivity;
|
||||
import basics.route.PickupActivity;
|
||||
import basics.route.DeliverService;
|
||||
import basics.route.PickupService;
|
||||
import basics.route.ServiceActivity;
|
||||
import basics.route.Start;
|
||||
import basics.route.TourActivity;
|
||||
|
||||
public class ServiceBackhaulConstraint implements HardActivityStateLevelConstraint {
|
||||
|
||||
@Override
|
||||
public ConstraintsStatus fulfilled(InsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) {
|
||||
if(newAct instanceof PickupActivity && nextAct instanceof DeliveryActivity){ return ConstraintsStatus.NOT_FULFILLED; }
|
||||
if(newAct instanceof ServiceActivity && nextAct instanceof DeliveryActivity){ return ConstraintsStatus.NOT_FULFILLED; }
|
||||
if(newAct instanceof DeliveryActivity && prevAct instanceof PickupActivity){ return ConstraintsStatus.NOT_FULFILLED; }
|
||||
if(newAct instanceof DeliveryActivity && prevAct instanceof ServiceActivity){ return ConstraintsStatus.NOT_FULFILLED; }
|
||||
if(newAct instanceof PickupService && nextAct instanceof DeliverService){ return ConstraintsStatus.NOT_FULFILLED; }
|
||||
if(newAct instanceof ServiceActivity && nextAct instanceof DeliverService){ return ConstraintsStatus.NOT_FULFILLED; }
|
||||
if(newAct instanceof DeliverService && prevAct instanceof PickupService){ return ConstraintsStatus.NOT_FULFILLED_BREAK; }
|
||||
if(newAct instanceof DeliverService && prevAct instanceof ServiceActivity){ return ConstraintsStatus.NOT_FULFILLED_BREAK; }
|
||||
return ConstraintsStatus.FULFILLED;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
package algorithms;
|
||||
|
||||
import basics.route.DeliveryActivity;
|
||||
import basics.route.PickupActivity;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import basics.route.DeliverService;
|
||||
import basics.route.PickupService;
|
||||
import basics.route.ServiceActivity;
|
||||
import basics.route.Start;
|
||||
import basics.route.TourActivity;
|
||||
|
|
@ -17,6 +19,8 @@ import basics.route.TourActivity;
|
|||
*/
|
||||
class ServiceLoadActivityLevelConstraint implements HardActivityStateLevelConstraint {
|
||||
|
||||
private static Logger log = Logger.getLogger(ServiceLoadActivityLevelConstraint.class);
|
||||
|
||||
private StateGetter stateManager;
|
||||
|
||||
public ServiceLoadActivityLevelConstraint(StateGetter stateManager) {
|
||||
|
|
@ -26,31 +30,31 @@ class ServiceLoadActivityLevelConstraint implements HardActivityStateLevelConstr
|
|||
|
||||
@Override
|
||||
public ConstraintsStatus fulfilled(InsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) {
|
||||
int loadAtPrevAct;
|
||||
int futurePicks;
|
||||
int pastDeliveries;
|
||||
int futureMaxLoad;
|
||||
int prevMaxLoad;
|
||||
if(prevAct instanceof Start){
|
||||
loadAtPrevAct = (int)stateManager.getRouteState(iFacts.getRoute(), StateFactory.LOAD_AT_BEGINNING).toDouble();
|
||||
futurePicks = (int)stateManager.getRouteState(iFacts.getRoute(), StateFactory.LOAD_AT_END).toDouble();
|
||||
pastDeliveries = 0;
|
||||
futureMaxLoad = (int)stateManager.getRouteState(iFacts.getRoute(), StateFactory.MAXLOAD).toDouble();
|
||||
prevMaxLoad = (int)stateManager.getRouteState(iFacts.getRoute(), StateFactory.LOAD_AT_BEGINNING).toDouble();
|
||||
}
|
||||
else{
|
||||
loadAtPrevAct = (int) stateManager.getActivityState(prevAct, StateFactory.LOAD).toDouble();
|
||||
futurePicks = (int) stateManager.getActivityState(prevAct, StateFactory.FUTURE_PICKS).toDouble();
|
||||
pastDeliveries = (int) stateManager.getActivityState(prevAct, StateFactory.PAST_DELIVERIES).toDouble();
|
||||
futureMaxLoad = (int) stateManager.getActivityState(prevAct, StateFactory.FUTURE_PICKS).toDouble();
|
||||
prevMaxLoad = (int) stateManager.getActivityState(prevAct, StateFactory.PAST_DELIVERIES).toDouble();
|
||||
|
||||
}
|
||||
if(newAct instanceof PickupActivity || newAct instanceof ServiceActivity){
|
||||
if(loadAtPrevAct + newAct.getCapacityDemand() + futurePicks > iFacts.getNewVehicle().getCapacity()){
|
||||
if(newAct instanceof PickupService || newAct instanceof ServiceActivity){
|
||||
if(newAct.getCapacityDemand() + futureMaxLoad > iFacts.getNewVehicle().getCapacity()){
|
||||
// log.debug("insertionOf("+newAct+").BETWEEN("+prevAct+").AND("+nextAct+")=NOT_POSSIBLE");
|
||||
return ConstraintsStatus.NOT_FULFILLED;
|
||||
}
|
||||
}
|
||||
if(newAct instanceof DeliveryActivity){
|
||||
if(loadAtPrevAct + Math.abs(newAct.getCapacityDemand()) + pastDeliveries > iFacts.getNewVehicle().getCapacity()){
|
||||
return ConstraintsStatus.NOT_FULFILLED;
|
||||
if(newAct instanceof DeliverService){
|
||||
if(Math.abs(newAct.getCapacityDemand()) + prevMaxLoad > iFacts.getNewVehicle().getCapacity()){
|
||||
// log.debug("insertionOf("+newAct+").BETWEEN("+prevAct+").AND("+nextAct+")=NOT_POSSIBLE[break=neverBePossibleAnymore]");
|
||||
return ConstraintsStatus.NOT_FULFILLED_BREAK;
|
||||
}
|
||||
|
||||
}
|
||||
// log.debug("insertionOf("+newAct+").BETWEEN("+prevAct+").AND("+nextAct+")=POSSIBLE");
|
||||
return ConstraintsStatus.FULFILLED;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package algorithms;
|
||||
|
||||
import basics.route.DeliverShipment;
|
||||
import basics.route.PickupShipment;
|
||||
import basics.route.TourActivity;
|
||||
|
||||
public class ShipmentPickupsFirstConstraint implements HardActivityStateLevelConstraint {
|
||||
|
||||
@Override
|
||||
public ConstraintsStatus fulfilled(InsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) {
|
||||
if(newAct instanceof DeliverShipment && nextAct instanceof PickupShipment){ return ConstraintsStatus.NOT_FULFILLED; }
|
||||
if(newAct instanceof PickupShipment && prevAct instanceof DeliverShipment){ return ConstraintsStatus.NOT_FULFILLED_BREAK; }
|
||||
return ConstraintsStatus.FULFILLED;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -3,7 +3,6 @@ package algorithms;
|
|||
import org.apache.log4j.Logger;
|
||||
|
||||
import util.ActivityTimeTracker;
|
||||
|
||||
import basics.costs.ForwardTransportTime;
|
||||
import basics.route.ActivityVisitor;
|
||||
import basics.route.TourActivity;
|
||||
|
|
|
|||
|
|
@ -1,39 +0,0 @@
|
|||
package algorithms;
|
||||
|
||||
import basics.route.PickupActivity;
|
||||
import basics.route.ReverseActivityVisitor;
|
||||
import basics.route.ServiceActivity;
|
||||
import basics.route.TourActivity;
|
||||
import basics.route.VehicleRoute;
|
||||
|
||||
class UpdateFuturePickups implements ReverseActivityVisitor, StateUpdater {
|
||||
private StateManager stateManager;
|
||||
private int futurePicks = 0;
|
||||
private VehicleRoute route;
|
||||
|
||||
public UpdateFuturePickups(StateManager stateManager) {
|
||||
super();
|
||||
this.stateManager = stateManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void begin(VehicleRoute route) {
|
||||
this.route = route;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(TourActivity act) {
|
||||
stateManager.putActivityState(act, StateFactory.FUTURE_PICKS, StateFactory.createState(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;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,8 @@ package algorithms;
|
|||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import basics.Delivery;
|
||||
import basics.Job;
|
||||
import basics.Pickup;
|
||||
|
|
@ -27,6 +29,7 @@ class UpdateLoads implements ActivityVisitor, StateUpdater, InsertionStartsListe
|
|||
private StateManager stateManager;
|
||||
private int currentLoad = 0;
|
||||
private VehicleRoute route;
|
||||
private static Logger log = Logger.getLogger(UpdateLoads.class);
|
||||
|
||||
/**
|
||||
* Updates load at activity level.
|
||||
|
|
@ -89,6 +92,8 @@ class UpdateLoads implements ActivityVisitor, StateUpdater, InsertionStartsListe
|
|||
|
||||
@Override
|
||||
public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) {
|
||||
// log.debug("insert("+job2insert+").into("+inRoute+")");
|
||||
// log(inRoute);
|
||||
if(job2insert instanceof Delivery){
|
||||
int loadAtDepot = (int) stateManager.getRouteState(inRoute, StateFactory.LOAD_AT_BEGINNING).toDouble();
|
||||
// log.info("loadAtDepot="+loadAtDepot);
|
||||
|
|
@ -101,4 +106,13 @@ class UpdateLoads implements ActivityVisitor, StateUpdater, InsertionStartsListe
|
|||
}
|
||||
}
|
||||
|
||||
// private void log(VehicleRoute inRoute) {
|
||||
// log.debug(inRoute.getStart());
|
||||
// for(TourActivity act : inRoute.getTourActivities().getActivities()){
|
||||
// log.debug(act);
|
||||
// }
|
||||
// log.debug(inRoute.getEnd());
|
||||
//
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
@ -1,67 +1,44 @@
|
|||
package algorithms;
|
||||
|
||||
import basics.route.ActivityVisitor;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import basics.route.ReverseActivityVisitor;
|
||||
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 {
|
||||
class UpdateMaxLoad implements ReverseActivityVisitor, StateUpdater {
|
||||
private static Logger log = Logger.getLogger(UpdateMaxLoad.class);
|
||||
private StateManager stateManager;
|
||||
private int currentLoad = 0;
|
||||
private VehicleRoute route;
|
||||
private int maxLoad = 0;
|
||||
private double maxLoad;
|
||||
private double currLoad;
|
||||
|
||||
/**
|
||||
* Updates load at activity level.
|
||||
*
|
||||
* <p>Note that this assumes that StateTypes.LOAD_AT_DEPOT is already updated, i.e. it starts by setting loadAtDepot to StateTypes.LOAD_AT_DEPOT.
|
||||
* If StateTypes.LOAD_AT_DEPOT is not set, it starts with 0 load at depot.
|
||||
*
|
||||
* <p>Thus it DEPENDS on StateTypes.LOAD_AT_DEPOT
|
||||
*
|
||||
*
|
||||
*
|
||||
* <p>The loads can be retrieved by <br>
|
||||
* <code>stateManager.getActivityState(activity,StateTypes.LOAD);</code>
|
||||
*
|
||||
*
|
||||
* @author stefan
|
||||
*
|
||||
*/
|
||||
public UpdateMaxLoad(StateManager stateManager) {
|
||||
super();
|
||||
this.stateManager = stateManager;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void begin(VehicleRoute route) {
|
||||
currentLoad = (int) stateManager.getRouteState(route, StateFactory.LOAD_AT_BEGINNING).toDouble();
|
||||
maxLoad = currentLoad;
|
||||
this.route = route;
|
||||
maxLoad = stateManager.getRouteState(route, StateFactory.LOAD_AT_END).toDouble();
|
||||
// currLoad = maxLoad;
|
||||
// log.debug("maxLoad@end="+maxLoad);
|
||||
}
|
||||
|
||||
@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";
|
||||
maxLoad = Math.max(maxLoad, stateManager.getActivityState(act, StateFactory.LOAD).toDouble());
|
||||
// currLoad -= act.getCapacityDemand();
|
||||
// log.debug("maxLoad@"+act+"="+maxLoad);
|
||||
stateManager.putActivityState(act, StateFactory.FUTURE_PICKS, StateFactory.createState(maxLoad));
|
||||
assert maxLoad <= route.getVehicle().getCapacity() : "maxLoad can never be bigger than vehicleCap";
|
||||
assert maxLoad >= 0 : "maxLoad can never be smaller than 0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
stateManager.putRouteState(route, StateFactory.MAXLOAD, StateFactory.createState(maxLoad));
|
||||
currentLoad = 0;
|
||||
maxLoad = 0;
|
||||
// stateManager.putRouteState(route, StateFactory.MAXLOAD, StateFactory.createState(maxLoad));
|
||||
// log.debug("maxLoad@start="+maxLoad);
|
||||
}
|
||||
}
|
||||
67
jsprit-core/src/main/java/algorithms/UpdateMaxLoad_.java
Normal file
67
jsprit-core/src/main/java/algorithms/UpdateMaxLoad_.java
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
package algorithms;
|
||||
|
||||
import basics.route.ActivityVisitor;
|
||||
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>The loads can be retrieved by <br>
|
||||
* <code>stateManager.getActivityState(activity,StateTypes.LOAD);</code>
|
||||
*
|
||||
*
|
||||
* @author stefan
|
||||
*
|
||||
*/
|
||||
public UpdateMaxLoad_(StateManager stateManager) {
|
||||
super();
|
||||
this.stateManager = stateManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void begin(VehicleRoute route) {
|
||||
currentLoad = (int) stateManager.getRouteState(route, StateFactory.LOAD_AT_BEGINNING).toDouble();
|
||||
maxLoad = currentLoad;
|
||||
this.route = route;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(TourActivity act) {
|
||||
currentLoad += act.getCapacityDemand();
|
||||
maxLoad = Math.max(maxLoad, currentLoad);
|
||||
assert currentLoad <= route.getVehicle().getCapacity() : "currentLoad at activity must not be > vehicleCapacity";
|
||||
assert currentLoad >= 0 : "currentLoad at act must not be < 0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
stateManager.putRouteState(route, StateFactory.MAXLOAD, StateFactory.createState(maxLoad));
|
||||
currentLoad = 0;
|
||||
maxLoad = 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
package algorithms;
|
||||
|
||||
import basics.route.ActivityVisitor;
|
||||
import basics.route.DeliveryActivity;
|
||||
import basics.route.TourActivity;
|
||||
import basics.route.VehicleRoute;
|
||||
|
||||
class UpdateOccuredDeliveries implements ActivityVisitor, StateUpdater {
|
||||
private StateManager stateManager;
|
||||
private int deliveries = 0;
|
||||
private VehicleRoute route;
|
||||
|
||||
public UpdateOccuredDeliveries(StateManager 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, StateFactory.PAST_DELIVERIES, StateFactory.createState(deliveries));
|
||||
assert deliveries >= 0 : "deliveries < 0";
|
||||
assert deliveries <= route.getVehicle().getCapacity() : "deliveries > vehicleCap";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
deliveries = 0;
|
||||
route = null;
|
||||
}
|
||||
}
|
||||
42
jsprit-core/src/main/java/algorithms/UpdatePrevMaxLoad.java
Normal file
42
jsprit-core/src/main/java/algorithms/UpdatePrevMaxLoad.java
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
package algorithms;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import basics.route.ActivityVisitor;
|
||||
import basics.route.TourActivity;
|
||||
import basics.route.VehicleRoute;
|
||||
|
||||
class UpdatePrevMaxLoad implements ActivityVisitor, StateUpdater {
|
||||
private static Logger log = Logger.getLogger(UpdatePrevMaxLoad.class);
|
||||
private StateManager stateManager;
|
||||
private VehicleRoute route;
|
||||
private double currLoad;
|
||||
private double prevMaxLoad;
|
||||
|
||||
public UpdatePrevMaxLoad(StateManager stateManager) {
|
||||
super();
|
||||
this.stateManager = stateManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void begin(VehicleRoute route) {
|
||||
this.route = route;
|
||||
currLoad = stateManager.getRouteState(route, StateFactory.LOAD_AT_BEGINNING).toDouble();
|
||||
prevMaxLoad = currLoad;
|
||||
// log.debug("prevMaxLoad@start="+prevMaxLoad);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(TourActivity act) {
|
||||
prevMaxLoad = Math.max(prevMaxLoad, stateManager.getActivityState(act, StateFactory.LOAD).toDouble());
|
||||
// log.debug("prevMaxLoad@"+act+"="+prevMaxLoad);
|
||||
stateManager.putActivityState(act, StateFactory.PAST_DELIVERIES, StateFactory.createState(prevMaxLoad));
|
||||
assert prevMaxLoad >= 0 : "maxLoad can never be smaller than 0";
|
||||
assert prevMaxLoad <= route.getVehicle().getCapacity() : "maxLoad can never be bigger than vehicleCap";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
// log.debug("prevMaxLoad@end="+prevMaxLoad);
|
||||
}
|
||||
}
|
||||
|
|
@ -3,14 +3,12 @@ package algorithms;
|
|||
import org.apache.log4j.Logger;
|
||||
|
||||
import util.ActivityTimeTracker;
|
||||
|
||||
import algorithms.StateManager.StateImpl;
|
||||
import basics.costs.ForwardTransportCost;
|
||||
import basics.costs.VehicleRoutingActivityCosts;
|
||||
import basics.costs.VehicleRoutingTransportCosts;
|
||||
import basics.route.ActivityVisitor;
|
||||
import basics.route.TourActivity;
|
||||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleRoute;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -25,8 +25,12 @@ public class VehicleRoutingAlgorithmFactoryImpl implements VehicleRoutingAlgorit
|
|||
@Override
|
||||
public VehicleRoutingAlgorithm createAlgorithm(VehicleRoutingProblem vrp) {
|
||||
this.stateManager.addActivityVisitor(new UpdateVariableCosts(vrp.getActivityCosts(), vrp.getTransportCosts(), this.stateManager));
|
||||
this.stateManager.addActivityVisitor(new UpdateMaxLoad(this.stateManager));
|
||||
//<<<<<<< HEAD
|
||||
// this.stateManager.addActivityVisitor(new UpdateMaxLoad(this.stateManager));
|
||||
this.stateManager.addActivityVisitor(new UpdateActivityTimes(vrp.getTransportCosts()));
|
||||
//=======
|
||||
//// this.stateManager.addActivityVisitor(new UpdateMaxLoad_(this.stateManager));
|
||||
//>>>>>>> refs/heads/pickupAndDelivery
|
||||
VehicleRoutingAlgorithm algorithm = new VehicleRoutingAlgorithm(vrp, searchStrategyManager);
|
||||
algorithm.getAlgorithmListeners().addListener(stateManager);
|
||||
algorithm.getSearchStrategyManager().addSearchStrategyModuleListener(stateManager);
|
||||
|
|
|
|||
|
|
@ -46,7 +46,6 @@ import algorithms.selectors.SelectRandomly;
|
|||
import algorithms.selectors.SolutionSelector;
|
||||
import basics.VehicleRoutingAlgorithm;
|
||||
import basics.VehicleRoutingProblem;
|
||||
import basics.VehicleRoutingProblem.Constraint;
|
||||
import basics.VehicleRoutingProblem.FleetSize;
|
||||
import basics.VehicleRoutingProblemSolution;
|
||||
import basics.algo.AlgorithmStartsListener;
|
||||
|
|
@ -446,16 +445,8 @@ public class VehicleRoutingAlgorithms {
|
|||
*/
|
||||
//constraint manager
|
||||
ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager);
|
||||
constraintManager.addConstraint(new TimeWindowConstraint(stateManager, vrp.getTransportCosts()));
|
||||
|
||||
if(vrp.getProblemConstraints().contains(Constraint.DELIVERIES_FIRST)){
|
||||
constraintManager.addConstraint(new ServiceBackhaulConstraint());
|
||||
}
|
||||
else{
|
||||
constraintManager.addConstraint(new ServiceLoadActivityLevelConstraint(stateManager));
|
||||
}
|
||||
|
||||
constraintManager.addConstraint(new ServiceLoadRouteLevelConstraint(stateManager));
|
||||
constraintManager.addTimeWindowConstraint();
|
||||
constraintManager.addLoadConstraint();
|
||||
|
||||
//construct initial solution creator
|
||||
AlgorithmStartsListener createInitialSolution = createInitialSolution(config,vrp,vehicleFleetManager,stateManager,algorithmListeners,definedClasses,executorService,nuOfThreads,constraintManager);
|
||||
|
|
@ -492,24 +483,15 @@ public class VehicleRoutingAlgorithms {
|
|||
/*
|
||||
* define stateUpdates
|
||||
*/
|
||||
|
||||
// stateManager.addListener(new UpdateLoadsAtStartAndEndOfRouteWhenInsertionStarts(stateManager));
|
||||
// stateManager.addListener(new UpdateLoadsAtStartAndEndOfRouteWhenJobHasBeenInserted(stateManager));
|
||||
//
|
||||
|
||||
UpdateLoads loadUpdater = new UpdateLoads(stateManager);
|
||||
stateManager.addListener(loadUpdater);
|
||||
stateManager.addActivityVisitor(loadUpdater);
|
||||
|
||||
// UpdateLoads loadUpdater = new UpdateLoads(stateManager);
|
||||
// stateManager.addListener(loadUpdater);
|
||||
// stateManager.addActivityVisitor(loadUpdater);
|
||||
stateManager.addActivityVisitor(new UpdateActivityTimes(vrp.getTransportCosts()));
|
||||
|
||||
|
||||
stateManager.addActivityVisitor(new UpdateVariableCosts(vrp.getActivityCosts(), vrp.getTransportCosts(), stateManager));
|
||||
|
||||
stateManager.addActivityVisitor(new UpdateOccuredDeliveries(stateManager));
|
||||
stateManager.addActivityVisitor(new TimeWindowUpdater(stateManager, vrp.getTransportCosts()));
|
||||
stateManager.addActivityVisitor(new UpdateFuturePickups(stateManager));
|
||||
|
||||
// stateManager.addActivityVisitor(new UpdateOccuredDeliveries(stateManager));
|
||||
// stateManager.addActivityVisitor(new TimeWindowUpdater(stateManager, vrp.getTransportCosts()));
|
||||
// stateManager.addActivityVisitor(new UpdateFuturePickups(stateManager));
|
||||
|
||||
metaAlgorithm.getSearchStrategyManager().addSearchStrategyModuleListener(stateManager);
|
||||
metaAlgorithm.getAlgorithmListeners().addListener(stateManager);
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ public class Service implements Job {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[id=" + id + "][locationId=" + locationId + "][coord="+coord+"][size=" + demand + "][serviceTime=" + serviceTime + "][timeWindow=" + timeWindow + "]";
|
||||
return "[id=" + id + "][type="+type+"][locationId=" + locationId + "][coord="+coord+"][size=" + demand + "][serviceTime=" + serviceTime + "][timeWindow=" + timeWindow + "]";
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
|
|||
|
|
@ -83,6 +83,6 @@ public final class DeliverService implements DeliveryActivity{
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[act="+getName()+"][loc="+getLocationId()+"]";
|
||||
return "[act="+getName()+"][capDemand="+getCapacityDemand()+"][loc="+getLocationId()+"]";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
******************************************************************************/
|
||||
package basics.route;
|
||||
|
||||
import basics.Delivery;
|
||||
import basics.route.TourActivity.JobActivity;
|
||||
|
||||
public interface DeliveryActivity extends JobActivity{
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ public final class PickupService implements PickupActivity{
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[act="+getName()+"][loc="+getLocationId()+"]";
|
||||
return "[act="+getName()+"][capDemand="+getCapacityDemand()+"][loc="+getLocationId()+"]";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue