Skip to content

Commit

Permalink
Add steiner tree functionality to rustworkx-core (#1103)
Browse files Browse the repository at this point in the history
* Implement deduplicate edge

* Move MetricClousureEdge

* Add definition of _metric_clousure_edges

* Add definition of metric_clousure

* Add definition of fast_metric_edges

* Add definition of steiner_tree

* Add mod steiner_tree to lib.rs

* Add necessary crate

* correct type

* change MetricClousureEdge to generic

* Update steiner_tree

* Finish rustworkx-core port

This commit finishes the rustworkx-core port of the steiner tree and
metric closure functions. In particular this was especially tricky
because the petgraph traits make it exceedingly difficult to have a
generic function that takes in a graph for analysis and modifies it as
most of the traits required for visiting/iteration that are used for
analysis are only defined on borrowed graphs, and the limited traits for
modifying graphs are defined on owned graph types. This causes a
conflict where you can't easily express that a generic type G created in
a function from a user input is both mutated using a trait and analyzed
as there is a type mismatch between G and &G. After spending far too
long to fail to find a pattern to express this, I opted to just use a
discrete type for the return and leave the actual graph mutation up to
the rustworkx-core user because we're lacking the ability to cleanly
express what is needed via petgraph.

* Add back checking on valid weights and terminal nodes

---------

Co-authored-by: Ryuhei Yoshida <[email protected]>
  • Loading branch information
mtreinish and yoshida-ryuhei authored Mar 4, 2024
1 parent 6e37baf commit c8172d5
Show file tree
Hide file tree
Showing 4 changed files with 642 additions and 222 deletions.
2 changes: 2 additions & 0 deletions rustworkx-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ mod min_scored;
pub mod token_swapper;
pub mod utils;

pub mod steiner_tree;

// re-export petgraph so there is a consistent version available to users and
// then only need to require rustworkx-core in their dependencies
pub use petgraph;
Loading

0 comments on commit c8172d5

Please sign in to comment.