dijkstra-methods | R Documentation |
The methods dijkstraFrom
and dijkstraBetween
are wrappers of
procedures implemented in RBGL package, designed for gGraph
and gData object.
dijkstraBetween(x, ...)
## S4 method for signature 'gGraph'
dijkstraBetween(x, from, to)
## S4 method for signature 'gData'
dijkstraBetween(x)
dijkstraFrom(x, ...)
## S4 method for signature 'gGraph'
dijkstraFrom(x, start)
## S4 method for signature 'gData'
dijkstraFrom(x, start)
## S3 method for class 'gPath'
plot(x, col = "rainbow", lwd = 3, ...)
gPath2dist(m, diag = FALSE, upper = FALSE, res.type = c("dist", "vector"))
x |
a gGraph or a gData object. For
plotting method of |
... |
further arguments passed to the |
from |
a vector of character strings giving node names. |
to |
a vector of character strings giving node names. |
start |
a character string naming the 'source' node. |
col |
a character string indicating a color or a palette of colors to be used for plotting edges. |
lwd |
a numeric value indicating the width of edges. |
m |
a |
diag , upper |
unused parameters added for consistency with
|
res.type |
a character string indicating what type of result should be
returned: a |
dijkstraFrom
finds minimum costs paths to nodes from a given 'source'
node.
dijkstraBetween
finds minimum costs paths between all possible pairs
of nodes given two sets of nodes.
All these functions return objects with S3 class "gPath". These objects can
be plotted using plot.gPath
.
gPath2dist
extracts the pairwise distances from the gPath
returned by dijkstraBetween
and returns a dist
object. Note
that if the gPath
does not contain pairwise information, a warning
will be issued, but the resulting output will likely be meaningless.
In 'dijkstraBetween', paths are seeked all possible pairs of nodes between 'from' and 'to'.
A "gPath" object. These are basically the outputs of RBGL's
sp.between
function (see ?sp.between
), with a class attribute
set to "gPath", and an additional slot 'xy' containing geographic
coordinates of the nodes involved in the paths.
## Not run:
## plotting
world <- worldgraph.40k
par(mar = rep(.1, 4))
plot(world, reset = TRUE)
## check connectivity
isConnected(hgdp) # must be ok
## Lowest cost path from an hypothetical origin
ori.coord <- list(33, 10) # one given location long/lat
points(data.frame(ori.coord), pch = "x", col = "black", cex = 3) # an 'x' shows the putative origin
ori <- closestNode(world, ori.coord) # assign it the closest node
myPath <- dijkstraFrom(hgdp, ori) # compute shortest path
## plotting
plot(world, pch = "") # plot the world
points(hgdp, lwd = 3) # plot populations
points(data.frame(ori.coord), pch = "x", col = "black", cex = 3) # add origin
plot(myPath) # plot the path
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.