Skip to content

Commit

Permalink
Refactor GRBupdatemodel calls (#552)
Browse files Browse the repository at this point in the history
  • Loading branch information
torressa committed Mar 26, 2024
1 parent 69d2d6e commit 64bffa9
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 123 deletions.
2 changes: 1 addition & 1 deletion src/MOI_wrapper/MOI_callbacks.jl
Expand Up @@ -83,7 +83,7 @@ function MOI.set(model::Optimizer, ::CallbackFunction, f::Function)
model.generic_callback = user_data
model.has_generic_callback = true
# Mark the update as necessary and immediately call for the update.
_require_update(model)
_require_update(model, model_change = true)
_update_if_necessary(model)
return
end
Expand Down
8 changes: 4 additions & 4 deletions src/MOI_wrapper/MOI_indicator_constraint.jl
Expand Up @@ -140,7 +140,7 @@ function MOI.add_constraint(
model.last_constraint_index += 1
info = _ConstraintInfo(length(model.indicator_constraint_info) + 1, s)
model.indicator_constraint_info[model.last_constraint_index] = info
_require_update(model)
_require_update(model, model_change = true)
return MOI.ConstraintIndex{typeof(func),typeof(s)}(
model.last_constraint_index,
)
Expand Down Expand Up @@ -180,22 +180,22 @@ function MOI.set(
name::String,
) where {S<:MOI.Indicator}
MOI.throw_if_not_valid(model, c)
_update_if_necessary(model)
_update_if_necessary(model, check_attribute_change = false)
info = _info(model, c)
info.name = name
if !isempty(name)
row = Cint(_info(model, c).row - 1)
ret = GRBsetstrattrelement(model, "GenConstrName", row, name)
_check_ret(model, ret)
end
_require_update(model, attribute_change = true)
return
end

function MOI.delete(
model::Optimizer,
c::MOI.ConstraintIndex{<:MOI.VectorAffineFunction,<:MOI.Indicator},
)
_update_if_necessary(model)
MOI.throw_if_not_valid(model, c)
row = _info(model, c).row
ind = Ref{Cint}(row - 1)
Expand All @@ -207,6 +207,6 @@ function MOI.delete(
info.row -= 1
end
end
_require_update(model)
_update_if_necessary(model, force = true)
return
end
3 changes: 1 addition & 2 deletions src/MOI_wrapper/MOI_multi_objective.jl
Expand Up @@ -36,7 +36,6 @@ function MOI.set(
obj[column] += term.coefficient
end
indices, coefficients = _indices_and_coefficients(model, f)
_update_if_necessary(model)
ret = GRBsetobjectiven(
model,
Cint(attr.index - 1),
Expand All @@ -51,7 +50,7 @@ function MOI.set(
coefficients,
)
_check_ret(model, ret)
_require_update(model)
_require_update(model, model_change = true)
return
end

Expand Down

0 comments on commit 64bffa9

Please sign in to comment.