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

Commit 7f4d09b

Browse files
authored
Update enums to JuMP style guide (#84)
1 parent 0fffd7f commit 7f4d09b

File tree

5 files changed

+40
-40
lines changed

5 files changed

+40
-40
lines changed

src/LinQuadOptInterface.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,9 @@ function Base.isempty(map::ConstraintMapping)
192192
end
193193

194194
@enum(ObjectiveType,
195-
SingleVariableObjective,
196-
AffineObjective,
197-
QuadraticObjective)
195+
SINGLE_VARIABLE_OBJECTIVE,
196+
AFFINE_OBJECTIVE,
197+
QUADRATIC_OBJECTIVE)
198198

199199
# Abstract + macro
200200
abstract type LinQuadOptimizer <: MOI.AbstractOptimizer end
@@ -230,7 +230,7 @@ function MOI.get(::LinQuadOptimizer, ::MOI.ListOfConstraintAttributesSet)
230230
return MOI.AbstractConstraintAttribute[]
231231
end
232232

233-
@enum(VariableType, Continuous, Binary, Integer, Semiinteger, Semicontinuous)
233+
@enum(VariableType, CONTINUOUS, BINARY, INTEGER, SEMI_INTEGER, SEMI_CONTINUOUS)
234234

235235
macro LinQuadOptimizerBase(inner_model_type=Any)
236236
esc(quote
@@ -281,7 +281,7 @@ end
281281
function MOI.is_empty(m::LinQuadOptimizer)
282282
ret = true
283283
ret = ret && m.name == ""
284-
ret = ret && m.obj_type == AffineObjective
284+
ret = ret && m.obj_type == AFFINE_OBJECTIVE
285285
ret = ret && isa(m.single_obj_var, Nothing)
286286
ret = ret && m.obj_sense == MOI.MIN_SENSE
287287
ret = ret && m.last_variable_reference == 0
@@ -315,7 +315,7 @@ function MOI.empty!(m::M, env = nothing) where M<:LinQuadOptimizer
315315
m.name = ""
316316
m.inner = LinearQuadraticModel(M,env)
317317

318-
m.obj_type = AffineObjective
318+
m.obj_type = AFFINE_OBJECTIVE
319319
m.single_obj_var = nothing
320320
# we assume the default is minimization
321321
m.obj_sense = MOI.MIN_SENSE

src/constraints/singlevariable.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ end
108108
function MOI.add_constraint(model::LinQuadOptimizer, variable::SinVar, set::S) where S <: LinSets
109109
__assert_supported_constraint__(model, SinVar, S)
110110
variable_type = model.variable_type[variable.variable]
111-
if !(variable_type == Continuous || variable_type == Integer)
111+
if !(variable_type == CONTINUOUS || variable_type == INTEGER)
112112
error("Cannot set bounds because variable is of type: $(variable_type).")
113113
end
114114
set_variable_bound(model, variable, set)
@@ -124,7 +124,7 @@ function MOI.add_constraints(model::LinQuadOptimizer, variables::Vector{SinVar},
124124
__assert_supported_constraint__(model, SinVar, S)
125125
for variable in variables
126126
variable_type = model.variable_type[variable.variable]
127-
if !(variable_type == Continuous || variable_type == Integer)
127+
if !(variable_type == CONTINUOUS || variable_type == INTEGER)
128128
error("Cannot set bounds because variable is of type: $(variable_type).")
129129
end
130130
end
@@ -145,7 +145,7 @@ function MOI.delete(model::LinQuadOptimizer, index::SVCI{S}) where S <: LinSets
145145
delete_constraint_name(model, index)
146146
dict = constrdict(model, index)
147147
variable = dict[index]
148-
model.variable_type[variable] = Continuous
148+
model.variable_type[variable] = CONTINUOUS
149149
set_variable_bound(model, SinVar(variable), IV(-Inf, Inf))
150150
delete!(dict, index)
151151
return
@@ -197,10 +197,10 @@ user does.
197197
function MOI.add_constraint(model::LinQuadOptimizer, variable::SinVar, set::MOI.ZeroOne)
198198
__assert_supported_constraint__(model, SinVar, MOI.ZeroOne)
199199
variable_type = model.variable_type[variable.variable]
200-
if variable_type != Continuous
200+
if variable_type != CONTINUOUS
201201
error("Cannot make variable binary because it is $(variable_type).")
202202
end
203-
model.variable_type[variable.variable] = Binary
203+
model.variable_type[variable.variable] = BINARY
204204
model.last_constraint_reference += 1
205205
index = SVCI{MOI.ZeroOne}(model.last_constraint_reference)
206206
column = get_column(model, variable)
@@ -223,7 +223,7 @@ function MOI.delete(model::LinQuadOptimizer, index::SVCI{MOI.ZeroOne})
223223
delete_constraint_name(model, index)
224224
dict = constrdict(model, index)
225225
(variable, lower, upper) = dict[index]
226-
model.variable_type[variable] = Continuous
226+
model.variable_type[variable] = CONTINUOUS
227227
column = get_column(model, variable)
228228
change_variable_types!(
229229
model, [column], [backend_type(model, Val{:Continuous}())])
@@ -254,10 +254,10 @@ end
254254
function MOI.add_constraint(model::LinQuadOptimizer, variable::SinVar, set::MOI.Integer)
255255
__assert_supported_constraint__(model, SinVar, MOI.Integer)
256256
variable_type = model.variable_type[variable.variable]
257-
if variable_type != Continuous
257+
if variable_type != CONTINUOUS
258258
error("Cannot make variable integer because it is $(variable_type).")
259259
end
260-
model.variable_type[variable.variable] = Integer
260+
model.variable_type[variable.variable] = INTEGER
261261
change_variable_types!(model, [get_column(model, variable)],
262262
[backend_type(model, set)])
263263
model.last_constraint_reference += 1
@@ -273,7 +273,7 @@ function MOI.delete(model::LinQuadOptimizer, index::SVCI{MOI.Integer})
273273
delete_constraint_name(model, index)
274274
dict = constrdict(model, index)
275275
variable = dict[index]
276-
model.variable_type[variable] = Continuous
276+
model.variable_type[variable] = CONTINUOUS
277277
change_variable_types!(model, [get_column(model, variable)],
278278
[backend_type(model, Val{:Continuous}())])
279279
delete!(dict, index)
@@ -295,12 +295,12 @@ end
295295
Semicontinuous / Semiinteger constraints
296296
=#
297297
const SEMI_TYPES = Union{MOI.Semicontinuous{Float64}, MOI.Semiinteger{Float64}}
298-
variable_type_(::Type{<:MOI.Semicontinuous}) = Semicontinuous
299-
variable_type_(::Type{<:MOI.Semiinteger}) = Semiinteger
298+
variable_type_(::Type{<:MOI.Semicontinuous}) = SEMI_CONTINUOUS
299+
variable_type_(::Type{<:MOI.Semiinteger}) = SEMI_INTEGER
300300
function MOI.add_constraint(model::LinQuadOptimizer, variable::SinVar, set::S) where S <: SEMI_TYPES
301301
__assert_supported_constraint__(model, SinVar, S)
302302
variable_type = model.variable_type[variable.variable]
303-
if variable_type != Continuous
303+
if variable_type != CONTINUOUS
304304
error("Cannot make variable $(S) because it is $(variable_type).")
305305
end
306306
model.variable_type[variable.variable] = variable_type_(S)
@@ -326,7 +326,7 @@ function MOI.delete(model::LinQuadOptimizer, index::SVCI{<:SEMI_TYPES})
326326
dict = constrdict(model, index)
327327
variable = dict[index]
328328
column = get_column(model, variable)
329-
model.variable_type[variable] = Continuous
329+
model.variable_type[variable] = CONTINUOUS
330330
change_variable_types!(model, [column], [backend_type(model, Val{:Continuous}())])
331331
change_variable_bounds!(model,
332332
[column, column],

src/objective.jl

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function MOI.set(model::LinQuadOptimizer, ::MOI.ObjectiveSense,
1919
unsafe_set!(model, MOI.ObjectiveFunction{Linear}(),
2020
MOI.ScalarAffineFunction(MOI.ScalarAffineTerm{Float64}[],
2121
0.0))
22-
model.obj_type = AffineObjective
22+
model.obj_type = AFFINE_OBJECTIVE
2323
model.obj_sense = MOI.FEASIBILITY_SENSE
2424
else
2525
throw(MOI.CannotSetAttribute(MOI.ObjectiveSense,
@@ -46,10 +46,10 @@ function MOI.set(model::LinQuadOptimizer,
4646
attribute::MOI.ObjectiveFunction{MOI.SingleVariable},
4747
objective::MOI.SingleVariable)
4848
__assert_objective__(model, attribute)
49-
if model.obj_type == QuadraticObjective
49+
if model.obj_type == QUADRATIC_OBJECTIVE
5050
set_quadratic_objective!(model, Int[], Int[], Float64[])
5151
end
52-
model.obj_type = SingleVariableObjective
52+
model.obj_type = SINGLE_VARIABLE_OBJECTIVE
5353
model.single_obj_var = objective.variable
5454
set_linear_objective!(model, [get_column(model, objective.variable)], [1.0])
5555
set_constant_objective!(model, 0.0)
@@ -68,11 +68,11 @@ Sets a linear objective function without cannonicalizing `objective`.
6868
"""
6969
function unsafe_set!(model::LinQuadOptimizer, ::MOI.ObjectiveFunction{F},
7070
objective::Linear) where F
71-
if model.obj_type == QuadraticObjective
71+
if model.obj_type == QUADRATIC_OBJECTIVE
7272
# previous objective was quadratic, so zero quadratic part
7373
set_quadratic_objective!(model, Int[], Int[], Float64[])
7474
end
75-
model.obj_type = AffineObjective
75+
model.obj_type = AFFINE_OBJECTIVE
7676
model.single_obj_var = nothing
7777
set_linear_objective!(model,
7878
map(term -> get_column(model, term.variable_index), objective.terms),
@@ -84,7 +84,7 @@ end
8484
function MOI.set(model::LinQuadOptimizer, attribute::MOI.ObjectiveFunction,
8585
objective::Quad)
8686
__assert_objective__(model, attribute)
87-
model.obj_type = QuadraticObjective
87+
model.obj_type = QUADRATIC_OBJECTIVE
8888
model.single_obj_var = nothing
8989
aff_cols, aff_coefs, quad_rows, quad_cols, quad_coefs = canonical_reduction(model, objective)
9090
set_linear_objective!(model, aff_cols, aff_coefs)
@@ -100,20 +100,20 @@ function MOI.supports(model::LinQuadOptimizer, ::MOI.ObjectiveFunction{F}) where
100100
end
101101

102102
function MOI.get(model::LinQuadOptimizer, ::MOI.ObjectiveFunctionType)
103-
if model.obj_type == SingleVariableObjective
103+
if model.obj_type == SINGLE_VARIABLE_OBJECTIVE
104104
return MOI.SingleVariable
105-
elseif model.obj_type == AffineObjective
105+
elseif model.obj_type == AFFINE_OBJECTIVE
106106
return MOI.ScalarAffineFunction{Float64}
107107
else
108-
@assert model.obj_type == QuadraticObjective
108+
@assert model.obj_type == QUADRATIC_OBJECTIVE
109109
return MOI.ScalarQuadraticFunction{Float64}
110110
end
111111
end
112112

113113
function MOI.get(model::LinQuadOptimizer, ::MOI.ObjectiveFunction{MOI.SingleVariable})
114-
if model.obj_type != SingleVariableObjective
114+
if model.obj_type != SINGLE_VARIABLE_OBJECTIVE
115115
if VERSION >= v"0.7-"
116-
throw(InexactError(:convert, SingleVariableObjective, model.obj_type))
116+
throw(InexactError(:convert, SINGLE_VARIABLE_OBJECTIVE, model.obj_type))
117117
else
118118
throw(InexactError())
119119
end
@@ -122,9 +122,9 @@ function MOI.get(model::LinQuadOptimizer, ::MOI.ObjectiveFunction{MOI.SingleVari
122122
end
123123

124124
function MOI.get(model::LinQuadOptimizer, ::MOI.ObjectiveFunction{Linear})
125-
if model.obj_type == QuadraticObjective
125+
if model.obj_type == QUADRATIC_OBJECTIVE
126126
if VERSION >= v"0.7-"
127-
throw(InexactError(:convert, AffineObjective, model.obj_type))
127+
throw(InexactError(:convert, AFFINE_OBJECTIVE, model.obj_type))
128128
else
129129
throw(InexactError())
130130
end
@@ -148,7 +148,7 @@ function MOI.get(model::LinQuadOptimizer, ::MOI.ObjectiveFunction{Quad})
148148
variable_coefficients
149149
)
150150
quadratic_terms = MOI.ScalarQuadraticTerm{Float64}[]
151-
if model.obj_type == QuadraticObjective
151+
if model.obj_type == QUADRATIC_OBJECTIVE
152152
Q = get_quadratic_terms_objective(model)
153153
rows = rowvals(Q)
154154
coefficients = nonzeros(Q)
@@ -174,15 +174,15 @@ end
174174

175175
function MOI.modify(model::LinQuadOptimizer, ::MOI.ObjectiveFunction{F},
176176
change::MOI.ScalarCoefficientChange{Float64}) where F<:MOI.AbstractScalarFunction
177-
if F <: MOI.ScalarQuadraticFunction && model.obj_type != QuadraticObjective
177+
if F <: MOI.ScalarQuadraticFunction && model.obj_type != QUADRATIC_OBJECTIVE
178178
throw(MOI.UnsupportedObjectiveModification(change,
179179
"ObjectiveFunction is not a ScalarQuadraticFunction."))
180-
elseif F <: MOI.ScalarAffineFunction && model.obj_type != AffineObjective
180+
elseif F <: MOI.ScalarAffineFunction && model.obj_type != AFFINE_OBJECTIVE
181181
throw(MOI.UnsupportedObjectiveModification(change,
182182
"ObjectiveFunction is not a ScalarAffineFunction."))
183183
end
184-
if model.obj_type == SingleVariableObjective
185-
model.obj_type = AffineObjective
184+
if model.obj_type == SINGLE_VARIABLE_OBJECTIVE
185+
model.obj_type = AFFINE_OBJECTIVE
186186
model.single_obj_var = nothing
187187
end
188188
change_objective_coefficient!(model, get_column(model, change.variable),

src/solve.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function has_quadratic(model::LinQuadOptimizer)
2-
return model.obj_type == QuadraticObjective ||
2+
return model.obj_type == QUADRATIC_OBJECTIVE ||
33
length(cmap(model).q_less_than) > 0 ||
44
length(cmap(model).q_greater_than) > 0 ||
55
length(cmap(model).q_equal_to) > 0

src/variables.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function MOI.add_variable(model::LinQuadOptimizer)
109109
push!(model.variable_references, index)
110110
push!(model.variable_primal_solution, NaN)
111111
push!(model.variable_dual_solution, NaN)
112-
model.variable_type[index] = Continuous
112+
model.variable_type[index] = CONTINUOUS
113113
return index
114114
end
115115

@@ -133,7 +133,7 @@ function MOI.add_variables(model::LinQuadOptimizer, number_to_add::Int)
133133
push!(model.variable_references, index)
134134
push!(model.variable_primal_solution, NaN)
135135
push!(model.variable_dual_solution, NaN)
136-
model.variable_type[index] = Continuous
136+
model.variable_type[index] = CONTINUOUS
137137
end
138138
return variable_indices
139139
end

0 commit comments

Comments
 (0)