Skip to content

Fix #439: Add StringToStringCorrection model#675

Merged
isPANN merged 9 commits intomainfrom
issue-439-string-to-string-correction
Mar 18, 2026
Merged

Fix #439: Add StringToStringCorrection model#675
isPANN merged 9 commits intomainfrom
issue-439-string-to-string-correction

Conversation

@GiggleLiu
Copy link
Copy Markdown
Contributor

Summary

Add the StringToStringCorrection problem model — a classical NP-complete satisfaction problem from Garey & Johnson (A4 SR20) concerning minimum-cost string transformation using only deletions and adjacent swaps.

Fixes #439

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.16%. Comparing base (6d2981d) to head (0db6b71).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #675      +/-   ##
==========================================
+ Coverage   97.15%   97.16%   +0.01%     
==========================================
  Files         300      302       +2     
  Lines       39753    39923     +170     
==========================================
+ Hits        38621    38791     +170     
  Misses       1132     1132              

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

Add the String-to-String Correction satisfaction problem (Garey & Johnson
SR20). Given source/target strings and bound K, determine if the target
can be derived from the source using at most K deletions and adjacent swaps.

- Model: src/models/misc/string_to_string_correction.rs
- Tests: 11 unit tests + 1 doctest (creation, evaluation, solver, paper example)
- CLI: --source-string, --target-string, --bound, --alphabet-size flags
- Paper: problem-def with figure, Wagner 1974/1975 references
- Example-db: canonical instance with 2 satisfying solutions
@GiggleLiu
Copy link
Copy Markdown
Contributor Author

Implementation Summary

Changes

  • New: src/models/misc/string_to_string_correction.rs — Model implementation (struct, constructor, Problem/SatisfactionProblem traits, declare_variants!, canonical example, ProblemSchemaEntry)
  • New: src/unit_tests/models/misc/string_to_string_correction.rs — 11 unit tests (creation, evaluation, invalid ops, invalid-after-deletion, serialization, solver, paper example, unsatisfiable, identity, empty strings, delete-only)
  • Modified: src/models/misc/mod.rs, src/models/mod.rs — Module registration and re-export
  • Modified: src/unit_tests/trait_consistency.rs — Added check_problem_trait entry
  • Modified: problemreductions-cli/src/cli.rs — Added --source-string, --target-string flags
  • Modified: problemreductions-cli/src/commands/create.rs — Added StringToStringCorrection creation support
  • Modified: docs/paper/reductions.typ — Display name + problem-def with figure showing operation trace
  • Modified: docs/paper/references.bib — Added Wagner 1974, 1975 references
  • Regenerated: src/example_db/fixtures/examples.json, docs/src/reductions/problem_schemas.json, docs/src/reductions/reduction_graph.json

Deviations from Plan

  • None

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 a new NP-complete satisfaction problem model, StringToStringCorrection, to the problemreductions model registry and CLI, including examples and documentation updates, to address issue #439.

Changes:

  • Introduce StringToStringCorrection model with schema registration, variant declaration, evaluation logic, and example-db spec.
  • Add unit tests and example fixtures for the new model.
  • Integrate the model into the CLI (pred create) and regenerate docs JSON + paper references/definition section.

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/string_to_string_correction.rs New model implementation, schema registration, variant declaration, and example-db spec
src/models/misc/mod.rs Export and include the new misc model + example-db spec aggregation
src/models/mod.rs Re-export StringToStringCorrection from the top-level models module
src/unit_tests/models/misc/string_to_string_correction.rs New unit tests covering creation, evaluation, invalid ops, serialization, and brute-force solving
src/unit_tests/trait_consistency.rs Add trait consistency check coverage for the new model
src/example_db/fixtures/examples.json Add example instance + sample/optimal configs for StringToStringCorrection
problemreductions-cli/src/cli.rs Add --source-string / --target-string flags and update help text
problemreductions-cli/src/commands/create.rs Add pred create StringToStringCorrection ... parsing and example string
docs/src/reductions/problem_schemas.json Add generated schema entry for the new model
docs/src/reductions/reduction_graph.json Add generated graph node entry for the new model and adjust indices
docs/paper/references.bib Add Wagner (1974/1975) references used by the paper
docs/paper/reductions.typ Add paper definition + example figure block for String-to-String Correction

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

Comment on lines +1415 to +1417
let bound_k = args.bound.ok_or_else(|| {
anyhow::anyhow!("StringToStringCorrection requires --bound\n\n{usage}")
})? as usize;
if config.iter().any(|&v| v >= domain) {
return false;
}
let noop = 2 * n;
…39-string-to-string-correction

# Conflicts:
#	docs/src/reductions/problem_schemas.json
#	docs/src/reductions/reduction_graph.json
#	problemreductions-cli/src/commands/create.rs
#	src/models/mod.rs
#	src/unit_tests/trait_consistency.rs
- reject negative StringToStringCorrection bounds in CLI creation
- tighten model pruning and add integration coverage for help/create/solve flows
- align StringToStringCorrection help and docs with brute-force solver usage
@GiggleLiu
Copy link
Copy Markdown
Contributor Author

Agentic Review Report

Structural Check

# Check Status
1 Model file exists (src/models/misc/string_to_string_correction.rs) PASS
2 inventory::submit! present PASS
3 #[derive(...Serialize, Deserialize)] on struct PASS
4 Problem trait impl PASS
5 SatisfactionProblem impl PASS
6 #[cfg(test)] + #[path = "..."] test link PASS
7 Test file exists (src/unit_tests/models/misc/string_to_string_correction.rs) PASS
8 Test file has >= 3 test functions PASS — 14 test functions
9 Registered in misc/mod.rs PASS
10 Re-exported in models/mod.rs PASS
11 declare_variants! entry exists PASS — default sat StringToStringCorrection => "(2 * source_length + 1) ^ bound_k"
12 CLI resolve_alias entry PASS — registry-driven via inventory::submit!
13 CLI create support PASS — --source-string, --target-string, --bound, optional --alphabet-size
14 Canonical model example registered PASS — aggregated through misc/mod.rs into model_builders.rs
15 Paper display-name entry PASS — "StringToStringCorrection": [String-to-String Correction]
16 Paper problem-def block PASS — full problem-def with example figure

Issue Compliance (#439):

# Check Status
1 Problem name matches issue OK
2 Mathematical definition matches OK
3 Problem type (opt/sat) matches OK — satisfaction (Metric = bool)
4 Type parameters match OK — none, as specified
5 Configuration space matches OK — vec![2 * source.len() + 1; bound_k]
6 Feasibility check matches OK
7 Objective function matches N/A — satisfaction problem
8 Complexity matches OK — "(2 * source_length + 1) ^ bound_k"

Semantic Review:

  • evaluate(): Correctly simulates the operation sequence on a working copy; handles delete/swap/no-op with proper boundary tracking. Early exits for structurally impossible instances.
  • dims(): Correct — vec![2 * source.len() + 1; bound_k].
  • Edge cases: Tested for empty strings, identity, unsatisfiable, target longer than source, excessive deletions, invalid operations after deletions.
  • Complexity string represents brute-force enumeration (appropriate — no better algorithm known for general swap-and-delete variant; documented in paper footnote).
  • Whitelist fail is expected: CLI help text, args, create logic, and CLI tests are standard for a model with full CLI support.

Build: make test PASS, make clippy PASS.

Structural summary: 16/16 checks passed, 8/8 issue compliance passed, no blocking issues.


Quality Check

Design Principles:

Principle Status Notes
DRY Minor issues See below
KISS OK Straightforward model implementation
HC/LC OK Clean separation of concerns

HCI (CLI changes):

Aspect Status Notes
Error messages OK Actionable messages with flag names and usage examples
Discoverability OK Listed in --help for both create and solve
Consistency OK Flag naming follows existing conventions
Least surprise OK Piped examples show --solver brute-force
Feedback OK No silent failures

Test Quality: OK — 14 unit tests with concrete value assertions, boundary/adversarial coverage, full brute-force enumeration in paper example test, plus 4 CLI integration tests.

Issues (all minor):

  1. DRY: Alphabet-size inference/validation duplicationcreate.rs:1580-1593 and 1512-1526 share near-identical logic between SCS and STSC handlers. A shared helper would reduce drift risk.
  2. DRY: Symbol index parsing closurecreate.rs:1570-1577 duplicates the inner loop of SCS handler. A reusable parse_comma_separated_usize() helper would be a small improvement.
  3. Test: Missing --alphabet-size validation CLI test — The handler validates alphabet-size is not smaller than inferred, but no CLI test exercises this error path.
  4. Docs: STSC pipe example inconsistencydocs/src/cli.md:302 uses piping (| pred solve -) instead of -o file.json pattern used by neighboring entries.

Quality summary: No critical or important issues. 4 minor suggestions.


Agentic Feature Tests

# Test Command Result
1 Catalog presence pred list PASS — StringToStringCorrection * appears with correct complexity
2 Details display pred show StringToStringCorrection PASS — description, complexity, 4 fields, 0 reductions
3 Example creation pred create --example StringToStringCorrection PASS — valid JSON output
4a Solve (ILP, expected fail) pred solve stsc.json PASS — correct "no reduction path" error with --solver brute-force hint
4b Solve (brute-force) pred solve --solver brute-force stsc.json PASS — solution [5, 7] manually verified correct
5 Create with CLI flags pred create StringToStringCorrection --source-string "0,1,2,3,1,0" --target-string "0,1,3,2,1" --bound 2 PASS — infers alphabet_size=4
6 Create-pipe-solve pred create ... | pred solve - --solver brute-force PASS — end-to-end pipeline works
7 Edge: identity source=target, bound=0 PASS — empty solution
8 Edge: unsatisfiable bound=0, source != target PASS — "No solution found"
9 Edge: empty strings source=[], target=[] PASS — trivially satisfied
10 Edge: swap only source=[0,1,2], target=[1,0,2] PASS — correct swap solution
11 Explicit --alphabet-size --alphabet-size 5 PASS — overrides inferred value
12 Unit tests cargo test --lib string_to_string_correction PASS — 14/14
13 Full test suite cargo test PASS — all tests
14 CLI integration tests cargo test -p problemreductions-cli --test cli_tests PASS — 185/185
15 Clippy cargo clippy --workspace FAIL (minor) — unreachable pattern at create.rs:239, duplicate "Vec<u64>" match arm
16 Format check cargo fmt --check FAIL (minor) — formatting diff in cli_tests.rs:38

Confirmed issues:

  1. Unreachable pattern (create.rs:239): Duplicate "Vec<u64>" match arm — second arm is dead code. Severity: low. Fix: remove duplicate arm or merge.
  2. Formatting diff (cli_tests.rs:38): assert! call needs line wrapping per nightly rustfmt. Severity: low. Fix: cargo +nightly fmt.

Agentic test summary: All functional tests PASS. 2 minor lint/format issues confirmed.


Generated by review-pipeline

isPANN and others added 3 commits March 18, 2026 15:45
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The previous highlighting used value-based comparison via `.position()`,
which finds the first occurrence and would produce incorrect highlights
for strings with repeated symbols. Now compares by position index directly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
ShortestCommonSupersequence and other models use `bound` as the field
name. Rename for consistency across the codebase.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@isPANN isPANN self-assigned this Mar 18, 2026
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@isPANN isPANN merged commit 08d5574 into main Mar 18, 2026
3 checks passed
@GiggleLiu GiggleLiu deleted the issue-439-string-to-string-correction 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] StringToStringCorrection

3 participants