% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/paths.R
\name{shortest_paths}
\alias{shortest_paths}
\title{Compute Shortest Path Distances}
\usage{
shortest_paths(x, from = NULL, to = NULL, weights = NULL, directed = NULL, ...)
}
\arguments{
\item{x}{Network input: matrix, igraph, network, cograph_network, or tna object}

\item{from}{Character or numeric node identifier(s) for the source. If NULL
(default), compute distances from all nodes.}

\item{to}{Character or numeric node identifier(s) for the target. If NULL
(default), compute distances to all nodes.}

\item{weights}{Edge weight handling: NULL (default) auto-detects from edge
attributes, NA forces unweighted distances, or a numeric vector of custom
weights.}

\item{directed}{Logical or NULL. If NULL (default), auto-detect from matrix
symmetry. Set TRUE to force directed, FALSE to force undirected.}

\item{...}{Additional arguments passed to \code{\link{to_igraph}}}
}
\value{
Depends on the query:
\itemize{
\item If both \code{from} and \code{to} are NULL: a full distance matrix
(all pairs)
\item If \code{from} is a single node and \code{to} is NULL: a named
numeric vector of distances from that node to all others
\item If \code{from} is multiple nodes and \code{to} is NULL: a matrix
with rows for each source
\item If both \code{from} and \code{to} are single nodes: a single numeric
value
\item Otherwise: a matrix of distances between the specified node sets
}
}
\description{
Computes shortest path distances between nodes in a network. Supports
all-pairs, single-source, and point-to-point queries.
}
\details{
Uses \code{igraph::distances()} internally. For weighted networks, edge
weights are used as distances by default. Pass \code{weights = NA} to
ignore weights and treat all edges as having unit distance.

Note: \code{igraph::distances()} with \code{weights = NULL} automatically
uses edge weight attributes if present. To force unweighted computation,
pass \code{weights = NA} explicitly.
}
\examples{
# All-pairs distances
adj <- matrix(c(
  0, 1, 0, 0,
  1, 0, 1, 0,
  0, 1, 0, 1,
  0, 0, 1, 0
), 4, 4)
rownames(adj) <- colnames(adj) <- LETTERS[1:4]
cograph::shortest_paths(adj)

# Single source to all
cograph::shortest_paths(adj, from = "A")

# Point-to-point
cograph::shortest_paths(adj, from = "A", to = "D")

}
\seealso{
\code{\link{k_shortest_paths}}, \code{\link{network_summary}}
}
