本文介紹了graphviz 分段錯誤的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在構建一個包含許多節點的圖形,大約 3000 個.我編寫了一個簡單的 python 程序來使用 graphviz 來解決這個問題,但是它給了我分段錯誤,我不知道為什么,如果圖形太大或如果我錯過了什么.
I'm building a graph with many nodes, around 3000. I wrote a simple python program to do the trick with graphviz, but it gives me segmentation fault and I don't know why, if the graph is too big or if i'm missing something.
代碼是:
#!/usr/bin/env python
# Import graphviz
import sys
sys.path.append('..')
sys.path.append('/usr/lib/graphviz')
import gv
# Import pygraph
from pygraph.classes.graph import graph
from pygraph.classes.digraph import digraph
from pygraph.algorithms.searching import breadth_first_search
from pygraph.readwrite.dot import write
# Graph creation
gr = graph()
file = open('nodes.dat', 'r')
line = file.readline()
while line:
gr.add_nodes([line[0:-1]])
line = file.readline()
file.close()
print 'nodes finished, beginning edges'
edges = open('edges_ok.dat', 'r')
edge = edges.readline()
while edge:
gr.add_edge((edge.split()[0], edge.split()[1]))
edge = edges.readline()
edges.close()
print 'edges finished'
print 'Drawing'
# Draw as PNG
dot = write(gr)
gvv = gv.readstring(dot)
gv.layout(gvv,'dot')
gv.render(gvv,'svg','graph.svg')
它在 gv.layout()
調用時崩潰.
這些文件類似于:節點:
The files are somthing like: nodes:
node1
node2
node3
edges_ok:
node1 node2
node2 node3
推薦答案
我把布局類型從dot改成neato,問題就解決了.
I changed the layout type from dot to neato and that solved the problem.
我搜索了一下,似乎點布局在大圖上有點錯誤.
I searched a bit and it seems that the dot layout is a bit faulty on large graphs.
這篇關于graphviz 分段錯誤的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!