Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Algorithms for biconnected graphs. #445

Merged
merged 15 commits into from
Jan 18, 2022
Merged

Conversation

georgios-ts
Copy link
Collaborator

This commit adds two new functions:

  1. retworkx.articulation_points. An articulation point is any node whose
    removal increases the number of connected components of a graph.
  2. retworkx.biconnected_components. A biconnected component is a
    maximal subgraph such that the removal of a node will not disconnect
    the subgraph.

This commit adds two new functions:
1. `retworkx.articulation_points`. An articulation point is any node whose
removal increases the number of connected components of a graph.
2. `retworkx.biconnected_components`. A  biconnected component is a
maximal subgraph such that the removal of a node will not disconnect
the subgraph.
@coveralls
Copy link

coveralls commented Sep 11, 2021

Pull Request Test Coverage Report for Build 1713301406

  • 149 of 150 (99.33%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.01%) to 98.49%

Changes Missing Coverage Covered Lines Changed/Added Lines %
retworkx-core/src/connectivity/biconnected.rs 106 107 99.07%
Totals Coverage Status
Change from base Build 1704536733: 0.01%
Covered Lines: 11742
Relevant Lines: 11922

💛 - Coveralls

georgios-ts added a commit to georgios-ts/retworkx that referenced this pull request Sep 27, 2021
Widely used graph libraries like Boost Graph Library and graph-tool
provide the ability to insert callback functions at specified event
points for many common graph search algorithms. petgraph has a similar
concept in `petgraph::visit::depth_first_search` function. This commit
implements an iterative version of `depth_first_search`, that will be
used in a follow-up in the pending PRs Qiskit#444, Qiskit#445. At the same time it
exposes this new functionality in Python by letting users subclassing
`retworkx.visit.DFSVisitor` and provide their own implementation for
the appropriate callback functions.

The benefit is less memory consumption since we avoid storing the results
but rather let the user take the desired action at specified points. For
example, if a user wants to process the nodes in dfs-order, we don't need
to create a new list with all the graph nodes in dfs-order but rather the user
can process a node on the fly. We can (probably) leverage this approach
in other algorithms as an alternative for our inability to provide "real" python
iterators.
@georgios-ts georgios-ts mentioned this pull request Sep 27, 2021
@mtreinish mtreinish added this to the 0.11.0 milestone Oct 2, 2021
mtreinish pushed a commit that referenced this pull request Jan 10, 2022
* Add dfs-search

Widely used graph libraries like Boost Graph Library and graph-tool
provide the ability to insert callback functions at specified event
points for many common graph search algorithms. petgraph has a similar
concept in `petgraph::visit::depth_first_search` function. This commit
implements an iterative version of `depth_first_search`, that will be
used in a follow-up in the pending PRs #444, #445. At the same time it
exposes this new functionality in Python by letting users subclassing
`retworkx.visit.DFSVisitor` and provide their own implementation for
the appropriate callback functions.

The benefit is less memory consumption since we avoid storing the results
but rather let the user take the desired action at specified points. For
example, if a user wants to process the nodes in dfs-order, we don't need
to create a new list with all the graph nodes in dfs-order but rather the user
can process a node on the fly. We can (probably) leverage this approach
in other algorithms as an alternative for our inability to provide "real" python
iterators.

* break or prune the search tree with custom exceptions

* tests

* move `depth_first_search` to retworkx-core + create a new traversal module together with `dfs_edges` function

* add option to pass a vector of starting nodes + in dfs events report the weight of an edge

* lint

* fix docs

* this is the last fix

* define custom exceptions `StopSearch`, `PruneSearch` in python and import them in rust so we can simplify a bit the namespaces

* minor doc fixes

* ignore flake warning

* run black

* deduplicate macro and mention petgraph DfsEvent struct
Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the updates. Just a couple of small nits inline in the unittests but other than those I think this is ready to merge.

@mtreinish mtreinish merged commit df4e02a into Qiskit:main Jan 18, 2022
InnovativeInventor pushed a commit to InnovativeInventor/retworkx that referenced this pull request Mar 19, 2022
* Algorithms for biconnected graphs.

This commit adds two new functions:

1. `retworkx.articulation_points`. An articulation point is any node whose
removal increases the number of connected components of a graph.
2. `retworkx.biconnected_components`. A  biconnected component is a
maximal subgraph such that the removal of a node will not disconnect
the subgraph.

* fix clippy warnings

* use petgraph traits as part of the effort to have generic functions in retworkx

* replace `search` with a `std::iter` build-in func

* move generic function to retworkx-core

* change type of biconnected components

* run fmt + pre-allocate only if needed

* use iterative dfs-search implementation

* revert unintentional doc change

* use a custom return type in biconnected components

* minor changes in tests

Co-authored-by: Matthew Treinish <[email protected]>
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.

3 participants