Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

Commit

Permalink
✋ indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
tpoisot committed Jul 8, 2019
1 parent fa12d6f commit 743fb82
Showing 1 changed file with 33 additions and 34 deletions.
67 changes: 33 additions & 34 deletions src/rand/shuffle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -257,39 +257,39 @@ end
TODO
"""
function shuffle!(N::UnipartiteQuantitativeNetwork{Float64,K}; ε::Float64=1e-2, constraint::Symbol=:degree, lims=(0.0, Inf)) where {K}
constraint [:degree, :generality, :vulnerability, :fill] || throw(ArgumentError("The constraint argument you specificied ($(constraint)) is invalid -- see ?shuffle! for a list."))
first(lims) < last(lims) || throw(ArgumentError("The interval you used for limits, $(lims), is invalid"))
all(first(lims) .<= N.A .<= last(lims)) || throw(ArgumentError("The interval you used for limits, $(lims), is smaller than the range of network values"))

# List of compatible swap schemes under different constraints
same_row = [[-1 1; -1 1], [-1 1; 0 0], [-1 1; 1 -1], [0 0; -1 1], [0 0; 1 -1], [1 -1; -1 1], [1 -1; 0 0], [1 -1; 1 -1],]
same_col = [[-1 -1; 1 1], [-1 0; 1 0], [-1 1; 1 -1], [0 -1; 0 1], [0 1; 0 -1], [1 -1; -1 1], [1 0; -1 0], [1 1; -1 -1],]
same_all = filter(x -> x same_row, same_col)
same_lnk = unique(vcat(same_row, same_col))

# Pick the correcty matrix series
m = same_lnk
constraint == :degree && (m = same_all)
constraint == :vulnerability && (m = same_col)
constraint == :generality && (m = same_row)
m = m.*ε

permuted = false
while !permuted
s1 = rand(1:richness(N; dims=1), 2)
while !quanti_shuffle_valid(N.A, s1, s1)
s1 = rand(1:richness(N; dims=1), 2)
end
st1 = filter(a -> all(first(lims).<=a.<=last(lims)), [N[s1,s1] .+ x for x in m])
st2 = filter(a -> all((N[s1,s1].!=0).==(a.!=0)), st1)
if length(st2) > 0
permuted = true
k = rand(st2)
for i in 1:2, j in 1:2
N[s1[i],s1[j]] = k[i,j]
end
end
end
constraint [:degree, :generality, :vulnerability, :fill] || throw(ArgumentError("The constraint argument you specificied ($(constraint)) is invalid -- see ?shuffle! for a list."))
first(lims) < last(lims) || throw(ArgumentError("The interval you used for limits, $(lims), is invalid"))
all(first(lims) .<= N.A .<= last(lims)) || throw(ArgumentError("The interval you used for limits, $(lims), is smaller than the range of network values"))

# List of compatible swap schemes under different constraints
same_row = [[-1 1; -1 1], [-1 1; 0 0], [-1 1; 1 -1], [0 0; -1 1], [0 0; 1 -1], [1 -1; -1 1], [1 -1; 0 0], [1 -1; 1 -1],]
same_col = [[-1 -1; 1 1], [-1 0; 1 0], [-1 1; 1 -1], [0 -1; 0 1], [0 1; 0 -1], [1 -1; -1 1], [1 0; -1 0], [1 1; -1 -1],]
same_all = filter(x -> x same_row, same_col)
same_lnk = unique(vcat(same_row, same_col))

# Pick the correcty matrix series
m = same_lnk
constraint == :degree && (m = same_all)
constraint == :vulnerability && (m = same_col)
constraint == :generality && (m = same_row)
m = m.*ε

permuted = false
while !permuted
s1 = rand(1:richness(N; dims=1), 2)
while !quanti_shuffle_valid(N.A, s1, s1)
s1 = rand(1:richness(N; dims=1), 2)
end
st1 = filter(a -> all(first(lims).<=a.<=last(lims)), [N[s1,s1] .+ x for x in m])
st2 = filter(a -> all((N[s1,s1].!=0).==(a.!=0)), st1)
if length(st2) > 0
permuted = true
k = rand(st2)
for i in 1:2, j in 1:2
N[s1[i],s1[j]] = k[i,j]
end
end
end
end

"""
Expand All @@ -299,7 +299,6 @@ Shuffle a quantitative network -- see shuffle!
"""
function shuffle(N::T; kwargs...) where {T <: QuantitativeNetwork}
Y = copy(N)
@info kwargs
shuffle!(Y; kwargs...)
return Y
end

0 comments on commit 743fb82

Please sign in to comment.