Fix #406: Add OptimalLinearArrangement satisfaction problem#616
Fix #406: Add OptimalLinearArrangement satisfaction problem#616
Conversation
Co-Authored-By: Claude Opus 4.6 <[email protected]>
- Add OptimalLinearArrangement<G> optimization problem (minimize total edge length) - Register in graph module, lib.rs prelude, CLI dispatch, alias, create command - Add 16 unit tests covering creation, evaluation, solver, serialization - Add problem-def entry in paper with display-name and references - Regenerate problem schemas JSON Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
- Paper definition now uses {0, ..., |V|-1} to match code implementation
- Removed OLA from ALIASES array (not established enough in literature)
- Keep "ola" as lowercase alias in resolve_alias for convenience
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
…nd K The issue specifies this as a decision problem (Garey & Johnson GT42): given graph G and bound K, is there a permutation f with total edge length <= K? This converts from OptimizationProblem to SatisfactionProblem with Metric = bool, adding the `bound` field as specified. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Implementation SummaryChanges
Deviations from Plan
Open Questions
|
There was a problem hiding this comment.
Pull request overview
Adds Optimal Linear Arrangement (GT42) as a new graph satisfaction (decision) problem to the problemreductions model suite, with corresponding CLI integration, documentation/schema updates, and unit tests.
Changes:
- Introduces
OptimalLinearArrangement<G>as aSatisfactionProblem(boolean metric) with permutation validation and bound-check evaluation. - Registers the new problem across model exports, CLI alias/dispatch, and generated schema documentation.
- Adds a dedicated unit test suite for correctness, solver behavior, and serialization.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
src/models/graph/optimal_linear_arrangement.rs |
New satisfaction-problem model implementation (evaluation, helpers, schema registration, variants, tests module). |
src/unit_tests/models/graph/optimal_linear_arrangement.rs |
New unit tests covering evaluation/edge cases/solver/serde round-trip. |
src/models/graph/mod.rs |
Exposes the new model module and re-exports it. |
src/models/mod.rs |
Re-exports OptimalLinearArrangement at the top-level models module. |
src/lib.rs |
Adds OptimalLinearArrangement to the crate prelude. |
problemreductions-cli/src/dispatch.rs |
Adds load/serialize dispatch support for the new problem. |
problemreductions-cli/src/problem_name.rs |
Adds OLA alias and alias resolution. |
problemreductions-cli/src/commands/create.rs |
Adds pred create and --random support hooks for the new problem. |
problemreductions-cli/src/cli.rs |
Updates CLI help text to mention the new problem. |
docs/src/reductions/problem_schemas.json |
Adds generated schema entry for the new problem. |
docs/paper/reductions.typ |
Adds/updates paper definition text for the decision formulation. |
docs/paper/references.bib |
Adds a supporting reference for NP-completeness discussion. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "{e}\n\nUsage: pred create OptimalLinearArrangement --graph 0-1,1-2,2-3" | ||
| ) | ||
| })?; | ||
| ( | ||
| ser(OptimalLinearArrangement::new(graph))?, |
There was a problem hiding this comment.
OptimalLinearArrangement::new is called with only graph, but the model constructor requires (graph, bound). This won’t compile, and even if a default were intended, the CLI needs a way to supply the decision bound K (likely via --bound or reusing --k).
| "{e}\n\nUsage: pred create OptimalLinearArrangement --graph 0-1,1-2,2-3" | |
| ) | |
| })?; | |
| ( | |
| ser(OptimalLinearArrangement::new(graph))?, | |
| "{e}\n\nUsage: pred create OptimalLinearArrangement --graph 0-1,1-2,2-3 --k K" | |
| ) | |
| })?; | |
| let bound = args.k.ok_or_else(|| { | |
| anyhow::anyhow!( | |
| "OptimalLinearArrangement requires --k (decision bound K)\n\n\ | |
| Usage: pred create OptimalLinearArrangement --graph 0-1,1-2,2-3 --k K" | |
| ) | |
| })?; | |
| ( | |
| ser(OptimalLinearArrangement::new(graph, bound))?, |
| let variant = variant_map(&[("graph", "SimpleGraph")]); | ||
| (ser(OptimalLinearArrangement::new(graph))?, variant) |
There was a problem hiding this comment.
Random instance generation for OptimalLinearArrangement also calls OptimalLinearArrangement::new(graph) without providing the required bound K. Decide how K should be chosen for --random (e.g., require --k/--bound, or derive a default like num_edges * (num_vertices-1)), and pass it to the constructor.
| let variant = variant_map(&[("graph", "SimpleGraph")]); | |
| (ser(OptimalLinearArrangement::new(graph))?, variant) | |
| // Use a safe upper bound K = m * (n - 1), where m is the number of edges | |
| let num_edges = graph.num_edges(); | |
| let k_bound = num_edges * num_vertices.saturating_sub(1); | |
| let variant = variant_map(&[("graph", "SimpleGraph")]); | |
| (ser(OptimalLinearArrangement::new(graph, k_bound))?, variant) |
| "SpinGlass" => "--graph 0-1,1-2 --couplings 1,1", | ||
| "KColoring" => "--graph 0-1,1-2,2-0 --k 3", | ||
| "Factoring" => "--target 15 --m 4 --n 4", | ||
| "OptimalLinearArrangement" => "--graph 0-1,1-2,2-3", |
There was a problem hiding this comment.
The help/example for OptimalLinearArrangement only shows --graph, but the schema includes a bound field and the model requires a bound K. Update the example to include the bound flag you support (e.g., --bound <K> or --k <K>), and ensure the CLI args actually define that flag so pred create help matches what clap accepts.
| "OptimalLinearArrangement" => "--graph 0-1,1-2,2-3", | |
| "OptimalLinearArrangement" => "--graph 0-1,1-2,2-3 --bounds 3", |
problemreductions-cli/src/cli.rs
Outdated
| BicliqueCover --left, --right, --biedges, --k | ||
| BMF --matrix (0/1), --rank | ||
| CVP --basis, --target-vec [--bounds] | ||
| OptimalLinearArrangement --graph |
There was a problem hiding this comment.
This flag list says OptimalLinearArrangement --graph, but the model/schema require a bound K as well. Also, CreateArgs currently has no bound field, so if you intend --bound (as printed from schema) clap will reject it. Either add --bound: Option<usize> to CreateArgs and use it in create, or explicitly document and reuse the existing --k flag for the bound.
| OptimalLinearArrangement --graph | |
| OptimalLinearArrangement --graph, --k |
src/models/graph/mod.rs
Outdated
| //! - [`TravelingSalesman`]: Traveling Salesman (minimum weight Hamiltonian cycle) | ||
| //! - [`SpinGlass`]: Ising model Hamiltonian | ||
| //! - [`BicliqueCover`]: Biclique cover on bipartite graphs | ||
| //! - [`OptimalLinearArrangement`]: Optimal linear arrangement (minimum total edge length) |
There was a problem hiding this comment.
The module-level docs describe OptimalLinearArrangement as “minimum total edge length”, but this model is implemented as a decision/satisfaction problem with an explicit bound K. Consider rewording this bullet to reflect the decision formulation (e.g., “total edge length at most K”) to avoid misleading users skimming the module docs.
| //! - [`OptimalLinearArrangement`]: Optimal linear arrangement (minimum total edge length) | |
| //! - [`OptimalLinearArrangement`]: Optimal linear arrangement (linear arrangement with total edge length at most K) |
…gration - CLI create/random now requires --bound for OptimalLinearArrangement - Updated help text and examples to include --bound - Fixed module doc to reflect decision formulation (at most K) Co-Authored-By: Claude Opus 4.6 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #616 +/- ##
==========================================
+ Coverage 96.81% 96.83% +0.01%
==========================================
Files 244 246 +2
Lines 31650 31855 +205
==========================================
+ Hits 30642 30846 +204
- Misses 1008 1009 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Add OptimalLinearArrangement to trait_consistency checks - Strengthen NO instance test with brute-force verification - Fix random generation default bound formula (n-1)*num_edges Co-Authored-By: Claude Opus 4.6 <[email protected]>
Review Pipeline Report
Fixes Applied
Notes
🤖 Generated by review-pipeline |
Summary
OptimalLinearArrangement<G>as a SatisfactionProblem withMetric = bool, following the Garey & Johnson GT42 decision formulationgraph: Gandbound: usize(upper bound K on total edge length)evaluate()checks if config is a valid permutation AND total edge length <= boundtotal_edge_length(),is_valid_solution(),num_vertices(),num_edges(),bound()gettersdeclare_variants!with complexity"2^num_vertices"(Held-Karp-style DP)deser_sat, aliasOLAaddedFixes #406
Test plan
cargo test optimal_linear_arrangement)cargo test)cargo clippy --all-targets)cargo fmt -- --check)make export-schemas)Generated with Claude Code