mpsread
Read MPS file for LP and MILP optimization data
Description
augments the returned problem
= mpsread(mpsfile
,'ReturnNames
',true)problem
structure with
variableNames
and constraintNames
fields
containing the names of the variables and constraints in
mpsfile
.
Examples
Import and Run an MPS File
Load an mps
file and solve
the problem it describes.
Load the eil332.mps
file from a public
repository. View the problem type.
gunzip('http://miplib.zib.de/WebData/instances/eil332.mps.gz') problem = mpsread('eil332.mps')
problem = f: [4516x1 double] Aineq: [0x4516 double] bineq: [0x1 double] Aeq: [32x4516 double] beq: [32x1 double] lb: [4516x1 double] ub: [4516x1 double] intcon: [4516x1 double] solver: 'intlinprog' options: [1x1 optim.options.Intlinprog]
Notice that problem.intcon
is not empty,
and problem.solver
is 'intlinprog'
.
The problem is an integer linear programming problem.
Change the options to suppress iterative display and to generate a plot as the solver progresses.
options = optimoptions('intlinprog','Display','final','PlotFcn',@optimplotmilp); problem.options = options;
Solve the problem by calling intlinprog
.
[x,fval,exitflag,output] = intlinprog(problem);
Optimal solution found. Intlinprog stopped because the objective value is within a gap tolerance of the optimal value, options.AbsoluteGapTolerance = 0 (the default value). The intcon variables are integer within tolerance, options.IntegerTolerance = 1e05 (the default value).
Obtain Variable and Constraint Names
Load an mps
file and obtain its variable
and constraint names.
Load the eil332.mps
file from a public repository.
View the returned problem structure.
gunzip('http://miplib.zib.de/WebData/instances/eil332.mps.gz') problem = mpsread('eil332.mps','ReturnNames',true)
problem = struct with fields: f: [4516×1 double] Aineq: [0×4516 double] bineq: [0×1 double] Aeq: [32×4516 double] beq: [32×1 double] lb: [4516×1 double] ub: [4516×1 double] intcon: [4516×1 double] solver: 'intlinprog' options: [1×1 optim.options.Intlinprog] variableNames: [4516×1 string] constraintNames: [1×1 struct]
View the first few names of each type.
problem.variableNames(1:4)
ans = 4×1 string array "x1" "x2" "x3" "x4"
problem.constraintNames.eqlin(1:4)
ans = 4×1 string array "c1" "c2" "c3" "c4"
There are no inequality constraints in the problem.
problem.constraintNames.ineqlin
ans = 0×1 empty string array
Input Arguments
mpsfile
— Path to MPS file
character vector  string scalar
Path to MPS file, specified as a character vector or string scalar. mpsfile
should be a file in the MPS
format.
Note
mpsread
does not support semicontinuous constraints or SOS constraints.mpsread
supports “fixed format” files.mpsread
does not support extensions such asobjsense
andobjname
.mpsread
silently ignores variables in theBOUNDS
section that do not previously appear in theCOLUMNS
section of the MPS file.
Example: "documents/optimization/milpproblem.mps"
Data Types: char
 string
ReturnNames
— Namevalue pair indicating to return variable and constraint names from the MPS file
false
(default)  true
Namevalue pair indicating to return variable and constraint names from
the MPS file, with the value specified as logical. false
indicates not to return the names. true
causes
mpsread
to return two extra fields in the
problem
output structure:
problem.variableNames
— String array of variable namesproblem.constraintNames
— Structure of constraint names:problem.constraintNames.eqlin
String array of linear equality constraint namesproblem.constraintNames.ineqlin
String array of linear inequality constraint names
The problem
structure inequality constraints
problem.Aineq
and problem.bineq
have the same order as the names in
problem.constraintNames.ineqlin
. Similarly, the
constraints problem.Aeq
and
problem.beq
have the same order as the names in
problem.constraintNames.eqlin
. The
problem.variableNames
order is the same as the order
of the solution variables x
after running
linprog
or intlinprog
on the
problem
structure.
Example: mpsread('filename','ReturnNames',true)
Data Types: logical
Output Arguments
problem
— Problem structure
structure
Problem structure, returned as a structure with fields:
f  Vector representing objective f'*x 
intcon  Vector indicating variables that take integer values (empty for LP, nonempty for MILP) 
Aineq  Matrix in linear inequality constraints Aineq*x ≤ bineq 
 Vector in linear inequality constraints Aineq*x ≤ bineq 
 Matrix in linear equality constraints Aeq*x = beq 
 Vector in linear equality constraints Aeq*x = beq 
lb  Vector of lower bounds 
ub  Vector of upper bounds 
solver  'intlinprog' (if intcon is
nonempty), or 'linprog' (if intcon is
empty) 

Default options, as returned by the command optimoptions(solver) 
variableNames  String array containing variable
names from the MPS file. This field appears only if
ReturnNames is
true . 
constraintNames  Structure containing constraint
names from the MPS file. For a description, see ReturnNames . This field appears only if
ReturnNames is
true . 
mpsread
returns problem.Aineq
and problem.Aeq
as
sparse matrices.
Version History
Introduced in R2015b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
 América Latina (Español)
 Canada (English)
 United States (English)
Europe
 Belgium (English)
 Denmark (English)
 Deutschland (Deutsch)
 España (Español)
 Finland (English)
 France (Français)
 Ireland (English)
 Italia (Italiano)
 Luxembourg (English)
 Netherlands (English)
 Norway (English)
 Österreich (Deutsch)
 Portugal (English)
 Sweden (English)
 Switzerland
 United Kingdom (English)