Or-tools: Routing -Different Vehicle Different Available Time

Created on 15 Feb 2019  路  6Comments  路  Source: google/or-tools

Hi,

I am having four vehicles, Availability of them is different and it is as per list.

horizon = [100,200,300,400]

since all vehicle has different speed, i am using -

routing.AddDimensionWithVehicleTransits(tevaluatorList,horizon,horizon,False,"Time")

Unfortunately, it is not working, however if i make horizon =300 i.e. only one value, than it works.

I am struggling in implementing different available time for vehicles. Any help is deeply appreciated.

Thanks
Shashank Trivedi

.

Help Needed Python Routing Solver

Most helpful comment

Hey @shashanktrivedi2018, how did you implement the different vehicle speeds? I have been struggling with the same problem, can I have an example of what you did? Any help would be nice

    for vr in range(num_veh):       
        time_callback1 = create_time_callback1(data,data["veh_speed"][vr])        
        tevaluatorList.append(time_callback1)
add_time_window_constraints(routing, data, time_callback,horiz,tevaluatorList)
routing.AddDimensionWithVehicleTransits(tevaluatorList,300,300,False,"Time")

def create_time_callback1(data,v):
  """Creates callback to get total times between locations."""
  def service_time(node):
    """Gets the service time for the specified location."""
    return abs(data["demands"][node]) * data["time_per_demand_unit"]

  def travel_time(from_node, to_node):
    """Gets the travel times between two locations."""
    travel_time = data["distances"][from_node][to_node] / v
    return travel_time

  def time_callback(from_node, to_node):
    """Returns the total time between the two nodes"""
    serv_time = service_time(from_node)
    trav_time = travel_time(from_node, to_node)
    return serv_time + trav_time

  return time_callback

hoping it will help u.

All 6 comments

While horizon should be the max you can still add constraint on the cumulVar of the end node of each vehicles...

solver = routing.solver()
for count, value in enumerate(horizon):
  solver.AddConstraint(routing.CumulVar(routing.End(i), dimension) < value)

Hey @shashanktrivedi2018, how did you implement the different vehicle speeds? I have been struggling with the same problem, can I have an example of what you did? Any help would be nice

While horizon should be the max you can still add constraint on the cumulVar of the end node of each vehicles...

solver = routing.solver()
for count, value in enumerate(horizon):
  solver.AddConstraint(routing.CumulVar(routing.End(i), dimension) < value)

Thanks Mizux, indeed it is great help

Hey @shashanktrivedi2018, how did you implement the different vehicle speeds? I have been struggling with the same problem, can I have an example of what you did? Any help would be nice

    for vr in range(num_veh):       
        time_callback1 = create_time_callback1(data,data["veh_speed"][vr])        
        tevaluatorList.append(time_callback1)
add_time_window_constraints(routing, data, time_callback,horiz,tevaluatorList)
routing.AddDimensionWithVehicleTransits(tevaluatorList,300,300,False,"Time")

def create_time_callback1(data,v):
  """Creates callback to get total times between locations."""
  def service_time(node):
    """Gets the service time for the specified location."""
    return abs(data["demands"][node]) * data["time_per_demand_unit"]

  def travel_time(from_node, to_node):
    """Gets the travel times between two locations."""
    travel_time = data["distances"][from_node][to_node] / v
    return travel_time

  def time_callback(from_node, to_node):
    """Returns the total time between the two nodes"""
    serv_time = service_time(from_node)
    trav_time = travel_time(from_node, to_node)
    return serv_time + trav_time

  return time_callback

hoping it will help u.

Thanks a lot for your reply @shashanktrivedi2018 ! I have been attempting a similar approach, but Im having it incorrect :/ Did you add the add_time_window_constraints() as just an additional constraint right? Can I know how you downloaded your google-or tool? Did you use the source or the binary? (https://developers.google.com/optimization/install/python/), cause I used the binary, which I think might be the root of my problem, but I'm unsure.

    tevaluator = []


    service_times = CreateServiceTimeCallback(demands, time_per_demand_unit)
    service_time_callback = service_times.ServiceTime
    for i in range(num_vehicles):
      total_times = CreateTotalTimeCallback(service_time_callback, dist_callback, vehice_speed[i])
      total_time_callback = total_times.TotalTime
      tevaluator.append(total_time_callback)

    # Note: In this case fix_start_cumul_to_zero is set to False,
    # because some vehicles start their routes after time 0, due to resource constraints.
    #add_time_window_constraints(routing,data,total_time_callback,horizon,tevaluatorList)
    fix_start_cumul_to_zero = False
    # Add a dimension for time and a limit on the total time_horizon
    routing.AddDimensionwithVehicleTransits(tevaluator,  # total time function callback
                         horizon,
                         horizon,
                         fix_start_cumul_to_zero,
                         time)

    time_dimension = routing.GetDimensionOrDie("Time")

Please raise a new issue,it is not right to comment on the closed issue.

Was this page helpful?
0 / 5 - 0 ratings