⍝ Cost vector for path ⍵ through weighted graph ⍺:

    ⎕io←1

    g←(2 3) 3 (2 4) (1 5) 3         ⍝ graph connections.
    w←(1 3) 1 (4 1) (1 1) 1         ⍝ graph weights.
    aa←2 5⍴g,w                      ⍝ weighted graph.

    1 disp aa                       ⍝ simple weighted graph "aa".
┌→──┬─┬───┬───┬─┐
↓2 3│3│2 4│1 5│3│
├~─→┼─┼~─→┼~─→┼─┤
│1 3│1│4 1│1 1│1│
└~─→┴─┴~─→┴~─→┴─┘

    aa wcost 1 3 4 5 3 2 3 2        ⍝ cost of path through graph.
3 1 1 1 4 1 4

Back to: code

Back to: Workspaces