You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix#439: Add StringToStringCorrection model (#675)
* Add plan for #439: StringToStringCorrection
* Implement #439: Add StringToStringCorrection model
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
* chore: remove plan file after implementation
* fix: address PR #675 review feedback
- 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
* Fix paper figure highlighting logic for repeated symbols
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>
* Rename bound_k to bound for consistency with other models
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>
* Fix formatting issues in PR code
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Xiwei Pan <xiwei.pan@connect.hkust-gz.edu.cn>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Given a finite alphabet $Sigma$, a source string $x inSigma^*$, a target string $y inSigma^*$, and a positive integer $K$, determine whether $y$ can be derived from $x$ by a sequence of at most $K$ operations, where each operation is either a _single-symbol deletion_ (remove one character at a chosen position) or an _adjacent-symbol interchange_ (swap two neighboring characters).
2284
+
][
2285
+
A classical NP-complete problem listed as SR20 in Garey and Johnson @garey1979. #cite(<wagner1975>, form: "prose") proved NP-completeness via transformation from Set Covering. The standard edit distance problem --- allowing insertion, deletion, and substitution --- is solvable in $O(|x| dot |y|)$ time by the Wagner--Fischer dynamic programming algorithm @wagner1974. However, restricting the operation set to only deletions and adjacent swaps makes the problem NP-complete for unbounded alphabets. When only adjacent swaps are allowed (no deletions), the problem reduces to counting inversions and is polynomial @wagner1975.#footnote[No algorithm improving on brute-force is known for the general swap-and-delete variant.]
caption: [String-to-String Correction: transforming $x = #src-str$ into $y = #tgt-str$ with $K = #bound-k$ operations. Step 1 swaps adjacent symbols at positions 2 and 3; step 2 deletes the symbol at position 5.],
2323
+
) <fig:stsc>
2324
+
2325
+
The transformation uses exactly $K = #bound-k$ operations (1 swap + 1 deletion), which is the minimum: a single operation cannot account for both the transposition of two symbols and the removal of one.
2326
+
]
2327
+
]
2328
+
}
2329
+
2263
2330
#problem-def("MinimumFeedbackArcSet")[
2264
2331
Given a directed graph $G = (V, A)$, find a minimum-size subset $A' subset.eq A$ such that $G - A'$ is a directed acyclic graph (DAG). Equivalently, $A'$ must contain at least one arc from every directed cycle in $G$.
0 commit comments