Skip to content

Fix #122: Add SteinerTree model#192

Merged
GiggleLiu merged 7 commits intoCodingThrust:mainfrom
zazabap:issue-122-steiner-tree
Mar 16, 2026
Merged

Fix #122: Add SteinerTree model#192
GiggleLiu merged 7 commits intoCodingThrust:mainfrom
zazabap:issue-122-steiner-tree

Conversation

@zazabap
Copy link
Collaborator

@zazabap zazabap commented Mar 9, 2026

Summary

  • Add SteinerTree problem model — minimum-weight tree connecting terminal vertices in a graph
  • Edge-based binary optimization following the TravelingSalesman pattern
  • Includes CLI support (dispatch, aliases, create with --terminals flag)
  • Dreyfus-Wagner complexity: O(3^|T| · n + 2^|T| · n²)

Fixes #122

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 detailed implementation plan document for introducing a new SteinerTree problem model (and associated tests/CLI/docs updates) to the codebase.

Changes:

  • Adds an implementation plan covering the SteinerTree model structure, validity checking, and trait impls
  • Outlines unit tests, CLI integration points, and documentation regeneration steps

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

Comment on lines +1 to +7
# SteinerTree Model Implementation Plan

> **For Claude:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.

**Goal:** Add the SteinerTree problem model — a minimization problem that finds a minimum-weight subtree connecting a set of terminal vertices.

**Architecture:** Edge-based binary optimization on graphs, following the TravelingSalesman pattern. Each edge variable is 0/1 (include or exclude). Feasibility requires selected edges to form an acyclic connected subgraph spanning all terminals. Uses `edge_weights: Vec<W>` plus a `terminals: Vec<usize>` field.
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

The PR title/description says the SteinerTree model + CLI support are added, but this PR currently only introduces an implementation plan document. Either update the PR metadata to reflect that this is documentation/planning only, or include the actual code/test/CLI/schema changes described in the plan before merging (so it truly fixes #122).

Copilot uses AI. Check for mistakes.
Comment on lines +179 to +180
// Count vertices in the connected component containing terminals
let component_vertices: usize = visited.iter().filter(|&&v| v && involved.iter().enumerate().any(|(i, &inv)| inv && i == 0).is_none() || v).count();
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

In the is_valid_steiner_tree snippet, component_vertices is computed with a very complex expression that appears incorrect and wouldn’t compile as Rust (and the variable is unused). Since this is meant to be a copy/paste starting point, consider removing this line entirely or replacing it with the simpler reachable_involved count described immediately below to avoid confusion.

Suggested change
// Count vertices in the connected component containing terminals
let component_vertices: usize = visited.iter().filter(|&&v| v && involved.iter().enumerate().any(|(i, &inv)| inv && i == 0).is_none() || v).count();

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented Mar 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.92%. Comparing base (ee5b77b) to head (92740d7).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #192      +/-   ##
==========================================
+ Coverage   96.88%   96.92%   +0.03%     
==========================================
  Files         269      271       +2     
  Lines       36036    36298     +262     
==========================================
+ Hits        34915    35182     +267     
+ Misses       1121     1116       -5     

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

@zazabap
Copy link
Collaborator Author

zazabap commented Mar 9, 2026

Implementation Summary

Changes

  • src/models/graph/steiner_tree.rs — New model: SteinerTree<G, W> with edge-based binary variables, validity checker (connected + acyclic + terminals covered), Problem/OptimizationProblem impls, declare_variants! with Dreyfus-Wagner complexity
  • src/unit_tests/models/graph/steiner_tree.rs — 12 unit tests covering creation, evaluation (valid/invalid/empty), direction, size getters, is_weighted, brute-force, MST special case, serialization
  • src/models/graph/mod.rs, src/lib.rs — Registration and prelude export
  • problemreductions-cli/src/dispatch.rs — load_problem + serialize_any_problem match arms
  • problemreductions-cli/src/problem_name.rs — ST/steiner aliases
  • problemreductions-cli/src/commands/create.rs — parse_terminals, create handler, example, random generation
  • problemreductions-cli/src/cli.rs — --terminals flag
  • docs/paper/reductions.typ — problem-def entry with background, Dreyfus-Wagner/Byrka citations, example figure
  • docs/paper/references.bib — Added dreyfuswagner1971, byrka2013
  • docs/src/reductions/problem_schemas.json, reduction_graph.json — Regenerated

Deviations from Plan

  • None significant. The validity checker pseudocode in the plan had rough spots (dead code, confusing comments); the implementation cleans it up to a straightforward BFS + tree property check.

Open Questions

  • None

@GiggleLiu
Copy link
Contributor

Review Pipeline Report

Check Result
Copilot comments 2 checked, 0 actionable
Issue/human comments checked, 0 pending
Structural review 4 gaps fixed
CI green
Agentic test passed; follow-up added static SteinerTree CLI examples
Board Review pool -> Under review -> Final review

🤖 Generated by review-pipeline

Clean rebase onto current main. Adds SteinerTree<G, W> with edge-based
binary variables, BFS+tree validity checker, Dreyfus-Wagner complexity,
full CLI integration (create, example, random), paper entry with CeTZ
figure, and 18 unit tests including coverage for all public methods.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@GiggleLiu GiggleLiu force-pushed the issue-122-steiner-tree branch from 4a9c585 to 63d99a4 Compare March 15, 2026 14:33
GiggleLiu and others added 4 commits March 16, 2026 15:19
…le from fixtures

- Move SteinerTree display-name entry to correct alphabetical position
- Use seeded Fisher-Yates shuffle for random terminal selection instead
  of always picking first N vertices
- Rewrite paper example to use load-model-example() from canonical
  examples.json fixtures instead of hand-written values
- Regenerate example fixtures to include SteinerTree model

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace hardcoded (v2,v4) reference with data-driven lookup from
the canonical example, eliminating the last hardcoded instance value.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@zazabap
Copy link
Collaborator Author

zazabap commented Mar 16, 2026

Run the final review on this PR with some quick fixes, now claude rate 80% quality. @GiggleLiu

GiggleLiu and others added 2 commits March 16, 2026 17:06
- Add lcg_choose() utility for Fisher-Yates partial shuffle
- Use random terminal selection and random edge weights in SteinerTree random generation
- Regenerate examples.json to include SteinerTree canonical example
- Fix pre-existing formatting issues from main merge

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Prefer reusable lcg_choose() over inlined Fisher-Yates shuffle.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@GiggleLiu GiggleLiu merged commit 9a2b2b7 into CodingThrust:main Mar 16, 2026
3 checks passed
zazabap added a commit to zazabap/problem-reductions that referenced this pull request Mar 16, 2026
…, remove unrelated files

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
GiggleLiu added a commit that referenced this pull request Mar 16, 2026
* Add plan for #212: [Model] MultiprocessorScheduling

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

* Add plan for #219: [Model] SequencingWithinIntervals

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

* feat: implement SequencingWithinIntervals model for #219

Add a satisfaction problem model for scheduling tasks within time
windows without overlap (Garey & Johnson SS1, NP-complete).

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

* fix: update SequencingWithinIntervals for new API

Add missing display_name, aliases, dimensions fields to ProblemSchemaEntry.
Use 'default sat' prefix in declare_variants! macro.
Rename task_lengths CLI field to lengths to avoid clash with FlowShopScheduling.

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

* fix: address Copilot review comments

- Use checked_add to prevent u64 overflow in constructor
- Rename test functions to snake_case (test_sequencing_within_intervals_*)

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

* fix: add missing structural items for SequencingWithinIntervals

- Add canonical model example in example_db (satisfaction_example)
- Add trait_consistency test entry
- Add paper display-name and problem-def block in reductions.typ

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

* chore: regenerate JSON artifacts for SequencingWithinIntervals

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

* style: consolidate SequencingWithinIntervals re-exports into existing use blocks

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

* chore: trigger CI

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

* style: apply rustfmt

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

* fix: remove unreachable deadline check in evaluate()

The deadline guard `start + l[i] > d[i]` in evaluate() was dead code:
since c < dim = d[i] - r[i] - l[i] + 1, start + l[i] <= d[i] holds
by construction. Removing it fixes the 1-line codecov gap.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: align with PR #192 standard — use load-model-example, remove unrelated files

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: add Gantt chart figure, remove plan doc

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: add CLI tests, inline dims computation in evaluate()

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: GiggleLiu <cacate0129@gmail.com>
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] SteinerTree

3 participants