add_random_edges

add_random_edges#

graph_tool.generation.add_random_edges(g, M, parallel=False, self_loops=False, weight=None)[source]#

Add new edges to a graph, chosen uniformly at random.

Parameters:
gGraph

Graph to be modified.

Mint

Number of edges to be added.

parallelbool (optional, default: False)

Wheter to allow parallel edges to be added.

self_loopsbool (optional, default: False)

Wheter to allow self_loops to be added.

weightEdgePropertyMap, optional (default: None)

Integer edge multiplicities. If supplied, this will be incremented for edges already in the graph, instead of new edges being added.

See also

remove_random_edges

remove random edges to the graph

Notes

If the graph is not being filtered, this algorithm runs in time \(O(M)\) if parallel == True or \(O(M\left<k\right>)\) if parallel == False, where \(\left<k\right>\) is the average degree of the graph.

For filtered graphs, this algorithm runs in time \(O(M + E)\) if parallel == True or \(O(M\left<k\right> + E)\) if parallel == False, where \(E\) is the number of edges in the graph.

Examples

Generating a Newman–Watts–Strogatz small-world graph:

>>> g = gt.circular_graph(100)
>>> gt.add_random_edges(g, 30)