Skip to content

dijkstra.m

Basic Information

  SYNTAX:  [path, totalCost] = dijkstra(n, CostMatrix, s, d)

  PURPOSE:  Find the least cost path between two nodes in a network.

  INPUT:
    n = the number of nodes in the network
    CostMatrix = matrix whose (i,j)th entry defines the cost of moving from
    node i to node j or conversely.  Use Inf if impossible.
    s = source node index
    d = destination node index

  OUTPUT:
    path = the list of nodes in the path from source to destination
    totalCost = the total cost of the path

  RESTRICTIONS: Node numbers must be consecutive, starting at 1.

Dependencies