Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FileFormats.MPS] write out LI and UI in BOUNDS instead of LO and UP #2492

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

# ==============================================================================
# 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 @@
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 @@
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 @@
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
Loading