You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Adding constants to parameters in the objective #125
I found an issue when trying out this package. It seems an error occurs when trying to add a constant to a parameter in the objective.
Here is an example:
using JuMP, ParametricOptInterface, Gurobi
const POI = ParametricOptInterface
optimizer = () -> POI.Optimizer(Gurobi.Optimizer())
mdl = Model(optimizer)
@variable(mdl, p in POI.Parameter(1.0))
@variable(mdl, 0 <= x <= 1)
@objective(mdl, Max, (p + 0.5) * x)
optimize!(mdl)
@show objective_value(mdl)
@show value(objective_function(mdl))
objective_value(mdl) = 0.5
value(objective_function(mdl)) = 1.5
The optimal solution should be 1.5, but it becomes 0.5. It is as if the parameter goes to zero when added to a constant. This seems to only happen in the objective, not for constraints.
Using JuMP v1.3.0, ParametricOptInterface v0.4.3 and Gurobi v0.11.3
julia> model =Model(() -> POI.Optimizer(GLPK.Optimizer()))
A JuMP Model
Feasibility problem with:
Variables:0
Model mode: AUTOMATIC
CachingOptimizer state: EMPTY_OPTIMIZER
Solver name: Parametric Optimizer with GLPK attached
julia>@variable(model, p in POI.Parameter(1.0))
p
julia>@variable(model, 0<= x <=1)
x
julia>@objective(model, Max, (p +0.5) * x)
p*x +0.5 x
julia>optimize!(model)
julia>@testvalue(x) ≈1.0
Test Passed
julia>@testobjective_value(model) ≈1.5
Test Failed at REPL[20]:1
Expression:objective_value(model) ≈1.5
Evaluated:0.5≈1.5
ERROR: There was an error during testing
julia>@testvalue(objective_function(model)) ≈1.5
Test Passed
The issue is that the objective passed to GLPK is just completely wrong:
julia>print(unsafe_backend(model).optimizer)
Maximize ScalarAffineFunction{Float64}:0.0+0.5 x
Subject to:
VariableIndex-in-GreaterThan{Float64}
x >=0.0
VariableIndex-in-LessThan{Float64}
x <=1.0
Activity
odow commentedon Dec 6, 2022
I can reproduce:
odow commentedon Dec 6, 2022
The issue is that the objective passed to GLPK is just completely wrong: