jump-dev / MathOptInterface.jl

A data structure for mathematical optimization problems
http://jump.dev/MathOptInterface.jl/
Other
387 stars 87 forks source link

[FileFormats.MPS] Problem when reading generated MPS with CPLEX #2425

Closed remi-garcia closed 6 months ago

remi-garcia commented 7 months ago

When a binary variable is fixed, the generated MPS cannot be read with CPLEX due to 'FX' bound type illegal when prior bound given.

using JuMP
m = Model()
@variable(m, foo, Bin)
fix(foo, 1)
write_to_file(m, "mwe.mps")

mwe.mps file content:

NAME          
ROWS
 N  OBJ
COLUMNS
    MARKER    'MARKER'                 'INTORG'
    foo       OBJ       0
RHS
RANGES
BOUNDS
 BV bounds    foo
 FX bounds    foo       1
ENDATA

Then in CPLEX:

CPLEX> read mwe.mps
Selected objective sense:  MINIMIZE
Selected objective  name:  OBJ
Selected bound      name:  bounds
CPLEX Error  1454: Line 11: 'FX' bound type illegal when prior bound given.
No file read.

Removing BV bounds foo works. If the variable is fixed, the fact that it is a binary variable should not be stated anymore in the MPS file.

odow commented 7 months ago

I hate non-standardized file formats.

Gurobi can read it fine:

(base) oscar@Oscars-MBP /tmp % gurobi_cl bug.mps 
Set parameter LogFile to value "gurobi.log"
Using license file /Users/oscar/gurobi.lic

Gurobi Optimizer version 10.0.0 build v10.0.0rc2 (mac64[x86])
Copyright (c) 2022, Gurobi Optimization, LLC

Warning: duplicate bounds for column foo.
Read MPS format model from file bug.mps
Reading time = 0.00 seconds
: 0 rows, 1 columns, 0 nonzeros

CPU model: Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz
Thread count: 4 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 0 rows, 1 columns and 0 nonzeros
Model fingerprint: 0x4557e55e
Variable types: 0 continuous, 1 integer (1 binary)
Coefficient statistics:
  Matrix range     [0e+00, 0e+00]
  Objective range  [0e+00, 0e+00]
  Bounds range     [1e+00, 1e+00]
  RHS range        [0e+00, 0e+00]
Found heuristic solution: objective 0.0000000

Explored 0 nodes (0 simplex iterations) in 0.00 seconds (0.00 work units)
Thread count was 1 (of 8 available processors)

Solution count 1: 0 

Optimal solution found (tolerance 1.00e-04)
Best objective 0.000000000000e+00, best bound 0.000000000000e+00, gap 0.0000%

although it gives Warning: duplicate bounds for column foo..

From https://www.ibm.com/docs/en/icos/22.1.0?topic=standard-records-in-mps-format

image

So I guess we should treat BV as having implicit bounds, even though MOI tends to tread ZeroOne and bounds as a separate concept. (You could declare a variable as binary and fix it to 2, rendering the problem infeasible.)

I don't have a CPLEX binary, so can you check what it does for this (I assume also error):

NAME          
ROWS
 N  OBJ
COLUMNS
    MARKER    'MARKER'                 'INTORG'
    foo       OBJ       0
RHS
RANGES
BOUNDS
 BV bounds    foo
 UP bounds    foo       0.5
ENDATA
remi-garcia commented 7 months ago

Thank you for your quick reply!

It fails again:

CPLEX> read test.mps
Selected objective sense:  MINIMIZE
Selected objective  name:  OBJ
Selected bound      name:  bounds
CPLEX Error  1458: Line 11: Repeated upper bound.
No file read.
odow commented 7 months ago

Sigh. I guess we can/should fix this to prevent duplicate bounds from being written.