## `Network::shortPathTo` -- shortest paths to one single node

#### Introduction

``Network::shortPathTo`(G, v)` finds the shortest paths in the network `G` ending at node `v`.

#### Call(s)

`Network::shortPathTo(G,v <, w> <, Length> <, Path>)`

#### Parameters

`G` | - | network
`v, w` | - | nodes in the network

#### Options

`Length` | - | include table of path lengths; default if Path not given

#### Returns

a number, a table or a sequence of two tables

#### Details

- ``Network::shortPathTo`(G, v)` returns a table with the length of shortest paths to `v` from all other nodes in the network with respect to the edge weight.
- ``Network::shortPathTo`(G, v, w)` gives the length of a shortest path from `w` to `v`.
- If the optional argument Pathis given, then a table with shortest paths is returned. If Lengthand Pathare given, then both the length of the shortest paths and the paths are returned.

#### Example 1

    >> V := [1,2,3,4,5]:
       Vw := [25,0,0,0,-25]:
       Ed := [[1,2], [1,3], [2,3], [2,4], [3,4], [3,5], [4,5]]:
       Ew := [7, 6, 5, 4, 2, 2, 1]:
       Ecap := [30, 20, 25, 10, 20, 25, 20]:
       N1 := Network(V,Ed,Eweight=Ew, Capacity=Ecap, Vweight=Vw):

    >> Network::shortPathTo(N1, 5)

                                     table(
                                       5 = 0,
                                       4 = 1,
                                       3 = 2,
                                       2 = 5,
                                       1 = 8
                                     )

    >> Network::shortPathTo(N1, 5, Path)

                                 table(
                                   4 = [4, 5],
                                   3 = [3, 5],
                                   2 = [2, 4, 5],
                                   1 = [1, 3, 5]
                                 )

#### Background

- If there are only non negative edge weights the algorithm of Dijkstra is used. If there are positive and negative edge weights the algorithm of Bellman is used.

#### Changes

- used to be called `Network::ShortPathTo`

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000