Skip to content

Commit 1426502

Browse files
committed
add tests and cleanup
1 parent 90903ee commit 1426502

File tree

3 files changed

+54
-31
lines changed

3 files changed

+54
-31
lines changed

src/infeasibility.jl

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -293,15 +293,16 @@ function ModelAnalyzer.analyze(
293293
func = MOI.get(model, MOI.ConstraintFunction(), con)
294294
failed = false
295295
interval = _eval_variables(func) do var_idx
296-
if !haskey(variables, var_idx)
297-
failed = true
298-
return Interval(-Inf, Inf)
299-
end
296+
# this only fails if we allow continuing after bounds issues
297+
# if !haskey(variables, var_idx)
298+
# failed = true
299+
# return Interval(-Inf, Inf)
300+
# end
300301
return variables[var_idx]
301302
end
302-
if failed
303-
continue
304-
end
303+
# if failed
304+
# continue
305+
# end
305306
rhs = set.value
306307
if interval.lo > rhs || interval.hi < rhs
307308
push!(
@@ -323,15 +324,16 @@ function ModelAnalyzer.analyze(
323324
func = MOI.get(model, MOI.ConstraintFunction(), con)
324325
failed = false
325326
interval = _eval_variables(func) do var_idx
326-
if !haskey(variables, var_idx)
327-
failed = true
328-
return Interval(-Inf, Inf)
329-
end
327+
# this only fails if we allow continuing after bounds issues
328+
# if !haskey(variables, var_idx)
329+
# failed = true
330+
# return Interval(-Inf, Inf)
331+
# end
330332
return variables[var_idx]
331333
end
332-
if failed
333-
continue
334-
end
334+
# if failed
335+
# continue
336+
# end
335337
rhs = set.upper
336338
if interval.lo > rhs
337339
push!(
@@ -353,15 +355,16 @@ function ModelAnalyzer.analyze(
353355
func = MOI.get(model, MOI.ConstraintFunction(), con)
354356
failed = false
355357
interval = _eval_variables(func) do var_idx
356-
if !haskey(variables, var_idx)
357-
failed = true
358-
return Interval(-Inf, Inf)
359-
end
358+
# this only fails if we allow continuing after bounds issues
359+
# if !haskey(variables, var_idx)
360+
# failed = true
361+
# return Interval(-Inf, Inf)
362+
# end
360363
return variables[var_idx]
361364
end
362-
if failed
363-
continue
364-
end
365+
# if failed
366+
# continue
367+
# end
365368
rhs = set.lower
366369
if interval.hi < rhs
367370
push!(
@@ -401,8 +404,9 @@ function _fix_to_zero(model, variable::MOI.VariableIndex, ::Type{T}) where {T}
401404
if MOI.is_valid(model, lb_idx)
402405
MOI.delete(model, lb_idx)
403406
has_lower = true
404-
elseif MOI.is_valid(model, ub_idx)
405-
MOI.delete(model, ub_idx)
407+
# MOI.PenaltyRelaxation only creates variables with LB
408+
# elseif MOI.is_valid(model, ub_idx)
409+
# MOI.delete(model, ub_idx)
406410
else
407411
error("Variable is not bounded")
408412
end
@@ -422,8 +426,9 @@ function _set_bound_zero(
422426
MOI.delete(model, eq_idx)
423427
if has_lower
424428
MOI.add_constraint(model, variable, MOI.GreaterThan{T}(zero(T)))
425-
else
426-
MOI.add_constraint(model, variable, MOI.LessThan{T}(zero(T)))
429+
# MOI.PenaltyRelaxation only creates variables with LB
430+
# else
431+
# MOI.add_constraint(model, variable, MOI.LessThan{T}(zero(T)))
427432
end
428433
return
429434
end
@@ -479,6 +484,7 @@ function iis_elastic_filter(original_model::MOI.ModelLike, optimizer)
479484
if value1 > tolerance && value2 > tolerance
480485
error("IIS failed due numerical instability")
481486
elseif value1 > tolerance
487+
# TODO: coef is alwayas 1.0
482488
has_lower = _fix_to_zero(model, var1, T)
483489
delete!(constraint_to_affine, con)
484490
constraint_to_affine[con] = coef2 * var2

test/feasibility.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ function test_skip_missing_primal()
830830
skip_missing = true,
831831
dual_check = true,
832832
)
833-
@show list = ModelAnalyzer.list_of_issue_types(data)
833+
list = ModelAnalyzer.list_of_issue_types(data)
834834
@test length(list) == 0
835835
return
836836
end
@@ -888,7 +888,7 @@ function test_skip_missing_primal_empty_con()
888888
skip_missing = true,
889889
dual_check = true,
890890
)
891-
@show list = ModelAnalyzer.list_of_issue_types(data)
891+
list = ModelAnalyzer.list_of_issue_types(data)
892892
@test length(list) == 0
893893
return
894894
end
@@ -917,7 +917,7 @@ function test_skip_missing_dual()
917917
skip_missing = true,
918918
dual_check = true,
919919
)
920-
@show list = ModelAnalyzer.list_of_issue_types(data)
920+
list = ModelAnalyzer.list_of_issue_types(data)
921921
@test length(list) == 0
922922
return
923923
end
@@ -951,7 +951,7 @@ function test_dual_vector()
951951
primal_point = Dict(JuMP.index(x) => 0.5),
952952
dual_point = Dict(JuMP.index(c1) => [0.0, 0.5]),
953953
)
954-
@show list = ModelAnalyzer.list_of_issue_types(data)
954+
list = ModelAnalyzer.list_of_issue_types(data)
955955
@test length(list) == 0
956956
return
957957
end
@@ -969,7 +969,7 @@ function test_nl_con()
969969
primal_point = Dict(JuMP.index(x) => 0.0),
970970
dual_point = Dict(JuMP.index(c1) => 0.0),
971971
)
972-
@show list = ModelAnalyzer.list_of_issue_types(data)
972+
list = ModelAnalyzer.list_of_issue_types(data)
973973
@test length(list) == 0
974974
return
975975
end
@@ -987,7 +987,7 @@ function test_nl_obj()
987987
primal_point = Dict(JuMP.index(x) => 0.0),
988988
dual_point = Dict(JuMP.index(c1) => 0.0),
989989
)
990-
@show list = ModelAnalyzer.list_of_issue_types(data)
990+
list = ModelAnalyzer.list_of_issue_types(data)
991991
@test length(list) == 0
992992
return
993993
end

test/infeasibility.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,23 @@ function test_range_equalto_3()
311311
return
312312
end
313313

314+
function test_interval()
315+
model = Model(HiGHS.Optimizer)
316+
set_silent(model)
317+
@variable(model, x in MOI.Interval(0, 10))
318+
@variable(model, 0 <= y <= 20)
319+
@constraint(model, c1, x + y <= 1)
320+
@objective(model, Max, x + y)
321+
optimize!(model)
322+
data = ModelAnalyzer.analyze(
323+
ModelAnalyzer.Infeasibility.Analyzer(),
324+
model,
325+
optimizer = HiGHS.Optimizer,
326+
)
327+
list = ModelAnalyzer.list_of_issue_types(data)
328+
@test length(list) == 0
329+
end
330+
314331
function test_iis_feasible()
315332
model = Model(HiGHS.Optimizer)
316333
set_silent(model)

0 commit comments

Comments
 (0)