Skip to content

Commit 300ab74

Browse files
authored
make default spring_layout deterministic
Fixes #76.
1 parent adeda23 commit 300ab74

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/layout.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,16 @@ Number of iterations we apply the forces
9191
*INITTEMP*
9292
Initial "temperature", controls movement per iteration
9393
94+
*seed*
95+
Integer seed for pseudorandom generation of locations (default = 0).
96+
9497
**Examples**
9598
```
9699
julia> g = graphfamous("karate")
97100
julia> locs_x, locs_y = spring_layout(g)
98101
```
99102
"""
100-
function spring_layout(g::AbstractGraph{T}, locs_x=2*rand(nv(g)).-1.0, locs_y=2*rand(nv(g)).-1.0; C=2.0, MAXITER=100, INITTEMP=2.0) where {T<:Integer}
103+
function spring_layout(g::AbstractGraph{T}, locs_x, locs_y; C=2.0, MAXITER=100, INITTEMP=2.0) where {T<:Integer}
101104

102105
#size(adj_matrix, 1) != size(adj_matrix, 2) && error("Adj. matrix must be square.")
103106
N = nv(g)
@@ -165,6 +168,11 @@ function spring_layout(g::AbstractGraph{T}, locs_x=2*rand(nv(g)).-1.0, locs_y=2*
165168
return locs_x,locs_y
166169
end
167170

171+
function spring_layout(g::AbstractGraph; seed::Integer=0, kws...)
172+
rng = MersenneTwister(seed)
173+
spring_layout(g, 2 .* rand(rng, nv(g)) .- 1.0, 2 .* rand(rng,nv(g)) .- 1.0; kws...)
174+
end
175+
168176
"""
169177
This function is copy from [IainNZ](https://github.com/IainNZ)'s [GraphLayout.jl](https://github.com/IainNZ/GraphLayout.jl)
170178

0 commit comments

Comments
 (0)