Skip to content

Bug when objective changed with different constant #492

@odow

Description

@odow

Reported on https://discourse.julialang.org/t/bug-in-detecting-changed-constant-in-objective-function/91235

julia> using Gurobi

julia> const MOI = Gurobi.MOI
MathOptInterface

julia> model = Gurobi.Optimizer();

julia> x = MOI.add_variable(model)
MathOptInterface.VariableIndex(1)

julia> MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE)

julia> attr = MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}()
MathOptInterface.ObjectiveFunction{MathOptInterface.ScalarAffineFunction{Float64}}()

julia> MOI.set(model, attr, 1.0 * x - 1.0)

julia> MOI.set(model, attr, 1.0 * x + 1.0)

julia> MOI.get(model, attr)
MathOptInterface.ScalarAffineFunction{Float64}(MathOptInterface.ScalarAffineTerm{Float64}[MathOptInterface.ScalarAffineTerm{Float64}(1.0, MathOptInterface.VariableIndex(1))], -1.0)

Final constant should be +1.0, not -1.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions