Skip to content

Commit b7594e2

Browse files
authored
Soft-deprecate POI.ParameterDual and POI.ParameterValue (#208)
1 parent 583615a commit b7594e2

5 files changed

Lines changed: 20 additions & 35 deletions

File tree

docs/src/index.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ choose the approach which works best for your model.
215215

216216
In some applications you may need the dual of a parameter. The dual can be
217217
computed only if the parameter appears additively in the problem. Query the dual
218-
assocaited with the parameter using [`ParameterDual`](@ref):
218+
associated with the parameter as follows:
219219
```@repl
220220
using JuMP, HiGHS
221221
import ParametricOptInterface as POI
@@ -226,10 +226,11 @@ set_silent(model)
226226
@constraint(model, x + p >= 3);
227227
@objective(model, Min, 2x);
228228
optimize!(model)
229-
get_attribute(p, POI.ParameterDual())
229+
dual(VariableInSetRef(p))
230230
```
231231

232-
Note how the dual is the same as the `reduced_cost` of an equivalent fixed variable:
232+
Note how the dual is the same as the `reduced_cost` of an equivalent fixed
233+
variable:
233234
```@repl
234235
using JuMP, HiGHS
235236
model = Model(HiGHS.Optimizer);

docs/src/reference.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,3 @@ Optimizer
2121
```@docs
2222
ConstraintsInterpretation
2323
```
24-
25-
## `ParameterDual`
26-
```@docs
27-
ParameterDual
28-
```
29-
30-
## `ParameterValue`
31-
```@docs
32-
ParameterValue
33-
```

src/duals.jl

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -139,32 +139,21 @@ function MOI.get(
139139
::ParameterDual,
140140
v::MOI.VariableIndex,
141141
) where {T}
142-
if !_is_additive(
143-
model,
144-
MOI.ConstraintIndex{MOI.VariableIndex,MOI.Parameter{T}}(v.value),
145-
)
146-
error("Cannot compute the dual of a multiplicative parameter")
147-
end
148-
return model.dual_value_of_parameters[p_val(v)]
142+
ci = MOI.ConstraintIndex{MOI.VariableIndex,MOI.Parameter{T}}(v.value)
143+
return MOI.get(model, MOI.ConstraintDual(), ci)
149144
end
150145

151146
function MOI.get(
152147
model::Optimizer{T},
153-
::MOI.ConstraintDual,
148+
attr::MOI.ConstraintDual,
154149
cp::MOI.ConstraintIndex{MOI.VariableIndex,MOI.Parameter{T}},
155150
) where {T}
156151
if !model.evaluate_duals
157-
throw(
158-
MOI.GetAttributeNotAllowed(
159-
MOI.ConstraintDual(),
160-
"$(MOI.ConstraintDual()) not available when " *
161-
"evaluate_duals is set to false. " *
162-
"Create an optimizer such as POI.Optimizer(HiGHS.Optimizer(); evaluate_duals = true) to enable this feature.",
163-
),
164-
)
165-
end
166-
if !_is_additive(model, cp)
167-
error("Cannot compute the dual of a multiplicative parameter")
152+
msg = "$attr not available when evaluate_duals is set to false. Create an optimizer such as `POI.Optimizer(HiGHS.Optimizer(); evaluate_duals = true)` to enable this feature."
153+
throw(MOI.GetAttributeNotAllowed(attr, msg))
154+
elseif !_is_additive(model, cp)
155+
msg = "Cannot compute the dual of a multiplicative parameter"
156+
throw(MOI.GetAttributeNotAllowed(attr, msg))
168157
end
169158
return model.dual_value_of_parameters[p_val(cp)]
170159
end

test/test_JuMP.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,9 +553,11 @@ function test_jump_dual_multiplicative_fail()
553553
@constraint(model, cons, x * p >= 3)
554554
@objective(model, Min, 2x)
555555
optimize!(model)
556-
@test_throws ErrorException(
556+
err = MOI.GetAttributeNotAllowed(
557+
MOI.ConstraintDual(),
557558
"Cannot compute the dual of a multiplicative parameter",
558-
) MOI.get(model, POI.ParameterDual(), p)
559+
)
560+
@test_throws err MOI.get(model, POI.ParameterDual(), p)
559561
return
560562
end
561563

test/test_MathOptInterface.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2450,7 +2450,10 @@ function test_multiplicative_dual_error()
24502450
p, pc = MOI.add_constrained_variable(model, MOI.Parameter(1.0))
24512451
f = 1.0 * x * p
24522452
ci = MOI.add_constraint(model, f, MOI.EqualTo{Float64}(0.0))
2453-
@test_throws ErrorException MOI.get(model, MOI.ConstraintDual(), pc)
2453+
@test_throws(
2454+
MOI.GetAttributeNotAllowed,
2455+
MOI.get(model, MOI.ConstraintDual(), pc),
2456+
)
24542457
return
24552458
end
24562459

0 commit comments

Comments
 (0)