Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor GRBupdatemodel calls #552

Merged
merged 10 commits into from Mar 26, 2024
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