mpsread
读取 MPS 文件中的 LP 和 MILP 优化数据
说明
读取线性规划 (LP) 和混合整数线性规划 (MILP) 问题的数据。它以 problem
= mpsread(mpsfile
)intlinprog
或 linprog
求解器接受的结构体形式返回数据。
用 problem
= mpsread(mpsfile
,'ReturnNames
',true)variableNames
和 constraintNames
字段扩充返回的 problem
结构体,这些字段包含 mpsfile
中变量和约束的名称。
示例
加载 mps
文件并求解它描述的问题。
从公共存储库中加载 eil33-2.mps
文件。查看问题类型。
gunzip("https://miplib.zib.de/WebData/instances/eil33-2.mps.gz") problem = mpsread("eil33-2.mps")
Running HiGHS 1.7.0 (git hash: n/a): Copyright (c) 2024 HiGHS under MIT licence terms
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]
请注意,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 = 1e-06. The intcon variables are integer within tolerance, options.ConstraintTolerance = 1e-06.
加载一个 mps
文件,并获取其变量和约束名称。
从公共存储库中加载 eil33-2.mps
文件。查看返回的问题结构体。
gunzip("https://miplib.zib.de/WebData/instances/eil33-2.mps.gz") problem = mpsread("eil33-2.mps",ReturnNames=true)
Running HiGHS 1.7.0 (git hash: n/a): Copyright (c) 2024 HiGHS under MIT licence terms
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
"x1"
"x2"
"x3"
"x4"
problem.constraintNames.eqlin(1:4)
ans = 4×1 string
"c1"
"c2"
"c3"
"c4"
问题中没有不等式约束。
problem.constraintNames.ineqlin
ans = 0×1 empty string array
输入参数
MPS 文件的路径,指定为字符向量或字符串标量。mpsfile
应为 MPS 格式的文件。
注意
mpsread
不支持半连续约束或 SOS 约束。mpsread
支持“固定格式”文件。mpsread
不支持扩展,如objsense
和objname
。对于以前没有出现在 MPS 文件的
COLUMNS
部分中的变量,mpsread
会以静默方式忽略BOUNDS
部分中的这些变量。
示例: "documents/optimization/milpproblem.mps"
数据类型: char
| string
名称-值对组,指示从 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
输出参量
问题结构体,以具有以下字段的结构体形式返回:
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 中推出mpsread
现在使用 HiGHS 开源软件将 MPS 文件读为 intlinprog
和 linprog
接受的格式。mpsread
显示现在包括对 HiGHS 的引用。
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.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)