Skip to content

adding fixed locations to sfdp #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/sfdp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@ struct Layout{M<:AbstractMatrix,P<:AbstractVector,T<:AbstractFloat}
C::T
K::T
iterations::Int
fixed::BitVector
end

function Layout(adj_matrix, PT::Type{Point{N,T}}=Point{2,Float64};
startpositions=map(x -> 2 .* rand(PT) .- 1, 1:size(adj_matrix, 1)), tol=1.0, C=0.2, K=1.0,
iterations=100) where {N,T}
return Layout(adj_matrix, startpositions, T(tol), T(C), T(K), Int(iterations))
startpositions=map(x -> 2 .* rand(PT) .- 1, 1:size(adj_matrix, 1)),
tol=1.0,
C=0.2,
K=1.0,
iterations=100,
fixed = falses(length(startpositions))) where {N,T}
return Layout(adj_matrix, startpositions, T(tol), T(C), T(K), Int(iterations), fixed)
end

layout(adj_matrix, dim::Int; kw_args...) = layout(adj_matrix, Point{dim,Float64}; kw_args...)
Expand Down Expand Up @@ -78,7 +83,9 @@ function iterate(network::Layout, state)
((locs[j] .- locs[i]) / norm(locs[j] .- locs[i])))
end
end
locs[i] = locs[i] .+ step .* (force ./ norm(force))
if !network.fixed[i]
locs[i] = locs[i] .+ step .* (force ./ norm(force))
end
energy = energy + norm(force)^2
end
step, progress = update_step(step, energy, energy0, progress)
Expand Down