Skip to content

Commit bc36f8c

Browse files
authored
[FileFormats.MPS] write out LI and UI in BOUNDS instead of LO and UP (#2492)
1 parent 5ad5269 commit bc36f8c

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

src/FileFormats/MPS/MPS.jl

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -672,23 +672,27 @@ end
672672

673673
# ==============================================================================
674674
# BOUNDS
675-
# Variables default to [0, ∞).
676-
# FR free variable -∞ < x < ∞
675+
#
676+
# Variables default to [0, ∞), or [0, 1] if the variable appears in INTORG and
677+
# does not appear in BOUNDS.
678+
#
677679
# FX fixed variable x == b
680+
# FR free variable -∞ < x < ∞
678681
# MI lower bound -inf -∞ < x
679-
# UP upper bound x <= b
680-
# PL upper bound +inf x < ∞
681682
# LO lower bound b <= x
683+
# LI integer variable b <= x
684+
# PL upper bound +inf x < ∞
685+
# UP upper bound x <= b
686+
# UI integer variable x <= b
682687
# BV binary variable x = 0 or 1
683688
#
684689
# Not yet implemented:
685-
# LI integer variable b <= x
686-
# UI integer variable x <= b
690+
#
687691
# SC semi-cont variable x = 0 or l <= x <= b
688692
# l is the lower bound on the variable. If none set then defaults to 1
689693
# ==============================================================================
690694

691-
function write_single_bound(io::IO, var_name::String, lower, upper)
695+
function write_single_bound(io::IO, var_name::String, lower, upper, vtype)
692696
if lower == upper
693697
println(
694698
io,
@@ -708,7 +712,7 @@ function write_single_bound(io::IO, var_name::String, lower, upper)
708712
println(
709713
io,
710714
Card(
711-
f1 = "LO",
715+
f1 = vtype == VTYPE_CONTINUOUS ? "LO" : "LI",
712716
f2 = "bounds",
713717
f3 = var_name,
714718
f4 = _to_string(lower),
@@ -721,7 +725,7 @@ function write_single_bound(io::IO, var_name::String, lower, upper)
721725
println(
722726
io,
723727
Card(
724-
f1 = "UP",
728+
f1 = vtype == VTYPE_CONTINUOUS ? "UP" : "UI",
725729
f2 = "bounds",
726730
f3 = var_name,
727731
f4 = _to_string(upper),
@@ -783,16 +787,18 @@ function write_bounds(io::IO, model::Model, var_to_column)
783787
if lower <= 0 && upper >= 1
784788
println(io, Card(f1 = "BV", f2 = "bounds", f3 = var_name))
785789
else
790+
lower = max(0, lower)
786791
if lower > 0
787792
lower = 1
788793
end
794+
upper = min(1, upper)
789795
if upper < 1
790796
upper = 0
791797
end
792-
write_single_bound(io, var_name, max(0, lower), min(1, upper))
798+
write_single_bound(io, var_name, lower, upper, vtype)
793799
end
794800
else
795-
write_single_bound(io, var_name, lower, upper)
801+
write_single_bound(io, var_name, lower, upper, vtype)
796802
end
797803
end
798804
return

test/FileFormats/MPS/MPS.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,8 +1219,8 @@ function test_binary_with_infeasible_bounds()
12191219
RHS
12201220
RANGES
12211221
BOUNDS
1222-
LO bounds x 1
1223-
UP bounds x 0
1222+
LI bounds x 1
1223+
UI bounds x 0
12241224
ENDATA
12251225
"""
12261226
for test in [

0 commit comments

Comments
 (0)