You are correct that it is not trivial to set up the weight functions to convert from shortest_path to widest_path.
You have to somehow change the addition operator to a max operator.
Perhaps something like this:
class Widest_Add():
def __init__(self, width):
self.width = width
def __add__(self, other):
# maybe put a check that other has class Widest_Add. But shouldn't need.
return Widest_Add(max(self.width, other.width))
def __le__(self, other):
return self.width <= other.width
def __lt__(self, other):
return self.width < other.width
def __eq__(self, other):
return self.width == other.width
# might need > or >= too, but I don't think so... look at _dijkstra_multisource and operations on uv_dist
def widest_weight(node1, node2, datadict):
# This assume the graph stores a number in edge attribute 'width'
return Widest_Add(datadict['width'])
Then, in the shortest path algorithm (e.g. dijkstra) when it stores dist[u] it stores a Widest_Add object.
So,
uv_dist = dist[u] + cost
actually computes
uv_dist = Widest_Add(max(self.width, other.width))
Seems like this would be good to put in the docs somewhere, or maybe create a function that does it.
Thanks for the question!
Dan