Skip to content

Commit 1fac19d

Browse files
authored
Change dual_check default to whether model is supported by Dualization (#60)
1 parent 736f1e3 commit 1fac19d

File tree

3 files changed

+15
-37
lines changed

3 files changed

+15
-37
lines changed

src/Feasibility/analyze.jl

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,16 @@ function MathOptAnalyzer.analyze(
1212
dual_objective::Union{Nothing,Float64} = nothing,
1313
atol::Float64 = 1e-6,
1414
skip_missing::Bool = false,
15-
dual_check = true,
15+
dual_check::Bool = _can_dualize(model),
1616
)
17-
can_dualize = false
18-
if dual_check
19-
can_dualize = _can_dualize(model)
20-
if !can_dualize
21-
println(
22-
"The model cannot be dualized. Automatically setting `dual_check = false`.",
23-
)
24-
dual_check = false
25-
end
26-
end
27-
28-
data = Data(
29-
primal_point = primal_point,
30-
dual_point = dual_point,
31-
primal_objective = primal_objective,
32-
dual_objective = dual_objective,
33-
atol = atol,
34-
skip_missing = skip_missing,
35-
dual_check = dual_check,
17+
data = Data(;
18+
primal_point,
19+
dual_point,
20+
primal_objective,
21+
dual_objective,
22+
atol,
23+
skip_missing,
24+
dual_check,
3625
)
3726

3827
if data.primal_point === nothing
@@ -423,24 +412,14 @@ function _last_dual_solution(model::MOI.ModelLike)
423412
end
424413

425414
function _can_dualize(model::MOI.ModelLike)
426-
types = MOI.get(model, MOI.ListOfConstraintTypesPresent())
427-
428-
for (F, S) in types
415+
for (F, S) in MOI.get(model, MOI.ListOfConstraintTypesPresent())
429416
if !Dualization.supported_constraint(F, S)
430417
return false
431418
end
432419
end
433-
434420
F = MOI.get(model, MOI.ObjectiveFunctionType())
435-
436421
if !Dualization.supported_objective(F)
437422
return false
438423
end
439-
440-
sense = MOI.get(model, MOI.ObjectiveSense())
441-
if sense == MOI.FEASIBILITY_SENSE
442-
return false
443-
end
444-
445-
return true
424+
return MOI.get(model, MOI.ObjectiveSense()) != MOI.FEASIBILITY_SENSE
446425
end

src/Feasibility/structs.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ julia> data = MathOptAnalyzer.analyze(
2020
dual_objective::Union{Nothing, Float64} = nothing,
2121
atol::Float64 = 1e-6,
2222
skip_missing::Bool = false,
23-
dual_check = true,
23+
dual_check::Bool = true,
2424
);
2525
```
2626
@@ -39,9 +39,9 @@ The additional parameters:
3939
- `atol`: The absolute tolerance for feasibility checking.
4040
- `skip_missing`: If `true`, constraints with missing variables in the provided
4141
point will be ignored.
42-
- `dual_check`: If `true`, it will perform dual feasibility checking. Disabling
43-
the dual check will also disable complementarity checking and dual objective
44-
checks.
42+
- `dual_check`: If `true`, it will perform dual feasibility checking if the
43+
model is compatible with Dualization.jl. Disabling the dual check will also
44+
disable complementarity checking and dual objective checks.
4545
"""
4646
struct Analyzer <: MathOptAnalyzer.AbstractAnalyzer end
4747

test/test_Numerical.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,6 @@ function test_dyn_range_objective()
15461546
data,
15471547
MathOptAnalyzer.Numerical.LargeDynamicRangeObjective,
15481548
)
1549-
@show ret
15501549
@test length(ret) == 1
15511550
@test MathOptAnalyzer.variables(ret[], model) == [x, y]
15521551
@test MathOptAnalyzer.values(ret[]) == [1e-4, 7e4]

0 commit comments

Comments
 (0)