# 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
|
|
| 5288 | 5288 | Then for digraphs:: |
| 5289 | 5289 | |
| 5290 | 5290 | sage: from operator import itemgetter |
| | 5291 | sage: set_random_seed(0) |
| 5291 | 5292 | sage: n = 20 |
| 5292 | 5293 | sage: for i in range(20): |
| 5293 | 5294 | ... g = DiGraph() |
diff --git a/sage/graphs/graph_generators.py b/sage/graphs/graph_generators.py
|
a
|
b
|
|
| 5083 | 5083 | # Random Graphs |
| 5084 | 5084 | ################################################################################ |
| 5085 | 5085 | |
| 5086 | | def RandomGNP(self, n, p, seed=None, fast=False, method='networkx'): |
| | 5086 | def RandomGNP(self, n, p, seed=None, fast=True, method='Sage'): |
| 5087 | 5087 | 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 |
| 5089 | 5089 | with probability `p`. |
| 5090 | 5090 | |
| 5091 | 5091 | INPUTS: |
| … |
… |
|
| 5096 | 5096 | |
| 5097 | 5097 | - ``seed`` -- integer seed for random number generator (default=None). |
| 5098 | 5098 | |
| 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 |
| 5102 | 5102 | *LARGE* instances (try it to know whether it is useful for you). |
| 5103 | 5103 | |
| 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. |
| 5110 | 5111 | |
| 5111 | 5112 | REFERENCES: |
| 5112 | 5113 | |
| … |
… |
|
| 5125 | 5126 | |
| 5126 | 5127 | sage: set_random_seed(0) |
| 5127 | 5128 | 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)] |
| 5129 | 5130 | |
| 5130 | 5131 | We plot a random graph on 12 nodes with probability |
| 5131 | 5132 | `p = .71`:: |
| … |
… |
|
| 5162 | 5163 | sage: graphs.RandomGNP(50,.2, method="Sage").size() |
| 5163 | 5164 | 243 |
| 5164 | 5165 | sage: graphs.RandomGNP(50,.2, method="networkx").size() |
| 5165 | | 231 |
| | 5166 | 258 |
| 5166 | 5167 | """ |
| 5167 | 5168 | if n < 0: |
| 5168 | 5169 | raise ValueError("The number of nodes must be positive or null.") |
| … |
… |
|
| 5181 | 5182 | else: |
| 5182 | 5183 | G = networkx.gnp_random_graph(n, p, seed=seed) |
| 5183 | 5184 | return graph.Graph(G) |
| 5184 | | elif method == "Sage": |
| | 5185 | elif method in ['Sage', 'sage']: |
| 5185 | 5186 | # We use the Sage generator |
| 5186 | 5187 | from sage.graphs.graph_generators_pyx import RandomGNP as sageGNP |
| 5187 | 5188 | return sageGNP(n, p) |