Skip to content

Commit 1ab99f4

Browse files
committed
more tests
1 parent a10e19e commit 1ab99f4

File tree

3 files changed

+68
-13
lines changed

3 files changed

+68
-13
lines changed

src/range.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,20 @@ function _range_infeasibility!(
4141
return range_consistent
4242
end
4343
func = MOI.get(optimizer.original_model, MOI.ConstraintFunction(), con)
44-
# failed = false
44+
failed = false
4545
list_of_variables = MOI.VariableIndex[]
4646
interval = _eval_variables(func) do var_idx
4747
push!(list_of_variables, var_idx)
4848
# this only fails if we allow continuing after bounds issues
49-
# if !haskey(variables, var_idx)
50-
# failed = true
51-
# return Interval(-Inf, Inf)
52-
# end
49+
if !haskey(variables, var_idx)
50+
failed = true
51+
return Interval(-Inf, Inf)
52+
end
5353
return variables[var_idx]
5454
end
55-
# if failed
56-
# continue
57-
# end
55+
if failed
56+
continue
57+
end
5858
set = MOI.get(optimizer.original_model, MOI.ConstraintSet(), con)
5959
if _invalid_range(set, interval)
6060
cons = Set{MOI.ConstraintIndex}()

src/solver.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ function _elastic_filter(optimizer::Optimizer)
135135
obj_sense = MOI.get(model, MOI.ObjectiveSense())
136136

137137
# deletion filter
138-
cadidates = MOI.ConstraintIndex[]
138+
candidates = MOI.ConstraintIndex[]
139139
for (con, var) in de_elastisized
140140
if !_in_time(optimizer)
141141
return nothing
@@ -153,7 +153,7 @@ function _elastic_filter(optimizer::Optimizer)
153153
MOI.LOCALLY_SOLVED,
154154
MOI.ALMOST_LOCALLY_SOLVED,
155155
)
156-
push!(cadidates, con)
156+
push!(candidates, con)
157157
_fix_slack(model, var, T)
158158
elseif status in ( # possibily primal unbounded statuses
159159
MOI.INFEASIBLE_OR_UNBOUNDED,
@@ -166,7 +166,7 @@ function _elastic_filter(optimizer::Optimizer)
166166
# the unbounded case:
167167
if primal_status in (MOI.FEASIBLE_POINT, MOI.NEARLY_FEASIBLE_POINT)
168168
# this constraint is not in IIS
169-
push!(cadidates, con)
169+
push!(candidates, con)
170170
_fix_slack(model, var, T)
171171
MOI.set(model, MOI.ObjectiveSense(), obj_sense)
172172
MOI.set(
@@ -183,11 +183,11 @@ function _elastic_filter(optimizer::Optimizer)
183183
end
184184
end
185185

186-
if isempty(cadidates)
186+
if isempty(candidates)
187187
return nothing
188188
end
189189

190-
pre_iis = Set(cadidates)
190+
pre_iis = Set(candidates)
191191
iis = MOI.ConstraintIndex[]
192192
for (F, S) in
193193
MOI.get(optimizer.original_model, MOI.ListOfConstraintTypesPresent())

test/iis.jl

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,61 @@ function test_range()
191191
return
192192
end
193193

194+
function test_range_and_bound()
195+
model = Model()
196+
@variable(model, 10 <= x <= 11)
197+
@variable(model, 1 <= y <= 11)
198+
@variable(model, 1 <= z <= 0)
199+
@constraint(model, c, x + y <= 1)
200+
@objective(model, Max, x + y)
201+
solver = MOCS.Optimizer()
202+
MOI.set(solver, MOCS.InfeasibleModel(), JuMP.backend(model))
203+
MOI.compute_conflict!(solver)
204+
data = solver.results
205+
@test length(data) == 1
206+
@test _isequal_unordered(
207+
data[].constraints,
208+
[
209+
JuMP.index(LowerBoundRef(z)),
210+
JuMP.index(UpperBoundRef(z)),
211+
],
212+
)
213+
@test MOI.get(solver, MOCS.StopIfInfeasibleBounds()) == true
214+
MOI.set(solver, MOCS.StopIfInfeasibleBounds(), false)
215+
@test MOI.get(solver, MOCS.StopIfInfeasibleBounds()) == false
216+
MOI.compute_conflict!(solver)
217+
data = solver.results
218+
@test length(data) == 2
219+
@test _isequal_unordered(
220+
data[1].constraints,
221+
[
222+
JuMP.index(LowerBoundRef(z)),
223+
JuMP.index(UpperBoundRef(z)),
224+
],
225+
)
226+
@test _isequal_unordered(
227+
data[2].constraints,
228+
[
229+
JuMP.index(c),
230+
JuMP.index(UpperBoundRef(x)),
231+
JuMP.index(LowerBoundRef(x)),
232+
JuMP.index(UpperBoundRef(y)),
233+
JuMP.index(LowerBoundRef(y)),
234+
],
235+
)
236+
@test data[2].irreducible
237+
@test data[2].metadata ==
238+
MOCS.RangeData(11.0, 22.0, MOI.LessThan{Float64}(1.0))
239+
@test MOI.get(solver, MOCS.StopIfInfeasibleRanges()) == true
240+
MOI.set(solver, MOCS.StopIfInfeasibleRanges(), false)
241+
@test MOI.get(solver, MOCS.StopIfInfeasibleRanges()) == false
242+
MOI.set(solver, MOCS.InnerOptimizer(), HiGHS.Optimizer)
243+
MOI.compute_conflict!(solver)
244+
data = solver.results
245+
@test length(data) == 2
246+
return
247+
end
248+
194249
function test_range_neg()
195250
model = Model()
196251
@variable(model, 10 <= x <= 11)

0 commit comments

Comments
 (0)