Skip to content

Commit ee1d031

Browse files
committed
fix: vertices can be initialized at same position
1 parent cc0badf commit ee1d031

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/sfdp.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ function Base.iterate(iter::LayoutIterator{<:SFDP}, state)
101101
((locs[j] .- locs[i]) / norm(locs[j] .- locs[i])))
102102
end
103103
end
104+
if any(isnan, force)
105+
# if two points are at the exact same location
106+
# use random force in any direction
107+
rng = MersenneTwister(algo.seed + i)
108+
force = randn(rng, Ftype)
109+
end
104110
mask = (!).(pin[i]) # where pin=true mask will multiply with 0
105111
locs[i] = locs[i] .+ (step .* (force ./ norm(force))) .* mask
106112
energy = energy + norm(force)^2

src/spring.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,15 @@ function Base.iterate(iter::LayoutIterator{<:Spring}, state)
104104
# / | cos θ = d_x/d = fx/F
105105
# /--- -> fx = F*d_x/d
106106
# dx fx
107-
force_vec += Ftype(F_d .* (locs[j] .- locs[i]))
107+
if !iszero(d)
108+
force_vec += Ftype(F_d .* (locs[j] .- locs[i]))
109+
else
110+
# if two points are at the exact same location
111+
# use random force in any direction
112+
rng = MersenneTwister(algo.seed + i)
113+
force_vec += randn(rng, Ftype)
114+
end
115+
108116
end
109117
force[i] = force_vec
110118
end

0 commit comments

Comments
 (0)