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
. For example, if the
element one of this vector has value 10, that means that the
predecessor of node 1 is node 10. The next predecessor is
found by examining penult[10].
start
The start node that was supplied in the call to
bellman.ford.sp.
The Boost Graph Library: User Guide and Reference Manual;
by Jeremy G. Siek, Lie-Quan Lee, and Andrew Lumsdaine;
(Addison-Wesley, Pearson Education Inc., 2002), xxiv+321pp.
ISBN 0-201-72914-8
con <- file(system.file("XML/conn2.gxl",package="RBGL"), open="r")
dd <- fromGXL(con)
close(con)
bellman.ford.sp(dd)
bellman.ford.sp(dd,nodes(dd)[2])
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(RBGL)
Loading required package: graph
Loading required package: BiocGenerics
Loading required package: parallel
Attaching package: 'BiocGenerics'
The following objects are masked from 'package:parallel':
clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
clusterExport, clusterMap, parApply, parCapply, parLapply,
parLapplyLB, parRapply, parSapply, parSapplyLB
The following objects are masked from 'package:stats':
IQR, mad, xtabs
The following objects are masked from 'package:base':
Filter, Find, Map, Position, Reduce, anyDuplicated, append,
as.data.frame, cbind, colnames, do.call, duplicated, eval, evalq,
get, grep, grepl, intersect, is.unsorted, lapply, lengths, mapply,
match, mget, order, paste, pmax, pmax.int, pmin, pmin.int, rank,
rbind, rownames, sapply, setdiff, sort, table, tapply, union,
unique, unsplit
> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/RBGL/bellman.ford.sp.Rd_%03d_medium.png", width=480, height=480)
> ### Name: bellman.ford.sp
> ### Title: Bellman-Ford shortest paths using boost C++
> ### Aliases: bellman.ford.sp
> ### Keywords: graphs
>
> ### ** Examples
>
> con <- file(system.file("XML/conn2.gxl",package="RBGL"), open="r")
> dd <- fromGXL(con)
> close(con)
> bellman.ford.sp(dd)
$`all edges minimized`
[1] TRUE
$distance
A B C D E G H F
0 1 1 1 2 2 2 3
$penult
A B C D E G H F
1 1 1 1 3 3 4 5
$start
[1] "A"
> bellman.ford.sp(dd,nodes(dd)[2])
$`all edges minimized`
[1] TRUE
$distance
A B C D E G H F
Inf 0 1 1 2 2 2 3
$penult
A B C D E G H F
1 2 2 2 3 3 4 5
$start
[1] "B"
>
>
>
>
>
> dev.off()
null device
1
>