Skip to content

Commit c8f03bd

Browse files
authored
Improve performance of DominguezRios (#174)
1 parent 8013151 commit c8f03bd

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

src/algorithms/DominguezRios.jl

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,30 +124,46 @@ function _update!(
124124
end
125125
end
126126
L .= T
127-
for k in 1:length(L)
127+
for (k, L_k) in enumerate(L)
128128
i = 1
129-
N = length(L[k])
129+
N = length(L_k)
130130
while i < N
131131
index_to_remove = Int[]
132-
for j in i:N
133-
if i != j
134-
if all(L[k][i].u .<= L[k][j].u)
135-
L[k][i] = _join(L[k][i], L[k][j], k, z, yI, yN)
136-
push!(index_to_remove, j)
137-
elseif all(L[k][i].u .>= L[k][j].u)
138-
L[k][i] = _join(L[k][j], L[k][i], k, z, yI, yN)
139-
push!(index_to_remove, j)
140-
end
132+
for j in (i+1):N
133+
i_leq_j, j_leq_i = _leq_comparison(L_k[i].u, L_k[j].u)
134+
if i_leq_j
135+
L_k[i] = _join(L_k[i], L_k[j], k, z, yI, yN)
136+
push!(index_to_remove, j)
137+
elseif j_leq_i
138+
L_k[i] = _join(L_k[j], L_k[i], k, z, yI, yN)
139+
push!(index_to_remove, j)
141140
end
142141
end
143142
i += 1
144143
N -= length(index_to_remove)
145-
deleteat!(L[k], index_to_remove)
144+
deleteat!(L_k, index_to_remove)
146145
end
147146
end
148147
return
149148
end
150149

150+
function _leq_comparison(x::Vector, y::Vector)
151+
@assert length(x) == length(y)
152+
x_leq_y, y_leq_x = true, true
153+
for i in 1:length(x)
154+
@inbounds xi, yi = x[i], y[i]
155+
if xi > yi
156+
x_leq_y = false
157+
elseif xi < yi
158+
y_leq_x = false
159+
end
160+
if x_leq_y == y_leq_x == false
161+
break
162+
end
163+
end
164+
return x_leq_y, y_leq_x
165+
end
166+
151167
_isapprox(::Nothing, ::_DominguezRiosBox) = false
152168

153169
_isapprox(A::_DominguezRiosBox, B::_DominguezRiosBox) = A.l B.l && A.u B.u

0 commit comments

Comments
 (0)