GraphHopper.com | Forum | GitHub | Maps | Blog

Depot Capacity and Vehicles in HardRouteConstraint? How does it work?


#1

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


#2

If you don’t know, give me please atleast a clue where can I find the answer. Thank you


#3

i might be overlooking but can you define “depot capacity”?

vehicles over a certain size cannot get into the depot? or there is a max number of vehicles that the depot can hold at the same time?


#4

As Vehicle has Capacity it can handle, I’ve created Depot class, with Capacity. It means, how big the Warehouse is, for example it can store up to 1000m3 of goods (per calculation). And every Vehicle with starting Location at Depot can deliver only amount of goods that can take from Depot, so it means sth like f.e. 10 vehicles has one extra shared Capacity. And I can’t find a way how to implement it into an algorithm.


#5

I think you can solve this by a route constraint. First you need a state updater to memorize the total amount of goods picked up at each depot.

If all your jobs are Shipments, then, in the constraint, if the pickup of the job to be inserted is at a depot, you calculate the new total amount of goods picked up at that depot, and, if it exceeds the capacity of the depot, you disallow the insertion.

If the jobs are Deliveries, it would be more tricky, because the pickup of the goods for a Delivery is assumed to be at the vehicle start location, and, if you allow vehicle switch, you will need to take that into account in the constraint.


#6

Hi!

Can you describe how to memorize the goods picked up at a depot. I can only store it for a route. How can i summarize the routes for a depot?


#7

I think you can store it as a problem state.