Skip to contents

For each vertex in a given set, computes the minimum graph distance to any vertex in a trajectory. This is useful for characterizing how far vertices in a tubular neighborhood are from the central path.

Usage

vertex.distances.to.trajectory(
  vertices,
  trajectory.vertices,
  adj.list,
  weight.list
)

Arguments

vertices

Integer vector of vertex indices for which to compute distances. Vertex indices should be 1-based.

trajectory.vertices

Integer vector of vertex indices forming the trajectory (or any reference vertex set). Vertex indices should be 1-based.

adj.list

List of integer vectors specifying the adjacency structure. Each element adj.list[[i]] contains the indices of vertices adjacent to vertex i.

weight.list

List of numeric vectors specifying edge weights (lengths). Each element weight.list[[i]] contains the weights of edges from vertex i to its neighbors in adj.list[[i]].

Value

A list with components:

min.distances

Numeric vector of length equal to the number of input vertices. Each element is the minimum graph distance from the corresponding vertex to any vertex in the trajectory.

nearest.traj.vertices

Integer vector of the trajectory vertex that is closest to each input vertex.

nearest.traj.positions

Integer vector of the position within the trajectory where the nearest vertex occurs (1-based). Useful when trajectory order is meaningful.

vertices

The input vertices (for reference).

trajectory.vertices

The trajectory vertices (for reference).

Details

The function constructs an igraph object from the adjacency and weight lists, then computes shortest path distances from all trajectory vertices to all input vertices. For each input vertex, it identifies the trajectory vertex with the smallest distance.

Vertices that are part of the trajectory will have a minimum distance of zero.

See also

trajectory.distances.to.vertex for the inverse operation (distance from trajectories to a single vertex), compute.harmonic.extension which produces tubular neighborhoods that can be analyzed with this function

Examples

if (FALSE) { # \dontrun{
## Compute harmonic extension to get tubular neighborhood
hext <- compute.harmonic.extension(adj.list, weight.list, trajectory,
                                   tube.radius = 2)

## Get distances from tubular vertices to the trajectory
tube.dists <- vertex.distances.to.trajectory(
    vertices = hext$tubular.vertices,
    trajectory.vertices = trajectory,
    adj.list = adj.list,
    weight.list = weight.list
)

## Vertices on the trajectory have distance 0
sum(tube.dists$min.distances == 0)  # equals length(trajectory)
} # }