简体   繁体   中英

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM