Skip to content

Fix #108: Add LongestCommonSubsequence model#170

Open
zazabap wants to merge 4 commits intoCodingThrust:mainfrom
zazabap:issue-108-longest-common-subsequence
Open

Fix #108: Add LongestCommonSubsequence model#170
zazabap wants to merge 4 commits intoCodingThrust:mainfrom
zazabap:issue-108-longest-common-subsequence

Conversation

@zazabap
Copy link
Collaborator

@zazabap zazabap commented Mar 4, 2026

Summary

  • Add LongestCommonSubsequence problem model in src/models/misc/
  • Binary config space over shortest string characters; feasibility checks subsequence property against all strings
  • 14 unit tests covering creation, evaluation, brute force solver, serialization
  • CLI dispatch with LCS alias
  • Registered in module tree and prelude

Closes #108

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

zazabap and others added 4 commits March 4, 2026 18:33
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>
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

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/OptimizationProblem trait implementations, schema registration, and declare_variants! macro
  • CLI dispatch support with LCS alias, 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"
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

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

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".

Suggested change
"complexity": "2^total_length"
"complexity": "2^min_string_length"

Copilot uses AI. Check for mistakes.
Comment on lines 38 to 39
// 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
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
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] LongestCommonSubsequence

2 participants