Skip to content

Commit

Permalink
Fix infinite loop in EpsilonConstraint.jl (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-garcia authored Mar 21, 2023
1 parent 3e3bca2 commit d3f45d9
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/algorithms/EpsilonConstraint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,13 @@ function optimize_multiobjective!(
# Add epsilon constraint
sense = MOI.get(model.inner, MOI.ObjectiveSense())
variables = MOI.get(model.inner, MOI.ListOfVariableIndices())
SetType, bound, direction = if sense == MOI.MIN_SENSE
MOI.LessThan{Float64}, right, -1.0
SetType, bound = if sense == MOI.MIN_SENSE
MOI.LessThan{Float64}, right
else
MOI.GreaterThan{Float64}, left, 1.0
MOI.GreaterThan{Float64}, left
end
ci = MOI.add_constraint(model, f1, SetType(bound))
# Set a finite upper bound on the number of iterations so that we don't loop
# forever.
for i in 1:ceil(Int, abs(right - left) / ε + 3)
while true
MOI.set(model, MOI.ConstraintSet(), ci, SetType(bound))
MOI.optimize!(model.inner)
if !_is_scalar_status_optimal(model)
Expand All @@ -116,7 +114,11 @@ function optimize_multiobjective!(
if isempty(solutions) || !(Y solutions[end].y)
push!(solutions, SolutionPoint(X, Y))
end
bound = Y[1] + direction * ε
if sense == MOI.MIN_SENSE
bound = min(Y[1] - ε, bound - ε)
else
bound = max(Y[1] + ε, bound + ε)
end
end
MOI.delete(model, ci)
return MOI.OPTIMAL, filter_nondominated(sense, solutions)
Expand Down

0 comments on commit d3f45d9

Please sign in to comment.