Skip to content

Commit

Permalink
Fix constraint primal for SingleVariable constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Jun 29, 2018
1 parent d39043e commit e980a65
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
23 changes: 17 additions & 6 deletions src/SemidefiniteOptInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const CI{F, S} = MOI.ConstraintIndex{F, S}
mutable struct SOItoMOIBridge{T, SIT <: AbstractSDOptimizer} <: MOI.AbstractOptimizer
sdoptimizer::SIT
setconstant::Dict{Int64, T}
blkconstant::Dict{Int, T}
objconstant::T
objsign::Int
objshift::T
Expand All @@ -42,7 +43,7 @@ mutable struct SOItoMOIBridge{T, SIT <: AbstractSDOptimizer} <: MOI.AbstractOpti
slackmap::Vector{Tuple{Int, Int, Int, T}} # c -> blk, i, j, coef
double::Vector{CI} # created when there are two cones for same variable
function SOItoMOIBridge{T}(sdoptimizer::SIT) where {T, SIT}
new{T, SIT}(sdoptimizer, Dict{Int64, T}(),
new{T, SIT}(sdoptimizer, Dict{Int64, T}(), Dict{Int, T}(),
zero(T), 1, zero(T), 0, 0,
Int[],
IntSet(),
Expand Down Expand Up @@ -70,6 +71,7 @@ include("load.jl")
function MOI.isempty(optimizer::SOItoMOIBridge)
isempty(optimizer.double) &&
isempty(optimizer.setconstant) &&
isempty(optimizer.blkconstant) &&
iszero(optimizer.objconstant) &&
optimizer.objsign == 1 &&
iszero(optimizer.objshift) &&
Expand All @@ -88,6 +90,7 @@ function MOI.empty!(optimizer::SOItoMOIBridge{T}) where T
end
optimizer.double = CI[]
optimizer.setconstant = Dict{Int64, T}()
optimizer.blkconstant = Dict{Int, T}()
optimizer.objconstant = zero(T)
optimizer.objsign = 1
optimizer.objshift = zero(T)
Expand All @@ -105,14 +108,22 @@ function setconstant!(optimizer::SOItoMOIBridge, ci::CI, s) end
function setconstant!(optimizer::SOItoMOIBridge, ci::CI, s::MOI.AbstractScalarSet)
optimizer.setconstant[ci.value] = MOIU.getconstant(s)
end
function addconstant(optimizer::SOItoMOIBridge, ci::CI{<:Any, <:MOI.AbstractScalarSet}, x)
function addsetconstant(optimizer::SOItoMOIBridge, ci::CI{<:Any, <:MOI.AbstractScalarSet}, x)
x + optimizer.setconstant[ci.value]
end
function addconstant(optimizer::SOItoMOIBridge, ci::CI, x)
function addsetconstant(optimizer::SOItoMOIBridge, ci::CI, x)
x
end
function addblkconstant(optimizer::SOItoMOIBridge, ci::CI{<:Any, <:Union{NS, PS}}, x)
blk = -ci.value
x + optimizer.blkconstant[blk]
end
function addblkconstant(optimizer::SOItoMOIBridge, ci::CI, x)
x
end


MOI.supports(::SOItoMOIBridge{T}, ::MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}) where T = true
MOI.supports(::SOItoMOIBridge{T}, ::MOI.ObjectiveFunction{<:Union{MOI.SingleVariable, MOI.ScalarAffineFunction{T}}}) where T = true
MOI.supportsconstraint(::SOItoMOIBridge{T}, ::Type{<:Union{VF, AF{T}}}, ::Type{<:SupportedSets}) where T = true
MOI.copy!(dest::SOItoMOIBridge, src::MOI.ModelLike; copynames=true) = MOIU.allocateload!(dest, src, copynames)

Expand Down Expand Up @@ -216,11 +227,11 @@ end

function MOI.get(m::SOItoMOIBridge, a::MOI.ConstraintPrimal, ci::CI{F, S}) where {F, S}
if ci.value >= 0
addconstant(m, ci, _getattribute(m, ci, getslack))
addsetconstant(m, ci, _getattribute(m, ci, getslack))
else
# Variable Function-in-S with S different from Zeros and EqualTo and not a double variable constraint
blk = -ci.value
getvarprimal(m, blk, S)
addblkconstant(m, ci, getvarprimal(m, blk, S))
end
end

Expand Down
4 changes: 3 additions & 1 deletion src/variable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ _enumerate(vi::VI) = enumerate((vi,))
_enumerate(vi::Vector{VI}) = enumerate(vi)
function _constraintvariable!(m::SOItoMOIBridge, vs::VIS, s::S) where S<:Union{NS, PS}
blk = newblock(m, -_length(vs))
cst = _getconstant(m, s)
m.blkconstant[blk] = cst
for (i, v) in _enumerate(vs)
setvarmap!(m, v, (blk, i, i, vscaling(S), _getconstant(m, s)))
setvarmap!(m, v, (blk, i, i, vscaling(S), cst))
unfree(m, v)
end
blk
Expand Down

0 comments on commit e980a65

Please sign in to comment.