Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Mar 8, 2021
1 parent 61c4d25 commit 3c29f6b
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 180 deletions.
2 changes: 1 addition & 1 deletion src/Utilities/DoubleDicts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Works as a `AbstractDict{CI, V}` with minimal differences.
Note that `CI` is not a concrete type, opposed to `CI{MOI.SingleVariable, MOI.Integers}`,
which is a concrete type.
When optimal performance or type stability is required its possible to obtain a
When optimal performance or type stability is required it is possible to obtain a
fully type stable dictionary with values of type `V` and keys of type
`CI{MOI.SingleVariable, MOI.Integers}` from the dictionary `dict`, for instance:
Expand Down
63 changes: 28 additions & 35 deletions src/Utilities/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,6 @@ function _delete_variable(
vi::MOI.VariableIndex,
) where {T}
MOI.throw_if_not_valid(model, vi)
# If a variable is removed, the `VectorOfVariables` constraints using this
# variable only need to be removed too. `vov_to_remove` is the list of
# indices of the `VectorOfVariables` constraints of `vi`.
vov_to_remove =
broadcastvcat(constrs -> _vector_of_variables_with(constrs, vi), model)
for ci in vov_to_remove
MOI.delete(model, ci)
end
model.single_variable_mask[vi.value] = 0x0
if model.variable_indices === nothing
model.variable_indices =
Expand Down Expand Up @@ -113,33 +105,42 @@ function _delete_variable(
)
end
function MOI.delete(model::AbstractModel, vi::MOI.VariableIndex)
vis = [vi]
broadcastcall(model) do constrs
_throw_if_cannot_delete(constrs, vis, vis)
end
_delete_variable(model, vi)
# `VectorOfVariables` constraints with sets not supporting dimension update
# were either deleted or an error was thrown. The rest is modified now.
broadcastcall(constrs -> _remove_variable(constrs, vi), model)
return model.objective = remove_variable(model.objective, vi)
broadcastcall(model) do constrs
_deleted_constraints(constrs, vi) do ci
delete!(model.con_to_name, ci)
end
end
model.objective = remove_variable(model.objective, vi)
model.name_to_con = nothing
return
end
function MOI.delete(model::AbstractModel, vis::Vector{MOI.VariableIndex})
if isempty(vis)
# In `keep`, we assume that `model.variable_indices !== nothing` so
# at least one variable need to be deleted.
return
end
# Delete `VectorOfVariables(vis)` constraints as otherwise, it will error
# when removing variables one by one.
vov_to_remove =
broadcastvcat(constrs -> _vector_of_variables_with(constrs, vis), model)
for ci in vov_to_remove
MOI.delete(model, ci)
fast_in_vis = Set(vis)
broadcastcall(model) do constrs
_throw_if_cannot_delete(constrs, vis, fast_in_vis)
end
broadcastcall(model) do constrs
_deleted_constraints(constrs, vis) do ci
delete!(model.con_to_name, ci)
end
end
for vi in vis
_delete_variable(model, vi)
end
# `VectorOfVariables` constraints with sets not supporting dimension update
# were either deleted or an error was thrown. The rest is modified now.
keep(vi::MOI.VariableIndex) = vi in model.variable_indices
model.objective = filter_variables(keep, model.objective)
return broadcastcall(constrs -> _filter_variables(keep, constrs), model)
model.name_to_con = nothing
return
end

function MOI.is_valid(
Expand Down Expand Up @@ -555,14 +556,6 @@ function MOI.set(
)
return throw(MOI.SettingSingleVariableFunctionNotAllowed())
end
function MOI.set(
model::AbstractModel,
attr::Union{MOI.ConstraintFunction, MOI.ConstraintSet},
ci::MOI.ConstraintIndex,
func_or_set,
)
return MOI.set(constraints(model, ci), attr, ci, func_or_set)
end
function MOI.set(
model::AbstractModel{T},
::MOI.ConstraintSet,
Expand All @@ -580,11 +573,11 @@ function MOI.set(
end
function MOI.set(
model::AbstractModel,
attr::MOI.ConstraintSet,
ci::MOI.ConstraintIndex{F,S},
set::S,
) where {F,S}
return MOI.set(constraints(model, ci), attr, ci, set)
attr::Union{MOI.ConstraintFunction, MOI.ConstraintSet},
ci::MOI.ConstraintIndex,
func_or_set,
)
return MOI.set(constraints(model, ci), attr, ci, func_or_set)
end

function MOI.get(
Expand Down Expand Up @@ -700,7 +693,7 @@ function _get_single_variable_set(
return S(model.lower_bound[index], model.upper_bound[index])
end
function _get_single_variable_set(
model::AbstractModel,
::AbstractModel,
S::Type{<:Union{MOI.Integer,MOI.ZeroOne}},
index,
)
Expand Down
Loading

0 comments on commit 3c29f6b

Please sign in to comment.