diff --git a/src/Bridges/Constraint/bridges/all_different_reif.jl b/src/Bridges/Constraint/bridges/all_different_reif.jl index 9c4b64d567..fa1848f714 100644 --- a/src/Bridges/Constraint/bridges/all_different_reif.jl +++ b/src/Bridges/Constraint/bridges/all_different_reif.jl @@ -195,7 +195,7 @@ function MOI.get( bridge::ReifiedAllDifferentToCountDistinctBridge{T}, ::MOI.ListOfConstraintIndices{MOI.VariableIndex,MOI.EqualTo{T}}, ) where {T} - F, S = MOI.VariableIndex,MOI.EqualTo{T} + F, S = MOI.VariableIndex, MOI.EqualTo{T} ret = MOI.ConstraintIndex{F,S}[] if bridge.y === nothing push!(ret, MOI.ConstraintIndex{F,S}(something(bridge.y).value)) diff --git a/src/FileFormats/MOF/read.jl b/src/FileFormats/MOF/read.jl index 000b37751f..78df5254df 100644 --- a/src/FileFormats/MOF/read.jl +++ b/src/FileFormats/MOF/read.jl @@ -297,9 +297,11 @@ function function_to_moi( object::Object, name_map::Dict{String,MOI.VariableIndex}, ) - return MOI.VectorOfVariables(MOI.VariableIndex[ - name_map[variable] for variable::String in object["variables"] - ]) + return MOI.VectorOfVariables( + MOI.VariableIndex[ + name_map[variable] for variable::String in object["variables"] + ], + ) end # ========== Typed vector functions ========== diff --git a/src/Nonlinear/evaluator.jl b/src/Nonlinear/evaluator.jl index 2414ac7db1..c8cdc491cf 100644 --- a/src/Nonlinear/evaluator.jl +++ b/src/Nonlinear/evaluator.jl @@ -102,15 +102,16 @@ function MOI.constraint_expr(evaluator::Evaluator, i::Int) constraint.expression; moi_output_format = true, ) - if constraint.set isa MOI.LessThan - return :($f <= $(constraint.set.upper)) - elseif constraint.set isa MOI.GreaterThan - return :($f >= $(constraint.set.lower)) - elseif constraint.set isa MOI.EqualTo - return :($f == $(constraint.set.value)) + set = constraint.set + if set isa MOI.LessThan + return :($f <= $(set.upper)) + elseif set isa MOI.GreaterThan + return :($f >= $(set.lower)) + elseif set isa MOI.EqualTo + return :($f == $(set.value)) else - @assert constraint.set isa MOI.Interval - return :($(constraint.set.lower) <= $f <= $(constraint.set.upper)) + @assert set isa MOI.Interval + return :($(set.lower) <= $f <= $(set.upper)) end end diff --git a/src/Utilities/objective_container.jl b/src/Utilities/objective_container.jl index 78d397bc5e..d8fd4db793 100644 --- a/src/Utilities/objective_container.jl +++ b/src/Utilities/objective_container.jl @@ -130,7 +130,7 @@ function MOI.get( MOI.VectorAffineFunction{T}, MOI.VectorQuadraticFunction{T}, MOI.VectorNonlinearFunction, - } + }, } if o.scalar_affine !== nothing return convert(F, something(o.scalar_affine)) diff --git a/src/Utilities/parser.jl b/src/Utilities/parser.jl index 01e942cd8d..8b030be9ce 100644 --- a/src/Utilities/parser.jl +++ b/src/Utilities/parser.jl @@ -60,10 +60,10 @@ function _parse_function(ex, ::Type{T} = Float64) where {T} if isa(ex, Symbol) return _ParsedVariableIndex(ex) elseif Meta.isexpr(ex, :vect) - if all(s -> isa(s, Symbol), ex.args) + if all(Base.Fix2(isa, Symbol), ex.args) return _ParsedVectorOfVariables(copy(ex.args)) else - singlefunctions = _parse_function.(ex.args, T) + singlefunctions = map(Base.Fix2(_parse_function, T), ex.args) affine_terms = _ParsedVectorAffineTerm{T}[] quadratic_terms = _ParsedVectorQuadraticTerm{T}[] constant = T[] diff --git a/src/Utilities/print.jl b/src/Utilities/print.jl index 41d3e747bc..0c282d17eb 100644 --- a/src/Utilities/print.jl +++ b/src/Utilities/print.jl @@ -113,10 +113,10 @@ function _to_string( var_name = replace(var_name, "^" => "\\^") # Convert any x[args] to x_{args} so that indices on x print as subscripts. m = match(r"^(.*)\[(.+)\]$", var_name) - if m !== nothing - var_name = m[1] * "_{" * m[2] * "}" + if m === nothing + return var_name end - return var_name + return string(m[1]::AbstractString, "_{", m[2]::AbstractString, "}") end function _shorten(options::_PrintOptions, x::Float64) diff --git a/src/Utilities/product_of_sets.jl b/src/Utilities/product_of_sets.jl index cc2973e82d..cc7ac78512 100644 --- a/src/Utilities/product_of_sets.jl +++ b/src/Utilities/product_of_sets.jl @@ -219,7 +219,7 @@ function rows( ci::MOI.ConstraintIndex{MOI.ScalarAffineFunction{T},S}, ) where {T,S} @assert sets.final_touch - i = set_index(sets, S) + i = set_index(sets, S)::Int return (i == 1 ? 0 : sets.num_rows[i-1]) + ci.value end @@ -228,7 +228,7 @@ function rows( ci::MOI.ConstraintIndex{MOI.VectorAffineFunction{T},S}, ) where {T,S} @assert sets.final_touch - i = set_index(sets, S) + i = set_index(sets, S)::Int offset = i == 1 ? 0 : sets.num_rows[i-1] return (offset + ci.value - 1) .+ (1:sets.dimension[(i, ci.value)]) end @@ -263,7 +263,7 @@ Return the number of rows corresponding to a set of type `S`. That is, it is the sum of the dimensions of the sets of type `S`. """ function num_rows(sets::OrderedProductOfSets, ::Type{S}) where {S} - i = set_index(sets, S) + i = set_index(sets, S)::Int if !sets.final_touch || i == 1 return sets.num_rows[i] end diff --git a/src/Utilities/vector_of_constraints.jl b/src/Utilities/vector_of_constraints.jl index 886447edd5..6033121118 100644 --- a/src/Utilities/vector_of_constraints.jl +++ b/src/Utilities/vector_of_constraints.jl @@ -102,7 +102,8 @@ function MOI.get( ci::MOI.ConstraintIndex{F,S}, ) where {F,S} MOI.throw_if_not_valid(v, ci) - return v.constraints[ci][1] + f, _ = v.constraints[ci]::Tuple{F,S} + return f end function MOI.get( @@ -111,7 +112,8 @@ function MOI.get( ci::MOI.ConstraintIndex{F,S}, ) where {F,S} MOI.throw_if_not_valid(v, ci) - return v.constraints[ci][2] + _, s = v.constraints[ci]::Tuple{F,S} + return s end function MOI.set( @@ -121,7 +123,8 @@ function MOI.set( func::F, ) where {F,S} MOI.throw_if_not_valid(v, ci) - v.constraints[ci] = (func, v.constraints[ci][2]) + _, s = v.constraints[ci]::Tuple{F,S} + v.constraints[ci] = (func, s) return end @@ -132,7 +135,8 @@ function MOI.set( set::S, ) where {F,S} MOI.throw_if_not_valid(v, ci) - v.constraints[ci] = (v.constraints[ci][1], set) + f, _ = v.constraints[ci]::Tuple{F,S} + v.constraints[ci] = (f, set) return end @@ -162,7 +166,7 @@ function MOI.modify( ci::MOI.ConstraintIndex{F,S}, change::MOI.AbstractFunctionModification, ) where {F,S} - func, set = v.constraints[ci] + func, set = v.constraints[ci]::Tuple{F,S} v.constraints[ci] = (modify_function!(func, change), set) return end