Adding a loop to graph
I have a for loop that adds edges to a graph g
, but I also want the graph to add loops. How can I do this, for a general graph whose structure I do not know (that is, I want to add the loop to a graph, rather than make a new graph)?
I've tried using the g.add_edge(1,1)
function, but that doesn't work, i.e. no loop is added. I also tried using g.add_edge
three times, then g.merge_vertices
to contract the cycle to a loop, but also to no avail. Sage justs simplifies the graph.
Any approach to this would be appreciated, direct or indirect.