本文整理汇总了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)
示例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)