Skip to content

Commit f09d573

Browse files
committed
more tests
1 parent 6e6c373 commit f09d573

File tree

2 files changed

+114
-5
lines changed

2 files changed

+114
-5
lines changed

src/infeasibility.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -317,19 +317,20 @@ function iis_elastic_filter(original_model::JuMP.GenericModel, optimizer)
317317
var = collect(keys(func.terms))
318318
coef1 = func.terms[var[1]]
319319
coef2 = func.terms[var[2]]
320-
if JuMP.value(var1) > tolerance && JuMP.value(var2) > tolerance
320+
if JuMP.value(var[1]) > tolerance &&
321+
JuMP.value(var[2]) > tolerance
321322
error("IIS failed due numerical instability")
322323
elseif JuMP.value(var[1]) > tolerance
323324
has_lower = JuMP.has_lower_bound(var[1])
324325
JuMP.fix(var[1], 0.0; force = true)
325-
# or delete(model, var1)
326+
# or delete(model, var[1])
326327
delete!(constraint_to_affine, con)
327328
constraint_to_affine[con] = coef2 * var[2]
328329
push!(de_elastisized, (con, var[1], has_lower))
329330
elseif JuMP.value(var[2]) > tolerance
330331
has_lower = JuMP.has_lower_bound(var[2])
331332
JuMP.fix(var[2], 0.0; force = true)
332-
# or delete(model, var2)
333+
# or delete(model, var[2])
333334
delete!(constraint_to_affine, con)
334335
constraint_to_affine[con] = coef1 * var[1]
335336
push!(de_elastisized, (con, var[2], has_lower))
@@ -572,7 +573,7 @@ function ModelAnalyzer._summarize(
572573
end
573574

574575
function ModelAnalyzer._summarize(io::IO, issue::IrreducibleInfeasibleSubset)
575-
return print(io, "IIS: ", join(map(issue.constraint, _name), ", "))
576+
return print(io, "IIS: ", join(map(_name, issue.constraint), ", "))
576577
end
577578

578579
function ModelAnalyzer._verbose_summarize(
@@ -631,7 +632,7 @@ function ModelAnalyzer._verbose_summarize(
631632
return print(
632633
io,
633634
"Irreducible Infeasible Subset: ",
634-
join(map(issue.constraint, _name), ", "),
635+
join(map(_name, issue.constraint), ", "),
635636
)
636637
end
637638

test/infeasibility.jl

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,114 @@ function test_iis()
260260
@test length(ret[].constraint) == 2
261261
@test ret[].constraint[1] == c2
262262
@test ret[].constraint[2] == c1
263+
#
264+
buf = IOBuffer()
265+
ModelAnalyzer.summarize(
266+
buf,
267+
ModelAnalyzer.Infeasibility.IrreducibleInfeasibleSubset,
268+
)
269+
str = String(take!(buf))
270+
@test startswith(str, "# `IrreducibleInfeasibleSubset`")
271+
ModelAnalyzer.summarize(
272+
buf,
273+
ModelAnalyzer.Infeasibility.IrreducibleInfeasibleSubset,
274+
verbose = false,
275+
)
276+
str = String(take!(buf))
277+
@test str == "# IrreducibleInfeasibleSubset"
278+
#
279+
ModelAnalyzer.summarize(buf, ret[1], verbose = true)
280+
str = String(take!(buf))
281+
@test startswith(str, "Irreducible Infeasible Subset: ")
282+
@test contains(str, ", ")
283+
ModelAnalyzer.summarize(buf, ret[1], verbose = false)
284+
str = String(take!(buf))
285+
@test startswith(str, "IIS: ")
286+
@test contains(str, ", ")
287+
288+
buf = IOBuffer()
289+
Base.show(buf, data)
290+
str = String(take!(buf))
291+
return
292+
end
293+
294+
function test_iis_multiple()
295+
model = Model(HiGHS.Optimizer)
296+
set_silent(model)
297+
@variable(model, 0 <= x <= 10)
298+
@variable(model, 0 <= y <= 20)
299+
@constraint(model, c1, x + y <= 1)
300+
@constraint(model, c3, x + y <= 1.5)
301+
@constraint(model, c2, x + y >= 2)
302+
@objective(model, Max, x + y)
303+
optimize!(model)
304+
data = ModelAnalyzer.analyze(ModelAnalyzer.Infeasibility.Analyzer(), model)
305+
list = ModelAnalyzer.list_of_issue_types(data)
306+
@test length(list) == 0
307+
data = ModelAnalyzer.analyze(
308+
ModelAnalyzer.Infeasibility.Analyzer(),
309+
model,
310+
optimizer = HiGHS.Optimizer,
311+
)
312+
list = ModelAnalyzer.list_of_issue_types(data)
313+
@test length(list) == 1
314+
ret = ModelAnalyzer.list_of_issues(data, list[1])
315+
@test length(ret) == 1
316+
@test length(ret[].constraint) == 2
317+
@test c2 in Set([ret[].constraint[1], ret[].constraint[2]])
318+
@test Set([ret[].constraint[1], ret[].constraint[2]]) Set([c3, c2, c1])
319+
return
320+
end
321+
322+
function test_iis_interval_right()
323+
model = Model(HiGHS.Optimizer)
324+
set_silent(model)
325+
@variable(model, 0 <= x <= 10)
326+
@variable(model, 0 <= y <= 20)
327+
@constraint(model, c1, 0 <= x + y <= 1)
328+
@constraint(model, c2, x + y >= 2)
329+
@objective(model, Max, x + y)
330+
optimize!(model)
331+
data = ModelAnalyzer.analyze(ModelAnalyzer.Infeasibility.Analyzer(), model)
332+
list = ModelAnalyzer.list_of_issue_types(data)
333+
@test length(list) == 0
334+
data = ModelAnalyzer.analyze(
335+
ModelAnalyzer.Infeasibility.Analyzer(),
336+
model,
337+
optimizer = HiGHS.Optimizer,
338+
)
339+
list = ModelAnalyzer.list_of_issue_types(data)
340+
@test length(list) == 1
341+
ret = ModelAnalyzer.list_of_issues(data, list[1])
342+
@test length(ret) == 1
343+
@test length(ret[].constraint) == 2
344+
@test Set([ret[].constraint[1], ret[].constraint[2]]) == Set([c2, c1])
345+
return
346+
end
347+
348+
function test_iis_interval_left()
349+
model = Model(HiGHS.Optimizer)
350+
set_silent(model)
351+
@variable(model, 0 <= x <= 10)
352+
@variable(model, 0 <= y <= 20)
353+
@constraint(model, c1, x + y <= 1)
354+
@constraint(model, c2, 2 <= x + y <= 5)
355+
@objective(model, Max, x + y)
356+
optimize!(model)
357+
data = ModelAnalyzer.analyze(ModelAnalyzer.Infeasibility.Analyzer(), model)
358+
list = ModelAnalyzer.list_of_issue_types(data)
359+
@test length(list) == 0
360+
data = ModelAnalyzer.analyze(
361+
ModelAnalyzer.Infeasibility.Analyzer(),
362+
model,
363+
optimizer = HiGHS.Optimizer,
364+
)
365+
list = ModelAnalyzer.list_of_issue_types(data)
366+
@test length(list) == 1
367+
ret = ModelAnalyzer.list_of_issues(data, list[1])
368+
@test length(ret) == 1
369+
@test length(ret[].constraint) == 2
370+
@test Set([ret[].constraint[1], ret[].constraint[2]]) == Set([c2, c1])
263371
return
264372
end
265373

0 commit comments

Comments
 (0)