Learn R Programming

movecost (version 3.0.0)

mc_rank: Ranked (sub-optimal) least-cost paths between an origin and a destination

Description

Computes the optimal least-cost path and up to k - 1 progressively sub-optimal alternatives between two locations. Alternatives are obtained by iterative penalisation: after each path is found, the conductance of the graph edges incident to its cells is multiplied by penalty (0.01 by default), and Dijkstra's algorithm is run again. This discourages, without strictly forbidding, the reuse of earlier routes, and therefore returns spatially distinct alternatives rather than trivial one-cell deviations (which is what an exact k-shortest-path algorithm would return on a raster graph). The procedure is the same in spirit as movecost <= 2.x's moverank(), but operates directly on the graph edge weights, so the conductance matrix is never rebuilt and any number of ranks can be requested (movecost <= 2.x was limited to 6).

Usage

mc_rank(surface, origin, destin, k = 3, penalty = 0.01, time = "h")

Value

An object of class movecost_rank, a list with components

  • paths: sf lines with rank, cost, (for time-based functions) cost_hms, and length attributes;

  • corridor: the least-cost corridor (SpatRaster) between the two locations, stored so that plot(x, type = "corridor") can draw the ranked paths over it without further computation;

  • origin, destin: the input locations (sf);

  • metadata used by the plot method.

Plot it at any time with plot(): plot(x) draws the paths over the terrain, plot(x, type = "corridor") draws them over the least-cost corridor, and plot(x, type = "chart") draws a bubble chart of length and cost by rank (see plot.movecost_rank).

Arguments

surface

a movecost_surface object created by mc_surface.

origin

single origin location (sf points, SpatVector, or legacy SpatialPointsDataFrame).

destin

single destination location (same accepted classes).

k

number of paths to return, optimal one included (default 3).

penalty

conductance multiplier applied to edges incident to already found paths (default 0.01; smaller values push alternatives further away from earlier routes).

time

unit for time-based cost functions: "h" (hours, default) or "m" (minutes).

Details

Each returned path carries its rank (1 = optimal), its accumulated cost computed on the original (unpenalised) graph - so costs of different ranks are directly comparable - and its length.

See Also

mc_surface, plot.movecost_rank, mc_paths

Examples

Run this code
dtm <- mc_volc()
start <- mc_volc_loc()
destin <- mc_destin_loc()

surf <- mc_surface(dtm, funct = "t", move = 8)
rk <- mc_rank(surf, origin = start, destin = destin[2, ], k = 3)

rk$paths        # ranks, costs, lengths
plot(rk)

Run the code above in your browser using DataLab