paul shannon
paul shannon

Reputation: 375

python igraph: add.edge (simplest case) always reorders source and target

Surely I am missing something!

from igraph import *
g = Graph()
g.add_vertices(3)
g.add_edge(0, 1)
g.add_edge(2, 1)
g.es[0].source; g.es[0].target   # as expected: 0 -> 1
g.es[1].source; g.es[1].target   # reordered:   1 -> 2 - not 2 -> 1

Yet the API specifies

add_edge(source, target, **kwds)

Can you offer any help?

Thanks!

Upvotes: 0

Views: 37

Answers (1)

paqmo
paqmo

Reputation: 3729

You need to make the graph directed, otherwise igraph treats it as undirected and simply orders the dyads sequentially.

from igraph import *
g = Graph(directed=True)
g.add_vertices(3)
g.add_edge(0, 1)
g.add_edge(2, 1)

Check it:

>>> g.es[1].source
2
>>> g.es[1].target
1

Upvotes: 1

Related Questions