Skip to content

Fix #412: Add ShortestCommonSupersequence model#627

Merged
GiggleLiu merged 11 commits intomainfrom
issue-412-shortest-common-supersequence
Mar 13, 2026
Merged

Fix #412: Add ShortestCommonSupersequence model#627
GiggleLiu merged 11 commits intomainfrom
issue-412-shortest-common-supersequence

Conversation

@zazabap
Copy link
Copy Markdown
Collaborator

@zazabap zazabap commented Mar 13, 2026

Summary

  • Add the Shortest Common Supersequence (SCS) satisfaction problem model
  • SCS asks: given strings R over alphabet Sigma and bound K, does a string w of length <= K exist containing all strings as subsequences?
  • Classic NP-complete problem from Garey & Johnson (A4 SR8) with applications in bioinformatics and data compression

Fixes #412

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.83%. Comparing base (fa0e238) to head (baa2a98).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #627      +/-   ##
==========================================
+ Coverage   96.82%   96.83%   +0.01%     
==========================================
  Files         238      240       +2     
  Lines       31129    31242     +113     
==========================================
+ Hits        30140    30254     +114     
+ Misses        989      988       -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.

@zazabap
Copy link
Copy Markdown
Collaborator Author

zazabap commented Mar 13, 2026

Implementation Summary

Changes

  • src/models/misc/shortest_common_supersequence.rs — New satisfaction problem model with evaluate() using greedy subsequence matching
  • src/unit_tests/models/misc/shortest_common_supersequence.rs — 10 unit tests (basic, evaluate yes/no, out-of-range, wrong length, brute force, serialization, empty instance, unsatisfiable, single string)
  • src/models/misc/mod.rs, src/models/mod.rs — Module registration
  • problemreductions-cli/src/dispatch.rs — Load/serialize dispatch
  • problemreductions-cli/src/problem_name.rs — Alias "scs" + "shortestcommonsupersequence"
  • problemreductions-cli/src/commands/create.rspred create SCS --strings "0,1,2;1,2,0" --bound 4 with optional --alphabet-size
  • problemreductions-cli/src/cli.rs — CLI flags (--strings, --bound, --alphabet-size)
  • docs/paper/reductions.typ — Problem definition with formal definition, background, and example figure
  • docs/paper/references.bib — Maier 1978 + Raiha & Ukkonen 1981 citations

Deviations from Plan

  • Added --alphabet-size optional CLI flag (not in original plan; identified during review to avoid silent inference issues)
  • Documentation says "exactly B" rather than "at most B" since the config space is fixed at bound positions

Open Questions

  • None

Copy link
Copy Markdown

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 the Shortest Common Supersequence (SCS) satisfaction problem model to the core library, wires it into the CLI (name resolution, dispatch, and pred create), and updates the paper documentation to include the new problem definition and references.

Changes:

  • Introduce ShortestCommonSupersequence model (schema registration, evaluation, variants) plus unit tests.
  • Extend CLI support: alias (SCS), load/serialize dispatch, and pred create flags for constructing instances.
  • Update paper docs (problem definition + bibliography) and apply minor formatting/ordering tweaks in examples.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/models/misc/shortest_common_supersequence.rs New SCS model implementation + schema inventory entry + variant declaration + tests module hook
src/unit_tests/models/misc/shortest_common_supersequence.rs Unit tests covering evaluation, brute force solving, edge cases, and serialization
src/models/misc/mod.rs Registers and re-exports the new misc model module/type
src/models/mod.rs Re-exports ShortestCommonSupersequence at the top-level models module
problemreductions-cli/src/problem_name.rs Adds SCS alias and alias resolution for the new model
problemreductions-cli/src/dispatch.rs Enables CLI load/serialize dispatch for SCS instances
problemreductions-cli/src/commands/create.rs Adds pred create ShortestCommonSupersequence construction from --strings/--bound/--alphabet-size
problemreductions-cli/src/cli.rs Adds new CLI flags (--strings, --bound, --alphabet-size) and mentions SCS in help text
docs/paper/reductions.typ Adds a paper definition block for SCS (incl. explanation + figure)
docs/paper/references.bib Adds Maier (1978) and Räihä & Ukkonen (1981) citations
examples/reduction_binpacking_to_ilp.rs Formatting-only changes
examples/detect_unreachable_from_3sat.rs Formatting-only changes
docs/paper/examples/maximumindependentset_to_maximumclique.json Reorders JSON keys (example formatting)

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

Comment on lines +3 to +7
//! Given a set of strings over an alphabet and a bound `B`, the problem asks
//! whether there exists a common supersequence of length exactly `B`. A string
//! `w` is a supersequence of `s` if `s` is a subsequence of `w` (i.e., `s` can
//! be obtained by deleting zero or more characters from `w`). This problem is
//! NP-hard (Maier, 1978).
Comment on lines +117 to +129
fn dims(&self) -> Vec<usize> {
vec![self.alphabet_size; self.bound]
}

fn evaluate(&self, config: &[usize]) -> bool {
if config.len() != self.bound {
return false;
}
if config.iter().any(|&v| v >= self.alphabet_size) {
return false;
}
self.strings.iter().all(|s| is_subsequence(s, config))
}
crate::variant_params![]
}

fn dims(&self) -> Vec<usize> {
Comment on lines +13 to +24
inventory::submit! {
ProblemSchemaEntry {
name: "ShortestCommonSupersequence",
module_path: module_path!(),
description: "Find a common supersequence of bounded length for a set of strings",
fields: &[
FieldInfo { name: "alphabet_size", type_name: "usize", description: "Size of the alphabet" },
FieldInfo { name: "strings", type_name: "Vec<Vec<usize>>", description: "Input strings over the alphabet {0, ..., alphabet_size-1}" },
FieldInfo { name: "bound", type_name: "usize", description: "Upper bound on supersequence length" },
],
}
}
Comment on lines +475 to +487
let strings: Vec<Vec<usize>> = strings_str
.split(';')
.map(|s| {
s.trim()
.split(',')
.map(|v| {
v.trim()
.parse::<usize>()
.map_err(|e| anyhow::anyhow!("Invalid alphabet index: {}", e))
})
.collect::<Result<Vec<_>>>()
})
.collect::<Result<Vec<_>>>()?;
BMF --matrix (0/1), --rank
CVP --basis, --target-vec [--bounds]
FVS --arcs [--weights] [--num-vertices]
SCS --strings, --bound
zazabap and others added 5 commits March 13, 2026 15:56
Keep both ShortestCommonSupersequence (from PR) and LongestCommonSubsequence,
SubgraphIsomorphism, SubsetSum (from main) in all affected files.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
- Align docs/schema wording: bound is exact config length, equivalent to |w| ≤ B via padding
- Add alphabet_size > 0 validation in constructor
- Handle empty string segments in --strings CLI parsing
- Add --alphabet-size to CLI help text
- Regenerate problem_schemas.json

Co-Authored-By: Claude Opus 4.6 <[email protected]>
- Add ShortestCommonSupersequence to prelude re-exports (was missing unlike
  all other misc models)
- Fix duplicate CLI struct fields (strings, bound) by sharing between LCS/SCS
  and RuralPostman/SCS with i64 type and casts at usage sites

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
@zazabap
Copy link
Copy Markdown
Collaborator Author

zazabap commented Mar 13, 2026

Review Pipeline Report

Check Result
Merge with main 4 conflicts resolved (additive — both branches added new models)
Copilot comments 6 reviewed, all addressed (docs alignment, validation, CLI help, empty strings, schema regen)
Issue/human comments 3 checked, 0 actionable (quality-check bot + implementation summary only)
CI pending (GitHub Actions runners unavailable; local make check passes: fmt + clippy + tests)
Agentic test passed (2 issues found and fixed: missing prelude export, CLI duplicate fields)
Board review-agentic → In Review

Fixes Applied

  1. Merged origin/main — resolved conflicts in mod.rs, dispatch.rs, create.rs, reductions.typ (kept both SCS + LCS/SubgraphIsomorphism/SubsetSum)
  2. Copilot review fixes:
    • Aligned docs/schema wording on bound semantics (exact config length ≡ ≤B via padding)
    • Added alphabet_size > 0 constructor validation
    • Handle empty string segments in --strings CLI parsing
    • Added --alphabet-size to CLI help text
    • Regenerated problem_schemas.json
  3. Agentic test fixes:
    • Added ShortestCommonSupersequence to prelude (was missing unlike all other misc models)
    • Fixed duplicate CLI struct fields (strings, bound) by sharing between LCS/SCS and RuralPostman/SCS

🤖 Generated by review-pipeline

@GiggleLiu GiggleLiu merged commit 3811aff into main Mar 13, 2026
5 checks passed
GiggleLiu added a commit that referenced this pull request Mar 13, 2026
* Add plan for #244: [Model] IsomorphicSpanningTree

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* feat: add IsomorphicSpanningTree satisfaction problem model (#244)

Implements the Isomorphic Spanning Tree decision problem: given a graph G
and a tree T with |V(G)| = |V(T)|, determine if G contains a spanning
tree isomorphic to T. NP-complete (Garey & Johnson ND8).

- Model with SatisfactionProblem (Metric = bool), permutation-based config
- Constructor validates tree connectivity and edge count
- CLI support with --graph and --tree flags
- 11 unit tests covering evaluation, solver, serialization, edge cases

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* chore: remove plan file after implementation

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* Fix #412: Add ShortestCommonSupersequence model (#627)

* Add plan for #412: ShortestCommonSupersequence model

* Implement #412: Add ShortestCommonSupersequence model

* style: apply rustfmt formatting

* Address review: fix docs, add --alphabet-size flag, add edge case tests

* chore: remove plan file after implementation

* Address Copilot review comments

- Align docs/schema wording: bound is exact config length, equivalent to |w| ≤ B via padding
- Add alphabet_size > 0 validation in constructor
- Handle empty string segments in --strings CLI parsing
- Add --alphabet-size to CLI help text
- Regenerate problem_schemas.json

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* Fix agentic test issues: add SCS to prelude, fix CLI duplicate fields

- Add ShortestCommonSupersequence to prelude re-exports (was missing unlike
  all other misc models)
- Fix duplicate CLI struct fields (strings, bound) by sharing between LCS/SCS
  and RuralPostman/SCS with i64 type and casts at usage sites

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* chore: trigger CI

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* style: apply rustfmt formatting

Co-Authored-By: Claude Opus 4.6 <[email protected]>

---------

Co-authored-by: Claude Opus 4.6 <[email protected]>
Co-authored-by: GiggleLiu <[email protected]>

* Fix #507: Add FlowShopScheduling model (#629)

* Add plan for #507: FlowShopScheduling model

* Implement #507: Add FlowShopScheduling model

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* chore: remove plan file after implementation

* fix: address Copilot review comments on FlowShopScheduling

- Switch dims() from vec![n;n] to Lehmer code encoding [n,n-1,...,1]
- Update evaluate() to decode Lehmer code into permutations
- Fix complexity from "3^num_jobs" to "num_jobs^num_jobs"
- Add validation to compute_makespan() for out-of-bounds indices
- Add --num-processors CLI flag instead of overloading --m
- Validate task_lengths row lengths in CLI with bail! instead of panic
- Fix test comment about deadline value

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* docs: add Lehmer code encoding explanation to FlowShopScheduling

Add concrete example of how Lehmer code configs map to job orderings
in the struct doc comment, improving discoverability for new users.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* fix: remove unused enumerate in Lehmer code decoding

Fixes clippy::unused_enumerate_index warning.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* fix: add missing paper section, trait_consistency entry, and correct complexity

- Add FlowShopScheduling problem-def and display-name to docs/paper/reductions.typ
- Add FlowShopScheduling to trait_consistency test
- Fix complexity from "num_jobs^num_jobs" to "factorial(num_jobs)" (n! is the exact search space)
- Relax check_problem_trait assertion from >= 2 to >= 1 (Lehmer code encoding produces trailing dim of 1)

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* docs: add Gantt chart visualization and use issue's 5-job example in paper

Replace the simple 2-machine example with the issue's canonical 3-machine,
5-job example. Add a CeTZ Gantt chart showing the feasible schedule with
job order (j4, j1, j5, j3, j2) achieving makespan 23 within deadline 25.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

---------

Co-authored-by: Claude Opus 4.6 <[email protected]>
Co-authored-by: GiggleLiu <[email protected]>

* Add paper section, trait_consistency entry, and formatting fixes for IsomorphicSpanningTree

- Add display-name and problem-def entry in docs/paper/reductions.typ
  with formal definition, background (Garey & Johnson ND8), and CeTZ figure
- Add bibliography entry for Papadimitriou & Yannakakis 1982
- Add check_problem_trait for IsomorphicSpanningTree in trait_consistency.rs
- Apply cargo fmt formatting fixes from merge

Co-Authored-By: Claude Opus 4.6 <[email protected]>

---------

Co-authored-by: Claude Opus 4.6 <[email protected]>
Co-authored-by: GiggleLiu <[email protected]>
@GiggleLiu GiggleLiu deleted the issue-412-shortest-common-supersequence branch April 12, 2026 00:53
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] ShortestCommonSupersequence

3 participants