當前位置: 首頁>>代碼示例>>Python>>正文


Python Algorithm.constructSpanningTree方法代碼示例

本文整理匯總了Python中algorithm.Algorithm.constructSpanningTree方法的典型用法代碼示例。如果您正苦於以下問題:Python Algorithm.constructSpanningTree方法的具體用法?Python Algorithm.constructSpanningTree怎麽用?Python Algorithm.constructSpanningTree使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在algorithm.Algorithm的用法示例。


在下文中一共展示了Algorithm.constructSpanningTree方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Vertex

# 需要導入模塊: from algorithm import Algorithm [as 別名]
# 或者: from algorithm.Algorithm import constructSpanningTree [as 別名]
from vertex import Vertex
from edge import Edge
from algorithm import Algorithm

vertex1 = Vertex("1")
vertex2 = Vertex("2")
vertex3 = Vertex("3")
vertex4 = Vertex("4")

edge1 = Edge(1, vertex1, vertex2)
edge2 = Edge(1, vertex1, vertex3)
edge3 = Edge(0.01, vertex1, vertex4)
edge4 = Edge(1, vertex3, vertex4)

vertex1.adjacencies.append(edge1)
vertex1.adjacencies.append(edge2)
vertex1.adjacencies.append(edge3)
vertex3.adjacencies.append(edge4)

unvisitedList = []
unvisitedList.append(vertex1)
unvisitedList.append(vertex2)
unvisitedList.append(vertex3)
unvisitedList.append(vertex4)

algorithm = Algorithm(unvisitedList)
algorithm.constructSpanningTree(vertex1)
開發者ID:bjorncooley,項目名稱:algorithms-python,代碼行數:29,代碼來源:app.py

示例2: Edge

# 需要導入模塊: from algorithm import Algorithm [as 別名]
# 或者: from algorithm.Algorithm import constructSpanningTree [as 別名]
edge2 = Edge(4, vertex1, vertex4)
edge3 = Edge(4, vertex2, vertex3)
edge4 = Edge(4, vertex2, vertex4)
edge5 = Edge(3, vertex2, vertex5)
edge6 = Edge(1, vertex2, vertex6)
edge7 = Edge(5, vertex3, vertex6)
edge8 = Edge(2, vertex4, vertex5)
edge9 = Edge(5, vertex5, vertex6)

vertexList = []
vertexList.append(vertex1)
vertexList.append(vertex2)
vertexList.append(vertex3)
vertexList.append(vertex4)
vertexList.append(vertex5)
vertexList.append(vertex6)

edgeList = []
edgeList.append(edge1)
edgeList.append(edge2)
edgeList.append(edge3)
edgeList.append(edge4)
edgeList.append(edge5)
edgeList.append(edge6)
edgeList.append(edge7)
edgeList.append(edge8)
edgeList.append(edge9)

algorithm = Algorithm()
algorithm.constructSpanningTree(vertexList, edgeList)
開發者ID:bjorncooley,項目名稱:algorithms-python,代碼行數:32,代碼來源:app.py


注:本文中的algorithm.Algorithm.constructSpanningTree方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。