Skip to content

Fix #439: Add StringToStringCorrection model#675

Open
GiggleLiu wants to merge 5 commits intomainfrom
issue-439-string-to-string-correction
Open

Fix #439: Add StringToStringCorrection model#675
GiggleLiu wants to merge 5 commits intomainfrom
issue-439-string-to-string-correction

Conversation

@GiggleLiu
Copy link
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

codecov bot commented Mar 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.06%. Comparing base (dfcc313) to head (e817bc8).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #675      +/-   ##
==========================================
+ Coverage   97.04%   97.06%   +0.01%     
==========================================
  Files         284      286       +2     
  Lines       38037    38212     +175     
==========================================
+ Hits        36914    37089     +175     
  Misses       1123     1123              

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

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

2 participants