本文整理汇总了Python中graph.Vertex.add_neighbor方法的典型用法代码示例。如果您正苦于以下问题:Python Vertex.add_neighbor方法的具体用法?Python Vertex.add_neighbor怎么用?Python Vertex.add_neighbor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graph.Vertex
的用法示例。
在下文中一共展示了Vertex.add_neighbor方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Vertex
# 需要导入模块: from graph import Vertex [as 别名]
# 或者: from graph.Vertex import add_neighbor [as 别名]
import cPickle as pickle
from graph import Vertex
from graph import Graph
v1 = Vertex({},{"name":"John"})
v2 = Vertex({v1:3},{"name":"Jane"})
v1.add_neighbor(v2,3)
v3 = Vertex({v2:2},{"name":"Charles"})
v2.add_neighbor(v3,2)
v4 = Vertex({v1:4,v2:2},{"name":"Catherine"})
v1.add_neighbor(v4,4)
v2.add_neighbor(v4,2)
v5 = Vertex({v1:9,v2:3,v3:8,v4:9},{"name":"Jessica"})
v1.add_neighbor(v5,9)
v2.add_neighbor(v5,3)
v3.add_neighbor(v5,8)
v4.add_neighbor(v5,9)
v6 = Vertex({v2:6,v3:10},{"name":"Hugo"})
v2.add_neighbor(v6,6)
v3.add_neighbor(v6,10)
v7 = Vertex({v5:2,v6:10},{"name":"Stanley"})
v5.add_neighbor(v7,2)
v6.add_neighbor(v7,10)
v8 = Vertex({v3:9,v7:3},{"name":"Emily"})
v3.add_neighbor(v7,9)
v7.add_neighbor(v7,3)
graph_var = Graph([v1,v2,v3,v4,v5,v6,v7,v8],[[0,1,0,1,1,0,0,0],[1,0,1,1,1,1,0,0],
[0,1,0,0,1,1,0,1],[1,1,0,0,1,0,0,0],[1,1,1,1,0,0,1,0],[0,1,1,0,0,0,1,0],
[0,1,1,0,0,0,1,0],[0,0,0,0,1,1,0,1],[0,0,1,0,0,0,1,0]])
pickle.dump(graph_var,open('test.p','wb'))