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


Python Algorithm.calculateShortestPath方法代碼示例

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


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

示例1: Node

# 需要導入模塊: from algorithm import Algorithm [as 別名]
# 或者: from algorithm.Algorithm import calculateShortestPath [as 別名]
from algorithm import Algorithm
from edge import Edge
from node import Node

node1 = Node('A')
node2 = Node('B')
node3 = Node('C')
node4 = Node('D')

edge1 = Edge(1, node1, node2)
edge2 = Edge(1, node2, node3)
edge3 = Edge(1, node3, node4)
edge4 = Edge(-10, node3, node2)
edge5 = Edge(300, node1, node4)

node1.adjacencies.append(edge1)
node1.adjacencies.append(edge2)
node2.adjacencies.append(edge3)
node3.adjacencies.append(edge4)
node3.adjacencies.append(edge2)

nodeList = {node1, node2, node3, node4}
edgeList = [edge1, edge2, edge3, edge4, edge5]

algorithm = Algorithm()
algorithm.calculateShortestPath(nodeList, edgeList, node1)
algorithm.getShortestPath(node4)
開發者ID:bjorncooley,項目名稱:algorithms-python,代碼行數:29,代碼來源:app.py

示例2: Vertex

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

vertex1 = Vertex('A')
vertex2 = Vertex('B')
vertex3 = Vertex('C')

edge1 = Edge(1, vertex1, vertex2)
edge2 = Edge(1, vertex2, vertex3)
edge3 = Edge(10, vertex1, vertex3)

vertex1.adjacencies.append(edge1)
vertex1.adjacencies.append(edge2)
vertex2.adjacencies.append(edge3)

vertexList = {vertex1, vertex2, vertex3}

algorithm = Algorithm()
algorithm.calculateShortestPath(vertexList, vertex1)
algorithm.getShortestPath(vertex3)
開發者ID:bjorncooley,項目名稱:algorithms-python,代碼行數:23,代碼來源:app.py


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