Skip to content

Fix #400: [Model] SetBasis#661

Merged
zazabap merged 6 commits intomainfrom
issue-400-setbasis
Mar 16, 2026
Merged

Fix #400: [Model] SetBasis#661
zazabap merged 6 commits intomainfrom
issue-400-setbasis

Conversation

@GiggleLiu
Copy link
Contributor

@GiggleLiu GiggleLiu commented Mar 16, 2026

Summary

Implement the SetBasis model and wire it through the library, CLI, docs, and example fixtures for issue #400.

Fixes #400

@codecov
Copy link

codecov bot commented Mar 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.94%. Comparing base (9a2b2b7) to head (a38421d).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #661      +/-   ##
==========================================
+ Coverage   96.92%   96.94%   +0.01%     
==========================================
  Files         271      273       +2     
  Lines       36298    36505     +207     
==========================================
+ Hits        35182    35388     +206     
- Misses       1116     1117       +1     

☔ 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
Contributor Author

Implementation Summary

Changes

  • Added src/models/set/set_basis.rs and src/unit_tests/models/set/set_basis.rs to implement and test the new SetBasis satisfaction model, plus registry wiring in src/models/set/mod.rs, src/models/mod.rs, src/lib.rs, and src/unit_tests/trait_consistency.rs.
  • Added CLI creation support in problemreductions-cli/src/commands/create.rs, problemreductions-cli/src/cli.rs, and regression coverage in problemreductions-cli/tests/cli_tests.rs.
  • Updated docs and generated artifacts in docs/paper/reductions.typ, docs/paper/references.bib, docs/src/reductions/problem_schemas.json, docs/src/reductions/reduction_graph.json, and src/example_db/fixtures/examples.json.

Deviations from Plan

  • The issue's example instance has 12 satisfying encodings rather than 6. Implementation and tests found two distinct valid 3-set bases ({0},{1},{2} and {0,1},{1,2},{0,2}), each with 3! row permutations, so the example expectations were updated to match the actual model semantics.

Open Questions

  • None.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds first-class support for the SetBasis NP-complete set problem across the library (model implementation, registry/docs schema export), CLI creation flow, and canonical examples—addressing issue #400.

Changes:

  • Introduces SetBasis model with brute-force-friendly boolean encoding and registers it via ProblemSchemaEntry + declare_variants!.
  • Adds unit tests (model behavior, brute-force satisfiable set, serde roundtrip) and integrates SetBasis into trait-consistency checks.
  • Extends CLI pred create to construct SetBasis instances; regenerates fixtures and docs JSON/typst content to include the new model.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/models/set/set_basis.rs New SetBasis model implementation + schema registration + variant declaration + example-db spec
src/models/set/mod.rs Exposes set_basis module and includes example-db specs
src/models/mod.rs Re-exports SetBasis from models::set
src/lib.rs Adds SetBasis to the public prelude
src/unit_tests/models/set/set_basis.rs New unit test coverage for SetBasis semantics/serialization/solver
src/unit_tests/trait_consistency.rs Adds SetBasis to trait consistency checks
problemreductions-cli/src/commands/create.rs Adds pred create SetBasis ... support + help example string
problemreductions-cli/src/cli.rs Documents SetBasis CLI flags and adds an example invocation
problemreductions-cli/tests/cli_tests.rs Adds CLI tests for creating SetBasis and missing --k handling
src/example_db/fixtures/examples.json Adds SetBasis canonical example; fixture regeneration updates other entries
docs/src/reductions/problem_schemas.json Adds generated schema entry for SetBasis
docs/src/reductions/reduction_graph.json Adds SetBasis node (and index shifts from regeneration)
docs/paper/references.bib Adds Stockmeyer 1975 tech report reference
docs/paper/reductions.typ Adds SetBasis section/definition/example + mapping entry

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +128 to +139
fn can_represent_target(basis: &[Vec<usize>], target: &[usize], universe_size: usize) -> bool {
let mut covered = vec![false; universe_size];
for subset in basis {
if Self::is_subset(subset, target) {
for &element in subset {
covered[element] = true;
}
}
}

target.iter().all(|&element| covered[element])
}
#[test]
fn test_set_basis_rejects_wrong_config_length() {
let problem = issue_example_problem(3);
assert!(!problem.evaluate(&canonical_solution()[..11]));
Comment on lines +1 to +6
//! Set Basis problem implementation.
//!
//! Given a collection of sets over a finite universe and an integer `k`,
//! determine whether there exist `k` basis sets such that every target set
//! can be reconstructed as a union of some subcollection of the basis.

GiggleLiu and others added 2 commits March 16, 2026 20:38
- harden SetBasis evaluation against malformed serialized input
- validate SetBasis CLI subsets before construction
- align problem-specific create help with actual CLI flags
Add targeted tests for uncovered code paths:
- is_subset returning false (basis set not subset of target)
- is_valid_solution wrapper method
- k=0 with empty/non-empty collection (edge cases)
- Empty collection with k > 0 (trivially satisfiable)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Collaborator

@zazabap zazabap left a comment

Choose a reason for hiding this comment

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

Final review passed — all CI green, coverage fixed, quality ~85%.

@zazabap zazabap merged commit 54e54c2 into main Mar 16, 2026
5 checks passed
@zazabap zazabap deleted the issue-400-setbasis branch March 16, 2026 13:25
@zazabap zazabap restored the issue-400-setbasis branch March 16, 2026 13:43
zazabap added a commit that referenced this pull request Mar 16, 2026
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] SetBasis

3 participants