I am new to Julia and LightGraphs and I have been trying to find the most efficient way of detecting and removing self-loops. So far, the only way I have found is to iterate over all nodes in the Simplegraph, check whether it has a self-loop, and remove them. Is there any better way like using this combination in Python NetworkX: G.remove_edges_from(G.selfloop_edges())?
The way I am doing it right now:
path = adrs\to\my\edgeList
G = SimpleGraph(loadgraph(path, GraphIO.EdgeList.EdgeListFormat()))
for node in vertices(G)
if has_edge(G,node,node)
rem_edge!(G,node,node)
end
end
I did a quick benchmarking between my solution (without the
has_edge(), thanks @sbromberger!) and the one proposed by @Przemyslaw (looks quite neat!). It seems my simple way of doing it is still the most efficient way, both in terms of memory and time. I was surprised to see thesimplecycles_limited_length()does worse than the loop, considering the function seems to be for this specific purpose. If you know why that is, please let me know.Here are my benchmarking results (my_graph has 22,470 nodes and 170,823 edges with 179 self-loops):
Edit: Added the interpolated benchmarks as requested.