Common graphs and digraphs generators (Cython) - Graph Theory

Skip to content
Back to top
View this page
Edit this page

# Common graphs and digraphs generators (Cython)

AUTHORS:

- David Coudert (2012)

sage.graphs.graph_generators_pyx.RandomGNP(n, p, directed=False, loops=False, seed=None, immutable=False)

  Return a random graph or a digraph on \(n\) nodes.

  Each edge is inserted independently with probability \(p\).

  INPUT:

  - `n` – number of nodes of the digraph

  - `p` – probability of an edge

  - `directed` – boolean (default: `False`); whether the random graph is directed or undirected (default)

  - `loops` – boolean (default: `False`); whether the random digraph may have loops or not. This value is used only when `directed == True`

  - `seed` – a `random.Random` seed or a Python `int` for the random number generator (default: `None`)

  - `immutable` – boolean (default: `False`); whether to return an immutable or mutable (di)graph.

  REFERENCES:

  - [ER1959]

  - [Gil1959]

  EXAMPLES:

  Sage

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

  Python

      >>> from sage.all import *
      >>> from sage.graphs.graph_generators_pyx import RandomGNP
      >>> D = RandomGNP(Integer(10), RealNumber('.2'), directed=True, seed=Integer(0))
      >>> D.n_vertices()
      10
      >>> D.edges(sort=True, labels=False)
      [(0, 3), (0, 6), (1, 7), (1, 9), (4, 6), (4, 7), (5, 4), (5, 6),
       (5, 8), (5, 9), (6, 3), (7, 2), (7, 9), (8, 5), (9, 1), (9, 5)]