在pygraph中使用超图,需要验证示例是否正确 [英] Using hypergraphs in pygraph, need verification that example is correct

查看:95
本文介绍了在pygraph中使用超图,需要验证示例是否正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在pygraph中使用超图,下面是我插入的一个简单示例:

I am trying to get my head around using hypergraphs in pygraph, the following is a simple example I inserted:

hgr = hypergraph()
hgr.add_nodes(["A1", "B1", "C1", "D1"]) 
hgr.add_nodes(["A2", "B2", "C2", "D2"])
hgr.add_nodes(["A3", "B3", "C3", "D3"])
hgr.add_nodes(["A4", "B4", "C4", "D4"])

hgr.add_hyperedge(("A1", "A2", "A3", "A4"))
hgr.add_hyperedge(("B1", "B2", "B3", "B4"))
hgr.add_hyperedge(("C1", "C2", "C3", "C4"))
hgr.add_hyperedge(("D1", "D2", "D3", "D4"))

h_dot = write(hgr)
h_gvv = gv.readstring(h_dot)
gv.layout(h_gvv,'dot')
gv.render(h_gvv, 'png', 'hypergraph.png')

我得到的图像是(单击以查看完整尺寸的版本):

The image I am getting is (click to see full size version):

请确认这是使用pygraph创建超图的正确方法.

Please verify that this is the correct way to create hypergraphs using pygraph.

非常感谢!

推荐答案

由于每个hyperedge都不是节点的集合,而是表示为节点,因此对于 hyperedges ,就像您需要对节点进行操作,然后

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.

请考虑有关超图的维基百科文章中的示例图:

要在pygraph中创建此图,您可以执行以下操作:

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))

,它将使用dot生成此图像输出:

which will produce this image output with dot:

我猜这是一个正确的表示,但不像Wikipedia的图像那样直观.如果要实现超图的可视化,则应查看

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.

这篇关于在pygraph中使用超图,需要验证示例是否正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆