A route model can use a cost of zero for a transition that is allowed but carries no added penalty. That zero still represents an edge. If a conversion treats all zero entries as missing, the route planner receives a different graph and can choose a more expensive path or report that a destination is unreachable.

Test a directed graph with three states

In this synthetic model, state 0 can reach state 1 for zero cost and state 2 for nine cost units. State 1 can reach state 2 for two units. The lowest total from state 0 to state 2 is two through state 1. The zero in this model expresses an incremental penalty convention. It does not mean that a physical robot crosses that transition instantly.

The dense matrix below uses infinity for absent edges. SciPy's dense-to-sparse graph converter defaults to treating zero as an absent edge too. Pass an explicit null value that matches the input's missing-edge representation to retain the zero entry.

import numpy as np

from scipy.sparse.csgraph import csgraph_from_dense, dijkstra

inf = np.inf

cost = np.array([[inf, 0., 9.], [inf, inf, 2.], [inf, inf, inf]])

default_graph = csgraph_from_dense(cost)

explicit_graph = csgraph_from_dense(cost, null_value=np.inf)

default = dijkstra(default_graph, directed=True, indices=0)

preserved = dijkstra(explicit_graph, directed=True, indices=0)

assert default[2] == 9

assert preserved[1] == 0

assert preserved[2] == 2

assert explicit_graph.nnz == 3

With SciPy 1.18.1 and NumPy 2.5.5, the default graph leaves state 1 unreachable from state 0 and reports a cost of nine for state 2. The explicit conversion gives costs of zero and two, respectively. The change occurs when the matrix is converted, before the shortest-path algorithm runs.

Carry the missing-edge convention through the pipeline

Write down how the exported graph represents absent edges and valid weights. A dense CSV filled with zeros is ambiguous if zero is also an allowed cost. An edge list can encode existence directly by listing the endpoints of every allowed transition and placing the cost in a separate column. A dense matrix needs a distinguishable marker for missing edges and a matching import rule.

For the in-memory graph, check a known zero-cost transition after every conversion that may discard stored zeros. Compare the shortest-path cost and the reachability of intermediate nodes against a small expected result. Keep the graph directed when transitions differ by direction, and verify that the route cost units match the purpose of the search. A low modeled penalty says nothing by itself about travel time or whether an aisle is physically available.

Sources

SciPy dense-to-sparse graph converter reference for its missing-edge marker

https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.csgraph.csgraph_from_dense.html

SciPy Dijkstra reference for directed graphs and path costs

https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.csgraph.dijkstra.html