python-igraph: Multiple weight attributes for shortest_paths_dijkstra

Question:

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[1].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?

Asked By: frasheed

||

Answers:

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"])
]
Answered By: frasheed
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.