Skip to content

Commit 49647d9

Browse files
authored
uniform sense, documentation (#23)
1 parent d56c4aa commit 49647d9

File tree

3 files changed

+77
-21
lines changed

3 files changed

+77
-21
lines changed

src/change_form.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function change_form(::Type{LPForm{T, AT, VT}}, lp::LPForm) where {T, AT, VT}
22
return LPForm{T, AT, VT}(
3-
lp.direction,
3+
lp.sense,
44
lp.c,
55
lp.A,
66
lp.c_lb,
@@ -12,7 +12,7 @@ end
1212

1313
function change_form(::Type{LPForm{T, AT, VT}}, lp::LPStandardForm{T}) where {T, AT, VT}
1414
return LPForm{T, AT, VT}(
15-
lp.direction,
15+
lp.sense,
1616
lp.c,
1717
lp.A,
1818
lp.b,
@@ -23,7 +23,7 @@ function change_form(::Type{LPForm{T, AT, VT}}, lp::LPStandardForm{T}) where {T,
2323
end
2424
function change_form(::Type{LPForm{T, AT, VT}}, lp::LPGeometricForm{T}) where {T, AT, VT}
2525
return LPForm{T, AT, VT}(
26-
lp.direction,
26+
lp.sense,
2727
lp.c,
2828
lp.A,
2929
fill(typemin(T), length(lp.b)),
@@ -48,7 +48,7 @@ function change_form(::Type{LPForm{T, AT, VT}}, lp::LPSolverForm{T}) where {T, A
4848
end
4949
end
5050
return LPForm{T, AT, VT}(
51-
lp.direction,
51+
lp.sense,
5252
lp.c,
5353
lp.A,
5454
c_lb,
@@ -60,7 +60,7 @@ end
6060

6161
function change_form(::Type{LPGeometricForm{T, AT, VT}}, lp::LPGeometricForm) where {T, AT, VT}
6262
return LPGeometricForm{T, AT, VT}(
63-
lp.direction,
63+
lp.sense,
6464
lp.c,
6565
lp.A,
6666
lp.b
@@ -105,7 +105,7 @@ function change_form(::Type{LPGeometricForm{T, AT, VT}}, lp::LPForm{T}) where {T
105105
-lp.v_lb[has_v_lower],
106106
)
107107
return LPGeometricForm{T, AT, VT}(
108-
lp.direction,
108+
lp.sense,
109109
lp.c,
110110
new_A,
111111
new_b
@@ -118,7 +118,7 @@ end
118118

119119
function change_form(::Type{LPStandardForm{T, AT, VT}}, lp::LPStandardForm) where {T, AT, VT}
120120
return LPStandardForm(
121-
lp.direction,
121+
lp.sense,
122122
lp.c,
123123
lp.A,
124124
lp.b
@@ -136,7 +136,7 @@ function change_form(::Type{LPStandardForm{T, AT, VT}}, lp::LPGeometricForm{T})
136136
fill(0.0, length(lp.b))
137137
)
138138
return LPStandardForm{T, AT, VT}(
139-
lp.direction,
139+
lp.sense,
140140
new_c,
141141
new_A,
142142
copy(lp.b)
@@ -150,7 +150,7 @@ end
150150

151151
function change_form(::Type{LPSolverForm{T, AT, VT}}, lp::LPSolverForm) where {T, AT, VT}
152152
return LPSolverForm{T, AT, VT}(
153-
lp.direction,
153+
lp.sense,
154154
lp.c,
155155
lp.A,
156156
lp.b,
@@ -182,7 +182,7 @@ function change_form(::Type{LPSolverForm{T, AT, VT}}, lp::LPForm{T}) where {T, A
182182
end
183183
end
184184
return LPSolverForm{T, AT, VT}(
185-
lp.direction,
185+
lp.sense,
186186
lp.c,
187187
new_A,
188188
new_b,

src/conic_form.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
2+
"""
3+
GeometricConicForm{T, AT, VT, C} <: MOI.ModelLike
4+
5+
Represents an optimization model of the form:
6+
```
7+
sense ⟨c, x⟩ + c0
8+
s.t. b_i - A_i x ∈ C_i ∀ i
9+
```
10+
with each `C_i` a cone defined in MOI.
11+
"""
112
mutable struct GeometricConicForm{T, AT, VT, C} <: MOI.ModelLike
213
num_rows::Vector{Int}
314
dimension::Dict{Int, Int}
@@ -25,7 +36,8 @@ end
2536
_set_type(::MOI.ConstraintIndex{F,S}) where {F,S} = S
2637

2738
MOI.is_empty(model::GeometricConicForm) = model.A === nothing
28-
function MOI.empty!(model::GeometricConicForm{T}) where T
39+
40+
function MOI.empty!(model::GeometricConicForm{T}) where {T}
2941
empty!(model.dimension)
3042
fill!(model.num_rows, 0)
3143
model.A = nothing

src/matrix_input.jl

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ end
1717
function MOI.get(model::AbstractLPForm, ::MOI.ListOfModelAttributesSet)
1818
list = MOI.AbstractModelAttribute[]
1919
push!(list, MOI.ObjectiveSense())
20-
if model.direction != MOI.FEASIBILITY_SENSE
20+
if model.sense != MOI.FEASIBILITY_SENSE
2121
push!(list, MOI.ObjectiveFunction{MOI.get(model, MOI.ObjectiveFunctionType())}())
2222
end
2323
return list
2424
end
25-
MOI.get(model::AbstractLPForm, ::MOI.ObjectiveSense) = model.direction
25+
MOI.get(model::AbstractLPForm, ::MOI.ObjectiveSense) = model.sense
2626
function MOI.get(model::AbstractLPForm{T},
2727
::MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}) where T
2828
return _dot(model.c)
@@ -47,15 +47,24 @@ function MOI.get(model::AbstractLPForm{T}, ::MOI.ConstraintFunction,
4747
return _dot(model.A[ci.value, :])
4848
end
4949

50+
"""
51+
LPStandardForm{T, AT<:AbstractMatrix{T}, VT <: AbstractVector{T}} <: AbstractLPForm{T}
5052
53+
Represents a problem of the form:
54+
```
55+
sense ⟨c, x⟩
56+
s.t. A x == b
57+
x ≥ 0
58+
```
59+
"""
5160
struct LPStandardForm{T, AT<:AbstractMatrix{T}, VT <: AbstractVector{T}} <: AbstractLPForm{T}
52-
direction::MOI.OptimizationSense
61+
sense::MOI.OptimizationSense
5362
c::VT
5463
A::AT
5564
b::VT
5665
end
5766

58-
function MOI.get(model::LPStandardForm{T}, ::MOI.ListOfConstraints) where T
67+
function MOI.get(::LPStandardForm{T}, ::MOI.ListOfConstraints) where T
5968
return [(MOI.ScalarAffineFunction{T}, MOI.EqualTo{T}),
6069
(MOI.VectorOfVariables, MOI.Nonnegatives)]
6170
end
@@ -77,7 +86,7 @@ function MOI.get(model::LPStandardForm, ::MOI.ConstraintSet,
7786
end
7887
const NONNEG = MOI.ConstraintIndex{MOI.VectorOfVariables, MOI.Nonnegatives}
7988
function MOI.get(
80-
model::LPStandardForm,
89+
::LPStandardForm,
8190
::MOI.ListOfConstraintIndices{
8291
MOI.VectorOfVariables, MOI.Nonnegatives}
8392
)
@@ -92,14 +101,23 @@ function MOI.get(model::LPStandardForm, ::MOI.ConstraintSet,
92101
return MOI.Nonnegatives(MOI.get(model, MOI.NumberOfVariables()))
93102
end
94103

104+
"""
105+
LPGeometricForm{T, AT<:AbstractMatrix{T}, VT <: AbstractVector{T}} <: AbstractLPForm{T}
106+
107+
Represents a linear problem of the form:
108+
```
109+
sense ⟨c, x⟩
110+
s.t. Ax <= b
111+
```
112+
"""
95113
struct LPGeometricForm{T, AT<:AbstractMatrix{T}, VT <: AbstractVector{T}} <: AbstractLPForm{T}
96-
direction::MOI.OptimizationSense
114+
sense::MOI.OptimizationSense
97115
c::VT
98116
A::AT
99117
b::VT
100118
end
101119

102-
function MOI.get(model::LPGeometricForm{T}, ::MOI.ListOfConstraints) where T
120+
function MOI.get(::LPGeometricForm{T}, ::MOI.ListOfConstraints) where T
103121
return [(MOI.ScalarAffineFunction{T}, MOI.LessThan{T})]
104122
end
105123
const LT{T} = MOI.ConstraintIndex{MOI.ScalarAffineFunction{T}, MOI.LessThan{T}}
@@ -175,15 +193,25 @@ function MOI.get(model::LPMixedForm{T}, ::MOI.ListOfConstraintIndices{MOI.Single
175193
VBOUND{S}(vi.value)
176194
end)
177195
end
178-
function MOI.get(model::LPMixedForm, ::MOI.ConstraintFunction, ci::VBOUND)
196+
function MOI.get(::LPMixedForm, ::MOI.ConstraintFunction, ci::VBOUND)
179197
return MOI.SingleVariable(MOI.VariableIndex(ci.value))
180198
end
181199
function MOI.get(model::LPMixedForm, ::MOI.ConstraintSet, ci::VBOUND)
182200
return _bound_set(model.v_lb[ci.value], model.v_ub[ci.value])
183201
end
184202

203+
"""
204+
LPForm{T, AT<:AbstractMatrix{T}, VT <: AbstractVector{T}}
205+
206+
Represents a problem of the form:
207+
```
208+
sense ⟨c, x⟩
209+
s.t. c_lb <= Ax <= c_ub
210+
v_lb <= x <= v_ub
211+
```
212+
"""
185213
struct LPForm{T, AT<:AbstractMatrix{T}, VT <: AbstractVector{T}} <: LPMixedForm{T} #, V<:AbstractVector{T} #, M<:AbstractMatrix{T}}
186-
direction::MOI.OptimizationSense
214+
sense::MOI.OptimizationSense
187215
c::VT
188216
A::AT
189217
c_lb::VT
@@ -199,8 +227,18 @@ function MOI.get(model::LPForm, ::MOI.ConstraintSet, ci::AFF)
199227
return _bound_set(model.c_lb[ci.value], model.c_ub[ci.value])
200228
end
201229

230+
"""
231+
LPSolverForm{T, AT<:AbstractMatrix{T}, VT<:AbstractVector{T}}
232+
233+
Represents a problem of the form:
234+
```
235+
sense ⟨c, x⟩
236+
s.t. Ax senses b
237+
v_lb <= x <= v_ub
238+
```
239+
"""
202240
struct LPSolverForm{T, AT<:AbstractMatrix{T}, VT<:AbstractVector{T}} <: LPMixedForm{T}
203-
direction::MOI.OptimizationSense
241+
sense::MOI.OptimizationSense
204242
c::VT
205243
A::AT
206244
b::VT
@@ -225,6 +263,12 @@ function MOI.get(model::LPSolverForm, ::MOI.ConstraintSet, ci::AFF)
225263
end
226264
end
227265

266+
"""
267+
MILP{T, LP<:AbstractLPForm{T}}
268+
269+
A mixed-integer problem represented by a linear problem of type `LP`
270+
and a vector indicating each `VariableType`.
271+
"""
228272
struct MILP{T, LP<:AbstractLPForm{T}}
229273
lp::LP
230274
variable_type::Vector{VariableType}

0 commit comments

Comments
 (0)