-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathconic_form.jl
More file actions
51 lines (46 loc) · 1.44 KB
/
conic_form.jl
File metadata and controls
51 lines (46 loc) · 1.44 KB
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
# Copyright (c) 2019: Joaquim Dias Garcia, and contributors
#
# Use of this source code is governed by an MIT-style license that can be found
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.
"""
empty_geometric_conic_form
Represents an optimization model of the form:
```
sense ⟨c, x⟩ + c0
s.t. A_i x + b_i ∈ C_i ∀ i
```
with each `C_i` a cone defined in MOI.
"""
function empty_geometric_conic_form(
cones;
Tv = Float64,
Ti = Int,
I = MOI.Utilities.OneBasedIndexing,
)
model = MOI.Utilities.GenericModel{Tv}(
MOI.Utilities.ObjectiveContainer{Tv}(),
MOI.Utilities.FreeVariables(),
MOI.Utilities.MatrixOfConstraints{
Tv,
MOI.Utilities.MutableSparseMatrixCSC{Tv,Ti,I},
Vector{Tv},
ProductOfSets{Tv},
}(),
)
set_set_types(model.constraints.sets, cones)
return model
end
function geometric_conic_form(model::MOI.ModelLike, cones; kws...)
form = empty_geometric_conic_form(cones; kws...)
index_map = MOI.copy_to(form, model)
return form, index_map
end
_coef_type(::MOI.Utilities.AbstractModel{T}) where {T} = T
function objective_vector(model::MOI.ModelLike; T = _coef_type(model))
obj = MOI.get(model, MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}())
c = zeros(MOI.get(model, MOI.NumberOfVariables()))
for term in obj.terms
c[term.variable.value] += term.coefficient
end
return c
end