NetworkXError: The graph must be a DiGraph in shortest‑path functions
0 reputation · 24 Jul 2025, 16:41 UTC
Problem Context
When invoking dijkstra_path or bellman_ford_path on an undirected Graph instance, NetworkX raises the documented error
NetworkXError: The graph must be a DiGraph. The functions are designed exclusively for directed graphs, and the exception enforces this precondition.
Goal
Determine whether there is a planned change that will allow shortest‑path algorithms to operate on undirected graphs, or whether a dedicated undirected variant should be added. Additionally, assess if the current error message could be improved to guide users toward the appropriate conversion.
Unresolved Decision
NetworkX currently does not provide a shortest‑path routine that accepts a Graph directly. The library’s documentation states the requirement for a DiGraph but does not mention future support for undirected inputs.
Specific Questions
- Is there an intention to extend
dijkstra_pathand related functions to accept undirected graphs, or to introduce separate shortest‑path algorithms forGraphinstances? - Would the error message be enhanced to suggest converting the graph to a directed version or using a dedicated undirected algorithm?