本文整理匯總了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'))