Skip to content

Commit dff7ec9

Browse files
authored
Add support for constraint attributes (#122)
* Add support for constraint attributes * Fix format
1 parent 35ece1a commit dff7ec9

File tree

2 files changed

+12
-29
lines changed

2 files changed

+12
-29
lines changed

src/QCQP/MOI_wrapper.jl

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function MOI.set(
7979
ci::MOI.ConstraintIndex{<:PolyJuMP.ScalarPolynomialFunction{T},S},
8080
value,
8181
) where {T,S<:MOI.AbstractScalarSet}
82-
return MOI.get(model.constraints[S][2], attr, model.index_map[ci], value)
82+
return MOI.set(model.constraints[S][2], attr, ci, value)
8383
end
8484

8585
function MOI.get(
@@ -425,7 +425,7 @@ function _add_constraints(
425425
dest,
426426
src,
427427
index_map,
428-
cis_src::Vector{MOI.ConstraintIndex{F,S}},
428+
cis_src::AbstractVector{MOI.ConstraintIndex{F,S}},
429429
index_to_var,
430430
d,
431431
div,
@@ -438,27 +438,7 @@ function _add_constraints(
438438
dest_ci = MOI.Utilities.normalize_and_add_constraint(dest, quad, set)
439439
index_map[ci] = dest_ci
440440
end
441-
# `Utilities.pass_attributes` needs `index_map` to be an `IndexMap` :(
442-
#MOI.Utilities.pass_attributes(dest, src, index_map, cis_src)
443-
# `ListOfConstraintAttributesSet` not defined for `VectorOfConstraints`
444-
# for attr in MOI.get(src, MOI.ListOfConstraintAttributesSet{F,S}())
445-
# if !MOI.supports(dest, attr)
446-
# if attr == MOI.Name()
447-
# continue # Skipping names is okay.
448-
# end
449-
# end
450-
# for ci in cis_src
451-
# value = MOI.get(src, attr, ci)
452-
# if value !== nothing
453-
# MOI.set(
454-
# dest,
455-
# attr,
456-
# index_map[ci],
457-
# MOI.Utilities.map_indices(index_map, attr, value),
458-
# )
459-
# end
460-
# end
461-
# end
441+
MOI.Utilities.pass_attributes(dest, src, index_map, cis_src)
462442
return
463443
end
464444

test/qcqp.jl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ function test_variable_primal(x, y, T)
315315
end
316316

317317
# We test names as it's supported by `MOI.Utilities.Model`
318-
function test_name(x, y, T)
318+
function test_name(_, _, T)
319319
model = JuMP.GenericModel{T}()
320320
JuMP.@variable(model, 1 <= a <= 3)
321321
JuMP.@variable(model, 1 <= b <= 3)
@@ -333,11 +333,6 @@ function test_name(x, y, T)
333333
attr = MOI.ConstraintName()
334334
@test MOI.get(qcqp, attr, idxmap[JuMP.index(aff)]) == "aff"
335335
@test MOI.get(qcqp, attr, idxmap[JuMP.index(con_ref)]) == "con_ref"
336-
inner = qcqp.model.model
337-
F = MOI.ScalarQuadraticFunction{T}
338-
S = MOI.GreaterThan{T}
339-
ci = first(MOI.get(inner, MOI.ListOfConstraintIndices{F,S}()))
340-
@test_broken MOI.get(inner, attr, ci) == "con_ref"
341336
end
342337

343338
function test_start(x, y, T)
@@ -349,10 +344,18 @@ function test_start(x, y, T)
349344
MOI.set(model, MOI.VariablePrimalStart(), b, 3one(T))
350345
p = PolyJuMP.ScalarPolynomialFunction(one(T) * x^3 - x * y^2, [a, b])
351346
ci = MOI.add_constraint(model, p, MOI.LessThan(zero(T)))
347+
MOI.set(model, MOI.ConstraintPrimalStart(), ci, 5one(T))
348+
@test MOI.get(model, MOI.ConstraintPrimalStart(), ci) == 5
352349
@test MOI.is_valid(model, ci)
353350
MOI.Utilities.final_touch(model, nothing)
354351
vis = MOI.get(inner, MOI.ListOfVariableIndices())
355352
@test sort(MOI.get(inner, MOI.VariablePrimalStart(), vis)) == T[2, 3, 4, 9]
353+
@test MOI.get(model, MOI.ConstraintPrimalStart(), ci) == 5
354+
@test MOI.get(
355+
model.model,
356+
MOI.ConstraintPrimalStart(),
357+
model.index_map[ci],
358+
) == 5
356359
end
357360

358361
function test_inner_bridge(x, y, T)

0 commit comments

Comments
 (0)