Common graphs and digraphs generators (Cython)

Common graphs and digraphs generators (Cython)

AUTHORS:

  • David Coudert (2012)
sage.graphs.graph_generators_pyx.RandomGNP(n, p, directed=False, loops=False)

Returns a random graph or a digraph on \(n\) nodes. Each edge is inserted independently with probability \(p\).

INPUTS:

  • n – number of nodes of the digraph
  • p – probability of an edge
  • directed – is a boolean indicating whether the random graph is directed or undirected (default).
  • loops – is a boolean set to True if the random digraph may have loops, and False (default) otherwise. This value is used only when directed == True.

REFERENCES:

[1]
  1. Erdos and A. Renyi. On Random Graphs, Publ. Math. 6, 290 (1959).
[2]
    1. Gilbert. Random Graphs, Ann. Math. Stat., 30, 1141 (1959).

EXAMPLE:

sage: from sage.graphs.graph_generators_pyx import RandomGNP
sage: set_random_seed(0)
sage: D = RandomGNP(10, .2, directed = True)
sage: D.num_verts()
10
sage: D.edges(labels=False)
[(0, 2), (0, 5), (1, 5), (1, 7), (4, 1), (4, 2), (4, 9), (5, 0), (5, 2), (5, 3), (5, 7), (6, 5), (7, 1), (8, 2), (8, 6), (9, 4)]

TESTS:

sage: abs(mean([RandomGNP(200,.2).density() for i in range(30)])-.2) < .001
True
sage: RandomGNP(150,.2, loops = True)
Traceback (most recent call last):
...
ValueError: The 'loops' argument can be set to True only when 'directed' is True.

Previous topic

Common Digraphs

Next topic

Graph database

This Page