File tree Expand file tree Collapse file tree 1 file changed +22
-7
lines changed
src/SimpleGraphs/generators Expand file tree Collapse file tree 1 file changed +22
-7
lines changed Original file line number Diff line number Diff line change @@ -160,13 +160,28 @@ function erdos_renyi(
160
160
seed:: Union{Nothing,Integer} = nothing ,
161
161
)
162
162
p >= 1 && return is_directed ? complete_digraph (n) : complete_graph (n)
163
- m = is_directed ? n * (n - 1 ) : div (n * (n - 1 ), 2 )
164
- ne = randbn (m, p; rng= rng, seed= seed)
165
- return if is_directed
166
- SimpleDiGraph (n, ne; rng= rng, seed= seed)
167
- else
168
- SimpleGraph (n, ne; rng= rng, seed= seed)
163
+ rng = getRNG (seed)
164
+ m = 0
165
+ fadj = [Int[] for u in 1 : n]
166
+ if is_directed
167
+ badj = [Int[] for u in 1 : n]
168
+ end
169
+ for u in 1 : n
170
+ start = is_directed ? 1 : u+ 1
171
+ for v in start: n
172
+ v == u && continue
173
+ if rand (rng) < p
174
+ m += 1
175
+ push! (fadj[u], v)
176
+ if is_directed
177
+ push! (badj[v], u)
178
+ else
179
+ push! (fadj[v], u)
180
+ end
181
+ end
182
+ end
169
183
end
184
+ return is_directed ? SimpleDiGraph (m, fadj, badj) : SimpleGraph (m, fadj)
170
185
end
171
186
172
187
"""
289
304
watts_strogatz(n, k, β)
290
305
291
306
Return a [Watts-Strogatz](https://en.wikipedia.org/wiki/Watts_and_Strogatz_model)
292
- small world random graph with `n` vertices, each with expected degree `k`
307
+ small world random graph with `n` vertices, each with expected degree `k`
293
308
(or `k - 1` if `k` is odd). Edges are randomized per the model based on probability `β`.
294
309
295
310
The algorithm proceeds as follows. First, a perfect 1-lattice is constructed,
You can’t perform that action at this time.
0 commit comments