-
Notifications
You must be signed in to change notification settings - Fork 27
/
MOI_wrapper.jl
574 lines (531 loc) · 20 KB
/
MOI_wrapper.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
using MathOptInterface
const MOI = MathOptInterface
const CI = MOI.ConstraintIndex
const VI = MOI.VariableIndex
const MOIU = MOI.Utilities
"""
ADMMIterations()
The number of ADMM iterations completed during the solve.
"""
struct ADMMIterations <: MOI.AbstractModelAttribute
end
MOI.is_set_by_optimize(::ADMMIterations) = true
mutable struct MOISolution
ret_val::Int
raw_status::String
primal::Vector{Float64}
dual::Vector{Float64}
slack::Vector{Float64}
objective_value::Float64
dual_objective_value::Float64
objective_constant::Float64
solve_time_sec::Float64
iterations::Int
end
MOISolution() = MOISolution(0, # SCS_UNFINISHED
"", Float64[], Float64[], Float64[], NaN, NaN, NaN,
0.0, 0)
# Used to build the data with allocate-load during `copy_to`.
# When `optimize!` is called, a the data is passed to SCS
# using `SCS_solve` and the `ModelData` struct is discarded
mutable struct ModelData
m::Int # Number of rows/constraints
n::Int # Number of cols/variables
I::Vector{Int} # List of rows
J::Vector{Int} # List of cols
V::Vector{Float64} # List of coefficients
b::Vector{Float64} # constants
objective_constant::Float64 # The objective is min c'x + objective_constant
c::Vector{Float64}
end
# This is tied to SCS's internal representation
mutable struct ConeData
f::Int # number of linear equality constraints
l::Int # length of LP cone
q::Int # length of SOC cone
qa::Vector{Int} # array of second-order cone constraints
s::Int # length of SD cone
sa::Vector{Int} # array of semi-definite constraints
ep::Int # number of primal exponential cone triples
ed::Int # number of dual exponential cone triples
p::Vector{Float64} # array of power cone params
nrows::Dict{Int, Int} # The number of rows of each vector sets, this is used by `constrrows` to recover the number of rows used by a constraint when getting `ConstraintPrimal` or `ConstraintDual`
function ConeData()
new(0, 0, 0, Int[], 0, Int[], 0, 0, Float64[], Dict{Int, Int}())
end
end
mutable struct Optimizer <: MOI.AbstractOptimizer
cone::ConeData
maxsense::Bool
data::Union{Nothing, ModelData} # only non-Void between MOI.copy_to and MOI.optimize!
sol::MOISolution
silent::Bool
options::Dict{Symbol, Any}
function Optimizer(; kwargs...)
optimizer = new(ConeData(), false, nothing, MOISolution(), false,
Dict{Symbol, Any}())
for (key, value) in kwargs
MOI.set(optimizer, MOI.RawParameter(key), value)
end
return optimizer
end
end
MOI.get(::Optimizer, ::MOI.SolverName) = "SCS"
function MOI.set(optimizer::Optimizer, param::MOI.RawParameter, value)
optimizer.options[param.name] = value
end
function MOI.get(optimizer::Optimizer, param::MOI.RawParameter)
return optimizer.options[param.name]
end
MOI.supports(::Optimizer, ::MOI.Silent) = true
function MOI.set(optimizer::Optimizer, ::MOI.Silent, value::Bool)
optimizer.silent = value
end
MOI.get(optimizer::Optimizer, ::MOI.Silent) = optimizer.silent
function MOI.is_empty(optimizer::Optimizer)
!optimizer.maxsense && optimizer.data === nothing
end
function MOI.empty!(optimizer::Optimizer)
optimizer.maxsense = false
optimizer.data = nothing # It should already be nothing except if an error is thrown inside copy_to
optimizer.sol.ret_val = 0
end
MOIU.supports_allocate_load(::Optimizer, copy_names::Bool) = !copy_names
function MOI.supports(::Optimizer,
::Union{MOI.ObjectiveSense,
MOI.ObjectiveFunction{MOI.SingleVariable},
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}})
return true
end
function MOI.supports(::Optimizer, ::MOI.VariablePrimalStart,
::Type{MOI.VariableIndex})
return true
end
function MOI.supports(::Optimizer,
::Union{MOI.ConstraintPrimalStart,
MOI.ConstraintDualStart},
::Type{<:MOI.ConstraintIndex})
return true
end
function MOI.supports_constraint(
::Optimizer,
::Type{<:MOI.VectorAffineFunction{Float64}},
::Type{<:Union{MOI.Zeros, MOI.Nonnegatives, MOI.SecondOrderCone,
MOI.ExponentialCone, MOI.DualExponentialCone,
MOI.PositiveSemidefiniteConeTriangle,
MOI.PowerCone, MOI.DualPowerCone}})
return true
end
function MOI.copy_to(dest::Optimizer, src::MOI.ModelLike; kws...)
return MOIU.automatic_copy_to(dest, src; kws...)
end
using SparseArrays
# Computes cone dimensions
function constroffset(cone::ConeData,
ci::CI{<:MOI.AbstractFunction, MOI.Zeros})
return ci.value
end
#_allocate_constraint: Allocate indices for the constraint `f`-in-`s`
# using information in `cone` and then update `cone`
function _allocate_constraint(cone::ConeData, f, s::MOI.Zeros)
ci = cone.f
cone.f += MOI.dimension(s)
return ci
end
function constroffset(cone::ConeData,
ci::CI{<:MOI.AbstractFunction, MOI.Nonnegatives})
return cone.f + ci.value
end
function _allocate_constraint(cone::ConeData, f, s::MOI.Nonnegatives)
ci = cone.l
cone.l += MOI.dimension(s)
return ci
end
function constroffset(cone::ConeData,
ci::CI{<:MOI.AbstractFunction, MOI.SecondOrderCone})
return cone.f + cone.l + ci.value
end
function _allocate_constraint(cone::ConeData, f, s::MOI.SecondOrderCone)
push!(cone.qa, s.dimension)
ci = cone.q
cone.q += MOI.dimension(s)
return ci
end
function constroffset(cone::ConeData,
ci::CI{<:MOI.AbstractFunction,
MOI.PositiveSemidefiniteConeTriangle})
return cone.f + cone.l + cone.q + ci.value
end
function _allocate_constraint(cone::ConeData, f,
s::MOI.PositiveSemidefiniteConeTriangle)
push!(cone.sa, s.side_dimension)
ci = cone.s
cone.s += MOI.dimension(s)
return ci
end
function constroffset(cone::ConeData,
ci::CI{<:MOI.AbstractFunction, MOI.ExponentialCone})
return cone.f + cone.l + cone.q + cone.s + ci.value
end
function _allocate_constraint(cone::ConeData, f, s::MOI.ExponentialCone)
ci = 3cone.ep
cone.ep += 1
return ci
end
function constroffset(cone::ConeData,
ci::CI{<:MOI.AbstractFunction, MOI.DualExponentialCone})
return cone.f + cone.l + cone.q + cone.s + 3cone.ep + ci.value
end
function _allocate_constraint(cone::ConeData, f, s::MOI.DualExponentialCone)
ci = 3cone.ed
cone.ed += 1
return ci
end
function constroffset(cone::ConeData,
ci::CI{<:MOI.AbstractFunction, <:MOI.PowerCone})
return cone.f + cone.l + cone.q + cone.s + 3cone.ep + 3cone.ed + ci.value
end
function _allocate_constraint(cone::ConeData, f, s::MOI.PowerCone)
ci = length(cone.p)
push!(cone.p, s.exponent)
return ci
end
function constroffset(cone::ConeData,
ci::CI{<:MOI.AbstractFunction, <:MOI.DualPowerCone})
return cone.f + cone.l + cone.q + cone.s + 3cone.ep + 3cone.ed + ci.value
end
function _allocate_constraint(cone::ConeData, f, s::MOI.DualPowerCone)
ci = length(cone.p)
# SCS' convention: dual cones have a negative exponent.
push!(cone.p, -s.exponent)
return ci
end
function constroffset(optimizer::Optimizer, ci::CI)
return constroffset(optimizer.cone, ci::CI)
end
function MOIU.allocate_constraint(optimizer::Optimizer, f::F, s::S) where {F <: MOI.AbstractFunction, S <: MOI.AbstractSet}
return CI{F, S}(_allocate_constraint(optimizer.cone, f, s))
end
# Vectorized length for matrix dimension n
sympackedlen(n) = div(n*(n+1), 2)
# Matrix dimension for vectorized length n
sympackeddim(n) = div(isqrt(1+8n) - 1, 2)
trimap(i::Integer, j::Integer) = i < j ? trimap(j, i) : div((i-1)*i, 2) + j
trimapL(i::Integer, j::Integer, n::Integer) = i < j ? trimapL(j, i, n) : i + div((2n-j) * (j-1), 2)
function _sympackedto(x, n, mapfrom, mapto)
@assert length(x) == sympackedlen(n)
y = similar(x)
for i in 1:n, j in 1:i
y[mapto(i, j)] = x[mapfrom(i, j)]
end
y
end
sympackedLtoU(x, n=sympackeddim(length(x))) = _sympackedto(x, n, (i, j) -> trimapL(i, j, n), trimap)
sympackedUtoL(x, n=sympackeddim(length(x))) = _sympackedto(x, n, trimap, (i, j) -> trimapL(i, j, n))
function sympackedUtoLidx(x::AbstractVector{<:Integer}, n)
y = similar(x)
map = sympackedLtoU(1:sympackedlen(n), n)
for i in eachindex(y)
y[i] = map[x[i]]
end
y
end
# Scale coefficients depending on rows index
# rows: List of row indices
# coef: List of corresponding coefficients
# d: dimension of set
# rev: if true, we unscale instead (e.g. divide by √2 instead of multiply for PSD cone)
function _scalecoef(rows, coef, d, rev)
scaling = rev ? 1 / √2 : 1 * √2
output = copy(coef)
diagidx = BitSet()
for i in 1:d
push!(diagidx, trimap(i, i))
end
for i in 1:length(output)
if !(rows[i] in diagidx)
output[i] *= scaling
end
end
return output
end
# Unscale the coefficients in `coef` with respective rows in `rows` for a set `s`
scalecoef(rows, coef, s) = _scalecoef(rows, coef, MOI.dimension(s), false)
# Unscale the coefficients in `coef` with respective rows in `rows` for a set of type `S` with dimension `d`
unscalecoef(rows, coef, d) = _scalecoef(rows, coef, sympackeddim(d), true)
output_index(t::MOI.VectorAffineTerm) = t.output_index
variable_index_value(t::MOI.ScalarAffineTerm) = t.variable_index.value
variable_index_value(t::MOI.VectorAffineTerm) = variable_index_value(t.scalar_term)
coefficient(t::MOI.ScalarAffineTerm) = t.coefficient
coefficient(t::MOI.VectorAffineTerm) = coefficient(t.scalar_term)
# constrrows: Recover the number of rows used by each constraint.
# When, the set is available, simply use MOI.dimension
constrrows(s::MOI.AbstractVectorSet) = 1:MOI.dimension(s)
# When only the index is available, use the `optimizer.ncone.nrows` field
constrrows(optimizer::Optimizer, ci::CI{<:MOI.AbstractVectorFunction, <:MOI.AbstractVectorSet}) = 1:optimizer.cone.nrows[constroffset(optimizer, ci)]
orderval(val, s) = val
function orderval(val, s::MOI.PositiveSemidefiniteConeTriangle)
sympackedUtoL(val, s.side_dimension)
end
orderidx(idx, s) = idx
function orderidx(idx, s::MOI.PositiveSemidefiniteConeTriangle)
sympackedUtoLidx(idx, s.side_dimension)
end
function MOIU.load_constraint(optimizer::Optimizer, ci::MOI.ConstraintIndex, f::MOI.VectorAffineFunction, s::MOI.AbstractVectorSet)
A = sparse(output_index.(f.terms), variable_index_value.(f.terms), coefficient.(f.terms))
# sparse combines duplicates with + but does not remove zeros created so we call dropzeros!
dropzeros!(A)
I, J, V = findnz(A)
offset = constroffset(optimizer, ci)
rows = constrrows(s)
optimizer.cone.nrows[offset] = length(rows)
i = offset .+ rows
b = f.constants
if s isa MOI.PositiveSemidefiniteConeTriangle
# FIXME shouldn't scale before ?
b = sympackedUtoL(b, s.side_dimension)
b = scalecoef(rows, b, s)
V = scalecoef(I, V, s)
I = sympackedUtoLidx(I, s.side_dimension)
end
# The SCS format is b - Ax ∈ cone
optimizer.data.b[i] = b
append!(optimizer.data.I, offset .+ I)
append!(optimizer.data.J, J)
append!(optimizer.data.V, -V)
end
function MOIU.allocate_variables(optimizer::Optimizer, nvars::Integer)
optimizer.cone = ConeData()
VI.(1:nvars)
end
function MOIU.load_variables(optimizer::Optimizer, nvars::Integer)
cone = optimizer.cone
m = cone.f + cone.l + cone.q + cone.s + 3cone.ep + 3cone.ed + 3length(cone.p)
I = Int[]
J = Int[]
V = Float64[]
b = zeros(m)
c = zeros(nvars)
optimizer.data = ModelData(m, nvars, I, J, V, b, 0., c)
# `optimizer.sol` contains the result of the previous optimization.
# It is used as a warm start if its length is the same, e.g.
# probably because no variable and/or constraint has been added.
if length(optimizer.sol.primal) != nvars
optimizer.sol.primal = zeros(nvars)
end
@assert length(optimizer.sol.dual) == length(optimizer.sol.slack)
if length(optimizer.sol.dual) != m
optimizer.sol.dual = zeros(m)
optimizer.sol.slack = zeros(m)
end
end
function MOIU.allocate(::Optimizer, ::MOI.VariablePrimalStart,
::MOI.VariableIndex, ::Union{Nothing, Float64})
end
function MOIU.allocate(::Optimizer, ::MOI.ConstraintPrimalStart,
::MOI.ConstraintIndex,
::Union{Nothing, AbstractVector{Float64}})
end
function MOIU.allocate(::Optimizer, ::MOI.ConstraintDualStart,
::MOI.ConstraintIndex,
::Union{Nothing, AbstractVector{Float64}})
end
function MOIU.allocate(optimizer::Optimizer, ::MOI.ObjectiveSense, sense::MOI.OptimizationSense)
optimizer.maxsense = sense == MOI.MAX_SENSE
end
function MOIU.allocate(::Optimizer, ::MOI.ObjectiveFunction,
::MOI.Union{MOI.SingleVariable,
MOI.ScalarAffineFunction{Float64}})
end
function MOIU.load(::Optimizer, ::MOI.VariablePrimalStart,
::MOI.VariableIndex, ::Nothing)
end
function MOIU.load(optimizer::Optimizer, ::MOI.VariablePrimalStart,
vi::MOI.VariableIndex, value::Float64)
optimizer.sol.primal[vi.value] = value
end
function MOIU.load(::Optimizer, ::MOI.ConstraintPrimalStart,
::MOI.ConstraintIndex, ::Nothing)
end
function MOIU.load(optimizer::Optimizer, ::MOI.ConstraintPrimalStart,
ci::MOI.ConstraintIndex, value)
offset = constroffset(optimizer, ci)
rows = constrrows(optimizer, ci)
optimizer.sol.slack[offset .+ rows] .= value
end
function MOIU.load(::Optimizer, ::MOI.ConstraintDualStart,
::MOI.ConstraintIndex, ::Nothing)
end
function MOIU.load(optimizer::Optimizer, ::MOI.ConstraintDualStart,
ci::MOI.ConstraintIndex, value)
offset = constroffset(optimizer, ci)
rows = constrrows(optimizer, ci)
optimizer.sol.dual[offset .+ rows] .= value
end
function MOIU.load(::Optimizer, ::MOI.ObjectiveSense, ::MOI.OptimizationSense)
end
function MOIU.load(optimizer::Optimizer, ::MOI.ObjectiveFunction,
f::MOI.SingleVariable)
MOIU.load(optimizer,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(),
MOI.ScalarAffineFunction{Float64}(f))
end
function MOIU.load(optimizer::Optimizer, ::MOI.ObjectiveFunction,
f::MOI.ScalarAffineFunction)
c0 = Vector(sparsevec(variable_index_value.(f.terms), coefficient.(f.terms),
optimizer.data.n))
optimizer.data.objective_constant = f.constant
optimizer.data.c = optimizer.maxsense ? -c0 : c0
return nothing
end
function MOI.optimize!(optimizer::Optimizer)
cone = optimizer.cone
m = optimizer.data.m
n = optimizer.data.n
A = sparse(optimizer.data.I, optimizer.data.J, optimizer.data.V)
b = optimizer.data.b
objective_constant = optimizer.data.objective_constant
c = optimizer.data.c
optimizer.data = nothing # Allows GC to free optimizer.data before A is loaded to SCS
options = optimizer.options
if optimizer.silent
options = copy(options)
options[:verbose] = 0
end
linear_solver, options = sanitize_SCS_options(options)
sol = SCS_solve(linear_solver, m, n, A, b, c,
cone.f, cone.l, cone.qa, cone.sa, cone.ep, cone.ed, cone.p,
optimizer.sol.primal, optimizer.sol.dual,
optimizer.sol.slack; options...)
ret_val = sol.ret_val
primal = sol.x
dual = sol.y
slack = sol.s
objective_value = (optimizer.maxsense ? -1 : 1) * sol.info.pobj
dual_objective_value = (optimizer.maxsense ? -1 : 1) * sol.info.dobj
solve_time = (sol.info.setupTime + sol.info.solveTime) / 1000
optimizer.sol = MOISolution(ret_val, raw_status(sol.info), primal, dual,
slack, objective_value, dual_objective_value,
objective_constant, solve_time, sol.info.iter)
end
function MOI.get(optimizer::Optimizer, ::MOI.SolveTime)
return optimizer.sol.solve_time_sec
end
function MOI.get(optimizer::Optimizer, ::MOI.RawStatusString)
return optimizer.sol.raw_status
end
function MOI.get(optimizer::Optimizer, ::ADMMIterations)
return optimizer.sol.iterations
end
# Implements getter for result value and statuses
# SCS returns one of the following integers:
# -7 SCS_INFEASIBLE_INACCURATE
# -6 SCS_UNBOUNDED_INACCURATE
# -5 SCS_SIGINT
# -4 SCS_FAILED
# -3 SCS_INDETERMINATE
# -2 SCS_INFEASIBLE : primal infeasible, dual unbounded
# -1 SCS_UNBOUNDED : primal unbounded, dual infeasible
# 0 SCS_UNFINISHED : never returned, used as placeholder
# 1 SCS_SOLVED
# 2 SCS_SOLVED_INACCURATE
function MOI.get(optimizer::Optimizer, ::MOI.TerminationStatus)
s = optimizer.sol.ret_val
@assert -7 <= s <= 2
if s == -7
return MOI.ALMOST_INFEASIBLE
elseif s == -6
return MOI.ALMOST_DUAL_INFEASIBLE
elseif s == 2
return MOI.ALMOST_OPTIMAL
elseif s == -5
return MOI.INTERRUPTED
elseif s == -4
return MOI.NUMERICAL_ERROR
elseif s == -3
return MOI.SLOW_PROGRESS
elseif s == -2
return MOI.INFEASIBLE
elseif s == -1
return MOI.DUAL_INFEASIBLE
elseif s == 1
return MOI.OPTIMAL
else
@assert s == 0
return MOI.OPTIMIZE_NOT_CALLED
end
end
function MOI.get(optimizer::Optimizer, attr::MOI.ObjectiveValue)
MOI.check_result_index_bounds(optimizer, attr)
value = optimizer.sol.objective_value
if !MOIU.is_ray(MOI.get(optimizer, MOI.PrimalStatus()))
value += optimizer.sol.objective_constant
end
return value
end
function MOI.get(optimizer::Optimizer, attr::MOI.DualObjectiveValue)
MOI.check_result_index_bounds(optimizer, attr)
value = optimizer.sol.dual_objective_value
if !MOIU.is_ray(MOI.get(optimizer, MOI.DualStatus()))
value += optimizer.sol.objective_constant
end
return value
end
function MOI.get(optimizer::Optimizer, attr::MOI.PrimalStatus)
if attr.N > MOI.get(optimizer, MOI.ResultCount())
return MOI.NO_SOLUTION
end
s = optimizer.sol.ret_val
if s in (-3, 1, 2)
MOI.FEASIBLE_POINT
elseif s in (-6, -1)
MOI.INFEASIBILITY_CERTIFICATE
else
MOI.INFEASIBLE_POINT
end
end
function MOI.get(optimizer::Optimizer, attr::MOI.VariablePrimal, vi::VI)
MOI.check_result_index_bounds(optimizer, attr)
optimizer.sol.primal[vi.value]
end
function MOI.get(optimizer::Optimizer, attr::MOI.VariablePrimal, vi::Vector{VI})
return MOI.get.(optimizer, attr, vi)
end
function MOI.get(optimizer::Optimizer, attr::MOI.ConstraintPrimal,
ci::CI{<:MOI.AbstractFunction, S}) where S <: MOI.AbstractSet
MOI.check_result_index_bounds(optimizer, attr)
offset = constroffset(optimizer, ci)
rows = constrrows(optimizer, ci)
primal = optimizer.sol.slack[offset .+ rows]
if S == MOI.PositiveSemidefiniteConeTriangle
primal = sympackedLtoU(primal)
primal = unscalecoef(rows, primal, length(rows))
end
return primal
end
function MOI.get(optimizer::Optimizer, attr::MOI.DualStatus)
if attr.N > MOI.get(optimizer, MOI.ResultCount())
return MOI.NO_SOLUTION
end
s = optimizer.sol.ret_val
if s in (-3, 1, 2)
MOI.FEASIBLE_POINT
elseif s in (-7, -2)
MOI.INFEASIBILITY_CERTIFICATE
else
MOI.INFEASIBLE_POINT
end
end
function MOI.get(optimizer::Optimizer, attr::MOI.ConstraintDual,
ci::CI{<:MOI.AbstractFunction, S}) where S <: MOI.AbstractSet
MOI.check_result_index_bounds(optimizer, attr)
offset = constroffset(optimizer, ci)
rows = constrrows(optimizer, ci)
dual = optimizer.sol.dual[offset .+ rows]
if S == MOI.PositiveSemidefiniteConeTriangle
dual = sympackedLtoU(dual)
dual = unscalecoef(rows, dual, length(rows))
end
return dual
end
MOI.get(optimizer::Optimizer, ::MOI.ResultCount) = 1