Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug modifying coefficient after constraint deletion #514

Closed
odow opened this issue Aug 15, 2023 · 1 comment · Fixed by #515
Closed

Bug modifying coefficient after constraint deletion #514

odow opened this issue Aug 15, 2023 · 1 comment · Fixed by #515

Comments

@odow
Copy link
Member

odow commented Aug 15, 2023

Found by someone at UoA. If I find their GitHub handle, I'll edit here.

julia> using Gurobi

julia> import MathOptInterface as MOI

julia> model = Gurobi.Optimizer()
    sense  : minimize
    number of variables             = 0
    number of linear constraints    = 0
    number of quadratic constraints = 0
    number of sos constraints       = 0
    number of non-zero coeffs       = 0
    number of non-zero qp objective terms  = 0
    number of non-zero qp constraint terms = 0


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

julia> c = [MOI.add_constraint(model, i * x, MOI.LessThan(i)) for i in [1.0, 2.0]]
2-element Vector{MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64}, MathOptInterface.LessThan{Float64}}}:
 MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64}, MathOptInterface.LessThan{Float64}}(2)
 MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64}, MathOptInterface.LessThan{Float64}}(3)

julia> MOI.optimize!(model)
Gurobi Optimizer version 10.0.0 build v10.0.0rc2 (mac64[x86])

CPU model: Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz
Thread count: 4 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 2 rows, 1 columns and 2 nonzeros
Model fingerprint: 0x04ae1447
Coefficient statistics:
  Matrix range     [1e+00, 2e+00]
  Objective range  [0e+00, 0e+00]
  Bounds range     [0e+00, 0e+00]
  RHS range        [1e+00, 2e+00]
Presolve removed 2 rows and 1 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    0.0000000e+00   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  0.000000000e+00

User-callback calls 31, time in user-callback 0.00 sec

julia> MOI.delete(model, c[1])

julia> MOI.modify(model, c[2], MOI.ScalarCoefficientChange(x, 4.0))

julia> MOI.optimize!(model)
Gurobi Optimizer version 10.0.0 build v10.0.0rc2 (mac64[x86])

CPU model: Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz
Thread count: 4 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 1 rows, 1 columns and 1 nonzeros
Model fingerprint: 0x742efd99
Coefficient statistics:
  Matrix range     [2e+00, 2e+00]
  Objective range  [0e+00, 0e+00]
  Bounds range     [0e+00, 0e+00]
  RHS range        [2e+00, 2e+00]
Presolve removed 1 rows and 1 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    0.0000000e+00   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  0.000000000e+00

User-callback calls 31, time in user-callback 0.00 sec

julia> GRBwrite(model, "bug.lp")
0

julia> print(read("bug.lp", String))
\ LP format - for model browsing. Use MPS format to capture full model detail.
Minimize
 
Subject To
 R1: 2 C0 <= 2
Bounds
 C0 free
End

R1 should be 4 C0 <= 2

@odow
Copy link
Member Author

odow commented Aug 15, 2023

Here's a C example:

julia> using Gurobi

julia> p_env = Ref{Ptr{Cvoid}}()
Base.RefValue{Ptr{Nothing}}(Ptr{Nothing} @0x0000000141e19590)

julia> GRBemptyenv(p_env)
0

julia> env = p_env[]
Ptr{Nothing} @0x00007ff5bf081800

julia> GRBstartenv(env)
0

julia> p_model = Ref{Ptr{Cvoid}}()
Base.RefValue{Ptr{Nothing}}(Ptr{Nothing} @0x000000010c432b90)

julia> GRBnewmodel(env, p_model, "", 0, C_NULL, C_NULL, C_NULL, C_NULL, C_NULL)
0

julia> model = p_model[]
Ptr{Nothing} @0x00007ff5afe4a9a0

julia> GRBaddvar(model, 0, C_NULL, C_NULL, 0.0, -Inf, Inf, GRB_CONTINUOUS, "")
0

julia> GRBaddconstr(model, 1, Cint[0], [1.0], Cchar('<'), 1.0, "")
0

julia> GRBaddconstr(model, 1, Cint[0], [2.0], Cchar('<'), 2.0, "")
0

julia> GRBdelconstrs(model, 1, Cint[0])
0

julia> nothing # GRBupdatemodel(model)

julia> GRBchgcoeffs(model, 1, Cint[0], Cint[0], [3.0])
0

julia> GRBwrite(model, "bug.lp")
0

julia> print(read("bug.lp", String))
\ LP format - for model browsing. Use MPS format to capture full model detail.
Minimize
 
Subject To
 R1: 2 C0 <= 2
Bounds
 C0 free
End

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant