Using hypergraphs in pygraph, need verification that example is correct

旧街凉风 提交于 2019-12-04 21:56:19
Maehler

Since each hyperedge isn't a collection of nodes, but instead represented as a node, you should use an unique (simple) identifier for the hyperedges, just as you do for the nodes, and then link them to the nodes.

Consider the example graph in the Wikipedia article for hypergraphs:

To create this graph in pygraph you could do the following:

from pygraph.classes.hypergraph import hypergraph
from pygraph.readwrite.dot import write_hypergraph

h = hypergraph()

h.add_nodes(['v1', 'v2', 'v3', 'v4', 'v5', 'v6', 'v7'])
h.add_hyperedges(['e1', 'e2', 'e3', 'e4'])

h.link('v1', 'e1')
h.link('v2', 'e1')
h.link('v3', 'e1')
h.link('v2', 'e2')
h.link('v3', 'e2')
h.link('v3', 'e3')
h.link('v5', 'e3')
h.link('v6', 'e3')
h.link('v4', 'e4')

with open('hypergraph.dot', 'w') as f:
    f.write(write_hypergraph(h))

which will produce this image output with dot:

This is a correct representation I guess, but not as visual as the image from Wikipedia. If you are pursuing a visualization of hypergraphs, you should check out this question.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!