Skip to content

Commit

Permalink
More updates
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Sep 20, 2023
1 parent f544951 commit b348bc0
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/Bridges/Constraint/bridges/all_different_reif.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}[]

Check warning on line 199 in src/Bridges/Constraint/bridges/all_different_reif.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Constraint/bridges/all_different_reif.jl#L198-L199

Added lines #L198 - L199 were not covered by tests
if bridge.y === nothing
push!(ret, MOI.ConstraintIndex{F,S}(something(bridge.y).value))

Check warning on line 201 in src/Bridges/Constraint/bridges/all_different_reif.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Constraint/bridges/all_different_reif.jl#L201

Added line #L201 was not covered by tests
Expand Down
8 changes: 5 additions & 3 deletions src/FileFormats/MOF/read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(

Check warning on line 300 in src/FileFormats/MOF/read.jl

View check run for this annotation

Codecov / codecov/patch

src/FileFormats/MOF/read.jl#L300

Added line #L300 was not covered by tests
MOI.VariableIndex[
name_map[variable] for variable::String in object["variables"]
],
)
end

# ========== Typed vector functions ==========
Expand Down
17 changes: 9 additions & 8 deletions src/Nonlinear/evaluator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Check warning on line 111 in src/Nonlinear/evaluator.jl

View check run for this annotation

Codecov / codecov/patch

src/Nonlinear/evaluator.jl#L105-L111

Added lines #L105 - L111 were not covered by tests
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))

Check warning on line 114 in src/Nonlinear/evaluator.jl

View check run for this annotation

Codecov / codecov/patch

src/Nonlinear/evaluator.jl#L113-L114

Added lines #L113 - L114 were not covered by tests
end
end

Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/objective_container.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions src/Utilities/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down
6 changes: 3 additions & 3 deletions src/Utilities/print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/Utilities/product_of_sets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions src/Utilities/vector_of_constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b348bc0

Please sign in to comment.