Multi-source shortest walks by breadth-first search #
A digraph is given by a list V of vertices and a Boolean arc test arc; two Boolean tests src
and tgt mark the sources and the targets. Breadth-first search from all sources at once
(Cslib.Reachability.findWalk) either returns a src-to-tgt walk with the fewest vertices or
returns the list of vertices reachable from the sources, which then contains every source, is
closed under arcs inside V and contains no target (Cslib.Reachability.IsSrcTgtSeparator). Such
a separator rules out every src-to-tgt walk, so the two outcomes are exclusive and decide
whether a walk exists.
The search stores, for each vertex found, a walk from a source that reaches it. Round k adds the
vertices first reached by walks with k + 2 vertices, so the first target found carries a
shortest walk. The number of rounds is bounded by V.length, since each round before the last
finds a new vertex of V.
Cslib.Reachability.search in CslibFrontier.Algorithms.Reachability.BreadthFirst computes the
reachable set from a single start element; the search here starts from many sources, records a
walk for every vertex it finds and stops at the first target.
Main definitions #
Cslib.Reachability.IsWalk,IsSrcTgtWalk,IsShortestSrcTgtWalk: walks in the digraph, walks from a source to a target, and the shortest such walks (by number of vertices).Cslib.Reachability.IsSrcTgtSeparator: a set of vertices containing every source, closed under arcs and containing no target.Cslib.Reachability.findWalk: multi-source breadth-first search.
Main results #
Cslib.Reachability.isShortestSrcTgtWalk_of_findWalk_eq_inl: a returned walk is a shortestsrc-to-tgtwalk.Cslib.Reachability.isSrcTgtSeparator_of_findWalk_eq_inr: a returned vertex list is a separator.Cslib.Reachability.IsSrcTgtSeparator.not_isSrcTgtWalk: a separator rules out everysrc-to-tgtwalk.Cslib.Reachability.findWalk_isLeft_iff: the search returns a walk exactly when one exists.
References #
A separator rules out every src-to-tgt walk.
The search #
The entries added by one round: each vertex v of V not found yet that some found entry
(u, w) has an arc to, with the walk w ++ [v] (for the first such entry).
Rounds of breadth-first search, each found entry (v, w) carrying a walk w to v. A found
target returns its walk; a round adding nothing, or running out of rounds, returns the vertices
found.
Multi-source breadth-first search: .inl p for a shortest src-to-tgt walk p, or
.inr R for the list R of vertices reachable from the sources when no target is.
Correctness #
A walk returned by findWalk is a shortest src-to-tgt walk.
A vertex list returned by findWalk separates the sources from the targets.
findWalk returns a walk exactly when some src-to-tgt walk exists.