Ask Your Question

Revision history [back]

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 function, then g.merge_vertices to contract a cycle to a loop, but to no avail. Sage justs simplifies the graph.

Any approach to this would be appreciated, direct or indirect.

click to hide/show revision 2
added what I've tried

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 function, three times, then g.merge_vertices to contract a 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.