# This is generally needed to explore different values of `k` on same graph:
dodgr_cache_off ()
graph <- weight_streetnet (hampi)
from <- sample (graph$from_id, size = 10)
to <- sample (graph$from_id, size = 20)
dens_from <- runif (length (from))
dens_to <- runif (length (to))
graph <- dodgr_flows_si (
graph,
from = from,
to = to,
dens_from = dens_from,
dens_to = dens_to
)
# graph then has an additonal 'flows' column of aggregate flows along all
# edges. These flows are directed, and can be aggregated to equivalent
# undirected flows on an equivalent undirected graph with:
graph_undir <- merge_directed_graph (graph)
# This graph will only include those edges having non-zero flows, and so:
nrow (graph)
nrow (graph_undir) # the latter is much smaller
# ----- One dispersal coefficient for each origin point:
# Remove `flow` column to avoid warning about over-writing values:
graph$flow <- NULL
k <- runif (length (from))
graph <- dodgr_flows_si (
graph,
from = from,
to = to,
dens_from = dens_from,
dens_to = dens_to,
k = k
)
grep ("^flow", names (graph), value = TRUE)
# single dispersal model; single "flow" column
# ----- Multiple models, muliple dispersal coefficients:
k <- 1:5
graph$flow <- NULL
graph <- dodgr_flows_si (
graph,
from = from,
to = to,
dens_from = dens_from,
dens_to = dens_to,
k = k
)
grep ("^flow", names (graph), value = TRUE)
# Rm all flow columns:
graph [grep ("^flow", names (graph), value = TRUE)] <- NULL
# Multiple models with unique coefficient at each origin point:
k <- matrix (runif (length (from) * 5), ncol = 5)
dim (k)
graph <- dodgr_flows_si (
graph,
from = from,
to = to,
dens_from = dens_from,
dens_to = dens_to,
k = k
)
grep ("^flow", names (graph), value = TRUE)
# 5 "flow" columns again, but this time different dispersal coefficients each
# each origin point.
Run the code above in your browser using DataLab