当前位置: 首页>>代码示例>>Python>>正文


Python Algorithm.getShortestPath方法代码示例

本文整理汇总了Python中algorithm.Algorithm.getShortestPath方法的典型用法代码示例。如果您正苦于以下问题:Python Algorithm.getShortestPath方法的具体用法?Python Algorithm.getShortestPath怎么用?Python Algorithm.getShortestPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在algorithm.Algorithm的用法示例。


在下文中一共展示了Algorithm.getShortestPath方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Node

# 需要导入模块: from algorithm import Algorithm [as 别名]
# 或者: from algorithm.Algorithm import getShortestPath [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 getShortestPath [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.getShortestPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。