Skip to content
This repository was archived by the owner on Jun 14, 2020. It is now read-only.

Commit d1ff1ae

Browse files
joaquimgodow
authored andcommitted
Add specialized versions of change_coefficient (#15)
* Add specialized versions of change_coefficient * add empty methods to mocksolver
1 parent dc8cce2 commit d1ff1ae

File tree

5 files changed

+27
-11
lines changed

5 files changed

+27
-11
lines changed

src/constraints/scalaraffine.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ end
163163
MOI.canmodifyconstraint(m::LinQuadOptimizer, c::LCI{<: LinSets}, ::Type{MOI.ScalarCoefficientChange{Float64}}) = true
164164
function MOI.modifyconstraint!(m::LinQuadOptimizer, c::LCI{<: LinSets}, chg::MOI.ScalarCoefficientChange{Float64})
165165
col = m.variable_mapping[chg.variable]
166-
change_coefficient!(m, m[c], col, chg.new_coefficient)
166+
change_matrix_coefficient!(m, m[c], col, chg.new_coefficient)
167167
end
168168

169169
#=
@@ -172,8 +172,7 @@ end
172172

173173
MOI.canmodifyconstraint(m::LinQuadOptimizer, c::LCI{S}, ::Type{S}) where S <: Union{LE, GE, EQ} = true
174174
function MOI.modifyconstraint!(m::LinQuadOptimizer, c::LCI{S}, newset::S) where S <: Union{LE, GE, EQ}
175-
# the column 0 (or -1 in 0-index) is the rhs.
176-
change_coefficient!(m, m[c], 0, _getrhs(newset))
175+
change_rhs_coefficient!(m, m[c], _getrhs(newset))
177176
end
178177

179178
MOI.canmodifyconstraint(m::LinQuadOptimizer, c::LCI{IV}, ::Type{IV}) = true

src/constraints/vectoraffine.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ MOI.canmodifyconstraint(m::LinQuadOptimizer, ::VLCI{<: VecLinSets}, ::Type{MOI.V
5353
function MOI.modifyconstraint!(m::LinQuadOptimizer, ref::VLCI{<: VecLinSets}, chg::MOI.VectorConstantChange{Float64})
5454
@assert length(chg.new_constant) == length(m[ref])
5555
for (r, v) in zip(m[ref], chg.new_constant)
56-
change_coefficient!(m, r, 0, -v)
56+
change_rhs_coefficient!(m, r, -v)
5757
m.constraint_constant[r] = v
5858
end
5959
end

src/mockoptimizer.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ function LQOI.get_linear_constraint(instance::MockLinQuadOptimizer, idx)
277277
end
278278

279279
# TODO SPLIT THIS ONE
280-
function LQOI.change_coefficient!(instance::MockLinQuadOptimizer, row, col, coef)
280+
function LQOI.change_matrix_coefficient!(instance::MockLinQuadOptimizer, row, col, coef)
281281
# if row == 0
282282
# set_dblattrlist!(instance.inner, "Obj", Cint[col], Float64[coef])
283283
# elseif col == 0
@@ -287,7 +287,10 @@ function LQOI.change_coefficient!(instance::MockLinQuadOptimizer, row, col, coef
287287
# #TODO fix this function in gurobi
288288
# end
289289
end
290-
290+
function LQOI.change_rhs_coefficient!(instance::MockLinQuadOptimizer, row, coef)
291+
end
292+
function LQOI.change_objective_coefficient!(instance::MockLinQuadOptimizer, col, coef)
293+
end
291294
function LQOI.delete_linear_constraints!(instance::MockLinQuadOptimizer, rowbeg, rowend)
292295
if rowbeg > 1 && rowend < length(instance.inner.b)
293296
instance.inner.A = vcat(instance.inner.A[1:rowbeg-1,:],instance.inner.A[rowend+1:end,:])

src/objective.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,5 +124,5 @@ function MOI.modifyobjective!(m::LinQuadOptimizer, chg::MOI.ScalarCoefficientCha
124124
end
125125
col = m.variable_mapping[chg.variable]
126126
# 0 row is the objective
127-
change_coefficient!(m, 0, col, chg.new_coefficient)
127+
change_objective_coefficient!(m, col, chg.new_coefficient)
128128
end

src/solver_interface.jl

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ function add_ranged_constraints! end
180180
181181
Modify the lower and upperbounds of a ranged constraint in the model `m`.
182182
183-
This is a special case compared to standard the `change_coefficient!` since it
183+
This is a special case compared to standard the `change_rhs_coefficient!` since it
184184
is often implemented via multiple API calls.
185185
"""
186186
function modify_ranged_constraints! end
@@ -205,13 +205,27 @@ function get_linear_constraint end
205205
@deprecate lqs_getrows get_linear_constraint
206206

207207
"""
208-
change_coefficient!(m, row, col, coef)
208+
change_matrix_coefficient!(m, row, col, coef)
209209
210210
Set the linear coefficient of the variable in column `col`, constraint `row` to
211211
`coef`.
212212
"""
213-
function change_coefficient! end
214-
@deprecate lqs_chgcoef! change_coefficient!
213+
function change_matrix_coefficient! end
214+
@deprecate lqs_chgcoef! change_matrix_coefficient!
215+
216+
"""
217+
change_objective_coefficient!(m, col, coef)
218+
219+
Set the linear coefficient of the variable in column `col` to `coef` in the objective function.
220+
"""
221+
function change_objective_coefficient! end
222+
223+
"""
224+
change_rhs_coefficient!(m, row, coef)
225+
226+
Set the rhs of the constraint in row `row` to `coef`.
227+
"""
228+
function change_rhs_coefficient! end
215229

216230
"""
217231
delete_linear_constraints!(m, start_row::Int, end_row::Int)::Void

0 commit comments

Comments
 (0)