Skip to contents

This function finds the shortest path from a given 'source' node to all other nodes in the graph using Dijkstra's algorithm. It can be applied to both gGraph and gData objects.

Usage

dijkstraFrom(x, start)

# S4 method for class 'gGraph'
dijkstraFrom(x, start)

# S4 method for class 'gData'
dijkstraFrom(x, start)

Arguments

x

A gGraph or gData object.

start

a character string naming the 'source' node.

Value

A gPath object.

Details

The function uses the RBGL package to compute the shortest paths. It checks for the connectivity of the graph and handles cases where there are duplicated paths.

Functions

  • dijkstraFrom(gGraph): method for gGraph

  • dijkstraFrom(gData): method for gData

See also

Examples

# Using a gData object:

# select a few populations from the HGDP dataset
hgdp.sub <- hgdp[getData(hgdp)$Population %in%
  c("Orcadian", "Adygei", "Russian", "Basque")]

# select a location of another HGDP population
french.hgdp <- hgdp[getData(hgdp)$Population %in%
  c("French")]

# Choose an origin node
french <- getNodes(french.hgdp)

my.path <- dijkstraFrom(hgdp.sub, french)