Ticket #12888: trac_12888.patch

File trac_12888.patch, 3.8 KB (added by dcoudert, 13 months ago)
  • sage/graphs/generic_graph.py

    # HG changeset patch
    # User dcoudert <david.coudert@inria.fr>
    # Date 1335642912 -7200
    # Node ID 277ab85497d75542a220c886109462b61d0ac6b4
    # Parent  38d39a4ac8f7e50cabac4c7c5e45d2ca3053ec90
    Trac #12888 -- Set new default parameters for RandomGNP
    
    diff --git a/sage/graphs/generic_graph.py b/sage/graphs/generic_graph.py
    a b  
    52885288        Then for digraphs:: 
    52895289 
    52905290            sage: from operator import itemgetter 
     5291            sage: set_random_seed(0) 
    52915292            sage: n = 20 
    52925293            sage: for i in range(20): 
    52935294            ...       g = DiGraph() 
  • sage/graphs/graph_generators.py

    diff --git a/sage/graphs/graph_generators.py b/sage/graphs/graph_generators.py
    a b  
    50835083#   Random Graphs 
    50845084################################################################################ 
    50855085 
    5086     def RandomGNP(self, n, p, seed=None, fast=False, method='networkx'): 
     5086    def RandomGNP(self, n, p, seed=None, fast=True, method='Sage'): 
    50875087        r""" 
    5088         Returns a Random graph on `n` nodes. Each edge is inserted independently 
     5088        Returns a random graph on `n` nodes. Each edge is inserted independently 
    50895089        with probability `p`. 
    50905090 
    50915091        INPUTS: 
     
    50965096 
    50975097        - ``seed`` -- integer seed for random number generator (default=None). 
    50985098 
    5099         - ``fast`` -- boolean set to True to use the algorithm with time 
    5100           complexity in `O(n+m)` proposed in [3]_. It is designed for generating 
    5101           large sparse digraphs, and faster than other methods only faster for 
     5099        - ``fast`` -- boolean set to True (default) to use the algorithm with 
     5100          time complexity in `O(n+m)` proposed in [3]_. It is designed for 
     5101          generating large sparse graphs. It is faster than other methods for 
    51025102          *LARGE* instances (try it to know whether it is useful for you). 
    51035103 
    5104         - ``method`` -- By default (```method='networkx'``), this function calls 
    5105           the NetworkX function ``gnp_random_graph``, unless ``fast=True``, then 
    5106           ``fast_gnp_random_graph``. When ``method='Sage'``, it uses the method 
    5107           implemented in ```sage.graphs.graph_generators_pyx.pyx`` (try it to 
    5108           know whether it is useful for you). The ``fast`` parameter is not 
    5109           taken into account by the 'Sage' method so far. 
     5104        - ``method`` -- By default (```method='Sage'``), this function uses the 
     5105          method implemented in ```sage.graphs.graph_generators_pyx.pyx``. When 
     5106          ``method='networkx'``, this function calls the NetworkX function 
     5107          ``fast_gnp_random_graph``, unless ``fast=False``, then 
     5108          ``gnp_random_graph``. Try them to know which method is the best for 
     5109          you. The ``fast`` parameter is not taken into account by the 'Sage' 
     5110          method so far. 
    51105111 
    51115112        REFERENCES: 
    51125113 
     
    51255126 
    51265127            sage: set_random_seed(0) 
    51275128            sage: graphs.RandomGNP(6, .4).edges(labels=False) 
    5128             [(0, 1), (0, 3), (0, 4), (1, 2), (1, 4), (3, 4)] 
     5129            [(0, 1), (0, 5), (1, 2), (2, 4), (3, 4), (3, 5), (4, 5)] 
    51295130 
    51305131        We plot a random graph on 12 nodes with probability 
    51315132        `p = .71`:: 
     
    51625163            sage: graphs.RandomGNP(50,.2, method="Sage").size() 
    51635164            243 
    51645165            sage: graphs.RandomGNP(50,.2, method="networkx").size() 
    5165             231 
     5166            258 
    51665167        """ 
    51675168        if n < 0: 
    51685169            raise ValueError("The number of nodes must be positive or null.") 
     
    51815182            else: 
    51825183                G = networkx.gnp_random_graph(n, p, seed=seed) 
    51835184            return graph.Graph(G) 
    5184         elif method == "Sage": 
     5185        elif method in ['Sage', 'sage']: 
    51855186            # We use the Sage generator 
    51865187            from sage.graphs.graph_generators_pyx import RandomGNP as sageGNP 
    51875188            return sageGNP(n, p)