Skip to content

Add variant-level aliases; introduce 2SAT and 3SAT#1054

Merged
GiggleLiu merged 3 commits intomainfrom
variant-aliases
Apr 17, 2026
Merged

Add variant-level aliases; introduce 2SAT and 3SAT#1054
GiggleLiu merged 3 commits intomainfrom
variant-aliases

Conversation

@GiggleLiu
Copy link
Copy Markdown
Contributor

Summary

Aliases in this codebase used to resolve only to a canonical problem name, never to a specific variant. That forced 3SAT to be excluded as an alias (see the old comment at problem_name.rs), because a plain alias 3SAT → KSatisfiability would silently give users the default variant KN, not K3.

This PR makes aliases a first-class per-variant concept so shorthand like 3SAT lines up with the actual reduction-graph node (KSatisfiability<K3>), not just the problem type. Problem-level aliases (MIS, SAT, MVC, MAX2SAT, ...) are unchanged.

What changes

  • VariantEntry gains aliases: &'static [&'static str].
  • declare_variants! accepts optional trailing aliases ["X", ...]:
    KSatisfiability<K2> => "num_variables + num_clauses" aliases ["2SAT"],
    KSatisfiability<K3> => "1.307^num_variables" aliases ["3SAT"],
  • registry::find_variant_by_alias(input) -> Option<(&VariantEntry, BTreeMap<_, _>)>
    — returns the matched entry and its variant map.
  • CLI parse_problem_spec and resolve_alias try variant-level aliases first,
    injecting the alias's variant tokens into the parsed spec. Problem-level alias
    resolution is untouched.
  • pred list shows variant-level aliases on their own rows (e.g., KSatisfiability/K2 shows 2SAT, KSatisfiability/K3 shows 3SAT).

Scope

Only the three aliases the user asked for: 2SAT, 3SAT, MAX2SAT. MAX2SAT was already a problem-level alias on the standalone Maximum2Satisfiability type and is left untouched. No other aliases changed.

End-to-end verification

$ pred show 3SAT   → KSatisfiability/K3 (Best Known Complexity: O(1.307^num_variables))
$ pred show 2SAT   → KSatisfiability/K2 (Best Known Complexity: O(num_clauses + num_variables))
$ pred show MAX2SAT → Maximum2Satisfiability (unchanged)
$ pred path 3SAT MaximumIndependentSet → 3-step path starting from KSatisfiability/K3

Test plan

  • cargo fmt --check
  • cargo clippy --all-targets --features ilp-highs -- -D warnings
  • make test (5092 unit tests + all integration/doc tests pass)
  • End-to-end: pred show {3SAT,2SAT,MAX2SAT} resolve correctly
  • End-to-end: pred path 3SAT MaximumIndependentSet finds a path from K3
  • End-to-end: pred list shows 2SAT/3SAT on the correct variant rows

🤖 Generated with Claude Code

Variant-level aliases attach to a specific reduction-graph node rather
than a canonical problem name, so shorthand like `3SAT` can resolve to
`KSatisfiability<K3>` directly instead of going through the problem's
default variant (which is `KN`, not what `3SAT` means in the literature).

- `VariantEntry` gains an `aliases: &'static [&'static str]` field.
- `declare_variants!` accepts optional `aliases ["X", ...]` trailing each
  entry and emits the field.
- `registry::find_variant_by_alias()` returns both the entry and its
  variant map.
- CLI `parse_problem_spec` and `resolve_alias` try variant-level aliases
  before problem-level ones, injecting the alias's variant tokens into
  the spec; problem-level resolution is unchanged for `MIS`, `SAT`, etc.
- Adds `2SAT` on `KSatisfiability<K2>` and `3SAT` on `KSatisfiability<K3>`.
- `pred list` now shows variant-level aliases on their own rows.
- `MAX2SAT` remains a problem-level alias on `Maximum2Satisfiability`
  (standalone problem, no variants).

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

codecov bot commented Apr 16, 2026

Codecov Report

❌ Patch coverage is 98.13665% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.92%. Comparing base (e38b1b5) to head (de23124).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/unit_tests/registry/variant.rs 96.34% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1054      +/-   ##
==========================================
- Coverage   97.94%   97.92%   -0.03%     
==========================================
  Files         979      964      -15     
  Lines      100890    99869    -1021     
==========================================
- Hits        98816    97793    -1023     
- Misses       2074     2076       +2     

☔ 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 and others added 2 commits April 16, 2026 22:11
Refactor validation into a testable `validate_aliases_inner` that accepts
mock data, so every conflict branch (empty alias, canonical-name collision,
problem-alias collision, duplicate variant alias, multi-conflict) is
exercised without depending on inventory state. Also test `variant_label`
with both empty and non-empty variant dimensions.

Patch coverage: 15 uncovered lines → ~2 (the inventory integration test
panic branch, which is inherently unreachable on a healthy codebase).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@GiggleLiu GiggleLiu merged commit d4060d6 into main Apr 17, 2026
5 checks passed
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