Skip to content
This repository was archived by the owner on Jun 14, 2020. It is now read-only.

Commit cefa4d2

Browse files
authored
Add get_quadratic_constraint and fix getting of quadratic function (#24)
* Add get_quadratic_constraint and fix getting of quadratic function * Enable getting of interval sets
1 parent e1b43ed commit cefa4d2

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

src/constraints/scalaraffine.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ function MOI.get(m::LinQuadOptimizer, ::MOI.ConstraintSet, c::LCI{S}) where S <:
137137
S(rhs+m.constraint_constant[m[c]])
138138
end
139139

140-
MOI.canget(::LinQuadOptimizer, ::MOI.ConstraintSet, ::Type{LCI{IV}}) = false
140+
MOI.canget(::LinQuadOptimizer, ::MOI.ConstraintSet, ::Type{LCI{IV}}) = true
141141
function MOI.get(m::LinQuadOptimizer, ::MOI.ConstraintSet, c::LCI{IV})
142142
lowerbound, upperbound = get_range(m, m[c])
143143
IV(lowerbound+m.constraint_constant[m[c]], upperbound + m.constraint_constant[m[c]])

src/constraints/scalarquadratic.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ end
103103

104104
MOI.canget(m::LinQuadOptimizer, ::MOI.ConstraintSet, ::Type{QCI{S}}) where S <: Union{LE, GE, EQ} = true
105105
function MOI.get(m::LinQuadOptimizer, ::MOI.ConstraintSet, c::QCI{S}) where S <: Union{LE, GE, EQ}
106-
rhs = get_rhs(m, m[c])
106+
rhs = get_quadratic_rhs(m, m[c])
107107
S(rhs)
108108
end
109109

@@ -118,8 +118,8 @@ function MOI.get(m::LinQuadOptimizer, ::MOI.ConstraintFunction, c::QCI{<: LinSet
118118
# TODO more efficiently
119119
colidx, coefs, Q = get_quadratic_constraint(m, m[c])
120120
affine_terms = map(
121-
(v,c)->MOI.ScalarAffineTerm{Float64}(c,v),
122-
m.variable_references[colidx+1],
121+
(v,c)->MOI.ScalarAffineTerm{Float64}(c, m.variable_references[v]),
122+
colidx,
123123
coefs
124124
)
125125
rows = rowvals(Q)
@@ -135,4 +135,4 @@ function MOI.get(m::LinQuadOptimizer, ::MOI.ConstraintFunction, c::QCI{<: LinSet
135135
end
136136
end
137137
Quad(affine_terms, quadratic_terms, 0.0) # constant was moved into set
138-
end
138+
end

src/solver_interface.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,13 @@ Where `Q` represents the matrix in CSC format.
351351
"""
352352
function get_quadratic_constraint end
353353

354+
"""
355+
get_quadratic_constraint(m, row::Int)::Float64
356+
357+
Get the right hand-side term of quadratic constraint in row `row` in model `m`.
358+
"""
359+
function get_quadratic_rhs end
360+
354361
"""
355362
set_linear_objective!(m, cols::Vector{Int}, coefs::Vector{Float64})::Void
356363

0 commit comments

Comments
 (0)