Skip to content

Commit

Permalink
[FileFormats.MPS] write out LI and UI in BOUNDS instead of LO and UP
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Apr 19, 2024
1 parent 5ad5269 commit 6e32d48
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
28 changes: 17 additions & 11 deletions src/FileFormats/MPS/MPS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -672,23 +672,27 @@ end

# ==============================================================================
# BOUNDS
# Variables default to [0, ∞).
# FR free variable -∞ < x < ∞
#
# Variables default to [0, ∞), or [0, 1] if the variable appears in INTORG and
# does not appear in BOUNDS.
#
# FX fixed variable x == b
# FR free variable -∞ < x < ∞
# MI lower bound -inf -∞ < x
# UP upper bound x <= b
# PL upper bound +inf x < ∞
# LO lower bound b <= x
# LI integer variable b <= x
# PL upper bound +inf x < ∞
# UP upper bound x <= b
# UI integer variable x <= b
# BV binary variable x = 0 or 1
#
# Not yet implemented:
# LI integer variable b <= x
# UI integer variable x <= b
#
# SC semi-cont variable x = 0 or l <= x <= b
# l is the lower bound on the variable. If none set then defaults to 1
# ==============================================================================

function write_single_bound(io::IO, var_name::String, lower, upper)
function write_single_bound(io::IO, var_name::String, lower, upper, vtype)
if lower == upper
println(
io,
Expand All @@ -708,7 +712,7 @@ function write_single_bound(io::IO, var_name::String, lower, upper)
println(
io,
Card(
f1 = "LO",
f1 = vtype == VTYPE_CONTINUOUS ? "LO" : "LI",
f2 = "bounds",
f3 = var_name,
f4 = _to_string(lower),
Expand All @@ -721,7 +725,7 @@ function write_single_bound(io::IO, var_name::String, lower, upper)
println(
io,
Card(
f1 = "UP",
f1 = vtype == VTYPE_CONTINUOUS ? "UP" : "UI",
f2 = "bounds",
f3 = var_name,
f4 = _to_string(upper),
Expand Down Expand Up @@ -783,16 +787,18 @@ function write_bounds(io::IO, model::Model, var_to_column)
if lower <= 0 && upper >= 1
println(io, Card(f1 = "BV", f2 = "bounds", f3 = var_name))
else
lower = max(0, lower)

Check warning on line 790 in src/FileFormats/MPS/MPS.jl

View check run for this annotation

Codecov / codecov/patch

src/FileFormats/MPS/MPS.jl#L790

Added line #L790 was not covered by tests
if lower > 0
lower = 1
end
upper = min(1, upper)

Check warning on line 794 in src/FileFormats/MPS/MPS.jl

View check run for this annotation

Codecov / codecov/patch

src/FileFormats/MPS/MPS.jl#L794

Added line #L794 was not covered by tests
if upper < 1
upper = 0
end
write_single_bound(io, var_name, max(0, lower), min(1, upper))
write_single_bound(io, var_name, lower, upper, vtype)

Check warning on line 798 in src/FileFormats/MPS/MPS.jl

View check run for this annotation

Codecov / codecov/patch

src/FileFormats/MPS/MPS.jl#L798

Added line #L798 was not covered by tests
end
else
write_single_bound(io, var_name, lower, upper)
write_single_bound(io, var_name, lower, upper, vtype)
end
end
return
Expand Down
4 changes: 2 additions & 2 deletions test/FileFormats/MPS/MPS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1219,8 +1219,8 @@ function test_binary_with_infeasible_bounds()
RHS
RANGES
BOUNDS
LO bounds x 1
UP bounds x 0
LI bounds x 1
UI bounds x 0
ENDATA
"""
for test in [
Expand Down

0 comments on commit 6e32d48

Please sign in to comment.