让
G=DiMultigraph(4)
add_edge!(G,2,4)
add_edge!(G,4,1)
add_edge!(G,4,1)
add_edge!(G,1,3)
add_edge!(G,1,3)
add_edge!(G,2,3)当我跑的时候
e=edges(G)
e1=collect(e)我得到了
Multiple edge 1 => 3 with multiplicity 2
Multiple edge 2 => 3 with multiplicity 1
Multiple edge 2 => 4 with multiplicity 1
Multiple edge 4 => 1 with multiplicity 2我想要的是未排序的列表
Multiple edge 2 => 4 with multiplicity 1
Multiple edge 4 => 1 with multiplicity 2
Multiple edge 1 => 3 with multiplicity 1
Multiple edge 2 => 3 with multiplicity 1似乎有一个这里的代码,但我并不真正理解它。
发布于 2022-07-25 18:32:28
我想你想按插入的顺序排列边缘。要做到这一点,您需要有一个键来排序。有一种方法:
edgevector = [[2,4], [4,1], [4,1],[1,3],[1,3],[2,3]]
G = DiMultigraph(4)
for edg in edgevector
add_edge!(G, edg[1], edg[2])
end
e = edges(G)
e1 = sort!(collect(e), by = edg -> findfirst(==([edg.src, edg.dst]), edgevector))https://stackoverflow.com/questions/73106870
复制相似问题