4

I am trying to use the google or tools for the vehicle routing problem. Here is the link https://developers.google.com/optimization/routing/vrp . I am trying to use the code by google but when I encounter this piece of code:

def add_distance_dimension(routing, distance_callback):
  """Add Global Span constraint"""
  distance = 'Distance'
  maximum_distance = 3000  # Maximum distance per vehicle.
  routing.AddDimension(
      distance_callback,
      0,  # null slack
      maximum_distance,
      True,  # start cumul to zero
      distance)
  distance_dimension = routing.GetDimensionOrDie(distance)
  # Try to minimize the max distance among vehicles.
  distance_dimension.SetGlobalSpanCostCoefficient(100)

I don't get the meaning of the last istruction

distance_dimension.SetGlobalSpanCostCoefficient(100)

What's the purpose of this function and what's the meaning of the argument? Why is there a "100" there?

Muhammad Altabba
  • 2,583
  • 19
  • 31

1 Answers1

0

The documentation, which may very well have been updated since this question was posted, spells out the meaning of the 100:

The method SetGlobalSpanCostCoefficient sets a large coefficient (100) for the global span of the routes, which in this example is the maximum of the distances of the routes. This makes the global span the predominant factor in the objective function, so the program minimizes the length of the longest route.

In general (from the API reference), the method

[sets] a cost proportional to the global dimension span, that is the difference between the largest value of route end cumul variables and the smallest value of route start cumul variables. In other words: global_span_cost = coefficient * (Max(dimension end value) - Min(dimension start value)).

fuglede
  • 17,388
  • 2
  • 54
  • 99