Skip to content

Commit e980a65

Browse files
committed
Fix constraint primal for SingleVariable constraint
1 parent d39043e commit e980a65

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

src/SemidefiniteOptInterface.jl

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const CI{F, S} = MOI.ConstraintIndex{F, S}
2929
mutable struct SOItoMOIBridge{T, SIT <: AbstractSDOptimizer} <: MOI.AbstractOptimizer
3030
sdoptimizer::SIT
3131
setconstant::Dict{Int64, T}
32+
blkconstant::Dict{Int, T}
3233
objconstant::T
3334
objsign::Int
3435
objshift::T
@@ -42,7 +43,7 @@ mutable struct SOItoMOIBridge{T, SIT <: AbstractSDOptimizer} <: MOI.AbstractOpti
4243
slackmap::Vector{Tuple{Int, Int, Int, T}} # c -> blk, i, j, coef
4344
double::Vector{CI} # created when there are two cones for same variable
4445
function SOItoMOIBridge{T}(sdoptimizer::SIT) where {T, SIT}
45-
new{T, SIT}(sdoptimizer, Dict{Int64, T}(),
46+
new{T, SIT}(sdoptimizer, Dict{Int64, T}(), Dict{Int, T}(),
4647
zero(T), 1, zero(T), 0, 0,
4748
Int[],
4849
IntSet(),
@@ -70,6 +71,7 @@ include("load.jl")
7071
function MOI.isempty(optimizer::SOItoMOIBridge)
7172
isempty(optimizer.double) &&
7273
isempty(optimizer.setconstant) &&
74+
isempty(optimizer.blkconstant) &&
7375
iszero(optimizer.objconstant) &&
7476
optimizer.objsign == 1 &&
7577
iszero(optimizer.objshift) &&
@@ -88,6 +90,7 @@ function MOI.empty!(optimizer::SOItoMOIBridge{T}) where T
8890
end
8991
optimizer.double = CI[]
9092
optimizer.setconstant = Dict{Int64, T}()
93+
optimizer.blkconstant = Dict{Int, T}()
9194
optimizer.objconstant = zero(T)
9295
optimizer.objsign = 1
9396
optimizer.objshift = zero(T)
@@ -105,14 +108,22 @@ function setconstant!(optimizer::SOItoMOIBridge, ci::CI, s) end
105108
function setconstant!(optimizer::SOItoMOIBridge, ci::CI, s::MOI.AbstractScalarSet)
106109
optimizer.setconstant[ci.value] = MOIU.getconstant(s)
107110
end
108-
function addconstant(optimizer::SOItoMOIBridge, ci::CI{<:Any, <:MOI.AbstractScalarSet}, x)
111+
function addsetconstant(optimizer::SOItoMOIBridge, ci::CI{<:Any, <:MOI.AbstractScalarSet}, x)
109112
x + optimizer.setconstant[ci.value]
110113
end
111-
function addconstant(optimizer::SOItoMOIBridge, ci::CI, x)
114+
function addsetconstant(optimizer::SOItoMOIBridge, ci::CI, x)
112115
x
113116
end
117+
function addblkconstant(optimizer::SOItoMOIBridge, ci::CI{<:Any, <:Union{NS, PS}}, x)
118+
blk = -ci.value
119+
x + optimizer.blkconstant[blk]
120+
end
121+
function addblkconstant(optimizer::SOItoMOIBridge, ci::CI, x)
122+
x
123+
end
124+
114125

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

@@ -216,11 +227,11 @@ end
216227

217228
function MOI.get(m::SOItoMOIBridge, a::MOI.ConstraintPrimal, ci::CI{F, S}) where {F, S}
218229
if ci.value >= 0
219-
addconstant(m, ci, _getattribute(m, ci, getslack))
230+
addsetconstant(m, ci, _getattribute(m, ci, getslack))
220231
else
221232
# Variable Function-in-S with S different from Zeros and EqualTo and not a double variable constraint
222233
blk = -ci.value
223-
getvarprimal(m, blk, S)
234+
addblkconstant(m, ci, getvarprimal(m, blk, S))
224235
end
225236
end
226237

src/variable.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ _enumerate(vi::VI) = enumerate((vi,))
2828
_enumerate(vi::Vector{VI}) = enumerate(vi)
2929
function _constraintvariable!(m::SOItoMOIBridge, vs::VIS, s::S) where S<:Union{NS, PS}
3030
blk = newblock(m, -_length(vs))
31+
cst = _getconstant(m, s)
32+
m.blkconstant[blk] = cst
3133
for (i, v) in _enumerate(vs)
32-
setvarmap!(m, v, (blk, i, i, vscaling(S), _getconstant(m, s)))
34+
setvarmap!(m, v, (blk, i, i, vscaling(S), cst))
3335
unfree(m, v)
3436
end
3537
blk

0 commit comments

Comments
 (0)