Re: [networkx-discuss] All shortest paths for weighted graphs?

35 views
Skip to first unread message

Dan Schult

unread,
May 15, 2013, 1:46:25 PM5/15/13
to networkx...@googlegroups.com
A short example would be very helpful.
Also, it depends what you mean by all shortest paths.
That is, how do you want to handle ties?


On May 15, 2013, at 11:18 AM, Federico Battiston wrote:

> Hello,
> does a function exist in networkx to calculate *all* shortest paths in weighted graphs? It looks like "dijkstra" does not allow you to do so. Theoretically "all_shortest_paths" should allow you to do this calculation, however if I use it on a graph which received a list of edges of the kind [node1,node2,weight between thetwo nodes] I get an error.
> Thanks for your help
>
> --
> You received this message because you are subscribed to the Google Groups "networkx-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to networkx-discu...@googlegroups.com.
> To post to this group, send email to networkx...@googlegroups.com.
> Visit this group at http://groups.google.com/group/networkx-discuss?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Sérgio Nery Simões

unread,
May 15, 2013, 4:01:42 PM5/15/13
to networkx...@googlegroups.com
Did you try to use the 'weight' parameter?
def all_shortest_paths(G, source, target, weight=None):
...
    Parameters
...
    weight : None or string, optional (default = None)
           If None, every edge has weight/distance/cost 1.
           If a string, use this edge attribute as the edge weight.
           Any edge attribute not present defaults to 1.

Att,
Sérgio
__________________
Reply all
Reply to author
Forward
0 new messages