@@ -24,7 +24,7 @@ the nodes.
24
24
positions will be truncated or filled up with random values between [-1,1] in every coordinate.
25
25
26
26
- `seed=1`: Seed for random initial positions.
27
- - `pin::Union{Nothing, Vector{Point{Dim, Bool}}}=nothing ` : Anchors positions of nodes to initial position
27
+ - `pin=Dict{Int, Bool}() ` : Anchors positions of nodes to initial position
28
28
"""
29
29
@addcall struct SFDP{Dim,Ptype,T<: AbstractFloat } <: IterativeLayout{Dim,Ptype}
30
30
tol:: T
@@ -33,11 +33,11 @@ the nodes.
33
33
iterations:: Int
34
34
initialpos:: Dict{Int, Point{Dim,Ptype}}
35
35
seed:: UInt
36
- pin:: Vector{Point{Dim, Bool} }
37
- function SFDP (tol, C, K, iterations, initialpos, seed, pin)
38
- for (ix, p) in enumerate ( pin)
39
- for (id, c) in enumerate (p)
40
- c && ! haskey (initialpos, ix) && error ( " Please provide coordinate for every pinned position" )
36
+ pin:: Dict{Int, Bool}
37
+ function SFDP (tol:: T , C:: T , K:: T , iterations:: Int , initialpos:: Dict , seed:: UInt , pin:: Dict ) where T <: AbstractFloat
38
+ for (ix, p) in pin
39
+ if ! haskey (initialpos, ix) && p
40
+ @warn " No coordinate provided for pinned position $ix "
41
41
end
42
42
end
43
43
dim = get_pt_dim (initialpos)
48
48
49
49
# TODO : check SFDP default parameters
50
50
function SFDP (; dim= 2 , Ptype= Float64, tol= 1.0 , C= 0.2 , K= 1.0 , iterations= 100 , initialpos= Dict {Int, Point{dim,Ptype}} (),
51
- seed:: UInt = UInt (1 ), pin = Vector {Bool} ())
52
- @show initialpos
51
+ seed:: UInt = UInt (1 ), pin = Dict {Int, Bool} ())
53
52
return SFDP (tol, C, K, iterations, initialpos, seed, pin)
54
53
end
55
54
56
55
function SFDP (tol:: T , C:: T , K:: T , iterations:: Int , initialpos:: Vector , seed:: UInt , pin) where T<: AbstractFloat
57
- @info " sfdp with ip vec"
58
- dim = get_pt_dim (initialpos)
59
56
initialpos = Dict (zip (1 : length (initialpos), Point .(initialpos)))
60
- Ptype = get_pt_ptype (initialpos)
61
57
# TODO fix initial pos if list has points of multiple types
62
58
return SFDP (tol, C, K, iterations, initialpos, seed, pin)
63
59
end
64
60
65
- function SFDP (tol:: T , C:: T , K:: T , iterations:: Int , initialpos:: Dict{Int, <:Point} , seed:: UInt , pin:: Dict{Int, <:Point} ) where {T<: AbstractFloat }
66
- @info " sfdp with ip dict and pin dict"
67
- fixed = falses (maximum (keys (pin)))
68
- for (i, p) in pin
69
- haskey (initialpos, i) && @warn " overwriting initial position of node $i with pin position"
70
- initialpos[i] = p
71
- fixed[i] = true
72
- end
73
- dim = get_pt_dim (initialpos)
74
- Ptype = get_pt_ptype (initialpos)
75
- return SFDP (tol, C, K, iterations, initialpos, seed, Point {dim,Bool} .(fixed))
76
- end
77
-
78
61
function SFDP (tol:: T , C:: T , K:: T , iterations:: Int , initialpos:: Dict{Int, <:Point} , seed:: UInt , pin:: Vector{Bool} ) where T<: AbstractFloat
79
- @info " sfdp with ip dict and pin vec"
80
62
dim = get_pt_dim (initialpos)
81
- Ptype = get_pt_ptype (initialpos )
82
- return SFDP (tol, C, K, iterations, initialpos, seed, Point {dim, Bool} .(pin) )
63
+ fixed = Dict ( zip ( 1 : length (pin), pin) )
64
+ return SFDP (tol, C, K, iterations, initialpos, seed, fixed )
83
65
end
84
66
85
67
function get_pt_ptype (ip:: Dict{Int, <:Point} )
@@ -141,7 +123,6 @@ function Base.iterate(iter::LayoutIterator{<:SFDP}, state)
141
123
energy = zero (energy0)
142
124
Ftype = eltype (locs)
143
125
N = size (adj_matrix, 1 )
144
- pin = N > length (algo. pin) ? vcat (algo. pin, falses (N- length (algo. pin))) : algo. pin
145
126
for i in 1 : N
146
127
force = zero (Ftype)
147
128
for j in 1 : N
@@ -156,7 +137,7 @@ function Base.iterate(iter::LayoutIterator{<:SFDP}, state)
156
137
((locs[j] .- locs[i]) / norm (locs[j] .- locs[i])))
157
138
end
158
139
end
159
- if ! pin[i]
140
+ if ! get (algo . pin, i, false )
160
141
locs[i] = locs[i] .+ step .* (force ./ norm (force))
161
142
end
162
143
energy = energy + norm (force)^ 2
0 commit comments