Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for constraint attributes #122

Merged
merged 2 commits into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
26 changes: 3 additions & 23 deletions src/QCQP/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function MOI.set(
ci::MOI.ConstraintIndex{<:PolyJuMP.ScalarPolynomialFunction{T},S},
value,
) where {T,S<:MOI.AbstractScalarSet}
return MOI.get(model.constraints[S][2], attr, model.index_map[ci], value)
return MOI.set(model.constraints[S][2], attr, ci, value)
Copy link
Member

Choose a reason for hiding this comment

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

oof

Copy link
Member Author

Choose a reason for hiding this comment

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

That's the power of coverage 😅

end

function MOI.get(
Expand Down Expand Up @@ -425,7 +425,7 @@ function _add_constraints(
dest,
src,
index_map,
cis_src::Vector{MOI.ConstraintIndex{F,S}},
cis_src::AbstractVector{MOI.ConstraintIndex{F,S}},
index_to_var,
d,
div,
Expand All @@ -438,27 +438,7 @@ function _add_constraints(
dest_ci = MOI.Utilities.normalize_and_add_constraint(dest, quad, set)
index_map[ci] = dest_ci
end
# `Utilities.pass_attributes` needs `index_map` to be an `IndexMap` :(
#MOI.Utilities.pass_attributes(dest, src, index_map, cis_src)
# `ListOfConstraintAttributesSet` not defined for `VectorOfConstraints`
# for attr in MOI.get(src, MOI.ListOfConstraintAttributesSet{F,S}())
# if !MOI.supports(dest, attr)
# if attr == MOI.Name()
# continue # Skipping names is okay.
# end
# end
# for ci in cis_src
# value = MOI.get(src, attr, ci)
# if value !== nothing
# MOI.set(
# dest,
# attr,
# index_map[ci],
# MOI.Utilities.map_indices(index_map, attr, value),
# )
# end
# end
# end
MOI.Utilities.pass_attributes(dest, src, index_map, cis_src)
return
end

Expand Down
15 changes: 9 additions & 6 deletions test/qcqp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ function test_variable_primal(x, y, T)
end

# We test names as it's supported by `MOI.Utilities.Model`
function test_name(x, y, T)
function test_name(_, _, T)
model = JuMP.GenericModel{T}()
JuMP.@variable(model, 1 <= a <= 3)
JuMP.@variable(model, 1 <= b <= 3)
Expand All @@ -333,11 +333,6 @@ function test_name(x, y, T)
attr = MOI.ConstraintName()
@test MOI.get(qcqp, attr, idxmap[JuMP.index(aff)]) == "aff"
@test MOI.get(qcqp, attr, idxmap[JuMP.index(con_ref)]) == "con_ref"
inner = qcqp.model.model
F = MOI.ScalarQuadraticFunction{T}
S = MOI.GreaterThan{T}
ci = first(MOI.get(inner, MOI.ListOfConstraintIndices{F,S}()))
@test_broken MOI.get(inner, attr, ci) == "con_ref"
end

function test_start(x, y, T)
Expand All @@ -349,10 +344,18 @@ function test_start(x, y, T)
MOI.set(model, MOI.VariablePrimalStart(), b, 3one(T))
p = PolyJuMP.ScalarPolynomialFunction(one(T) * x^3 - x * y^2, [a, b])
ci = MOI.add_constraint(model, p, MOI.LessThan(zero(T)))
MOI.set(model, MOI.ConstraintPrimalStart(), ci, 5one(T))
@test MOI.get(model, MOI.ConstraintPrimalStart(), ci) == 5
@test MOI.is_valid(model, ci)
MOI.Utilities.final_touch(model, nothing)
vis = MOI.get(inner, MOI.ListOfVariableIndices())
@test sort(MOI.get(inner, MOI.VariablePrimalStart(), vis)) == T[2, 3, 4, 9]
@test MOI.get(model, MOI.ConstraintPrimalStart(), ci) == 5
@test MOI.get(
model.model,
MOI.ConstraintPrimalStart(),
model.index_map[ci],
) == 5
end

function test_inner_bridge(x, y, T)
Expand Down
Loading