Skip to content

Latest commit

 

History

History
54 lines (40 loc) · 1009 Bytes

File metadata and controls

54 lines (40 loc) · 1009 Bytes

Visualise shortest path using Dijkstra's algorithm

Features

  • Generate random graphs and parse from string
  • Calculate the shortest path

Examples

>>> from dijsktra import Graph
>>> g = Graph.generate_random()
>>> g.view()

graph

>>> g.find_shortest_path("g->f")

graph-highlighted

>>> s = """
jln ahmad ibrahim, corporation, 4
corporation, teban, 3
teban, pie jeast, 5
jln ahmad ibrahim, pie jwest, 10
pie jwest, pie jeast, 3
teban, clementi, 2
clementi, clementi rd, 2
clementi rd, buona vista, 3
buona vista, alexandra, 4
pie jeast, pie imm, 3
pie imm, toh tuck, 1
toh tuck, bt timah, 4
"""
>>> g = Graph.from_string(s)
>>> g.view()

graph2

>>> g.find_shortest_path("teban->pie jeast")

graph2-highlight

Resources

Priority queues using heapq in Python (realpython.com)