I've got a problem where I need to find a connected loop within an adjacency matrix. I'd like to find a loop that connects back to the original node over x hops. shortest_path algorithms provided by NetworkX do not provide an option for a node to be the same source and target.
For an example, this is the graph, and I'd like to find three colors with the largest distance between each other:
This might be represented similar to:
SOLUTIONS THAT DIDN'T WORK
Modification of shortest path algorithm (route from a node to itself)
There is a post here that mentions potentially setting weights or distances to infinite along the diagonal, but it doesn't appear networkx.all_shortest_paths, and any of the pathing algoirthms respect the self-loops as seen below:


