dodgrpackage includes three functions for allocating and aggregating
flows throughout network, based on defined properties of a set of origin and
destination points. The three primary functions for flows are
each of which is now described in detail.
The first of the above functions aggregates ''flows'' throughout a
network from a set of origin (
from) and destination (
to) points. Flows
commonly arise in origin-destination matrices used in transport studies, but may
be any kind of generic flows on graphs. A flow matrix specifies the flow between
each pair of origin and destination points, and the
function aggregates all of these flows throughout a network and assigns a
resultant aggregate flow to each edge.
For a set of
nf points of origin and
nt points of destination, flows are
defined by a simple
nt matrix of values, as in the following code:
graph <- weight_streetnet (hampi, wt_profile = "foot") from <- sample (graph$from_id, size = 10) to <- sample (graph$to_id, size = 10) flows <- matrix (10 * runif (length (from) * length (to)), nrow = length (from))
flows matrix is then submitted to
which simply appends an additional column of
flows to the submitted
graph_f <- dodgr_flows_aggregate (graph, from = from, to = to, flows = flows) head (graph_f)
Most flows are zero because they have only been calculated between very few points in the graph.
The second function,
uses only a vector a origin (
from) points, and aggregates flows as they
disperse throughout the network
according to a simple exponential model. In place of the matrix of flows
dispersal requires an equivalent vector of densities dispersing from all origin
from) points. This is illustrated in
the following code, using the same graph as the previous example.
dens <- rep (1, length (from)) # uniform densities graph_f <- dodgr_flows_disperse (graph, from = from, dens = dens) summary (graph_f$flow)
Note that flows from both
are directed, so the flow from 'A' to 'B' will not necessarily equal the flow
from 'B' to 'A'. It is often desirable to aggregate flows in an undirected
manner, for example for visualisations where plotting pairs of directed flows
between each edge if often not feasible for large graphs. Directed flows can be
aggregated to equivalent undirected flows with the
graph_undir <- merge_directed_graph (graph_f)
Resultant graphs produced by
only include those edges having non-zero flows, and so:
nrow (graph_f); nrow (graph_undir) # the latter is much smaller
The resultant graph can readily be merged with the original graph to regain the original data on vertex coordinates through
graph <- graph [graph_undir$edge_id, ] graph$flow <- graph_undir$flow
This graph may then be used to visualise flows with the
graph_f <- graph_f [graph_f$flow > 0, ] dodgr_flowmap (graph_f, linescale = 5)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.