Fix #108: Add LongestCommonSubsequence model#170
Fix #108: Add LongestCommonSubsequence model#170zazabap wants to merge 4 commits intoCodingThrust:mainfrom
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Implement the k-string Longest Common Subsequence problem: - Model in src/models/misc/ with binary config over shortest string - 14 unit tests (creation, evaluation, brute force, serialization) - CLI dispatch and LCS alias - Registered in module tree and prelude Closes CodingThrust#108 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add problem-def entry with formal definition, background, and example - Add display-name entry - Add bibliography entries for Maier 1978 and Wagner & Fischer 1974 - Update reduction_graph.json and problem_schemas.json Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Change declare_variants! from 2^total_length to 2^min_string_length (actual brute-force enumerates subsequences of shortest string) - Make min_string_length() public getter (was private shortest_len) - Add #[should_panic] test for empty input - Add edge-case test for empty string in input - Fix paper text to reference shortest string length, not total Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR adds a new LongestCommonSubsequence (LCS) problem model to the problemreductions crate, implementing issue #108. The model represents the NP-hard k-string LCS problem where the configuration space is binary selection over characters of the shortest input string. The brute-force solver enumerates all 2^m subsequences of the shortest string and checks each against all other strings.
Changes:
- New model file with struct,
Problem/OptimizationProblemtrait implementations, schema registration, anddeclare_variants!macro - CLI dispatch support with
LCSalias, module tree registration, and prelude exports - 14 unit tests, paper documentation with figure, bibliography entries, and auto-generated JSON updates
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/models/misc/longest_common_subsequence.rs |
Core model: struct, constructor, evaluate, is_subsequence helper, variant declaration |
src/unit_tests/models/misc/longest_common_subsequence.rs |
14 unit tests covering creation, evaluation, brute-force, serialization, edge cases |
src/models/misc/mod.rs |
Register new module and re-export |
src/models/mod.rs |
Add LongestCommonSubsequence to public re-exports |
src/lib.rs |
Add to prelude; cosmetic consolidation of pub use statements |
problemreductions-cli/src/dispatch.rs |
Add LCS to load_problem() and serialize_any_problem() |
problemreductions-cli/src/problem_name.rs |
Add LCS alias and case-insensitive resolution |
docs/src/reductions/reduction_graph.json |
Add LCS node and bump edge indices |
docs/src/reductions/problem_schemas.json |
Add LCS schema entry |
docs/paper/reductions.typ |
Add problem definition, description, and figure |
docs/paper/references.bib |
Add Maier 1978 and Wagner & Fischer 1974 references |
docs/plans/2026-03-04-longest-common-subsequence.md |
Development plan document |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "variant": {}, | ||
| "category": "misc", | ||
| "doc_path": "models/misc/struct.LongestCommonSubsequence.html", | ||
| "complexity": "2^total_length" |
There was a problem hiding this comment.
The complexity field here is "2^total_length" but the declare_variants! macro in the source code specifies "2^min_string_length" (line 165 of src/models/misc/longest_common_subsequence.rs). Since this JSON is auto-generated by export_graph, it appears to be out of sync with the code. The code is correct (brute-force enumerates 2^m subsequences of the shortest string, not 2^total_length), so the JSON should be regenerated to reflect "2^min_string_length".
| "complexity": "2^total_length" | |
| "complexity": "2^min_string_length" |
| // Problem types | ||
| pub use crate::models::algebraic::{BMF, QUBO}; | ||
| pub use crate::models::formula::{CNFClause, CircuitSAT, KSatisfiability, Satisfiability}; | ||
| pub use crate::models::graph::{BicliqueCover, SpinGlass}; | ||
| pub use crate::models::graph::{ | ||
| KColoring, MaxCut, MaximalIS, MaximumClique, MaximumIndependentSet, MaximumMatching, | ||
| MinimumDominatingSet, MinimumVertexCover, TravelingSalesman, | ||
| }; | ||
| pub use crate::models::misc::{BinPacking, Factoring, PaintShop}; | ||
| pub use crate::models::set::{MaximumSetPacking, MinimumSetCovering}; | ||
|
|
||
| // Core traits | ||
| pub use crate::rules::{ReduceTo, ReductionResult}; | ||
| pub use crate::solvers::{BruteForce, Solver}; | ||
| pub use crate::traits::{OptimizationProblem, Problem, SatisfactionProblem}; | ||
|
|
||
| // Types |
There was a problem hiding this comment.
The comments // Problem types and // Types on lines 38-39 are now orphaned/misleading after the pub use consolidation. // Problem types has no corresponding import directly below it, and // Types precedes the error types import but the actual type imports are now inside the combined use block (line 57). Consider removing these stale section comments since the consolidated use block makes them unnecessary.
Summary
LongestCommonSubsequenceproblem model insrc/models/misc/LCSaliasCloses #108
Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com