For a discrete element modelling project I have recently started looking into the graph representation of a collection of particles in contact. The basic idea is this: I have a granular aggregate consisting of a number of particles. Each particle interacts with its neighbours through contact points, which can be represented as edges connecting the particles (nodes). The objective is then to extract the cycle basis, i.e. the set of smallest possible cycles from which larger cycles can be constructed. To this end, I construct a graph using the Python networkx
package, and then extract the cycle basis using the networkx.cycle_basis
function. A simple example pseudo-code to illustrate my procedure:
import networkx as nx
nodes = [particle IDs]
edges = [pairs of particle IDs]
G = nx.Graph()
G.add_nodes_from(nodes)
G.add_edges_from(edges)
cycles = nx.cycle_basis(G)
cycles
represents a list of lists of the particle IDs participating in each basis cycle. However, when I plot the graph (using the coordinates of the particles in the simulation), I see that cycles
contains a number of cycles that are actually a combination of smaller cycles, and are therefore not basis cycles (if I understood correctly). An example is shown below:
Here, the black lines connecting the particles represent the edges in the graph, and the red cycle is one contained in cycles
(which is clearly not a basis cycle). In addition, there are occasional duplicates present in the set.
My question: why does networkx.cycle_basis
display this behaviour? Is this expected and is my understanding of the cycle basis wrong, or is the output wrong? And is there any way to remove these non-basis cycles?