Skip to content

Commit 87aacb2

Browse files
committed
Finish feasibility rewrite
1 parent ed42075 commit 87aacb2

File tree

2 files changed

+92
-91
lines changed

2 files changed

+92
-91
lines changed

test/feasibility.jl

Lines changed: 90 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -573,97 +573,98 @@ function test_analyse_mip()
573573
return
574574
end
575575

576-
#=
577-
578576
function test_analyse_no_opt()
579-
model = Model(HiGHS.Optimizer)
580-
set_silent(model)
581-
@variable(model, x)
582-
@constraint(model, c, x >= 0)
583-
@objective(model, Min, x)
584-
585-
# test no primal point
586-
@test_throws ErrorException ModelAnalyzer.analyze(
587-
ModelAnalyzer.Feasibility.Analyzer(),
588-
model,
589-
)
590-
591-
# test no dual point
592-
@test_throws ErrorException ModelAnalyzer.analyze(
593-
ModelAnalyzer.Feasibility.Analyzer(),
594-
model,
595-
primal_point = Dict(x => 1.0),
596-
dual_check = true,
597-
)
598-
599-
data = ModelAnalyzer.analyze(
600-
ModelAnalyzer.Feasibility.Analyzer(),
601-
model,
602-
primal_point = Dict(x => 1.0),
603-
dual_check = false,
604-
)
605-
list = ModelAnalyzer.list_of_issue_types(data)
606-
@test length(list) == 0
607-
608-
data = ModelAnalyzer.analyze(
609-
ModelAnalyzer.Feasibility.Analyzer(),
610-
model,
611-
primal_point = Dict(x => -1.0),
612-
dual_check = false,
613-
)
614-
list = ModelAnalyzer.list_of_issue_types(data)
615-
@test length(list) == 1
616-
ret = ModelAnalyzer.list_of_issues(data, list[1])
617-
@test ret[] == ModelAnalyzer.Feasibility.PrimalViolation(c, 1.0)
618-
619-
data = ModelAnalyzer.analyze(
620-
ModelAnalyzer.Feasibility.Analyzer(),
621-
model,
622-
primal_point = Dict(x => 1.0),
623-
dual_point = Dict(c => 1.0),
624-
)
625-
list = ModelAnalyzer.list_of_issue_types(data)
626-
@test length(list) == 2
627-
ret = ModelAnalyzer.list_of_issues(data, list[1])
628-
@test ret[1] == ModelAnalyzer.Feasibility.ComplemetarityViolation(c, 1.0)
629-
ret = ModelAnalyzer.list_of_issues(data, list[2])
630-
@test ret[1] == ModelAnalyzer.Feasibility.PrimalDualMismatch(1.0, 0.0)
631-
632-
data = ModelAnalyzer.analyze(
633-
ModelAnalyzer.Feasibility.Analyzer(),
634-
model,
635-
primal_point = Dict(x => 0.0),
636-
dual_point = Dict(c => 1.0),
637-
)
638-
list = ModelAnalyzer.list_of_issue_types(data)
639-
@test length(list) == 0
640-
641-
data = ModelAnalyzer.analyze(
642-
ModelAnalyzer.Feasibility.Analyzer(),
643-
model,
644-
primal_point = Dict(x => -1.0),
645-
dual_point = Dict(c => 2.0),
646-
)
647-
list = ModelAnalyzer.list_of_issue_types(data)
648-
@test length(list) == 4
649-
ret = ModelAnalyzer.list_of_issues(data, list[1])
650-
@test ret[1] == ModelAnalyzer.Feasibility.PrimalViolation(c, 1.0)
651-
ret = ModelAnalyzer.list_of_issues(data, list[2])
652-
@test ret[1] == ModelAnalyzer.Feasibility.DualConstraintViolation(x, 1.0)
653-
ret = ModelAnalyzer.list_of_issues(data, list[3])
654-
@test ret[1] == ModelAnalyzer.Feasibility.ComplemetarityViolation(c, -2.0)
655-
ret = ModelAnalyzer.list_of_issues(data, list[4])
656-
@test ret[1] == ModelAnalyzer.Feasibility.PrimalDualMismatch(-1.0, 0.0)
657-
658-
buf = IOBuffer()
659-
660-
ModelAnalyzer.summarize(buf, data)
661-
662-
ModelAnalyzer.summarize(buf, data, verbose = false)
663-
664-
return
577+
model = Model(HiGHS.Optimizer)
578+
set_silent(model)
579+
@variable(model, x)
580+
@constraint(model, c, x >= 0)
581+
@objective(model, Min, x)
582+
583+
# test no primal point
584+
@test_throws ErrorException ModelAnalyzer.analyze(
585+
ModelAnalyzer.Feasibility.Analyzer(),
586+
model,
587+
)
588+
589+
# test no dual point
590+
@test_throws ErrorException ModelAnalyzer.analyze(
591+
ModelAnalyzer.Feasibility.Analyzer(),
592+
model,
593+
primal_point = Dict(JuMP.index(x) => 1.0),
594+
dual_check = true,
595+
)
596+
597+
data = ModelAnalyzer.analyze(
598+
ModelAnalyzer.Feasibility.Analyzer(),
599+
model,
600+
primal_point = Dict(JuMP.index(x) => 1.0),
601+
dual_check = false,
602+
)
603+
list = ModelAnalyzer.list_of_issue_types(data)
604+
@test length(list) == 0
605+
606+
data = ModelAnalyzer.analyze(
607+
ModelAnalyzer.Feasibility.Analyzer(),
608+
model,
609+
primal_point = Dict(JuMP.index(x) => -1.0),
610+
dual_check = false,
611+
)
612+
list = ModelAnalyzer.list_of_issue_types(data)
613+
@test length(list) == 1
614+
ret = ModelAnalyzer.list_of_issues(data, list[1])
615+
@test ret[] == ModelAnalyzer.Feasibility.PrimalViolation(JuMP.index(c), 1.0)
616+
617+
data = ModelAnalyzer.analyze(
618+
ModelAnalyzer.Feasibility.Analyzer(),
619+
model,
620+
primal_point = Dict(JuMP.index(x) => 1.0),
621+
dual_point = Dict(JuMP.index(c) => 1.0),
622+
)
623+
list = ModelAnalyzer.list_of_issue_types(data)
624+
@test length(list) == 2
625+
ret = ModelAnalyzer.list_of_issues(data, list[1])
626+
@test ret[1] ==
627+
ModelAnalyzer.Feasibility.ComplemetarityViolation(JuMP.index(c), 1.0)
628+
ret = ModelAnalyzer.list_of_issues(data, list[2])
629+
@test ret[1] == ModelAnalyzer.Feasibility.PrimalDualMismatch(1.0, 0.0)
630+
631+
data = ModelAnalyzer.analyze(
632+
ModelAnalyzer.Feasibility.Analyzer(),
633+
model,
634+
primal_point = Dict(JuMP.index(x) => 0.0),
635+
dual_point = Dict(JuMP.index(c) => 1.0),
636+
)
637+
list = ModelAnalyzer.list_of_issue_types(data)
638+
@test length(list) == 0
639+
640+
data = ModelAnalyzer.analyze(
641+
ModelAnalyzer.Feasibility.Analyzer(),
642+
model,
643+
primal_point = Dict(JuMP.index(x) => -1.0),
644+
dual_point = Dict(JuMP.index(c) => 2.0),
645+
)
646+
list = ModelAnalyzer.list_of_issue_types(data)
647+
@test length(list) == 4
648+
ret = ModelAnalyzer.list_of_issues(data, list[1])
649+
@test ret[1] ==
650+
ModelAnalyzer.Feasibility.PrimalViolation(JuMP.index(c), 1.0)
651+
ret = ModelAnalyzer.list_of_issues(data, list[2])
652+
@test ret[1] ==
653+
ModelAnalyzer.Feasibility.DualConstraintViolation(JuMP.index(x), 1.0)
654+
ret = ModelAnalyzer.list_of_issues(data, list[3])
655+
@test ret[1] ==
656+
ModelAnalyzer.Feasibility.ComplemetarityViolation(JuMP.index(c), -2.0)
657+
ret = ModelAnalyzer.list_of_issues(data, list[4])
658+
@test ret[1] == ModelAnalyzer.Feasibility.PrimalDualMismatch(-1.0, 0.0)
659+
660+
buf = IOBuffer()
661+
662+
ModelAnalyzer.summarize(buf, data)
663+
664+
ModelAnalyzer.summarize(buf, data, verbose = false)
665+
666+
return
665667
end
666-
=#
667668

668669
# these tests are harder to permorm with a real solver as they tipically
669670
# return coherent objectives

test/runtests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ using Test
77

88
@testset "ModelAnalyzer" begin
99
for file in ["feasibility.jl", "numerical.jl"]
10-
# for file in ["feasibility.jl"]
11-
# for file in readdir(@__DIR__)
10+
# for file in ["infeasibility.jl"]
11+
# for file in readdir(@__DIR__)
1212
if !endswith(file, ".jl") || file in ("runtests.jl",)
1313
continue
1414
end

0 commit comments

Comments
 (0)