Skip to content

Commit 403bc58

Browse files
authored
[Bridges] fix modify in Bridges.Objective.VectorSlack (#2144)
1 parent 1ac407e commit 403bc58

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/Bridges/Objective/bridges/vector_slack.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,11 @@ function MOI.get(
197197
g = MOI.Utilities.remove_variable(g, slacks)
198198
return MOI.Utilities.convert_approx(G, g)
199199
end
200+
201+
function MOI.modify(
202+
::MOI.ModelLike,
203+
::VectorSlackBridge{T},
204+
change::MOI.VectorConstantChange{T},
205+
) where {T}
206+
return throw(MOI.ModifyObjectiveNotAllowed(change))
207+
end

test/Bridges/Objective/vector_slack.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,24 @@ function test_objective_function_value()
148148
return
149149
end
150150

151+
function test_modify_vector_constant_change()
152+
inner = MOI.Utilities.MockOptimizer(
153+
MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()),
154+
)
155+
model = MOI.Bridges.Objective.VectorSlack{Float64}(inner)
156+
x = MOI.add_variable(model)
157+
f = MOI.Utilities.operate(vcat, Float64, -1.1 * x, 1.0 * x)
158+
MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE)
159+
attr = MOI.ObjectiveFunction{typeof(f)}()
160+
MOI.set(model, attr, f)
161+
@test MOI.get(model, attr) f
162+
@test_throws(
163+
MOI.ModifyObjectiveNotAllowed,
164+
MOI.modify(model, attr, MOI.VectorConstantChange([1.0, 2.0])),
165+
)
166+
return
167+
end
168+
151169
end # module
152170

153171
TestObjectiveVectorSlack.runtests()

0 commit comments

Comments
 (0)