首页 > 编程语言 > 详细

(python)Graph_tools模块学习

时间:2014-12-27 22:52:27      阅读:635      评论:0      收藏:0      [点我收藏+]

使用之前需要先导入:

from graph_tool.all import *

1、  创建一个图

有向图:g = Graph()

无向图:ug = Graph(directed=False)

或ug = Graph()
ug.set_directed(False)

2、 创建节点:v1 = g.add_vertex()

创建多个节点:vlist=g.add_vertex(10)

删除节点:g.remove_vertex(v2)

获取顶点的索引:print(g.vertex_index[v])

遍历顶点:for v in g.vertices():

              print(v)

查询点的出度:print(v1.out_degree())

入度:print(v1.in_degree())

遍历每个顶点的出入边及出入邻接节点:

for v in g.vertices():

   print vertex%d\‘s out_edges%g.vertex_index[v]

   for e in v.out_edges():

      print e

printvertex%d\‘sout_neighbours%g.vertex_index[v]

   for w in v.out_neighbours():

      print w

 

   

3、 创建边:e = g.add_edge(v1, v2)

删除边:g.remove_edge(e)

获取边的索引:print(g.edge_index[e])

遍历边:for e in e.edges():
         print(e)

查询边的源顶点,目标顶点:print(e.source(),e.target())

4、 输出到.pdf文件:

graph_draw(g,vertex_text=g.vertex_index,vertex_font_size=18,output_size=(200,200), output="8-nodes.pdf")

 

半途而废了,记录几个网址,万一以后会用到呢。

http://canoncial.blog.163.com/blog/static/184149801201345102530123/
http://graph-tool.skewed.de/
http://graph-tool.skewed.de/static/doc/index.html
http://graph-tool.skewed.de/download

(python)Graph_tools模块学习

原文:http://www.cnblogs.com/myblog-lyc/p/4189237.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!