I need to set up a limitation - Capacity on Depot. I’ve interpretated it as limitation on capacity used on multiple vehicles with the same starting point. But I can’t figure out how to implement it, because HardRouteConstraint manages routes and very often there are not any vehicle added into it yet (same with HardActivityConstraint). If I add them manually, it occurs an error, “cannot add vehicle twice” My code example:
public class DepotCapacityConstraint implements HardActivityConstraint{
@Override public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) { //next block initializes vehicles, without it solution has no routes if(prevAct.getName().equals("start")){ Vehicle v = iFacts.getNewVehicle(); iFacts.getRoute().setVehicleAndDepartureTime(v, v.getEarliestDeparture()); } if(isService(newAct)){ if(canDeliver(iFacts.getRoute().getVehicle(),newAct.getSize())){ deliver(iFacts.getRoute().getVehicle(),newAct.getSize()); return ConstraintsStatus.FULFILLED; }else{ return ConstraintsStatus.NOT_FULFILLED; } }else{ throw new IllegalStateException("Can handle services only!"); } }
private boolean isService(TourActivity newAct) { return newAct.getName().equals("service"); }
private boolean canDeliver(Vehicle v, Capacity delivery){ try{ //next line gets vehicles depot and returns if is new total demand small enough (depots capacity) return ModelLoader.vehicleIdToDepot.get(Integer.parseInt(v.getId())).canAddDemand(delivery); }catch(NullPointerException | NumberFormatException e){ return false; } }
private void deliver(Vehicle v, Capacity delivery){ //next line adds demand to depot ModelLoader.vehicleIdToDepot.get(Integer.parseInt(v.getId())).addDemand(delivery); } }
I pretty don’t understand StateManager, StateUpdater, ActivityVisitor classes, that are very often used in example package and I can’t find any documentation to it. Can you please help me? Can you explain me how does proccess of adding or not adding activity/route to solution works? I know, ruin and recreate, but I’m not sure what does this class exactly do, I thought it just checks the rule and if it’s passed it adds activity/route to solution.
Thank you