In my graph I have some edges with multiple weights. Is there any possibility to add multiple weights attributes for the shortest_paths_dijkstra in python-igraph?.
My sample code is given below:
import igraph from igraph import * g = Graph(directed=True) g.add_vertices(3) g.vs["name"]=["GO:1234567","GO:6789056","GO:5674321"] g.add_edge('GO:1234567','GO:6789056', weight=4, weight1 = 3) g.add_edge('GO:6789056','GO:5674321', weight=4, weight1 = None) weight=g.es["weight"] weight1=g.es["weight1"] print(g.es.attributes()) print(g.shortest_paths_dijkstra(source="GO:1234567", target="GO:5674321", weights=weight1, mode=OUT))
This code doesn’t work as the 2nd edge doesn’t have any value for weight1. How can I define that if weight1 doesnt exist then use weight as the weight attribute?
I have found a solution through one of the developers (on github)
g.es["weight1"] = [ w1 if w2 is None else w2 for w1, w2 in zip(g.es["weight"], g.es["weight1"]) ]