@@ -469,7 +469,8 @@ function test_read_model1_tricky()
469
469
@test occursin (" Var4 >= 5.5" , file)
470
470
@test occursin (" V3 >= -3" , file)
471
471
@test occursin (" V5 = 1" , file)
472
- @test occursin (" 0 <= V2 <= 3" , file)
472
+ @test occursin (" V2 <= 3" , file)
473
+ @test occursin (" V2 >= 0" , file)
473
474
@test occursin (" 0 <= V7 <= 1" , file)
474
475
@test occursin (" 0 <= V8 <= 1" , file)
475
476
@test occursin (" V6 free" , file)
@@ -717,15 +718,15 @@ end
717
718
function test_wrong_way_bounds ()
718
719
for (case, result) in [
719
720
" x >= 2" => " x >= 2" ,
720
- " x <= 2" => " 0 <= x <= 2 " ,
721
+ " x <= 2" => " x <= 2 \n x >= 0 " ,
721
722
" x == 2" => " x = 2" ,
722
723
" x > 2" => " x >= 2" ,
723
- " x < 2" => " 0 <= x <= 2 " ,
724
+ " x < 2" => " x <= 2 \n x >= 0 " ,
724
725
" x = 2" => " x = 2" ,
725
- " 2 >= x" => " 0 <= x <= 2 " ,
726
+ " 2 >= x" => " x <= 2 \n x >= 0 " ,
726
727
" 2 <= x" => " x >= 2" ,
727
728
" 2 == x" => " x = 2" ,
728
- " 2 > x" => " 0 <= x <= 2 " ,
729
+ " 2 > x" => " x <= 2 \n x >= 0 " ,
729
730
" 2 < x" => " x >= 2" ,
730
731
" 2 = x" => " x = 2" ,
731
732
]
@@ -758,6 +759,79 @@ function test_variable_coefficient_variable()
758
759
return
759
760
end
760
761
762
+ function _test_round_trip (bound, needle)
763
+ model = MOI. FileFormats. LP. Model ()
764
+ io = IOBuffer ()
765
+ write (io, " Minimize\n obj: x\n Bounds\n $bound \n End" )
766
+ seekstart (io)
767
+ read! (io, model)
768
+ seekstart (io)
769
+ write (io, model)
770
+ seekstart (io)
771
+ file = read (io, String)
772
+ @test occursin (needle, file)
773
+ return
774
+ end
775
+
776
+ function test_reading_bounds ()
777
+ # Test lower bound
778
+ _test_round_trip (" x >= 1" , " Bounds\n x >= 1\n End" )
779
+ _test_round_trip (" x >= 0" , " Bounds\n x >= 0\n End" )
780
+ _test_round_trip (" x >= -1" , " Bounds\n x >= -1\n End" )
781
+ _test_round_trip (" x > 1" , " Bounds\n x >= 1\n End" )
782
+ _test_round_trip (" x > 0" , " Bounds\n x >= 0\n End" )
783
+ _test_round_trip (" x > -1" , " Bounds\n x >= -1\n End" )
784
+ # Test reversed lower bound
785
+ _test_round_trip (" 1 <= x" , " Bounds\n x >= 1\n End" )
786
+ _test_round_trip (" 0 <= x" , " Bounds\n x >= 0\n End" )
787
+ _test_round_trip (" -1 <= x" , " Bounds\n x >= -1\n End" )
788
+ _test_round_trip (" 1 < x" , " Bounds\n x >= 1\n End" )
789
+ _test_round_trip (" 0 < x" , " Bounds\n x >= 0\n End" )
790
+ _test_round_trip (" -1 < x" , " Bounds\n x >= -1\n End" )
791
+ # Test upper bound
792
+ _test_round_trip (" x <= 1" , " Bounds\n x <= 1\n x >= 0\n End" )
793
+ _test_round_trip (" x <= 0" , " Bounds\n x <= 0\n x >= 0\n End" )
794
+ _test_round_trip (" x <= -1" , " Bounds\n x <= -1\n End" )
795
+ _test_round_trip (" x < 1" , " Bounds\n x <= 1\n x >= 0\n End" )
796
+ _test_round_trip (" x < 0" , " Bounds\n x <= 0\n x >= 0\n End" )
797
+ _test_round_trip (" x < -1" , " Bounds\n x <= -1\n End" )
798
+ # Test reversed upper bound
799
+ _test_round_trip (" 1 >= x" , " Bounds\n x <= 1\n x >= 0\n End" )
800
+ _test_round_trip (" 0 >= x" , " Bounds\n x <= 0\n x >= 0\n End" )
801
+ _test_round_trip (" -1 >= x" , " Bounds\n x <= -1\n End" )
802
+ _test_round_trip (" 1 > x" , " Bounds\n x <= 1\n x >= 0\n End" )
803
+ _test_round_trip (" 0 > x" , " Bounds\n x <= 0\n x >= 0\n End" )
804
+ _test_round_trip (" -1 > x" , " Bounds\n x <= -1\n End" )
805
+ # Test equality
806
+ _test_round_trip (" x == 1" , " Bounds\n x = 1\n End" )
807
+ _test_round_trip (" x == 0" , " Bounds\n x = 0\n End" )
808
+ _test_round_trip (" x == -1" , " Bounds\n x = -1\n End" )
809
+ _test_round_trip (" 1 = x" , " Bounds\n x = 1\n End" )
810
+ _test_round_trip (" 0 = x" , " Bounds\n x = 0\n End" )
811
+ _test_round_trip (" -1 = x" , " Bounds\n x = -1\n End" )
812
+ # Test interval
813
+ _test_round_trip (" 0 <= x <= 1" , " Bounds\n 0 <= x <= 1\n End" )
814
+ _test_round_trip (" -1 <= x <= 1" , " Bounds\n -1 <= x <= 1\n End" )
815
+ _test_round_trip (" -2 <= x <= -1" , " Bounds\n -2 <= x <= -1\n End" )
816
+ # Test reversed interval
817
+ _test_round_trip (" 1 >= x >= 0" , " Bounds\n 0 <= x <= 1\n End" )
818
+ _test_round_trip (" 1 >= x >= -1" , " Bounds\n -1 <= x <= 1\n End" )
819
+ _test_round_trip (" -1 >= x >= -2" , " Bounds\n -2 <= x <= -1\n End" )
820
+ # Test double-sided equality
821
+ _test_round_trip (" 1 <= x <= 1" , " Bounds\n x = 1\n End" )
822
+ _test_round_trip (" 0 <= x <= 0" , " Bounds\n x = 0\n End" )
823
+ _test_round_trip (" -2 <= x <= -2" , " Bounds\n x = -2\n End" )
824
+ # Test upper then lower
825
+ _test_round_trip (" x <= 1\n x >= 0" , " Bounds\n x <= 1\n x >= 0\n End" )
826
+ _test_round_trip (" x <= 2\n x >= 1" , " Bounds\n x <= 2\n x >= 1\n End" )
827
+ _test_round_trip (" x <= 2\n x >= -1" , " Bounds\n x <= 2\n x >= -1\n End" )
828
+ # Test lower then upper
829
+ _test_round_trip (" x >= 0\n x <= 1" , " Bounds\n x <= 1\n x >= 0\n End" )
830
+ _test_round_trip (" x >= 1\n x <= 2" , " Bounds\n x <= 2\n x >= 1\n End" )
831
+ _test_round_trip (" x >= -1\n x <= 2" , " Bounds\n x <= 2\n x >= -1\n End" )
832
+ return
833
+ end
834
+
761
835
function runtests ()
762
836
for name in names (@__MODULE__ , all = true )
763
837
if startswith (" $(name) " , " test_" )
0 commit comments