## `Network::longPath` -- longest paths from one single node

#### Introduction

``Network::longPath`(G, v)` finds the longest path in network `G` starting from vertex `v`.

#### Call(s)

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

#### Parameters

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

#### Options

`Length` | - | Return a table with the lengths of shortest paths
`Path` | - | Return a table with the paths themselves

#### Returns

a table, an integer or a list of nodes

#### Details

- ``Network::longPath`(G, v)` returns a table with the length of longest paths from `v` to all other nodes in the network with respect to the edge weight.
- ``Network::longPath`(G, v, w)` returns the length of a longest path from `v` to `w`.
- If the optional argument Path is given, a table with longest paths is returned. If both Length and Path are given, then both the length of the longest paths and the paths are returned. Paths are given as lists of nodes in reverse order.
- If Path is not given, the option Length has no effect.
- `G` should not contain cycles.

#### Example 1

We construct a network and try a few calls to `Network::longPath`:

    >> V := [1,2,3,4,5]:
       Ed := [[1,2], [1,3], [2,3], [2,4], [3,4], [3,5], [4,5]]:
       Ew := [7, 6, 5, 4, 2, 2, 1]:
       N1 := Network(V, Ed, Eweight=Ew):
       Network::longPath(N1,1)

                                     table(
                                       5 = 15,
                                       4 = 14,
                                       3 = 12,
                                       2 = 7,
                                       1 = 0
                                     )

    >> Network::longPath(N1,1,Path)

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

#### Background

- The implemented algorithm is a variation of the algorithm of Bellman.

#### Changes

- used to be called `Network::LongPath`

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