# Ticket #7487: trac_7487.patch

File trac_7487.patch, 2.9 KB (added by ncohen, 11 years ago)
• ## sage/graphs/graph_generators.py

# HG changeset patch
# User Nathann Cohen <nathann.cohen@gmail.com>
# Date 1258555677 -3600
# Node ID 578e394955d97b4bc443ef3f8a50f855533a61d5
# Parent  5db805d3bdafb3f79835cff2af6a333f749b500c
Random Interval Graphs added to graph_generators

diff -r 5db805d3bdaf -r 578e394955d9 sage/graphs/graph_generators.py
 a - RandomGNM - RandomNewmanWattsStrogatz - RandomHolmeKim - RandomInterval - RandomLobster - RandomTreePowerlaw - RandomRegular - RandomGNM - RandomNewmanWattsStrogatz - RandomHolmeKim - RandomInterval - RandomLobster - RandomTreePowerlaw - RandomRegular import networkx return graph.Graph(networkx.powerlaw_cluster_graph(n, m, p, seed)) def RandomInterval(self,n): """ Returns a random interval graph. An interval graph is built from a list (a_i,b_i)_{1\leq i \leq n} of intervals : to each interval of the list is associated one vertex, two vertices being adjacent if the two corresponding intervals intersect. A random interval graph of order n is generated by picking random values for the (a_i,b_j), each of the two coordinates being generated from the uniform distribution on the interval [0,1]. This definitions follows [boucheron2001]_. INPUT: - n (integer) -- the number of vertices in the random graph. EXAMPLE: As for any interval graph, the chromatic number is equal to the clique number :: sage: g = graphs.RandomInterval(15) sage: g.clique_number() == g.chromatic_number() True REFERENCE: - [boucheron2001] Boucheron, S. and FERNANDEZ de la VEGA, W., On the Independence Number of Random Interval Graphs, Combinatorics, Probability and Computing v10, issue 05, Pages 385--396, Cambridge Univ Press, 2001 """ from sage.misc.prandom import random s = lambda x,y : (x,y) if x<=y else (y,x) intervals = [s(random(), random()) for i in range(n)] intervals.sort(key=lambda x:x[0]) edges = [] while intervals: x = intervals.pop() for y in intervals: if y[0] <= x[1]: edges.append((x,y)) else: break g=graph.Graph(vertices=intervals) g.add_edges(edges) return g def RandomLobster(self, n, p, q, seed=None): """ Returns a random lobster.