使用图形工具使用Graph6格式 我从http://users.cecs.anu.edu.au/~bdm/data/data/graphs.html下载了一堆图形,我想进行一些分析。我想为此使用图形工具python模块,但我找不到一个

问题描述 投票:0回答:1
python模块,但是我找不到一种方便的方法,可以将

graph6格式转换为与graph-tools

兼容的格式。必须有一种简单的方法来做到这一点...任何帮助将不胜感激。
--编辑: 一个可能的解决方案是从G6转换为GT格式...但是我还没有找到任何可以做到的工具。
	
graph6

格式看起来很烦人,但幸运的是,

文档

提到了一个名为
graph graph-tool
1个回答
3
投票
的工具,以打印出精美的图形。 简单地解析该程序的输出很容易。 首先,构建

showg

工具。  (使用
clanggcc
适合您的系统。或者只需在其网站上下载它们提供的二进制文件即可。)

$ curl -sL http://users.cecs.anu.edu.au/%7Ebdm/data/showg.c > showg.c $ clang -o showg showg.c $ ./showg --help

下载一些示例数据并查看它。我认为
-e
选项可产生最容易使用的输出。
$ curl -sL http://users.cecs.anu.edu.au/%7Ebdm/data/graph4.g6 > graph4.g6 $ ./showg -p10 -e graph4.g6 Graph 10, order 4. 4 5 0 2 0 3 1 2 1 3 2 3
there是一个简单的脚本,它读取
./showg -p<N> -e

的边缘列表并创建一个
graph_tool.Graph
对象:

# load_graph.py
import sys
import graph_tool as gt

# Read stdin and parse last line as a list of edge pairs
line = sys.stdin.readlines()[-1]
nodes = [int(n) for n in line.split()]
n0 = nodes[0::2]
n1 = nodes[1::2]
edges = list(zip(n0, n1))

# Load graph
g = gt.Graph()
g.add_edge_list(edges)

print("Loaded graph with the following edges:")
print(g.get_edges())

LLET尝试一下:
$ ./showg -p10 -e graph4.g6 | python load_graph.py
Loaded graph with the following edges:
[[0 2]
 [0 3]
 [1 2]
 [1 3]
 [2 3]]

	
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.