Skip to content

Fix #122: Add SteinerTree model#192

Open
zazabap wants to merge 5 commits intoCodingThrust:mainfrom
zazabap:issue-122-steiner-tree
Open

Fix #122: Add SteinerTree model#192
zazabap wants to merge 5 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

❌ Patch coverage is 98.52941% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.90%. Comparing base (5fbde0e) to head (67122bb).

Files with missing lines Patch % Lines
src/models/graph/steiner_tree.rs 97.27% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #192      +/-   ##
==========================================
+ Coverage   96.88%   96.90%   +0.01%     
==========================================
  Files         200      202       +2     
  Lines       27537    27741     +204     
==========================================
+ Hits        26680    26882     +202     
- Misses        857      859       +2     

☔ 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 SteinerTree<G, W> problem model (edge-based minimization)
- Register in graph/mod.rs, prelude, CLI dispatch/aliases/create
- Add --terminals CLI flag for pred create SteinerTree
- 12 unit tests: creation, evaluation, brute-force, serialization
- Add paper entry with Dreyfus-Wagner complexity and example figure
- Regenerate problem_schemas.json and reduction_graph.json

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@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

zazabap and others added 3 commits March 9, 2026 09:03
- Add SteinerTree to CLI help table in cli.rs
- Add SteinerTree to random generation supported list in create.rs
- Add SteinerTree to models/mod.rs re-export
- Add SteinerTree to graph/mod.rs doc comment

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Wrong config length (line 138)
- Disconnected non-terminal edges (lines 181-182)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.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

2 participants