@@ -8,8 +8,8 @@ const MOIU = MOI.Utilities
8
8
const MPS = MOI. FileFormats. MPS
9
9
const MPS_TEST_FILE = " test.mps"
10
10
11
- function _test_model_equality (model_string, variables, constraints)
12
- model = MPS. Model ()
11
+ function _test_model_equality (model_string, variables, constraints; kwargs ... )
12
+ model = MPS. Model (; kwargs ... )
13
13
MOIU. loadfromstring! (model, model_string)
14
14
MOI. write_to_file (model, MPS_TEST_FILE)
15
15
model_2 = MPS. Model ()
@@ -114,7 +114,18 @@ function test_maximization()
114
114
MOI. set (model, MOI. VariableName (), x, " x" )
115
115
MOI. set (model, MOI. ObjectiveSense (), MOI. MAX_SENSE)
116
116
MOI. set (model, MOI. ObjectiveFunction {MOI.VariableIndex} (), x)
117
- @test sprint (MPS. write_columns, model, [" x" ], Dict (x => " x" )) ==
117
+ @test sprint (MPS. write_columns, model, true , [" x" ], Dict (x => " x" )) ==
118
+ " COLUMNS\n x OBJ -1\n "
119
+ end
120
+
121
+ function test_maximization_objsense_false ()
122
+ model = MPS. Model (; print_objsense = true )
123
+ x = MOI. add_variable (model)
124
+ MOI. set (model, MOI. VariableName (), x, " x" )
125
+ MOI. set (model, MOI. ObjectiveSense (), MOI. MAX_SENSE)
126
+ MOI. set (model, MOI. ObjectiveFunction {MOI.VariableIndex} (), x)
127
+ sprint (MPS. write, model)
128
+ @test sprint (MPS. write_columns, model, false , [" x" ], Dict (x => " x" )) ==
118
129
" COLUMNS\n x OBJ 1\n "
119
130
end
120
131
@@ -290,15 +301,27 @@ c1: 1.1 * x in Interval(1.0, 2.0)
290
301
end
291
302
292
303
function test_objsense_max ()
293
- return _test_model_equality (
304
+ _test_model_equality (
294
305
"""
295
306
variables: x
296
307
maxobjective: 1.2x
297
308
c1: 1.0 * x >= 0.0
298
309
""" ,
299
310
[" x" ],
300
311
[" c1" ],
312
+ print_objsense = true ,
313
+ )
314
+ _test_model_equality (
315
+ """
316
+ variables: x
317
+ minobjective: 1.2x
318
+ c1: 1.0 * x >= 0.0
319
+ """ ,
320
+ [" x" ],
321
+ [" c1" ],
322
+ print_objsense = true ,
301
323
)
324
+ return
302
325
end
303
326
304
327
function test_MARKER_INT ()
@@ -400,7 +423,6 @@ a_really_long_name <= 2.0
400
423
MOI. write_to_file (model, MPS_TEST_FILE)
401
424
@test read (MPS_TEST_FILE, String) ==
402
425
" NAME \n " *
403
- " OBJSENSE MIN\n " *
404
426
" ROWS\n " *
405
427
" N OBJ\n " *
406
428
" COLUMNS\n " *
@@ -446,7 +468,6 @@ function test_names_with_spaces()
446
468
MOI. set (model, MOI. ConstraintName (), c, " c c" )
447
469
@test sprint (write, model) ==
448
470
" NAME \n " *
449
- " OBJSENSE MIN\n " *
450
471
" ROWS\n " *
451
472
" N OBJ\n " *
452
473
" E c_c\n " *
@@ -460,6 +481,45 @@ function test_names_with_spaces()
460
481
" ENDATA\n "
461
482
end
462
483
484
+ function test_objsense_default ()
485
+ model = MPS. Model ()
486
+ x = MOI. add_variable (model)
487
+ MOI. set (model, MOI. VariableName (), x, " x" )
488
+ MOI. set (model, MOI. ObjectiveSense (), MOI. MAX_SENSE)
489
+ MOI. set (model, MOI. ObjectiveFunction {MOI.VariableIndex} (), x)
490
+ @test sprint (write, model) ==
491
+ " NAME \n " *
492
+ " ROWS\n " *
493
+ " N OBJ\n " *
494
+ " COLUMNS\n " *
495
+ " x OBJ -1\n " *
496
+ " RHS\n " *
497
+ " RANGES\n " *
498
+ " BOUNDS\n " *
499
+ " FR bounds x\n " *
500
+ " ENDATA\n "
501
+ end
502
+
503
+ function test_objsense_true ()
504
+ model = MPS. Model (; print_objsense = true )
505
+ x = MOI. add_variable (model)
506
+ MOI. set (model, MOI. VariableName (), x, " x" )
507
+ MOI. set (model, MOI. ObjectiveSense (), MOI. MAX_SENSE)
508
+ MOI. set (model, MOI. ObjectiveFunction {MOI.VariableIndex} (), x)
509
+ @test sprint (write, model) ==
510
+ " NAME \n " *
511
+ " OBJSENSE MAX\n " *
512
+ " ROWS\n " *
513
+ " N OBJ\n " *
514
+ " COLUMNS\n " *
515
+ " x OBJ 1\n " *
516
+ " RHS\n " *
517
+ " RANGES\n " *
518
+ " BOUNDS\n " *
519
+ " FR bounds x\n " *
520
+ " ENDATA\n "
521
+ end
522
+
463
523
function test_sos_constraints ()
464
524
model = MPS. Model ()
465
525
x = MOI. add_variables (model, 3 )
@@ -476,7 +536,6 @@ function test_sos_constraints()
476
536
)
477
537
@test sprint (write, model) ==
478
538
" NAME \n " *
479
- " OBJSENSE MIN\n " *
480
539
" ROWS\n " *
481
540
" N OBJ\n " *
482
541
" COLUMNS\n " *
0 commit comments