You need to define the “weight” attribute to the edges. This way any function or class that accepts the "weights=None” attribute will be able to retrieve the weights of the connections.
In a weighted graph, Shortest paths means paths with minimum sum of edge weights (path length). g = Graph() g.add_vertices(7) g.add_edge(0,1) g.add_edge(0,2) g.add_edge(1,3) g.add_edge(2,3) g.add_edge(5,4) g.add_edge(5,6) g.add_edge(6,4) g.es<http://g.es>['weight'] = [2,1,3,5,2,3,1] clust = g.clusters() for c in clust: print("subgraph:") gcomponent=g.subgraph(c) u=next(iter(gcomponent.vs)) paths=gcomponent.get_shortest_paths(u,to=None,weights=None,mode='ALL',output="vpath") print(paths) On 21 Mar 2019, at 15:11, Gokce Dilek <gokcedile...@gmail.com<mailto:gokcedile...@gmail.com>> wrote: Sure, here it is: g.add_vertices(7) g.add_edge(0,1,n=2) g.add_edge(0,2,n=1) g.add_edge(1,3,n=3) g.add_edge(2,3,n=5) g.add_edge(5,4,n=2) g.add_edge(5,6,n=3) g.add_edge(6,4,n=1) clust = g.clusters() for c in clust: print("subgraph:") gcomponent=g.subgraph(c) u=next(iter(gcomponent.vs)) paths=gcomponent.get_shortest_paths(u,to=None,weights=None,mode=ig.ALL,output="vpath") print(paths) Thank you very much! On Wed, 20 Mar 2019 at 15:52, serafim loukas <seral...@hotmail.com<mailto:seral...@hotmail.com>> wrote: Could you also add the actual graph weights and the full code so that we can reproduce this? On 20 Mar 2019, at 23:42, Gokce Dilek <gokcedile...@gmail.com<mailto:gokcedile...@gmail.com>> wrote: Hello, I would like to ask a question about the "get_shortest_paths" function in python-igraph. Could you explain what is the impact of adding edge weights when calculating path lengths? I had a very interesting occurrence that I couldn't explain why: Case 1: edge weights are nonzero (an attribute of edges) Result: [[], [0, 1], [0, 2], [0, 1, 3]] Case 2: edge weights are None Result: [[0], [0, 1], [0, 2], [0, 1, 3]] why does the first entry change like this?=O My code is here: clust = g1.clusters() for c in clust: print("subgraph:") gcomponent=g1.subgraph(c) u=next(iter(gcomponent.vs)) paths=gcomponent.get_shortest_paths(u,to=None,weights=None,mode=ig.ALL,output="vpath") print(paths) in which only the weights=None part is changed between the cases. I would appreciate if you could provide meaning to this! Thank you very much! _______________________________________________ igraph-help mailing list igraph-help@nongnu.org<mailto:igraph-help@nongnu.org> https://lists.nongnu.org/mailman/listinfo/igraph-help _______________________________________________ igraph-help mailing list igraph-help@nongnu.org<mailto:igraph-help@nongnu.org> https://lists.nongnu.org/mailman/listinfo/igraph-help _______________________________________________ igraph-help mailing list igraph-help@nongnu.org<mailto:igraph-help@nongnu.org> https://lists.nongnu.org/mailman/listinfo/igraph-help
_______________________________________________ igraph-help mailing list igraph-help@nongnu.org https://lists.nongnu.org/mailman/listinfo/igraph-help