Skip to content

Commit 515f7cc

Browse files
authored
Fix floating point comparison in TambyVanderpooten (#134)
1 parent 9363a93 commit 515f7cc

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

src/algorithms/KirlikSayin.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,5 +178,5 @@ function minimize_multiobjective!(algorithm::KirlikSayin, model::Optimizer)
178178
MOI.delete.(model, ε_constraints)
179179
MOI.delete(model, zₖ_constraint)
180180
end
181-
return status, solutions
181+
return status, filter_nondominated(MOI.MIN_SENSE, solutions)
182182
end

src/algorithms/TambyVanderpooten.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,19 +180,21 @@ function minimize_multiobjective!(
180180
MOI.delete.(model, ε_constraints)
181181
MOI.delete(model, y_k_constraint)
182182
push!(V[k], (u, Y))
183-
if Y U_N[u][k]
183+
# We want `if !(Y in U_N[u][k])` but this tests exact equality. We want
184+
# an approximate comparison.
185+
if all(!isapprox(Y; atol = 1e-6), U_N[u][k])
184186
_update_search_region(U_N, Y, yN)
185187
solutions[Y] = X
186188
end
187189
bounds_to_remove = Vector{Float64}[]
188190
for u_i in keys(U_N)
189191
for k in 1:n
190-
if u_i[k] == yI[k]
192+
if isapprox(u_i[k], yI[k]; atol = 1e-6)
191193
push!(bounds_to_remove, u_i)
192194
else
193195
for (u_j, y_j) in V[k]
194196
if all(_project(u_i, k) .<= _project(u_j, k)) &&
195-
(y_j[k] == u_i[k])
197+
isapprox(y_j[k], u_i[k]; atol = 1e-6)
196198
push!(bounds_to_remove, u_i)
197199
end
198200
end
@@ -205,6 +207,5 @@ function minimize_multiobjective!(
205207
end
206208
end
207209
end
208-
solutions = [SolutionPoint(X, Y) for (Y, X) in solutions]
209-
return status, solutions
210+
return status, [SolutionPoint(X, Y) for (Y, X) in solutions]
210211
end

test/problems.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,4 +472,28 @@ function test_issue_122(model)
472472
return
473473
end
474474

475+
function test_issue_133(model)
476+
#!format: off
477+
p = Float64[
478+
33 90 96 75 1 69 100 50 63 61 59 95 58 10 77 30 86 89 82 51 38 33 73 54 91 89 95 82 48 67
479+
55 36 80 58 20 96 75 57 24 68 37 58 8 85 27 25 71 53 47 72 57 64 1 8 12 68 3 80 20 90
480+
22 40 50 73 44 65 12 26 13 77 14 68 71 35 54 98 45 95 98 19 18 38 14 51 37 48 35 97 95 36
481+
]
482+
w = Float64[
483+
22, 13, 10, 25, 4, 15, 17, 15, 15, 28, 14, 13, 2, 23, 6, 22, 18, 6, 23,
484+
21, 7, 7, 14, 4, 3, 27, 10, 5, 9, 10
485+
]
486+
#!format: on
487+
x = MOI.add_variables(model, length(w))
488+
MOI.add_constraint.(model, x, MOI.ZeroOne())
489+
MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE)
490+
f = MOI.Utilities.vectorize(p * x)
491+
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
492+
MOI.add_constraint(model, w' * x, MOI.LessThan(204.0))
493+
MOI.optimize!(model)
494+
@test MOI.get(model, MOI.TerminationStatus()) == MOI.OPTIMAL
495+
@test MOI.get(model, MOI.ResultCount()) == 95
496+
return
497+
end
498+
475499
end # module Problems

0 commit comments

Comments
 (0)