dijkstra.sp: Dijkstra's shortest paths using boost C++

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/interfaces.R

Description

dijkstra's shortest paths

Usage

1
dijkstra.sp(g,start=nodes(g)[1], eW=unlist(edgeWeights(g)))

Arguments

g

instance of class graph

start

character: node name for start of path

eW

numeric: edge weights.

Details

These functions are interfaces to the Boost graph library C++ routines for Dijkstra's shortest paths.

For some graph subclasses, computing the edge weights can be expensive. If you are calling dijkstra.sp in a loop, you can pass the edge weights explicitly to avoid the edge weight creation cost.

Value

A list with elements:

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 dijkstra.sp.

Author(s)

VJ Carey <stvjc@channing.harvard.edu>

References

Boost Graph Library ( www.boost.org/libs/graph/doc/index.html )

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

See Also

bellman.ford.sp, dag.sp, johnson.all.pairs.sp, sp.between

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
con1 <- file(system.file("XML/dijkex.gxl",package="RBGL"), open="r")
dd <- fromGXL(con1)
close(con1)
dijkstra.sp(dd)
dijkstra.sp(dd,nodes(dd)[2])

con2 <- file(system.file("XML/ospf.gxl",package="RBGL"), open="r")
ospf <- fromGXL(con2)
close(con2)
dijkstra.sp(ospf,nodes(ospf)[6])

Example output

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, sd, var, xtabs

The following objects are masked from 'package:base':

    Filter, Find, Map, Position, Reduce, anyDuplicated, append,
    as.data.frame, cbind, colMeans, colSums, 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, rowMeans, rowSums, rownames, sapply,
    setdiff, sort, table, tapply, union, unique, unsplit, which,
    which.max, which.min

$distances
A B C D E 
0 6 1 4 5 

$penult
A B C D E 
1 5 1 3 4 

$start
A 
1 

$distances
A B C D E 
3 0 4 1 2 

$penult
A B C D E 
5 2 1 2 2 

$start
B 
2 

$distances
 RT1   N1   N3  RT2   N2  RT3  RT6   N4  RT4  RT5  RT7  N12  N13  N14 RT10   N6 
   1    4    1    1    4    0    8    2    1    9   15   17   17   17   15   16 
 N15  RT8   N7  RT9   N9  N11   N8 RT11 RT12  N10   H1 
  24   16   20   19   19   22   18   18   19   21   29 

$penult
 RT1   N1   N3  RT2   N2  RT3  RT6   N4  RT4  RT5  RT7  N12  N13  N14 RT10   N6 
   3    1    6    3    4    6    6    6    3    9   10   10   10   10    7   15 
 N15  RT8   N7  RT9   N9  N11   N8 RT11 RT12  N10   H1 
  11   16   18   21   24   20   15   23   21   25   25 

$start
RT3 
  6 

RBGL documentation built on Nov. 8, 2020, 5 p.m.