Skip to content

Fix #209: [Model] MinimumHittingSet#720

Merged
GiggleLiu merged 9 commits intomainfrom
issue-209
Mar 21, 2026
Merged

Fix #209: [Model] MinimumHittingSet#720
GiggleLiu merged 9 commits intomainfrom
issue-209

Conversation

@GiggleLiu
Copy link
Copy Markdown
Contributor

Summary

Add the plan and implementation for MinimumHittingSet, the set-based optimization model requested in issue #209.

Fixes #209

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 21, 2026

Codecov Report

❌ Patch coverage is 99.46524% with 1 line in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@accbb66). Learn more about missing BASE report.
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/models/set/minimum_hitting_set.rs 98.80% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #720   +/-   ##
=======================================
  Coverage        ?   97.60%           
=======================================
  Files           ?      397           
  Lines           ?    49354           
  Branches        ?        0           
=======================================
  Hits            ?    48171           
  Misses          ?     1183           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 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.

@GiggleLiu
Copy link
Copy Markdown
Contributor Author

Implemented MinimumHittingSet for issue #209.

What changed:

  • added the new optimization model with catalog metadata, example-db entry, and prelude/catalog registration
  • wired problemreductions-cli create MinimumHittingSet with --universe and --sets
  • documented the model in the paper with a rendered example and background references
  • added compiled unit and CLI coverage, including normalization, invalid-element rejection, metadata checks, and canonical example consistency

Verification:

  • make test
  • make clippy
  • make paper

Plan deviation:

  • I did not keep the planned edits to the global problem_size / trait-consistency test files. Those harnesses are currently stale or not exercised cleanly, so I moved the relevant coverage into active MinimumHittingSet tests instead.
  • No manual problem_name alias change was needed because the CLI uses the registry metadata directly.

@GiggleLiu
Copy link
Copy Markdown
Contributor Author

Agentic Review Report

Structural Check

Structural Review: model MinimumHittingSet

Structural Completeness

# Check Status
1 Model file exists PASS — src/models/set/minimum_hitting_set.rs
2 inventory::submit! present PASS — schema and size-field registrations are present in src/models/set/minimum_hitting_set.rs
3 Serialize / Deserialize derive on struct PASS — MinimumHittingSet derives both in src/models/set/minimum_hitting_set.rs:37
4 Problem trait impl PASS — implemented in src/models/set/minimum_hitting_set.rs:114
5 OptimizationProblem or SatisfactionProblem impl PASS — OptimizationProblem is implemented in src/models/set/minimum_hitting_set.rs:143
6 #[cfg(test)] + #[path = ...] test link PASS — present in src/models/set/minimum_hitting_set.rs:176
7 Test file exists PASS — src/unit_tests/models/set/minimum_hitting_set.rs
8 Test file has >= 3 test functions PASS — 10 test functions in src/unit_tests/models/set/minimum_hitting_set.rs
9 Registered in category mod.rs PASS — src/models/set/mod.rs:16 and src/models/set/mod.rs:27
10 Re-exported in models/mod.rs PASS — src/models/mod.rs:43
11 declare_variants! entry exists PASS — default opt MinimumHittingSet => "2^universe_size" in src/models/set/minimum_hitting_set.rs:151
12 CLI alias resolution coverage PASS — problemreductions-cli/src/problem_name.rs:16 resolves names via registry metadata; this model does not require a hand-written alias arm
13 CLI create support PASS — create arm and help text are present in problemreductions-cli/src/commands/create.rs:1733 and problemreductions-cli/src/cli.rs:243
14 Canonical model example registered PASS — canonical_model_example_specs() exists in src/models/set/minimum_hitting_set.rs:155 and is chained from src/models/set/mod.rs:35
15 Paper display-name entry PASS — docs/paper/reductions.typ:85
16 Paper problem-def block PASS — docs/paper/reductions.typ:1819
17 Changed files within model PR whitelist FAIL — current model whitelist excludes problemreductions-cli/src/cli.rs, problemreductions-cli/src/commands/create.rs, problemreductions-cli/tests/cli_tests.rs, and src/lib.rs
18 No blacklisted autogenerated files committed PASS — none of the forbidden generated files appear in the diff

Build Status

  • make test: PASS
  • make clippy: PASS

Semantic Review

  • evaluate() correctness: OK — invalid config length/value returns SolutionSize::Invalid, and valid solutions are exactly configurations whose selected universe elements hit every set (src/models/set/minimum_hitting_set.rs:122)
  • dims() correctness: OK — binary config space is vec![2; universe_size] (src/models/set/minimum_hitting_set.rs:118)
  • Size getter consistency: OK — universe_size(), num_sets(), and complexity string 2^universe_size line up with the declared size fields (src/models/set/minimum_hitting_set.rs:65, src/models/set/minimum_hitting_set.rs:71, src/models/set/minimum_hitting_set.rs:151)
  • Weight handling: OK / N/A — this is an unweighted set-system model and does not misuse weight traits

Issue Compliance (linked issue #209)

# Check Status
1 Problem name matches issue OK — MinimumHittingSet
2 Mathematical definition matches OK — minimum-cardinality subset of universe elements hitting every set
3 Problem type (opt/sat) matches OK — optimization framing matches the updated linked issue
4 Type parameters match OK — none
5 Configuration space matches OK — one binary variable per universe element
6 Feasibility check matches OK — every set must contain at least one selected element
7 Objective function matches OK — minimize the number of selected elements
8 Complexity matches OK — declare_variants! uses "2^universe_size" as requested

Summary

  • 17/18 structural checks passed
  • 8/8 issue compliance checks passed
  • FAIL — deterministic model-PR whitelist excludes the CLI/prelude exposure files touched by this PR: problemreductions-cli/src/cli.rs, problemreductions-cli/src/commands/create.rs, problemreductions-cli/tests/cli_tests.rs, src/lib.rs

Quality Check

Quality Review

Design Principles

  • DRY: ISSUE — MinimumHittingSet repeats the same “selected elements hit every set” predicate in both is_valid_solution and evaluate, so any future semantic change has to stay synchronized in two places (src/models/set/minimum_hitting_set.rs:103, src/models/set/minimum_hitting_set.rs:122).
  • KISS: OK — The model implementation is straightforward and avoids unnecessary abstraction.
  • HC/LC: ISSUE — the new create arm embeds its own universe-bounds validation inside the already-large dispatcher instead of delegating to a shared set-system validator, which increases coupling between CLI parsing and model invariants (problemreductions-cli/src/commands/create.rs:1734, problemreductions-cli/src/commands/create.rs:1758).

HCI (if CLI/MCP changed)

  • Error messages: ISSUE — missing --universe gets a problem-specific usage block, but missing --sets falls through to the generic parser message, so the same command has two different required-flag UX paths (problemreductions-cli/src/commands/create.rs:1735, problemreductions-cli/src/commands/create.rs:3809).
  • Discoverability: OK — the help text was updated so MinimumHittingSet appears in pred create --help with the right flags (problemreductions-cli/src/cli.rs:243).
  • Consistency: ISSUE — MinimumHittingSet now rejects out-of-range set elements, while the adjacent MinimumSetCovering path with the same --universe/--sets contract still accepts them, so sibling set-system commands behave differently on the same malformed input (problemreductions-cli/src/commands/create.rs:1742, problemreductions-cli/src/commands/create.rs:1758).
  • Least surprise: OK — the success path emits the expected JSON shape for the new model.
  • Feedback: OK — the rejection path names the offending set element and universe size, which is actionable (problemreductions-cli/src/commands/create.rs:1745).

Test Quality

  • Naive test detection: ISSUE
  • The new CLI tests cover happy-path creation, out-of-range rejection, and help text, but they do not exercise the two required-flag omission paths, so the asymmetric error handling above can regress unnoticed (problemreductions-cli/tests/cli_tests.rs:1425, problemreductions-cli/src/commands/create.rs:1735, problemreductions-cli/src/commands/create.rs:3809).
  • The paper/example tests do not pin the actual set family shown in the new Typst entry: they check the optimum value, universe size, set count, and optimal config, but not the concrete sets rendered in the paper, so doc/example drift can still slip through green tests (src/unit_tests/models/set/minimum_hitting_set.rs:110, src/unit_tests/models/set/minimum_hitting_set.rs:134, docs/paper/reductions.typ:1798).

Issues

Critical (Must Fix)

None.

Important (Should Fix)

  • The PR adds bespoke universe-bounds validation for MinimumHittingSet, but leaves the neighboring MinimumSetCovering path on the same --universe/--sets interface unvalidated. That makes sibling set-system commands disagree on malformed input and is a good place to extract/apply a shared validator (problemreductions-cli/src/commands/create.rs:1734, problemreductions-cli/src/commands/create.rs:1758).
  • The new tests do not actually lock the Typst example to the canonical set family they are meant to protect, so the paper entry can drift while the suite stays green (src/unit_tests/models/set/minimum_hitting_set.rs:110, src/unit_tests/models/set/minimum_hitting_set.rs:134, docs/paper/reductions.typ:1798).

Minor (Nice to Have)

  • MinimumHittingSet duplicates its hit-all-sets predicate between is_valid_solution and evaluate, which is small but unnecessary maintenance duplication (src/models/set/minimum_hitting_set.rs:103, src/models/set/minimum_hitting_set.rs:122).
  • The new CLI coverage misses the --sets-missing path, and the user-facing message on that path is less specific than the --universe-missing path (problemreductions-cli/src/commands/create.rs:1735, problemreductions-cli/src/commands/create.rs:3809, problemreductions-cli/tests/cli_tests.rs:1425).

Summary

  • Important: The new MinimumHittingSet CLI arm introduces one-off universe validation instead of a shared set-system validator, leaving adjacent commands inconsistent on the same malformed input.
  • Important: The new paper/example tests are too shallow to guarantee the Typst example still matches the canonical set family.
  • Minor: MinimumHittingSet repeats the same hit-check logic in two methods.
  • Minor: Required-flag error UX for pred create MinimumHittingSet is asymmetric and untested.

Agentic Feature Tests

MinimumHittingSet downstream CLI test: exercised pred list, pred show MinimumHittingSet, pred create --example MinimumHittingSet, pred create MinimumHittingSet --universe ... --sets ..., and solving the resulting instance in the current worktree.

  • Discoverability: pred list includes MinimumHittingSet as a default catalog entry. pred show MinimumHittingSet works and clearly shows the description, fields (universe_size, sets), and that the model has no registered reductions. pred create MinimumHittingSet with no data flags also prints the expected --universe / --sets parameter help.
  • Setup: Passed in the current worktree using the built CLI. No extra setup or hidden repo knowledge was needed.
  • Functionality: pred create --example MinimumHittingSet succeeds and emits valid JSON. pred create MinimumHittingSet --universe 6 --sets "0,1,2;0,3,4;1,3,5;2,4,5;0,1,5;2,3;1,4" also succeeds and matches the canonical example instance. Solving succeeds with pred solve ... --solver brute-force, returning Valid(3).
  • Expected vs Actual: Discovery and instance creation matched expectations. The first obvious solve attempt, pred create --example MinimumHittingSet | pred solve -, does not work on the default solver path because there is no reduction path to ILP. The CLI does suggest --solver brute-force, and that recovery path works immediately.
  • Blocked steps: None intentionally blocked; all required commands were runnable in read-only mode.
  • Friction: A downstream user can finish the flow, but only after one failed default pred solve attempt. pred show MinimumHittingSet does not surface solver guidance even though pred path MinimumHittingSet ILP confirms there is no ILP path.
  • Doc suggestions: Add a MinimumHittingSet CLI example that includes --solver brute-force, or surface a “no ILP path; use brute-force” hint in pred show or problem-specific create help.

Issues:

  • confirmed: The default solve flow for MinimumHittingSet is not seamless. pred create --example MinimumHittingSet | pred solve - fails with No reduction path from MinimumHittingSet to ILP ... Try --solver brute-force. Retrying with --solver brute-force succeeds in the current worktree.
  • not reproducible in current worktree: None from this run.

Generated by review-pipeline

@GiggleLiu
Copy link
Copy Markdown
Contributor Author

Structural follow-up: the delayed /review-structural report materially changes one point from the combined comment above.

  • MinimumHittingSet passed all 19 structural checks and 8/8 issue-compliance checks.
  • make test and make clippy both passed in the review worktree.
  • The review packet's whitelist failure appears to be tooling drift, not a defect in this PR: the flagged files are the expected CLI/help/tests/prelude touches for exposing a new model (problemreductions-cli/src/cli.rs, problemreductions-cli/src/commands/create.rs, problemreductions-cli/tests/cli_tests.rs, src/lib.rs).

So the structural read is: no blocking structural findings in this PR.

@GiggleLiu GiggleLiu merged commit 77577dd into main Mar 21, 2026
3 checks passed
@GiggleLiu GiggleLiu mentioned this pull request Mar 21, 2026
3 tasks
@GiggleLiu GiggleLiu deleted the issue-209 branch April 12, 2026 00:51
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.

[Model] MinimumHittingSet

1 participant