private boolean isBananaPickup(TourActivity act) { return act.getSize().get(BANANAS_DIMENSION_INDEX) > 0; } }
private boolean isApplePickup(TourActivity act) { return act.getSize().get(APPLES_DIMENSION_INDEX) > 0; }
private boolean isBananaPickup(TourActivity act) { return act.getSize().get(BANANAS_DIMENSION_INDEX) > 0; }
private boolean isApplePickup(TourActivity act) { return act.getSize().get(APPLES_DIMENSION_INDEX) > 0; }
private boolean isBananaDelivery(TourActivity act) { return act.getSize().get(BANANAS_DIMENSION_INDEX) < 0; }
private boolean isAppleDelivery(TourActivity act) { return act.getSize().get(APPLES_DIMENSION_INDEX) < 0; }
@Override public void visit(TourActivity act) { currentLoad = Capacity.addup(currentLoad, act.getSize()); stateManager.putInternalTypedActivityState(act, InternalStates.LOAD, currentLoad); // assert currentLoad.isLessOrEqual(route.getVehicle().getType().getCapacityDimensions()) : "currentLoad at activity must not be > vehicleCapacity"; // assert currentLoad.isGreaterOrEqual(Capacity.Builder.newInstance().build()) : "currentLoad at act must not be < 0 in one of the applied dimensions"; }
@Override public void visit(TourActivity act) { currentLoad = Capacity.addup(currentLoad, act.getSize()); maxLoad = Capacity.max(maxLoad, currentLoad); }
/** * @param activity to get the load from (before activity) * @return load just before the specified activity. If act is Start, it returns the load atBeginning of the specified * route. If act is End, it returns the load atEnd of specified route. */ public Capacity getLoadJustBeforeActivity(TourActivity activity, VehicleRoute route) { if (route == null) throw new IllegalArgumentException("route is missing."); if (activity == null) throw new IllegalArgumentException("activity is missing."); if (activity instanceof Start) return getLoadAtBeginning(route); if (activity instanceof End) return getLoadAtEnd(route); verifyThatRouteContainsAct(activity, route); Capacity afterAct = stateManager.getActivityState(activity, InternalStates.LOAD, Capacity.class); if (afterAct != null && activity.getSize() != null) { return Capacity.subtract(afterAct, activity.getSize()); } else if (afterAct != null) return afterAct; else return null; }
/** * Checks whether there is enough capacity to insert newAct between prevAct and nextAct. */ @Override public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) { if (!(newAct instanceof PickupShipment) && !(newAct instanceof DeliverShipment)) { return ConstraintsStatus.FULFILLED; } Capacity loadAtPrevAct; if (prevAct instanceof Start) { loadAtPrevAct = stateManager.getRouteState(iFacts.getRoute(), InternalStates.LOAD_AT_BEGINNING, Capacity.class); if (loadAtPrevAct == null) loadAtPrevAct = defaultValue; } else { loadAtPrevAct = stateManager.getActivityState(prevAct, InternalStates.LOAD, Capacity.class); if (loadAtPrevAct == null) loadAtPrevAct = defaultValue; } if (newAct instanceof PickupShipment) { if (!Capacity.addup(loadAtPrevAct, newAct.getSize()).isLessOrEqual(iFacts.getNewVehicle().getType().getCapacityDimensions())) { return ConstraintsStatus.NOT_FULFILLED; } } if (newAct instanceof DeliverShipment) { if (!Capacity.addup(loadAtPrevAct, Capacity.invert(newAct.getSize())).isLessOrEqual(iFacts.getNewVehicle().getType().getCapacityDimensions())) return ConstraintsStatus.NOT_FULFILLED_BREAK; } return ConstraintsStatus.FULFILLED; }
for (TourActivity act : route.getActivities()) { System.out.println("--"); System.out.println("actType: " + act.getName() + " demand: " + act.getSize()); System.out.println("dist@" + act.getLocation().getId() + ": " + analyser.getDistanceAtActivity(act, route)); System.out.println("load(before)@" + act.getLocation().getId() + ": " + analyser.getLoadJustBeforeActivity(act, route));
@Override public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) { Capacity futureMaxLoad; Capacity prevMaxLoad; if (prevAct instanceof Start) { futureMaxLoad = stateManager.getRouteState(iFacts.getRoute(), InternalStates.MAXLOAD, Capacity.class); if (futureMaxLoad == null) futureMaxLoad = defaultValue; prevMaxLoad = stateManager.getRouteState(iFacts.getRoute(), InternalStates.LOAD_AT_BEGINNING, Capacity.class); if (prevMaxLoad == null) prevMaxLoad = defaultValue; } else { futureMaxLoad = stateManager.getActivityState(prevAct, InternalStates.FUTURE_MAXLOAD, Capacity.class); if (futureMaxLoad == null) futureMaxLoad = defaultValue; prevMaxLoad = stateManager.getActivityState(prevAct, InternalStates.PAST_MAXLOAD, Capacity.class); if (prevMaxLoad == null) prevMaxLoad = defaultValue; } if (newAct instanceof PickupService || newAct instanceof ServiceActivity) { if (!Capacity.addup(newAct.getSize(), futureMaxLoad).isLessOrEqual(iFacts.getNewVehicle().getType().getCapacityDimensions())) { return ConstraintsStatus.NOT_FULFILLED; } } if (newAct instanceof DeliverService) { if (!Capacity.addup(Capacity.invert(newAct.getSize()), prevMaxLoad).isLessOrEqual(iFacts.getNewVehicle().getType().getCapacityDimensions())) { return ConstraintsStatus.NOT_FULFILLED_BREAK; } } return ConstraintsStatus.FULFILLED; } }
@Override public void visit(TourActivity act) { currentLoad = Capacity.addup(currentLoad, act.getSize()); stateManager.putInternalTypedActivityState(act, InternalStates.LOAD, currentLoad); // assert currentLoad.isLessOrEqual(route.getVehicle().getType().getCapacityDimensions()) : "currentLoad at activity must not be > vehicleCapacity"; // assert currentLoad.isGreaterOrEqual(Capacity.Builder.newInstance().build()) : "currentLoad at act must not be < 0 in one of the applied dimensions"; }
@Override public void visit(TourActivity act) { currentLoad = Capacity.addup(currentLoad, act.getSize()); maxLoad = Capacity.max(maxLoad, currentLoad); }
/** * @param activity to get the load from (before activity) * @return load just before the specified activity. If act is Start, it returns the load atBeginning of the specified * route. If act is End, it returns the load atEnd of specified route. */ public Capacity getLoadJustBeforeActivity(TourActivity activity, VehicleRoute route) { if (route == null) throw new IllegalArgumentException("route is missing."); if (activity == null) throw new IllegalArgumentException("activity is missing."); if (activity instanceof Start) return getLoadAtBeginning(route); if (activity instanceof End) return getLoadAtEnd(route); verifyThatRouteContainsAct(activity, route); Capacity afterAct = stateManager.getActivityState(activity, InternalStates.LOAD, Capacity.class); if (afterAct != null && activity.getSize() != null) { return Capacity.subtract(afterAct, activity.getSize()); } else if (afterAct != null) return afterAct; else return null; }
/** * Checks whether there is enough capacity to insert newAct between prevAct and nextAct. */ @Override public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) { if (!(newAct instanceof PickupShipment) && !(newAct instanceof DeliverShipment)) { return ConstraintsStatus.FULFILLED; } Capacity loadAtPrevAct; if (prevAct instanceof Start) { loadAtPrevAct = stateManager.getRouteState(iFacts.getRoute(), InternalStates.LOAD_AT_BEGINNING, Capacity.class); if (loadAtPrevAct == null) loadAtPrevAct = defaultValue; } else { loadAtPrevAct = stateManager.getActivityState(prevAct, InternalStates.LOAD, Capacity.class); if (loadAtPrevAct == null) loadAtPrevAct = defaultValue; } if (newAct instanceof PickupShipment) { if (!Capacity.addup(loadAtPrevAct, newAct.getSize()).isLessOrEqual(iFacts.getNewVehicle().getType().getCapacityDimensions())) { return ConstraintsStatus.NOT_FULFILLED; } } if (newAct instanceof DeliverShipment) { if (!Capacity.addup(loadAtPrevAct, Capacity.invert(newAct.getSize())).isLessOrEqual(iFacts.getNewVehicle().getType().getCapacityDimensions())) return ConstraintsStatus.NOT_FULFILLED_BREAK; } return ConstraintsStatus.FULFILLED; }
@Override public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) { Capacity futureMaxLoad; Capacity prevMaxLoad; if (prevAct instanceof Start) { futureMaxLoad = stateManager.getRouteState(iFacts.getRoute(), InternalStates.MAXLOAD, Capacity.class); if (futureMaxLoad == null) futureMaxLoad = defaultValue; prevMaxLoad = stateManager.getRouteState(iFacts.getRoute(), InternalStates.LOAD_AT_BEGINNING, Capacity.class); if (prevMaxLoad == null) prevMaxLoad = defaultValue; } else { futureMaxLoad = stateManager.getActivityState(prevAct, InternalStates.FUTURE_MAXLOAD, Capacity.class); if (futureMaxLoad == null) futureMaxLoad = defaultValue; prevMaxLoad = stateManager.getActivityState(prevAct, InternalStates.PAST_MAXLOAD, Capacity.class); if (prevMaxLoad == null) prevMaxLoad = defaultValue; } if (newAct instanceof PickupService || newAct instanceof ServiceActivity) { if (!Capacity.addup(newAct.getSize(), futureMaxLoad).isLessOrEqual(iFacts.getNewVehicle().getType().getCapacityDimensions())) { return ConstraintsStatus.NOT_FULFILLED; } } if (newAct instanceof DeliverService) { if (!Capacity.addup(Capacity.invert(newAct.getSize()), prevMaxLoad).isLessOrEqual(iFacts.getNewVehicle().getType().getCapacityDimensions())) { return ConstraintsStatus.NOT_FULFILLED_BREAK; } } return ConstraintsStatus.FULFILLED; } }