Skip to content

Adding constants to parameters in the objective #125

Closed

Description

@bnarum

Hi

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

Activity

  1. odow commented on Dec 6, 2022

    @odow
    Member

    I can reproduce:

    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> @test value(x) ≈ 1.0
    Test Passed
    
    julia> @test objective_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> @test value(objective_function(model)) ≈ 1.5
    Test Passed
  2. odow commented on Dec 6, 2022

    @odow
    Member

    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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions