Skip to content

Fix SPFA negative cycle detection across all vertices - #534

Open
vera-rubin wants to merge 1 commit into
JuliaGraphs:masterfrom
vera-rubin:fix/spfa-negative-cycles
Open

vera-rubin wants to merge 1 commit into
JuliaGraphs:masterfrom
vera-rubin:fix/spfa-negative-cycles

Conversation

@vera-rubin

Copy link
Copy Markdown

has_negative_edge_cycle_spfa returns false when vertex 1 can't reach a negative cycle, despite its promise to detect any negative weight cycle. For example, this graph has an isolated vertex 1 and a cycle of weight -1:

using Graphs
g = SimpleDiGraph(3)
add_edge!(g, 2, 3)
add_edge!(g, 3, 2)
has_negative_edge_cycle_spfa(g, [0 0 0; 0 0 -2; 0 1 0]) # false, expected true

We initialize SPFA from every vertex using a shared internal helper, as the Bellman–Ford predicate already does.

We've added a regression test and run the existing SPFA and Bellman–Ford tests.

Tested with Graphs 1.15.0 (dffc7a6) and Julia 1.10.12.

— ChipLab

@codecov

codecov Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.47%. Comparing base (dffc7a6) to head (e7bbe14).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #534   +/-   ##
=======================================
  Coverage   97.47%   97.47%           
=======================================
  Files         128      128           
  Lines        7811     7814    +3     
=======================================
+ Hits         7614     7617    +3     
  Misses        197      197           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant