Skip to content

Commit

Permalink
More updates
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Sep 19, 2023
1 parent 1eecb32 commit 32e934f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Benchmarks/Benchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ end
x = MOI.add_variables(model, 10_000)
MOI.add_constraints(
model,
[
MOI.ScalarAffineFunction{Float64}[
MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(1.0, xi)], 0.0) for
xi in x
],
Expand Down
11 changes: 6 additions & 5 deletions src/Bridges/Constraint/bridges/all_different.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function MOI.get(
if bridge.y === nothing
return MOI.VariableIndex[]
end
return [bridge.y]
return MOI.VariableIndex[something(bridge.y)]
end

function MOI.get(
Expand All @@ -182,11 +182,12 @@ function MOI.get(
bridge::AllDifferentToCountDistinctBridge{T},
::MOI.ListOfConstraintIndices{MOI.VariableIndex,MOI.EqualTo{T}},
) where {T}
if bridge.y === nothing
return MOI.ConstraintIndex{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))
end
ci = MOI.ConstraintIndex{MOI.VariableIndex,MOI.EqualTo{T}}(bridge.y.value)
return [ci]
return ret
end

function MOI.get(
Expand Down
10 changes: 5 additions & 5 deletions src/FileFormats/LP/LP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ function _parse_section(
)
if occursin(":", line) # Strip name of the objective
m = match(r"(.*?)\:(.*)", line)::RegexMatch
line = String(m[2])
line = String(m[2]::AbstractString)
end
if occursin("^", line)
line = replace(line, "^" => " ^ ")
Expand Down Expand Up @@ -677,8 +677,8 @@ function _parse_section(
if isempty(cache.constraint_name)
if occursin(":", line)
m = match(r"(.*?)\:(.*)", line)::RegexMatch
cache.constraint_name = String(m[1])
line = String(m[2])
cache.constraint_name = String(m[1]::AbstractString)
line = String(m[2]::AbstractString)
else
# Give it a temporary name for now
cache.constraint_name = "R$(cache.num_constraints)"
Expand Down Expand Up @@ -932,7 +932,7 @@ end
function _strip_comment(line::String)
if occursin("\\", line)
m = match(r"(.*?)\\(.*)", line)::RegexMatch
return strip(String(m[1]))
return strip(String(m[1]::AbstractString))
else
return strip(line)
end
Expand Down Expand Up @@ -1011,7 +1011,7 @@ function _readline(io::IO, line::AbstractString)
return _readline(io, line)
elseif any(Base.Fix1(endswith, line), ('+', '-', '[', '='))
# If the line ends with a continuation character, read in the next line.
return _readline(io, string(line, ' ', peeked_line))
return _readline(io, string(line, " ", peeked_line))
elseif any(Base.Fix1(startswith, peeked_line), (']', '/'))
# Always read in the next line if it starts with ] or /, which are used
# in quadratic functions.
Expand Down
4 changes: 2 additions & 2 deletions src/Nonlinear/ReverseAD/reverse_mode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ end
_extract_reverse_pass(
g::AbstractVector{T},
d::NLPEvaluator,
f::Union{_FunctionStorage,_SubexpressionStorage},
f::_FunctionStorage,
) where {T}
Fill the gradient vector `g` with the values from the reverse pass. Assumes you
Expand All @@ -323,7 +323,7 @@ have already called `_reverse_eval_all(d, x)`.
function _extract_reverse_pass(
g::AbstractVector{T},
d::NLPEvaluator,
f::Union{_FunctionStorage,_SubexpressionStorage},
f::_FunctionStorage,
) where {T}
for i in f.dependent_subexpressions
d.subexpression_reverse_values[i] = 0.0
Expand Down
7 changes: 5 additions & 2 deletions src/Utilities/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,11 @@ Do not name `VariableIndex` constraints.
* `x^2` does NOT currently parse. Instead, write `x * x`.
"""
function loadfromstring!(model, s)
parsedlines = filter(ex -> ex !== nothing, Meta.parse.(split(s, "\n")))
for line in parsedlines
for string_line in split(s, "\n")
line = Meta.parse(string_line)
if line === nothing
continue
end
label, ex = _separate_label(line)
T, label = _split_type(label)
if label == :variables
Expand Down

0 comments on commit 32e934f

Please sign in to comment.