Compute Trajectory Distances to a Target Vertex
Source:R/gfc_flow.R
trajectory.distances.to.vertex.RdFor each trajectory in a list, computes the minimum graph distance from any vertex in the trajectory to a specified target vertex. This is useful for identifying trajectories that pass near a landmark vertex (e.g., a community state type centroid) without necessarily including it.
Arguments
- trajectories
A list of integer vectors, where each vector contains vertex indices forming a trajectory. Vertex indices should be 1-based.
- target.vertex
Integer specifying the target vertex index (1-based).
- adj.list
List of integer vectors specifying the adjacency structure. Each element
adj.list[[i]]contains the indices of vertices adjacent to vertexi.- weight.list
List of numeric vectors specifying edge weights (lengths). Each element
weight.list[[i]]contains the weights of edges from vertexito its neighbors inadj.list[[i]].
Value
A list with components:
- min.distances
Numeric vector of length equal to the number of trajectories. Each element is the minimum graph distance from any vertex in the corresponding trajectory to the target vertex.
- nearest.vertices
Integer vector of the trajectory vertex that achieves the minimum distance to the target for each trajectory.
- nearest.positions
Integer vector of the position within each trajectory where the nearest vertex occurs (1-based).
- target.vertex
The target vertex index (for reference).
Details
The function constructs an igraph object from the adjacency and weight lists, then computes shortest path distances from the target vertex to all vertices in the graph. For each trajectory, it identifies the vertex with the smallest distance to the target and records both the distance and the vertex identity.
Trajectories that pass through the target vertex will have a minimum distance of zero.
See also
vertex.all.trajectories.gfc.flow for extracting
trajectories from a GFC flow result, cell.trajectories for
extracting trajectories within a specific cell
Examples
if (FALSE) { # \dontrun{
## Get all trajectories descending to minimum m2
m2.trajs <- vertex.all.trajectories.gfc.flow(gfc.res, m2.vertex)
## Find which trajectories pass closest to the Li landmark
traj.dists <- trajectory.distances.to.vertex(
trajectories = m2.trajs,
target.vertex = Li.vertex,
adj.list = adj.list,
weight.list = weight.list
)
## Select trajectories within distance 0.5 of Li
near.Li.idx <- which(traj.dists$min.distances < 0.5)
} # }