rustworkx icon indicating copy to clipboard operation
rustworkx copied to clipboard

Implementation of cycle_basis_edges

Open raynelfss opened this issue 2 years ago • 7 comments

Aims to fix #551

  • Inspired by the existing procedure cycle_basis.
  • Modified to return a tuple of NodeId in the format (source, target).
  • Added API calls so that method works in Python.
  • TO-DO: return weights:
    • weight() method from EdgeRef returns a reference and cannot be copied over.

raynelfss avatar May 31 '23 17:05 raynelfss

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar May 31 '23 17:05 CLAassistant

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

CLAassistant avatar May 31 '23 17:05 CLAassistant

Results from testing in Python:

image

raynelfss avatar May 31 '23 17:05 raynelfss

Pull Request Test Coverage Report for Build 9962098330

Details

  • 87 of 102 (85.29%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.06%) to 95.744%

Changes Missing Coverage Covered Lines Changed/Added Lines %
rustworkx-core/src/connectivity/cycle_basis.rs 79 94 84.04%
<!-- Total: 87 102
Totals Coverage Status
Change from base Build 9859812730: -0.06%
Covered Lines: 18108
Relevant Lines: 18913

💛 - Coveralls

coveralls avatar May 31 '23 21:05 coveralls

This looks pretty good to me, just a quick question: if there a reason to declare both a cycles_edges and a cycles_nodes if from what I understand we only return one or the other? Is it possible in Rust to declare variables like: if want_edge: let mut cycles: Vec<Vec<G::EdgeId>> = Vec::new(); else: let mut cycles: Vec<Vec<G::NodeId>> = Vec::new();. This is low-key just for me to learn

danielleodigie avatar Jun 06 '23 14:06 danielleodigie

if there a reason to declare both a cycles_edges and a cycles_nodes if from what I understand we only return one or the other? Is it possible in Rust to declare variables like: if want_edge: let mut cycles: Vec<Vec<G::EdgeId>> = Vec::new(); else: let mut cycles: Vec<Vec<G::NodeId>> = Vec::new();

Well, there might be a better way of doing so that doesn't involve two vectors. The reason I did it this way is that I couldn't conditionally assign this variable with different types (G::EdgeId || G::NodeId) without having to wrap two similar processes under if and else statements, which could be a bit redundant.

I could, however, change the enum so that it represents the individual nodes/edges (instead of Vec<Vec<T>> for each type) and make the function return an instance of Vec<Vec<EdgeOrNodes<E, N>>> and then unwrap the values of said Vec individually.

The problem happens when importing this enum into the wrapper function, which complains about the types in use. I could try and get this to work with enough time.

raynelfss avatar Jun 06 '23 15:06 raynelfss

if there a reason to declare both a cycles_edges and a cycles_nodes if from what I understand we only return one or the other? Is it possible in Rust to declare variables like: if want_edge: let mut cycles: Vec<Vec<G::EdgeId>> = Vec::new(); else: let mut cycles: Vec<Vec<G::NodeId>> = Vec::new();

Well, there might be a better way of doing so that doesn't involve two vectors. The reason I did it this way is that I couldn't conditionally assign this variable with different types (G::EdgeId || G::NodeId) without having to wrap two similar processes under if and else statements, which could be a bit redundant.

I could, however, change the enum so that it represents the individual nodes/edges (instead of Vec<Vec<T>> for each type) and make the function return an instance of Vec<Vec<EdgeOrNodes<E, N>>> and then unwrap the values of said Vec individually.

The problem happens when importing this enum into the wrapper function, which complains about the types in use. I could try and get this to work with enough time.

I mean if it works fine, I don't see any reason to change it, I was just asking. Maybe ask @mtreinish. Otherwise, looks good

danielleodigie avatar Jun 06 '23 15:06 danielleodigie