Skip to content

Commit 3b4f087

Browse files
committed
constant names consistent with style guide
1 parent 3ed02b0 commit 3b4f087

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

src/MOI_wrapper.jl

+25-25
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ const CI = MOI.ConstraintIndex
99
const SVF = MOI.SingleVariable
1010
const SAF = MOI.ScalarAffineFunction{Float64}
1111
# supported sets
12-
const Bounds = Union{MOI.EqualTo{Float64}, MOI.GreaterThan{Float64},
12+
const BOUNDS = Union{MOI.EqualTo{Float64}, MOI.GreaterThan{Float64},
1313
MOI.LessThan{Float64}, MOI.Interval{Float64}}
14-
const VarTypes = Union{MOI.ZeroOne, MOI.Integer}
14+
const VAR_TYPES = Union{MOI.ZeroOne, MOI.Integer}
1515
# other MOI types
16-
const AffTerm = MOI.ScalarAffineTerm{Float64}
16+
const AFF_TERM = MOI.ScalarAffineTerm{Float64}
1717

1818
const PtrMap = Dict{Ptr{Cvoid}, Union{VarRef, ConsRef}}
1919
const ConsTypeMap = Dict{Tuple{DataType, DataType}, Vector{ConsRef}}
@@ -85,11 +85,11 @@ end
8585
MOI.get(::Optimizer, ::MOI.SolverName) = "SCIP"
8686

8787
# variable bounds
88-
MOI.supports_constraint(o::Optimizer, ::Type{SVF}, ::Type{<:Bounds}) = true
88+
MOI.supports_constraint(o::Optimizer, ::Type{SVF}, ::Type{<:BOUNDS}) = true
8989
# variable types (binary, integer)
90-
MOI.supports_constraint(o::Optimizer, ::Type{SVF}, ::Type{<:VarTypes}) = true
90+
MOI.supports_constraint(o::Optimizer, ::Type{SVF}, ::Type{<:VAR_TYPES}) = true
9191
# linear constraints
92-
MOI.supports_constraint(o::Optimizer, ::Type{SAF}, ::Type{<:Bounds}) = true
92+
MOI.supports_constraint(o::Optimizer, ::Type{SAF}, ::Type{<:BOUNDS}) = true
9393

9494
MOI.supports(::Optimizer, ::MOI.ObjectiveSense) = true
9595
MOI.supports(::Optimizer, ::MOI.ObjectiveFunction{SAF}) = true
@@ -154,7 +154,7 @@ end
154154

155155
scip_vartype(::Type{MOI.ZeroOne}) = SCIP_VARTYPE_BINARY
156156
scip_vartype(::Type{MOI.Integer}) = SCIP_VARTYPE_INTEGER
157-
function MOI.add_constraint(o::Optimizer, func::SVF, set::S) where {S <: VarTypes}
157+
function MOI.add_constraint(o::Optimizer, func::SVF, set::S) where {S <: VAR_TYPES}
158158
allow_modification(o)
159159
v = var(o, func.variable)
160160
infeasible = Ref{Ptr{SCIP_Bool}}
@@ -169,7 +169,7 @@ function MOI.add_constraint(o::Optimizer, func::SVF, set::S) where {S <: VarType
169169
return register!(o, CI{SVF, S}(i))
170170
end
171171

172-
function MOI.add_constraint(o::Optimizer, func::SVF, set::S) where S <: Bounds
172+
function MOI.add_constraint(o::Optimizer, func::SVF, set::S) where S <: BOUNDS
173173
allow_modification(o)
174174
v = var(o, func.variable)
175175
lb, ub = bounds(set)
@@ -180,7 +180,7 @@ function MOI.add_constraint(o::Optimizer, func::SVF, set::S) where S <: Bounds
180180
return register!(o, CI{SVF, S}(i))
181181
end
182182

183-
function MOI.set(o::SCIP.Optimizer, ::MOI.ConstraintSet, ci::CI{SVF,S}, set::S) where {S <: Bounds}
183+
function MOI.set(o::SCIP.Optimizer, ::MOI.ConstraintSet, ci::CI{SVF,S}, set::S) where {S <: BOUNDS}
184184
allow_modification(o)
185185
v = var(o, VI(ci.value)) # cons index is actually var index
186186
lb, ub = bounds(set)
@@ -189,11 +189,11 @@ function MOI.set(o::SCIP.Optimizer, ::MOI.ConstraintSet, ci::CI{SVF,S}, set::S)
189189
return nothing
190190
end
191191

192-
function MOI.is_valid(o::Optimizer, ci::CI{SVF,<:Bounds})
192+
function MOI.is_valid(o::Optimizer, ci::CI{SVF,<:BOUNDS})
193193
return 1 <= ci.value <= length(o.mscip.vars)
194194
end
195195

196-
function MOI.add_constraint(o::Optimizer, func::SAF, set::S) where {S <: Bounds}
196+
function MOI.add_constraint(o::Optimizer, func::SAF, set::S) where {S <: BOUNDS}
197197
if func.constant != 0.0
198198
msg = "SCIP does not support linear constraints with a constant offset."
199199
throw(MOI.AddConstraintNotAllowed{SAF, S}(msg))
@@ -215,7 +215,7 @@ function MOI.add_constraint(o::Optimizer, func::SAF, set::S) where {S <: Bounds}
215215
return ci
216216
end
217217

218-
function MOI.set(o::SCIP.Optimizer, ::MOI.ConstraintSet, ci::CI{SAF,S}, set::S) where {S <: Bounds}
218+
function MOI.set(o::SCIP.Optimizer, ::MOI.ConstraintSet, ci::CI{SAF,S}, set::S) where {S <: BOUNDS}
219219
allow_modification(o)
220220

221221
lhs, rhs = bounds(set)
@@ -228,46 +228,46 @@ function MOI.set(o::SCIP.Optimizer, ::MOI.ConstraintSet, ci::CI{SAF,S}, set::S)
228228
return nothing
229229
end
230230

231-
function MOI.is_valid(o::Optimizer, ci::CI{SAF,<:Bounds})
231+
function MOI.is_valid(o::Optimizer, ci::CI{SAF,<:BOUNDS})
232232
return 1 <= ci.value <= length(o.mscip.cons)
233233
end
234234

235235
function MOI.get(o::Optimizer, ::MOI.NumberOfConstraints{F,S}) where {F,S}
236236
return haskey(o.constypes, (F, S)) ? length(o.constypes[F, S]) : 0
237237
end
238238

239-
function MOI.get(o::Optimizer, ::MOI.ConstraintFunction, ci::CI{SVF, S}) where S <: Bounds
239+
function MOI.get(o::Optimizer, ::MOI.ConstraintFunction, ci::CI{SVF, S}) where S <: BOUNDS
240240
return SVF(ci)
241241
end
242242

243-
function MOI.get(o::Optimizer, ::MOI.ConstraintSet, ci::CI{SVF, S}) where S <: Bounds
243+
function MOI.get(o::Optimizer, ::MOI.ConstraintSet, ci::CI{SVF, S}) where S <: BOUNDS
244244
v = var(o.mscip, ci.value)
245245
lb, ub = SCIPvarGetLbOriginal(v), SCIPvarGetUbOriginal(v)
246246
return from_bounds(S, lb, ub)
247247
end
248248

249-
function MOI.get(o::Optimizer, ::MOI.ConstraintFunction, ci::CI{SAF, S}) where S <: Bounds
249+
function MOI.get(o::Optimizer, ::MOI.ConstraintFunction, ci::CI{SAF, S}) where S <: BOUNDS
250250
s, cons = scip(o), cons(o, ci)
251251
nvars::Int = SCIPgetNVarsLinear(s, cons)
252252
vars = unsafe_wrap(Array{Ptr{SCIP_VAR}}, SCIPgetVarsLinear(s, cons), nvars)
253253
vals = unsafe_wrap(Array{Float64}, SCIPgetValsLinear(s, cons), nvars)
254254

255-
terms = [AffTerm(vals[i], VI(ref(o, vars[i]).val)) for i=1:nvars]
255+
terms = [AFF_TERM(vals[i], VI(ref(o, vars[i]).val)) for i=1:nvars]
256256
# can not identify constant anymore (is merged with lhs,rhs)
257257
return SAF(terms, 0.0)
258258
end
259259

260-
function MOI.get(o::Optimizer, ::MOI.ConstraintSet, ci::CI{SAF, S}) where S <: Bounds
260+
function MOI.get(o::Optimizer, ::MOI.ConstraintSet, ci::CI{SAF, S}) where S <: BOUNDS
261261
lhs = SCIPgetLhsLinear(scip(o), cons(o, ci))
262262
rhs = SCIPgetRhsLinear(scip(o), cons(o, ci))
263263
return from_bounds(S, lhs, rhs)
264264
end
265265

266-
function MOI.get(o::Optimizer, ::MOI.ConstraintName, ci::CI{SAF,<:Bounds})
266+
function MOI.get(o::Optimizer, ::MOI.ConstraintName, ci::CI{SAF,<:BOUNDS})
267267
return SCIPconsGetName(cons(o, ci))
268268
end
269269

270-
function MOI.set(o::Optimizer, ::MOI.ConstraintName, ci::CI{SAF,<:Bounds}, name::String)
270+
function MOI.set(o::Optimizer, ::MOI.ConstraintName, ci::CI{SAF,<:BOUNDS}, name::String)
271271
@SC SCIPchgConsName(scip(o), cons(o, ci), name)
272272
return nothing
273273
end
@@ -295,11 +295,11 @@ function MOI.set(o::Optimizer, ::MOI.ObjectiveFunction{SAF}, obj::SAF)
295295
end
296296

297297
function MOI.get(o::Optimizer, ::MOI.ObjectiveFunction{SAF})
298-
terms = AffTerm[]
298+
terms = AFF_TERM[]
299299
for i = 1:length(o.mscip.vars)
300300
vi = VI(i)
301301
coef = SCIPvarGetObj(var(o, vi))
302-
coef == 0.0 || push!(terms, AffTerm(coef, vi))
302+
coef == 0.0 || push!(terms, AFF_TERM(coef, vi))
303303
end
304304
constant = SCIPgetOrigObjoffset(scip(o))
305305
return SAF(terms, constant)
@@ -321,7 +321,7 @@ function MOI.get(o::Optimizer, ::MOI.ObjectiveSense)
321321
return SCIPgetObjsense(scip(o)) == SCIP_OBJSENSE_MAXIMIZE ? MOI.MAX_SENSE : MOI.MIN_SENSE
322322
end
323323

324-
function MOI.modify(o::Optimizer, ci::CI{SAF, <:Bounds},
324+
function MOI.modify(o::Optimizer, ci::CI{SAF, <:BOUNDS},
325325
change::MOI.ScalarCoefficientChange{Float64})
326326
allow_modification(o)
327327
@SC SCIPchgCoefLinear(scip(o), cons(o, ci),
@@ -386,11 +386,11 @@ function MOI.get(o::Optimizer, ::MOI.VariablePrimal, vi::VI)
386386
return SCIPgetSolVal(scip(o), SCIPgetBestSol(scip(o)), var(o, vi))
387387
end
388388

389-
function MOI.get(o::Optimizer, ::MOI.ConstraintPrimal, ci::CI{SVF,<:Bounds})
389+
function MOI.get(o::Optimizer, ::MOI.ConstraintPrimal, ci::CI{SVF,<:BOUNDS})
390390
return SCIPgetSolVal(scip(o), SCIPgetBestSol(scip(o)), var(o, VI(ci.value)))
391391
end
392392

393-
function MOI.get(o::Optimizer, ::MOI.ConstraintPrimal, ci::CI{SAF,<:Bounds})
393+
function MOI.get(o::Optimizer, ::MOI.ConstraintPrimal, ci::CI{SAF,<:BOUNDS})
394394
return SCIPgetActivityLinear(scip(o), cons(o, ci), SCIPgetBestSol(scip(o)))
395395
end
396396

0 commit comments

Comments
 (0)