Mashhood Ahmad
Mashhood Ahmad

Reputation: 322

ORTools: Multiple Vehicles: Large Vehicle shouldn't service nodes with less than given demand

I have already defined various constraints on a working code with multiple vehicle types. Now, I want to add a new constraint.

For a given vehicle, it shouldn't service nodes with less than given demand. So, when this constraint will be applied to one type of vehicle, any nodes less than that demand will be served by OTHER vehicles [which won't have this constraint.]

Need help. I am currently stuck on this.

Example code for 2 types of vehicles

for i in range(vehicle_type_1_starting_index, vehicle_type_1_ending_index):        
    # [my constraints here, setting arc costs etc]


for i in range(vehicle_type_2_starting_index, vehicle_type_2_ending_index):        
    # [my constraints here, setting arc costs etc]
    # NEW CONSTRAINT LIKE: routing.solver().Add((routing.ActiveVehicleVar(int(i)) * capacity_dimension.[? minimum demand each visited node ?] >= 20)

  1. Unsure how to proceed with setting the constraint that vehicle_type_2 shouldn't serve any node with less than or equal to 20 demand.
  2. There are unused vehicles as well. So their capacity/demand will be 0 but this will conflict with the above constraint of no node less than of 20 demand. How to make this apply to used vehicles only?

Upvotes: 1

Views: 586

Answers (1)

Mashhood Ahmad
Mashhood Ahmad

Reputation: 322

Solution:

for node_index in range(len(nodes)): 
    if nodes[node_index] according to criteria:
        routing.SetAllowedVehiclesForIndex(list(allowed_vehicle_list)), node_index)

I have just banned my vehicle type B from visiting nodes with demand less than X. They are visited by vehicle type A which have no such constraints.

Upvotes: 2

Related Questions