Skip to content

Functions for computing a cycle basis, part 2 - #2069

Closed
jfinkels wants to merge 10 commits into
networkx:mainfrom
jfinkels:cycle-basis
Closed

jfinkels wants to merge 10 commits into
networkx:mainfrom
jfinkels:cycle-basis

Conversation

@jfinkels

@jfinkels jfinkels commented Apr 8, 2016

Copy link
Copy Markdown
Contributor

Unfortunately, I had some problem with git not uploading my new commits for the pull request #1538; I couldn't figure out how to fix it so I opened this new pull request instead. Sorry about that.

Anyway, the new commit I made capitalizes on the changes introduced in pull request #1740 (the Graph.edge_subgraph() method) and in pull request #1741 (allowing keys to be returned by the minimum_spanning_edges() function). In fact, I extended the latter pull request in commit 1d4e7dd, the first commit in the current pull request, since I needed access to the edge key for the edges from which the minimum spanning tree of a multigraph was derived. The chords() function is now as simple as I had originally hoped.

@@ -0,0 +1,58 @@
#!/usr/bin/env python

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should kirchoffs_circuit_laws.py go with the examples?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

oops -- I see that this file is in the examples directory already...

Should we remove the if __name__ == "__main__":?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure, I'll update this file.

@jfinkels

Copy link
Copy Markdown
Contributor Author

There seems to be problems with the unit tests, some are not actually being run. I need to do a bit more reorganizing on this pull request.

@jfinkels

Copy link
Copy Markdown
Contributor Author

Due to duplicate test method names, the unit tests for the proposed cycle_basis_matrix function were not being run. I have fixed the naming issues, and the tests now fail.

Maybe it would be easier to deal with if I split this quite large pull request into several commits, each of which depends on the one above it:

  1. adding the as_multigraph keyword argument to the minimum_spanning_tree function
  2. adding the chords function
  3. adding the cycle_basis_matrix function
  4. adding the Kirchhoff circuit laws example

What do you think?

@dschult

dschult commented Apr 15, 2016

Copy link
Copy Markdown
Member

I think the tests are failing because "an arbitrary orientation of the edges is selected". Perhaps the test could check the absolute value of the matrix?

So, I don't think you need to rearrange the commits unless it helps you with debugging.

Is there a way to know (or maybe even determine) the order of the edges and cycles in the matrix?
That questions makes me realize that this feature has similarities with the laplacian and adjacency_matrix code. Should cycle_basis_matrix be a module inside the linalg directory?
I'm fine with leaving it in cycles.py but fine with moving it too.

@dschult

dschult commented Apr 15, 2016 •

Copy link
Copy Markdown
Member

Why doesn't the cycle_basis_matrix function use the existing cycle_basis and utils.misc.pairwise(_, cyclic=True) functions iterating over cycles and adding entries to the matrix?
Is this algorithm different? better? cited anywhere?

Wouldn't this work:

edges = {e: i for i,e in enumerate(G.edges())}                                           
basis = cycle_basis(G)                                                                   
M = np.zeros((len(basis),len(edges)))                                                    
for row, cycle in enumerate(basis):                                                      
    for e in pairwise(cycle, cyclic=True):                                               
        if e in edges:                                                                   
            M[row, edges[e]] = 1                                                         
        else:                                                                            
            M[row, edges[(e[1],e[0])]] = -1     
return M, edges, basis  # give the order of rows and cols to the user.                                         

@kakila

kakila commented Jun 22, 2020

Copy link
Copy Markdown

Dear Developers,
I am one of the original authors of the pull request and I was wondering if this was finally included or not in the software. As far as I can tell, the conversion to cycle matrix and the examples are not released, is this correct?
Please let me know if I can assist.

Regards,

@kakila

kakila commented Jun 23, 2020

Copy link
Copy Markdown

I think the change to add the optional argument to the spanning trees (commit 1d4e7dd) could be integrated right away. This is a useful enhancement independent of the cycle basis topic

@dschult dschult modified the milestones: networkx-2.5, networkx-2.6 Aug 14, 2020
Base automatically changed from master to main March 4, 2021 18:20
@dschult

dschult commented May 20, 2021

Copy link
Copy Markdown
Member

This should be replaced by #4822
Pick up the conversation on that thread.
Leaving this open for now in case the rebase of that one is too confusing.

@dschult dschult modified the milestones: networkx-2.6, networkx-3.0 May 20, 2021
@rossbar rossbar modified the milestones: networkx-2.7, networkx-3.0 Feb 12, 2022
@rossbar rossbar modified the milestones: networkx-3.0, networkx-3.1 Nov 29, 2022
@jarrodmillman jarrodmillman removed this from the 3.2 milestone Jul 20, 2023
@MridulS MridulS closed this Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

7 participants