-1

How can I make a function in Python that allows of the movement of the packets from source to target using the shortest path?

The shortest_path() function just returns the names of the nodes. How can I make the packet move through that particular path?

user812786
  • 4,302
  • 5
  • 38
  • 50
SSD Group
  • 1
  • 2

1 Answers1

0

Are you talking about maximum flow in your graph from start to finish? If so, there are bunch of methods for working with flows in NetworkX.

For example, maximum_flow(G, s, t, capacity='capacity', flow_func=None, **kwargs). It accepts your graph and start and finish nodes in it.

It returns:

  • flow_value (integer, float) – Value of the maximum flow, i.e., net outflow from the source.
  • flow_dict (dict) – A dictionary containing the value of the flow that went through each edge.

So your code will be like:

flow_value, flow_dict = nx.maximum_flow(G, 'x', 'y')

Now in dictionary you can find all the edges in the flow and their usage.

VMAtm
  • 27,943
  • 17
  • 79
  • 125