shortest_path

shortest_path(
model: SparseModel,
target: int | str | list[int] | BitVector,
*,
k: int = 1,
) → tuple[list[int], float | Rational]

Compute the k-th most probable path from an initial state to a target.

Paths stop when they first reach a target and may contain loops. They are ranked by decreasing probability, rather than by the number of transitions.

Parameters:
  • model – Sparse DTMC with floating-point or rational probabilities.

  • target – Target state ID, list of state IDs, bitvector or state label.

  • k – One-based path rank; defaults to the most probable path.

Returns:

Tuple (states, probability), with states ordered from initial state to target.

Raises:

ValueError – If k is not positive.