bellman.ford.sp {RBGL} | R Documentation

## Bellman-Ford shortest paths using boost C++

### Description

Algorithm for the single-source shortest paths problem for a graph with both positive and negative edge weights.

### Usage

    bellman.ford.sp(g,start=nodes(g)[1])

### Arguments

`g` | instance of class graph
`start` | character: node name for start of path

### Details

This function interfaces to the Boost graph library C++ routines for Bellman-Ford shortest paths. Choose the appropriate algorithm to calculate the shortest path carefully based on the properties of the given graph. See documentation on Bellman-Ford algorithm in Boost Graph Library for more details.

### Value

A list with elements:

`all edges minimized` | true if all edges are minimized, false otherwise.
`distance` | The vector of distances from `start` to each node of `g`; includes `Inf` when there is no path from `start`.
`penult` | A vector of indices (in `nodes(g)`) of predecessors corresponding to each node on the path from that node back to `start`
`start` | The start node that was supplied in the call to `bellman.ford.sp`.

### Author(s)

Li Long <li.long@isb-sib.ch>

### See Also

`dag.sp`, `dijkstra.sp`, `johnson.all.pairs.sp`, `sp.between`

### Examples

    dd <- fromGXL(file(system.file("XML/conn2.gxl",package="RBGL"), open="r"))
    bellman.ford.sp(dd)
    bellman.ford.sp(dd,nodes(dd)[2])

[Package RBGL version 1.10.0 Index]