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:
- g
Graph Graph to be modified.
- M
int Number of edges to be added.
- parallel
bool(optional, default:False) Wheter to allow parallel edges to be added.
- self_loops
bool(optional, default:False) Wheter to allow self_loops to be added.
- weight
EdgePropertyMap, optional (default:None) Integer edge multiplicities. If supplied, this will be incremented for edges already in the graph, instead of new edges being added.
- g
See also
remove_random_edgesremove random edges to the graph
Notes
If the graph is not being filtered, this algorithm runs in time \(O(M)\) if
parallel == Trueor \(O(M\left<k\right>)\) ifparallel == 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 == Trueor \(O(M\left<k\right> + E)\) ifparallel == 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)