@@ -1610,6 +1610,57 @@ function test_int_round_trip()
1610
1610
return
1611
1611
end
1612
1612
1613
+ function test_obj_constant_min ()
1614
+ model = MOI. FileFormats. MPS. Model ()
1615
+ x = MOI. add_variable (model)
1616
+ MOI. set (model, MOI. ObjectiveSense (), MOI. MIN_SENSE)
1617
+ f = 1.0 * x + 2.0
1618
+ MOI. set (model, MOI. ObjectiveFunction {typeof(f)} (), f)
1619
+ io = IOBuffer ()
1620
+ write (io, model)
1621
+ dest = MOI. FileFormats. MPS. Model ()
1622
+ seekstart (io)
1623
+ read! (io, dest)
1624
+ g = MOI. get (dest, MOI. ObjectiveFunction {typeof(f)} ())
1625
+ @test g. constant == 2.0
1626
+ @test MOI. get (dest, MOI. ObjectiveSense ()) == MOI. MIN_SENSE
1627
+ return
1628
+ end
1629
+
1630
+ function test_obj_constant_max_to_min ()
1631
+ model = MOI. FileFormats. MPS. Model ()
1632
+ x = MOI. add_variable (model)
1633
+ MOI. set (model, MOI. ObjectiveSense (), MOI. MAX_SENSE)
1634
+ f = 1.0 * x + 2.0
1635
+ MOI. set (model, MOI. ObjectiveFunction {typeof(f)} (), f)
1636
+ io = IOBuffer ()
1637
+ write (io, model)
1638
+ dest = MOI. FileFormats. MPS. Model ()
1639
+ seekstart (io)
1640
+ read! (io, dest)
1641
+ g = MOI. get (dest, MOI. ObjectiveFunction {typeof(f)} ())
1642
+ @test g. constant == - 2.0
1643
+ @test MOI. get (dest, MOI. ObjectiveSense ()) == MOI. MIN_SENSE
1644
+ return
1645
+ end
1646
+
1647
+ function test_obj_constant_max_to_max ()
1648
+ model = MOI. FileFormats. MPS. Model (; print_objsense = true )
1649
+ x = MOI. add_variable (model)
1650
+ MOI. set (model, MOI. ObjectiveSense (), MOI. MAX_SENSE)
1651
+ f = 1.0 * x + 2.0
1652
+ MOI. set (model, MOI. ObjectiveFunction {typeof(f)} (), f)
1653
+ io = IOBuffer ()
1654
+ write (io, model)
1655
+ dest = MOI. FileFormats. MPS. Model ()
1656
+ seekstart (io)
1657
+ read! (io, dest)
1658
+ g = MOI. get (dest, MOI. ObjectiveFunction {typeof(f)} ())
1659
+ @test g. constant == 2.0
1660
+ @test MOI. get (dest, MOI. ObjectiveSense ()) == MOI. MAX_SENSE
1661
+ return
1662
+ end
1663
+
1613
1664
end # TestMPS
1614
1665
1615
1666
TestMPS. runtests ()
0 commit comments