Skip to content

Conversation

@daehiff
Copy link
Contributor

@daehiff daehiff commented Nov 24, 2024

Motivation

This PR implements a generic Steiner Tree algorithm for undirected graphs based on Kou's algorithm. The algorithm leverages Dijkstra's shortest path, Floyd-Warshall path reconstruction, and minimum spanning tree computation to determine the Steiner tree for a set of terminal nodes.
The implementation follows the implementation in the networkx library. A detailed description can be found in A fast algorithm for Steiner trees.

petgraph has no algorithm to approximate a minimal steiner tree. The algorithm melhorn in the networkx documentation, seems to be only different by the complexity class and apperently is an extension. So this could be implemented at a later point.

Runtime

$\mathcal{O}(|S| |V|^2)$, where (|S|) is the terminal set size, (|V|) and (|E|) are graph nodes and edges, respectively.

Further Notes

Floyd-warshall implementation is adjusted to also allow path reconstruction (see here) this is required in the function subgraph_edges_from_metric_closure

@daehiff daehiff changed the title Add mst prim Add Kou's algorithm for finding a MST Nov 24, 2024
@daehiff daehiff force-pushed the add-mst-prim branch 3 times, most recently from e0d8b6b to ca0f4c2 Compare November 25, 2024 01:05
XVilka
XVilka previously requested changes Dec 23, 2024
Copy link
Member

@XVilka XVilka left a comment

Choose a reason for hiding this comment

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

Please fix this:


---- src/algo/floyd_warshall.rs - algo::floyd_warshall::floyd_warshall_path (line 127) stdout ----
error[E0432]: unresolved import `petgraph::algo::floyd_warshall_path`
 --> src/algo/floyd_warshall.rs:130:5
  |
6 | use petgraph::algo::floyd_warshall_path;
  |     ^^^^^^^^^^^^^^^^-------------------
  |     |               |
  |     |               help: a similar name exists in the module: `floyd_warshall`
  |     no `floyd_warshall_path` in `algo`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0432`.
Couldn't compile the test.

failures:
    src/algo/floyd_warshall.rs - algo::floyd_warshall::floyd_warshall_path (line 127)

@daehiff
Copy link
Contributor Author

daehiff commented Dec 23, 2024

I always get the following issue when trying to run the pipeline: 1 workflow awaiting approval . Any possible way around this?

At least cargo test --verbose --no-default-features went trough in the pipeline.
So this seems then to be a merge-commit/pipeline issue.

@XVilka
Copy link
Member

XVilka commented Dec 23, 2024

I always get the following issue when trying to run the pipeline: 1 workflow awaiting approval . Any possible way around this?

At least cargo test --verbose --no-default-features went trough in the pipeline. So this seems then to be a merge-commit/pipeline issue.

It is a restriction by GitHub to avoid malicious CI runs from external contributors. Once the first PR of you will get merged, it wont happen anymore on any subsequent PRs.

@XVilka
Copy link
Member

XVilka commented Dec 23, 2024

@daehiff it still happens

@daehiff
Copy link
Contributor Author

daehiff commented Dec 23, 2024

@daehiff it still happens

Ohh, sorry about that.

@daehiff daehiff force-pushed the add-mst-prim branch 3 times, most recently from 5149ec5 to 398820c Compare December 23, 2024 17:13
Copy link
Member

@ABorgna ABorgna left a comment

Choose a reason for hiding this comment

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

Looks great!

I ran the benchmarks to see if the extra code made the old floyd_warshal impl slower, but it actually seems to be sightly faster now :)

You mentioned you'll add a quickcheck test, I'll wait for that before merging.

daehiff and others added 14 commits February 8, 2025 00:25
Signed-off-by: David Winderl <winderl13@gmail.com>
Simplify compute_shortest_path_length, compute_shortest_path and format compute_metric_closure.
Format reconstruct_metric_closure, my_node_ids to simplify them.
Add basic tests for first stages of steiner tree.
Implement integration tests in test folder.
Signed-off-by: David Winderl <winderl13@gmail.com>
Signed-off-by: David Winderl <winderl13@gmail.com>
Signed-off-by: David Winderl <winderl13@gmail.com>
Signed-off-by: David Winderl <winderl13@gmail.com>
Signed-off-by: David Winderl <winderl13@gmail.com>
Signed-off-by: David Winderl <winderl13@gmail.com>
Signed-off-by: David Winderl <winderl13@gmail.com>
Signed-off-by: daehiff <winderl13@gmail.com>
Signed-off-by: daehiff <winderl13@gmail.com>
@daehiff daehiff force-pushed the add-mst-prim branch 2 times, most recently from 0f84f2c to 22747e8 Compare February 7, 2025 23:25
Signed-off-by: daehiff <winderl13@gmail.com>

Remove build errors

Signed-off-by: daehiff <winderl13@gmail.com>

Update src/algo/floyd_warshall.rs

Co-authored-by: Agustín Borgna <agustinborgna@gmail.com>

Fix PR: Update code such that steiner_trees requires stable graph

Signed-off-by: daehiff <winderl13@gmail.com>

Fix PR: Update module description

Signed-off-by: daehiff <winderl13@gmail.com>

Disable steiner_tree

Signed-off-by: daehiff <winderl13@gmail.com>

Add conditional build in quickcheck tests

Signed-off-by: daehiff <winderl13@gmail.com>

Fix PR: Fix formatting

Signed-off-by: daehiff <winderl13@gmail.com>

Fix PR: fix quickcheck tests

Signed-off-by: daehiff <winderl13@gmail.com>

Fix PR. Fix Clippy

Signed-off-by: daehiff <winderl13@gmail.com>

Fix PR: Fix Clippy

Signed-off-by: daehiff <winderl13@gmail.com>

Fix PR: Fix build

Signed-off-by: daehiff <winderl13@gmail.com>

Fix PR: Adjust typehints

Signed-off-by: daehiff <winderl13@gmail.com>

Fix PR: Fix clippy by adding typedefs

Signed-off-by: daehiff <winderl13@gmail.com>

Fix PR: Fix formatting

Signed-off-by: daehiff <winderl13@gmail.com>
@ABorgna ABorgna dismissed XVilka’s stale review March 19, 2025 22:31

Errors have been fixed

@ABorgna ABorgna changed the title Add Kou's algorithm for finding a MST feat: Add Kou's algorithm for finding a MST Mar 19, 2025
@ABorgna ABorgna added this pull request to the merge queue Mar 19, 2025
Merged via the queue into petgraph:master with commit d795edc Mar 19, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-new-algorithm Category: A feature request for a new graph algorithm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants