graph6
格式转换为与graph-tools
兼容的格式。必须有一种简单的方法来做到这一点...任何帮助将不胜感激。--编辑: 一个可能的解决方案是从G6转换为GT格式...但是我还没有找到任何可以做到的工具。
graph6
格式看起来很烦人,但幸运的是,文档
提到了一个名为showg
工具。 (使用
clang
或gcc
适合您的系统。或者只需在其网站上下载它们提供的二进制文件即可。)
$ 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]]