|
3 | 3 | # Use of this source code is governed by an MIT-style license that can be found |
4 | 4 | # in the LICENSE.md file or at https://opensource.org/licenses/MIT. |
5 | 5 |
|
| 6 | +# Helpers for objective function |
| 7 | + |
6 | 8 | # Representation of MOI functions using SparseArrays |
7 | 9 | # Might be able to replace in the future by a function in MOI, see |
8 | 10 | # https://github.com/jump-dev/MathOptInterface.jl/pull/1238 |
@@ -152,6 +154,8 @@ function sparse_array_representation( |
152 | 154 | ) |
153 | 155 | end |
154 | 156 |
|
| 157 | +# Helpers for scalar constraints |
| 158 | + |
155 | 159 | # In the future, we could replace by https://github.com/jump-dev/MathOptInterface.jl/pull/1238 |
156 | 160 | """ |
157 | 161 | VectorScalarAffineFunction{T, VT} <: MOI.AbstractScalarFunction |
@@ -228,6 +232,8 @@ function JuMP.coefficient( |
228 | 232 | return JuMP.coefficient(func.affine, vi) |
229 | 233 | end |
230 | 234 |
|
| 235 | +# Helpers for Vector constraints |
| 236 | + |
231 | 237 | """ |
232 | 238 | MatrixVectorAffineFunction{T, VT} <: MOI.AbstractVectorFunction |
233 | 239 |
|
@@ -260,6 +266,17 @@ function standard_form(func::MatrixVectorAffineFunction{T}) where {T} |
260 | 266 | return convert(MOI.VectorAffineFunction{T}, func) |
261 | 267 | end |
262 | 268 |
|
| 269 | +_get_terms(f::VectorScalarAffineFunction) = f.terms |
| 270 | +_get_constant(f::VectorScalarAffineFunction) = f.constant |
| 271 | +function _vectorize(vec::Vector{T}) where {T<:VectorScalarAffineFunction} |
| 272 | + terms = LazyArrays.@~ LazyArrays.ApplyArray(hcat, _get_terms.(vec)...)' |
| 273 | + constants = LazyArrays.ApplyArray(vcat, _get_constant.(vec)...) |
| 274 | + AT = typeof(terms) |
| 275 | + VT = typeof(constants) |
| 276 | + ret = MatrixVectorAffineFunction{AT,VT}(terms, constants) |
| 277 | + return ret |
| 278 | +end |
| 279 | + |
263 | 280 | # Only used for testing at the moment so performance is not critical so |
264 | 281 | # converting to standard form is ok |
265 | 282 | function MOIU.isapprox_zero( |
|
0 commit comments