Skip to content

Commit 57f65b6

Browse files
committed
bugfix: use ObjectiveFunction instead of the actual function
1 parent e73ab19 commit 57f65b6

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

src/Utilities/penalty_relaxation.jl

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,15 @@ function MOI.modify(
155155
scale = sense == MOI.MIN_SENSE ? one(T) : -one(T)
156156
a = scale * relax.penalty
157157
O = MOI.get(model, MOI.ObjectiveFunctionType())
158-
obj = MOI.get(model, MOI.ObjectiveFunction{O}())
159158
obj = MOI.ObjectiveFunction{O}()
159+
# This breaks if the objective is a VariableIndex or ScalarNonlinearFunction
160160
MOI.modify(model, obj, MOI.ScalarCoefficientChange(y, a))
161161
MOI.modify(model, obj, MOI.ScalarCoefficientChange(z, a))
162-
# This causes problems with other methods trying to modify the objective
163-
# function.
162+
# The following causes problems with other methods trying to modify the objective
163+
# function. We would have to branch/dispatch on objective type
164164
# To support existing nonlinear objectives as well as linear/quadratic objectives,
165165
# we just turn any objective into a ScalarNonlinearFunction
166+
#obj = MOI.get(model, MOI.ObjectiveFunction{O}())
166167
#newobj = MOI.ScalarNonlinearFunction(:+, [obj, a * y + a * z])
167168
#MOI.set(model, MOI.ObjectiveFunction{MOI.ScalarNonlinearFunction}(), newobj)
168169
return one(T) * y + one(T) * z
@@ -183,13 +184,8 @@ function MOI.modify(
183184
scale = sense == MOI.MIN_SENSE ? one(T) : -one(T)
184185
a = scale * relax.penalty
185186
O = MOI.get(model, MOI.ObjectiveFunctionType())
186-
obj = MOI.get(model, MOI.ObjectiveFunction{O}())
187+
obj = MOI.ObjectiveFunction{O}()
187188
MOI.modify(model, obj, MOI.ScalarCoefficientChange(y, a))
188-
# This causes problems. TODO: Revisit.
189-
# To support existing nonlinear objectives as well as linear/quadratic objectives,
190-
# we just turn any objective into a ScalarNonlinearFunction
191-
#newobj = MOI.ScalarNonlinearFunction(:+, [obj, a * y])
192-
#MOI.set(model, MOI.ObjectiveFunction{MOI.ScalarNonlinearFunction}(), newobj)
193189
return one(T) * y
194190
end
195191

@@ -208,13 +204,8 @@ function MOI.modify(
208204
scale = sense == MOI.MIN_SENSE ? one(T) : -one(T)
209205
a = scale * relax.penalty
210206
O = MOI.get(model, MOI.ObjectiveFunctionType())
211-
obj = MOI.get(model, MOI.ObjectiveFunction{O}())
207+
obj = MOI.ObjectiveFunction{O}()
212208
MOI.modify(model, obj, MOI.ScalarCoefficientChange(z, a))
213-
# This causes problems. TODO: Revisit.
214-
# To support existing nonlinear objectives as well as linear/quadratic objectives,
215-
# we just turn any objective into a ScalarNonlinearFunction
216-
#newobj = MOI.ScalarNonlinearFunction(:+, [obj, a * z])
217-
#MOI.set(model, MOI.ObjectiveFunction{MOI.ScalarNonlinearFunction}(), newobj)
218209
return one(T) * z
219210
end
220211

0 commit comments

Comments
 (0)