Skip to content

Commit 8d8beb3

Browse files
authored
[Utilities] Fix modifying an un-set objective sets the objective (#1215)
1 parent 76c247a commit 8d8beb3

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/Utilities/model.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,10 +510,12 @@ end
510510

511511
function MOI.modify(
512512
model::AbstractModel,
513-
obj::MOI.ObjectiveFunction,
513+
::MOI.ObjectiveFunction,
514514
change::MOI.AbstractFunctionModification,
515515
)
516-
return model.objective = modify_function(model.objective, change)
516+
model.objective = modify_function(model.objective, change)
517+
model.objectiveset = true
518+
return
517519
end
518520

519521
function MOI.get(::AbstractModel, ::MOI.ListOfOptimizerAttributesSet)

test/Utilities/model.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,3 +331,11 @@ end
331331
@test !haskey(dest.ext, :my_store)
332332
@test model.ext[:my_store] == 2
333333
end
334+
335+
@testset "Objective set via modify" begin
336+
model = MOIU.Model{Float64}()
337+
x = MOI.add_variable(model)
338+
attr = MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}()
339+
MOI.modify(model, attr, MOI.ScalarCoefficientChange(x, 1.0))
340+
@test attr in MOI.get(model, MOI.ListOfModelAttributesSet())
341+
end

0 commit comments

Comments
 (0)