Repository navigation
Fix cost function in min_weighted_dominating_set - #8531
Conversation
The greedy cost function divided by `len(neighborhood - dom_set)`, which only excludes nodes already in the dominating set. It should divide by the number of uncovered (undominated) nodes that would be newly covered, i.e. `len(neighborhood & vertices)`. A node can be dominated by being adjacent to a dom_set member without being in dom_set itself. This caused the approximation to return unnecessarily large dominating sets on highly connected graphs. Fixes networkx#8523. Co-Authored-By: Claude Opus 4.6 <[email protected]>
- Rename `vertices` variable to `uncovered_nodes` for clarity - Replace vertex/vertices with node/nodes in module docstring and comments - Use `dict` instead of `dictionary`, tighten comments to fit 88 chars Co-Authored-By: Claude Opus 4.6 <[email protected]>
dschult
left a comment
There was a problem hiding this comment.
Looks good to me!
Thanks @Fridayai700 !!
rossbar
left a comment
There was a problem hiding this comment.
LGTM, thanks @worksbyfriday . AIUI this is the minimal bit to fix #8523 ; there may be more worth exploring in #1573 , but that's a separate issue!
Replace loose len() check with exact expected sets per reviewer feedback. Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
Good catch! Yes, The test assertion |
|
Ideally the test condition admits all correct answers but not any incorrect ones. The problem with the So, if the only valid mds-es are |
Per rossbar's review: check len(dom_set) == 2 combined with
is_dominating_set to admit all valid minimum dominating sets
({i, j} where i from K5 and j from {5, 6}) without admitting
incorrect answers. Updated comment to list more examples.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
Updated — the assertion now checks The valid MDS-es are exactly |
|
Okay I'll stop arguing with the robots now - in this goes! |
Summary
The greedy cost function in
min_weighted_dominating_setdivided bylen(neighborhood - dom_set), which only excludes nodes already in the dominating set. It should divide by the number of uncovered nodes that would be newly covered:len(neighborhood & vertices).A node can be dominated (covered) by being adjacent to a dom_set member without being in dom_set itself. The old cost function didn't account for this, causing the algorithm to overestimate the value of nodes whose neighborhoods were already mostly dominated.
Before (buggy):
After (fixed):
Also adds a zero-division guard for nodes whose entire neighborhood is already dominated, and updates the docstring example.
Fixes #8523.