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

WIP: fix issues identified by MOI #354 #10

Merged
merged 6 commits into from
May 17, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/LinQuadOptInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,26 @@ function shift_references_after_delete_affine!(m, row)
end
end

"""
shift_references_after_delete_quadratic!(m, row)

This function updates all of the references in `m`
after we have deleted row `row` in the quadratic constraint matrix.
"""
function shift_references_after_delete_quadratic!(m, row)
for scalar_quadratic in [
cmap(m).q_less_than,
cmap(m).q_greater_than,
cmap(m).q_equal_to
]
for (key, val) in scalar_quadratic
if val > row
scalar_quadratic[key] -= 1
end
end
end
end

function Base.isempty(map::ConstraintMapping)

ret = true
Expand Down
2 changes: 1 addition & 1 deletion src/constraints/scalaraffine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ end
Delete a linear constraint
=#

MOI.candelete(m::LinQuadOptimizer, c::LCI{<: LinSets}) = true
MOI.candelete(m::LinQuadOptimizer, c::LCI{<: LinSets}) = MOI.isvalid(m, c)
function MOI.delete!(m::LinQuadOptimizer, c::LCI{<: LinSets})
deleteconstraintname!(m, c)
dict = constrdict(m, c)
Expand Down
14 changes: 14 additions & 0 deletions src/constraints/scalarquadratic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,17 @@ function reduceduplicates(rowi::Vector{T}, coli::Vector{T}, vals::Vector{S}) whe
end
ri, ci, vi
end


MOI.candelete(m::LinQuadOptimizer, c::QCI{<: LinSets}) = MOI.isvalid(m, c)
function MOI.delete!(m::LinQuadOptimizer, c::QCI{<: LinSets})
deleteconstraintname!(m, c)
dict = constrdict(m, c)
row = dict[c]
delete_quadratic_constraints!(m, row, row)
deleteat!(m.qconstraint_primal_solution, row)
deleteat!(m.qconstraint_dual_solution, row)
# shift all the other references
shift_references_after_delete_quadratic!(m, row)
delete!(dict, c)
end
6 changes: 3 additions & 3 deletions src/constraints/singlevariable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function MOI.addconstraint!(m::LinQuadOptimizer, v::SinVar, set::S) where S <: L
end

# delete constraint
MOI.candelete(m::LinQuadOptimizer, c::SVCI{S}) where S <: LinSets = true
MOI.candelete(m::LinQuadOptimizer, c::SVCI{S}) where S <: LinSets = MOI.isvalid(m, c)
function MOI.delete!(m::LinQuadOptimizer, c::SVCI{S}) where S <: LinSets
deleteconstraintname!(m, c)
dict = constrdict(m, c)
Expand Down Expand Up @@ -116,7 +116,7 @@ function MOI.addconstraint!(m::LinQuadOptimizer, v::SinVar, set::MOI.ZeroOne)
ref
end

MOI.candelete(m::LinQuadOptimizer, c::SVCI{MOI.ZeroOne}) = true
MOI.candelete(m::LinQuadOptimizer, c::SVCI{MOI.ZeroOne}) = MOI.isvalid(m, c)
function MOI.delete!(m::LinQuadOptimizer, c::SVCI{MOI.ZeroOne})
deleteconstraintname!(m, c)
dict = constrdict(m, c)
Expand Down Expand Up @@ -150,6 +150,7 @@ function MOI.addconstraint!(m::LinQuadOptimizer, v::SinVar, set::MOI.Integer)
ref
end

MOI.candelete(m::LinQuadOptimizer, c::SVCI{MOI.Integer}) = MOI.isvalid(m, c)
function MOI.delete!(m::LinQuadOptimizer, c::SVCI{MOI.Integer})
deleteconstraintname!(m, c)
dict = constrdict(m, c)
Expand All @@ -160,7 +161,6 @@ function MOI.delete!(m::LinQuadOptimizer, c::SVCI{MOI.Integer})
make_problem_type_continuous(m)
end
end
MOI.candelete(m::LinQuadOptimizer, c::SVCI{MOI.Integer}) = true

MOI.canget(m::LinQuadOptimizer, ::MOI.ConstraintSet, ::Type{SVCI{MOI.Integer}}) = true
MOI.get(m::LinQuadOptimizer, ::MOI.ConstraintSet, c::SVCI{MOI.Integer}) = MOI.Integer()
Expand Down
2 changes: 1 addition & 1 deletion src/constraints/vectoraffine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function MOI.modifyconstraint!(m::LinQuadOptimizer, ref::VLCI{<: VecLinSets}, ch
end
end

MOI.candelete(m::LinQuadOptimizer, c::VLCI{<:VecLinSets}) = true
MOI.candelete(m::LinQuadOptimizer, c::VLCI{<:VecLinSets}) = MOI.isvalid(m, c)
function MOI.delete!(m::LinQuadOptimizer, c::VLCI{<:VecLinSets})
deleteconstraintname!(m, c)
dict = constrdict(m, c)
Expand Down
4 changes: 2 additions & 2 deletions src/constraints/vectorofvariables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function MOI.addconstraint!(m::LinQuadOptimizer, func::VecVar, set::S) where S <
return ref
end

MOI.candelete(m::LinQuadOptimizer, c::VVCI{S}) where S <: VecLinSets = true
MOI.candelete(m::LinQuadOptimizer, c::VVCI{S}) where S <: VecLinSets = MOI.isvalid(m, c)
function MOI.delete!(m::LinQuadOptimizer, c::VVCI{S}) where S <: VecLinSets
deleteconstraintname!(m, c)
dict = constrdict(m, c)
Expand Down Expand Up @@ -87,7 +87,7 @@ function MOI.addconstraint!(m::LinQuadOptimizer, v::VecVar, sos::S) where S <: U
ref
end

MOI.candelete(m::LinQuadOptimizer, c::VVCI{<:Union{SOS1, SOS2}}) = true
MOI.candelete(m::LinQuadOptimizer, c::VVCI{<:Union{SOS1, SOS2}}) = MOI.isvalid(m, c)
function MOI.delete!(m::LinQuadOptimizer, c::VVCI{<:Union{SOS1, SOS2}})
deleteconstraintname!(m, c)
dict = constrdict(m, c)
Expand Down
8 changes: 8 additions & 0 deletions src/solver_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@ the model `m`.
function delete_linear_constraints! end
@deprecate lqs_delrows! delete_linear_constraints!

"""
delete_quadratic_constraints!(m, start_row::Int, end_row::Int)::Void

Delete the quadratic constraints `start_row`, `start_row+1`, ..., `end_row` from
the model `m`.
"""
function delete_quadratic_constraints! end
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joaquimg I added this method to the API

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Are there MOI tests for deleting quadratics?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


"""
lqs_chgctype(m, cols::Vector{Int}, types):Void

Expand Down