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 b  
    101101        - RandomGNM
    102102        - RandomNewmanWattsStrogatz
    103103        - RandomHolmeKim
     104        - RandomInterval
    104105        - RandomLobster
    105106        - RandomTreePowerlaw
    106107        - RandomRegular
     
    229230                    - RandomGNM
    230231                    - RandomNewmanWattsStrogatz
    231232                    - RandomHolmeKim
     233                    - RandomInterval
    232234                    - RandomLobster
    233235                    - RandomTreePowerlaw
    234236                    - RandomRegular
     
    33303332        import networkx
    33313333        return graph.Graph(networkx.powerlaw_cluster_graph(n, m, p, seed))
    33323334
     3335    def RandomInterval(self,n):
     3336        """
     3337        Returns a random interval graph.
     3338
     3339        An interval graph is built from a list `(a_i,b_i)_{1\leq i \leq n}`
     3340        of intervals : to each interval of the list is associated one
     3341        vertex, two vertices being adjacent if the two corresponding
     3342        intervals intersect.
     3343
     3344        A random interval graph of order `n` is generated by picking
     3345        random values for the `(a_i,b_j)`, each of the two coordinates
     3346        being generated from the uniform distribution on the interval
     3347        `[0,1]`.
     3348
     3349        This definitions follows [boucheron2001]_.
     3350
     3351        INPUT:
     3352
     3353        - ``n`` (integer) -- the number of vertices in the random
     3354          graph.
     3355
     3356        EXAMPLE:
     3357
     3358        As for any interval graph, the chromatic number is equal to
     3359        the clique number ::
     3360
     3361            sage: g = graphs.RandomInterval(15)
     3362            sage: g.clique_number() == g.chromatic_number()
     3363            True
     3364
     3365        REFERENCE:
     3366
     3367        - [boucheron2001] Boucheron, S. and FERNANDEZ de la VEGA, W.,
     3368          On the Independence Number of Random Interval Graphs,
     3369          Combinatorics, Probability and Computing v10, issue 05,
     3370          Pages 385--396,
     3371          Cambridge Univ Press, 2001
     3372        """
     3373
     3374        from sage.misc.prandom import random
     3375
     3376        s = lambda x,y : (x,y) if x<=y else (y,x)
     3377        intervals = [s(random(), random()) for i in range(n)]
     3378        intervals.sort(key=lambda x:x[0])
     3379        edges = []
     3380        while intervals:
     3381            x = intervals.pop()
     3382            for y in intervals:
     3383                if y[0] <= x[1]:
     3384                    edges.append((x,y))
     3385                else:
     3386                    break
     3387        g=graph.Graph(vertices=intervals)
     3388        g.add_edges(edges)
     3389        return g
     3390
    33333391    def RandomLobster(self, n, p, q, seed=None):
    33343392        """
    33353393        Returns a random lobster.