mpsread
读取 MPS 文件中的 LP 和 MILP 优化数据
说明
示例
导入并运行 MPS 文件
加载 mps
文件并求解它描述的问题。
从公共存储库中加载 eil33-2.mps
文件。查看问题类型。
gunzip('http://miplib.zib.de/WebData/instances/eil33-2.mps.gz') problem = mpsread('eil33-2.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]
请注意,problem.intcon
不为空,problem.solver
是 'intlinprog'
。该问题是整数线性规划问题。
更改选项以隐藏迭代输出,并随着求解器进度生成绘图。
options = optimoptions('intlinprog','Display','final','PlotFcn',@optimplotmilp); problem.options = options;
通过调用 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 = 1e-05 (the default value).
获取变量和约束名称
加载一个 mps
文件,并获取其变量和约束名称。
从公共存储库中加载 eil33-2.mps
文件。查看返回的问题结构体。
gunzip('http://miplib.zib.de/WebData/instances/eil33-2.mps.gz') problem = mpsread('eil33-2.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]
查看每种类型的前几个名称。
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"
问题中没有不等式约束。
problem.constraintNames.ineqlin
ans = 0×1 empty string array
输入参数
mpsfile
— MPS 文件的路径
字符向量 | 字符串标量
MPS 文件的路径,指定为字符向量或字符串标量。mpsfile
应为 MPS 格式的文件。
注意
mpsread
不支持半连续约束或 SOS 约束。mpsread
支持“固定格式”文件。mpsread
不支持扩展,如objsense
和objname
。对于以前没有出现在 MPS 文件的
COLUMNS
部分中的变量,mpsread
会以静默方式忽略BOUNDS
部分中的这些变量。
示例: "documents/optimization/milpproblem.mps"
数据类型: char
| string
ReturnNames
— 指示从 MPS 文件返回变量和约束名称的名称-值对组
false
(默认) | true
名称-值对组,指示从 MPS 文件返回变量和约束名称,值指定为逻辑值。false
指示不返回名称。true
导致 mpsread
在 problem
输出结构体中返回两个额外的字段:
problem.variableNames
- 变量名称的字符串数组problem.constraintNames
- 约束名称的结构体:problem.constraintNames.eqlin
线性等式约束名称的字符串数组problem.constraintNames.ineqlin
线性不等式约束名称的字符串数组
problem
结构体不等式约束 problem.Aineq
和 problem.bineq
的顺序与 problem.constraintNames.ineqlin
中名称的顺序相同。同样,约束 problem.Aeq
和 problem.beq
的顺序与 problem.constraintNames.eqlin
中名称的顺序相同。在对 problem
结构体运行 linprog
或 intlinprog
后,problem.variableNames
顺序与解变量 x
的顺序相同。
示例: mpsread('filename','ReturnNames',true)
数据类型: logical
输出参量
problem
— 问题结构体
结构体
问题结构体,以具有以下字段的结构体形式返回:
f | 表示目标 f'*x 的向量 |
intcon | 表示取整数值的变量的向量(对于 LP 为空,对于 MILP 为非空) |
Aineq | 线性不等式约束 Aineq*x ≤ bineq 中的矩阵 |
| 线性不等式约束 Aineq*x ≤ bineq 中的向量 |
| 线性等式约束 Aeq*x = beq 中的矩阵 |
| 线性等式约束 Aeq*x = beq 中的向量 |
lb | 由下界组成的向量 |
ub | 由上界组成的向量 |
solver | 'intlinprog' (如果 intcon 为非空),或 'linprog' (如果 intcon 为空) |
| 由以下命令返回的默认选项 optimoptions(solver) |
variableNames | 包含来自 MPS 文件的变量名称的字符串数组。仅当 ReturnNames 为 true 时,此字段才会出现。 |
constraintNames | 包含来自 MPS 文件的约束名称的结构体。有关说明,请参阅 ReturnNames 。仅当 ReturnNames 为 true 时,此字段才会出现。 |
mpsread
将 problem.Aineq
和 problem.Aeq
以稀疏矩阵形式返回。
版本历史记录
在 R2015b 中推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
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)