Skip to content

fix #2583: fix negative and asymmetric edge costs in stoer wagner tests#3104

Open
prashsti29 wants to merge 2 commits intopgRouting:developfrom
prashsti29:prashsti29-mincut
Open

fix #2583: fix negative and asymmetric edge costs in stoer wagner tests#3104
prashsti29 wants to merge 2 commits intopgRouting:developfrom
prashsti29:prashsti29-mincut

Conversation

@prashsti29
Copy link
Copy Markdown

@prashsti29 prashsti29 commented Apr 5, 2026

Fixes #2583

Changes proposed in this pull request:

  • Ensures edge costs and reverse_costs are non-negative and symmetric before running Stoer-Wagner tests
  • Fixes test failures caused by negative and asymmetric edge weights which violate Stoer-Wagner algorithm requirements

@pgRouting/admins

Summary by CodeRabbit

  • Tests
    • Updated minimum-cut tests to normalize edge costs to non-negative values so negative inputs now map to positive representations.
    • Tightened a test input filter to target a smaller set of edges during an error assertion, improving test precision.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 5, 2026

Walkthrough

Updates Stoer–Wagner test scripts to normalize edges.cost and edges.reverse_cost using abs(sign(...)) instead of sign(...), making stored normalized values non-negative; also adjusts one pgr_stoerWagner call filter in edge_cases.pg.

Changes

Cohort / File(s) Summary
Stoer–Wagner cost normalization
pgtap/mincut/stoerWagner/compare_components.pg, pgtap/mincut/stoerWagner/inner_query.pg, pgtap/mincut/stoerWagner/types_check.pg
Changed test setup to write edges.cost and edges.reverse_cost as abs(sign(...)) instead of sign(...), ensuring normalized values are 0 or 1 (negative inputs now map to 1).
Edge-case test & query filter
pgtap/mincut/stoerWagner/edge_cases.pg
Same abs(sign(...)) normalization change; also modified a pgr_stoerWagner call filter to use WHERE id < 17 (replacing the prior FROM edges id < 17 form).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • cvvergara
  • robe2

Poem

🐇 I hopped through tests with whiskers keen,

Turned signs to absolutes, tidy and clean,
No negatives hiding where edges roam,
Now cuts and paths have a brighter home.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main objective of the PR: fixing negative and asymmetric edge costs in Stoer-Wagner tests, which aligns with all four modified test files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@prashsti29 prashsti29 changed the title fix negative and asymmetric edge costs in stoer wagner tests fix #2583: fix negative and asymmetric edge costs in stoer wagner tests Apr 5, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pgtap/mincut/stoerWagner/edge_cases.pg (1)

17-22: 🧹 Nitpick | 🔵 Trivial

Pre-existing SQL syntax issue in the test query.

The inner query has a missing WHERE keyword: FROM edges id < 17 should be FROM edges WHERE id < 17. While this test passes because it expects the function signature error (function with 2 args doesn't exist), the SQL error would occur first if the function signature matched.

This is a pre-existing issue unrelated to this PR's changes.

Suggested fix for the SQL syntax
 SELECT throws_ok(
     'SELECT * FROM pgr_stoerWagner(
-        ''SELECT id, source, target, cost, reverse_cost FROM edges id < 17'',
+        ''SELECT id, source, target, cost, reverse_cost FROM edges WHERE id < 17'',
         3
     )','42883','function pgr_stoerwagner(unknown, integer) does not exist',
     '6: Documentation says it does not work with 1 flags');
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pgtap/mincut/stoerWagner/edge_cases.pg` around lines 17 - 22, The test
contains a SQL syntax error in the inner query of the SELECT throws_ok call:
replace the malformed fragment "FROM edges id < 17" with a proper WHERE clause
so the inner query is "SELECT id, source, target, cost, reverse_cost FROM edges
WHERE id < 17"; update the test that invokes pgr_stoerWagner (the SELECT
throws_ok wrapping pgr_stoerWagner call) to use the corrected inner SQL so the
intended function-signature error remains the first possible error when
appropriate.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@pgtap/mincut/stoerWagner/edge_cases.pg`:
- Around line 17-22: The test contains a SQL syntax error in the inner query of
the SELECT throws_ok call: replace the malformed fragment "FROM edges id < 17"
with a proper WHERE clause so the inner query is "SELECT id, source, target,
cost, reverse_cost FROM edges WHERE id < 17"; update the test that invokes
pgr_stoerWagner (the SELECT throws_ok wrapping pgr_stoerWagner call) to use the
corrected inner SQL so the intended function-signature error remains the first
possible error when appropriate.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: d2ee35b1-a4d2-4422-a2cb-3f2a4e98ec3d

📥 Commits

Reviewing files that changed from the base of the PR and between e06c177 and 0d93eff.

📒 Files selected for processing (4)
  • pgtap/mincut/stoerWagner/compare_components.pg
  • pgtap/mincut/stoerWagner/edge_cases.pg
  • pgtap/mincut/stoerWagner/inner_query.pg
  • pgtap/mincut/stoerWagner/types_check.pg

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.

pgtap/mincut/compare.test.sql test data is flawed

1 participant