intlinprog
混合整数线性规划 (MILP)
语法
说明
混合整数线性规划求解器。
求以下问题的最小值:
f、x、b、bl、beq、lb 和 ub 是向量,intcon 是一个向量或一个 integerConstraint 对象,而 A 和 Aeq 是矩阵。
您可以将 f、intcon、lb 和 ub 指定为向量或数组。请参阅矩阵参量。
注意
intlinprog 仅适用于基于求解器的方法。使用 solve 作为基于问题的方法。有关这两种优化方法的讨论,请参阅首先选择基于问题或基于求解器的方法。
使用 x = intlinprog(problem)problem 结构体封装所有求解器输入。您可以使用 mpsread 从 MPS 文件中导入 problem 结构体。您还可以使用 prob2struct 从 OptimizationProblem 对象创建 problem 结构体。
示例
求解问题
编写目标函数向量和由整数变量组成的向量。
f = [8;1]; intcon = 2;
通过将“大于”不等式乘以 -1,将所有不等式转换为 A*x <= b 形式。
A = [-1,-2;
-4,-1;
2,1];
b = [14;-33;20];调用 intlinprog。
x = intlinprog(f,intcon,A,b)
Running HiGHS 1.11.0: Copyright (c) 2025 HiGHS under MIT licence terms
MIP has 3 rows; 2 cols; 6 nonzeros; 1 integer variables (0 binary)
Coefficient ranges:
Matrix [1e+00, 4e+00]
Cost [1e+00, 8e+00]
Bound [0e+00, 0e+00]
RHS [1e+01, 3e+01]
Presolving model
3 rows, 2 cols, 6 nonzeros 0s
3 rows, 2 cols, 6 nonzeros 0s
Solving MIP model with:
3 rows
2 cols (0 binary, 1 integer, 0 implied int., 1 continuous, 0 domain fixed)
6 nonzeros
Src: B => Branching; C => Central rounding; F => Feasibility pump; J => Feasibility jump;
H => Heuristic; L => Sub-MIP; P => Empty MIP; R => Randomized rounding; Z => ZI Round;
I => Shifting; S => Solve LP; T => Evaluate node; U => Unbounded; X => User solution;
z => Trivial zero; l => Trivial lower; u => Trivial upper; p => Trivial point
Nodes | B&B Tree | Objective Bounds | Dynamic Constraints | Work
Src Proc. InQueue | Leaves Expl. | BestBound BestSol Gap | Cuts InLp Confl. | LpIters Time
J 0 0 0 0.00% -inf 80 Large 0 0 0 0 0.0s
T 0 0 0 0.00% -inf 59 Large 0 0 0 3 0.0s
1 0 1 100.00% 59 59 0.00% 0 0 0 3 0.0s
Solving report
Status Optimal
Primal bound 59
Dual bound 59
Gap 0% (tolerance: 0.01%)
P-D integral 0
Solution status feasible
59 (objective)
0 (bound viol.)
1.7763568394e-15 (int. viol.)
0 (row viol.)
Timing 0.01 (total)
0.00 (presolve)
0.00 (solve)
0.00 (postsolve)
Max sub-MIP depth 0
Nodes 1
Repair LPs 0 (0 feasible; 0 iterations)
LP iterations 3 (total)
0 (strong br.)
0 (separation)
0 (heuristics)
Optimal solution found.
Intlinprog stopped at the root node 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.
x = 2×1
6.5000
7.0000
求解问题
编写目标函数向量和由整数变量组成的向量。
f = [-3;-2;-1]; intcon = 3;
编写线性不等式约束。
A = [1,1,1]; b = 7;
编写线性等式约束。
Aeq = [4,2,1]; beq = 12;
编写边界约束。
lb = zeros(3,1);
ub = [Inf;Inf;1]; % Enforces x(3) is binary调用 intlinprog。
x = intlinprog(f,intcon,A,b,Aeq,beq,lb,ub)
Running HiGHS 1.11.0: Copyright (c) 2025 HiGHS under MIT licence terms
MIP has 2 rows; 3 cols; 6 nonzeros; 1 integer variables (1 binary)
Coefficient ranges:
Matrix [1e+00, 4e+00]
Cost [1e+00, 3e+00]
Bound [1e+00, 1e+00]
RHS [7e+00, 1e+01]
Presolving model
2 rows, 3 cols, 6 nonzeros 0s
0 rows, 0 cols, 0 nonzeros 0s
Presolve: Optimal
Src: B => Branching; C => Central rounding; F => Feasibility pump; J => Feasibility jump;
H => Heuristic; L => Sub-MIP; P => Empty MIP; R => Randomized rounding; Z => ZI Round;
I => Shifting; S => Solve LP; T => Evaluate node; U => Unbounded; X => User solution;
z => Trivial zero; l => Trivial lower; u => Trivial upper; p => Trivial point
Nodes | B&B Tree | Objective Bounds | Dynamic Constraints | Work
Src Proc. InQueue | Leaves Expl. | BestBound BestSol Gap | Cuts InLp Confl. | LpIters Time
0 0 0 0.00% -12 -12 0.00% 0 0 0 0 0.0s
Solving report
Status Optimal
Primal bound -12
Dual bound -12
Gap 0% (tolerance: 0.01%)
P-D integral 0
Solution status feasible
-12 (objective)
0 (bound viol.)
0 (int. viol.)
0 (row viol.)
Timing 0.00 (total)
0.00 (presolve)
0.00 (solve)
0.00 (postsolve)
Max sub-MIP depth 0
Nodes 0
Repair LPs 0 (0 feasible; 0 iterations)
LP iterations 0 (total)
0 (strong br.)
0 (separation)
0 (heuristics)
Optimal solution found.
Intlinprog stopped at the root node 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.
x = 3×1
0
6
0
比较在具有和没有初始可行点的情况下求解整数规划问题的步数。此问题有八个变量、四个线性等式约束,所有变量都约束为正值。
定义线性等式约束矩阵和向量。
Aeq = [22 13 26 33 21 3 14 26
39 16 22 28 26 30 23 24
18 14 29 27 30 38 26 26
41 26 28 36 18 38 16 26];
beq = [ 7872
10466
11322
12058];设置下界以将所有变量限制为非负值。
N = 8; lb = zeros(N,1);
指定所有变量均为整数值。
intcon = 1:N;
设置目标函数向量 f。
f = [2 10 13 17 7 5 7 3];
在不使用初始点的情况下求解该问题,并查看显示结果,以了解求解过程中分支定界法的节点数和线性规划迭代次数。
[x1,fval1,exitflag1,output1] = intlinprog(f,intcon,[],[],Aeq,beq,lb);
Running HiGHS 1.11.0: Copyright (c) 2025 HiGHS under MIT licence terms
MIP has 4 rows; 8 cols; 32 nonzeros; 8 integer variables (0 binary)
Coefficient ranges:
Matrix [3e+00, 4e+01]
Cost [2e+00, 2e+01]
Bound [0e+00, 0e+00]
RHS [8e+03, 1e+04]
Presolving model
4 rows, 8 cols, 32 nonzeros 0s
4 rows, 8 cols, 27 nonzeros 0s
Objective function is integral with scale 1
Solving MIP model with:
4 rows
8 cols (0 binary, 8 integer, 0 implied int., 0 continuous, 0 domain fixed)
27 nonzeros
Src: B => Branching; C => Central rounding; F => Feasibility pump; J => Feasibility jump;
H => Heuristic; L => Sub-MIP; P => Empty MIP; R => Randomized rounding; Z => ZI Round;
I => Shifting; S => Solve LP; T => Evaluate node; U => Unbounded; X => User solution;
z => Trivial zero; l => Trivial lower; u => Trivial upper; p => Trivial point
Nodes | B&B Tree | Objective Bounds | Dynamic Constraints | Work
Src Proc. InQueue | Leaves Expl. | BestBound BestSol Gap | Cuts InLp Confl. | LpIters Time
0 0 0 0.00% 0 inf inf 0 0 0 0 0.0s
0 0 0 0.00% 1554.047531 inf inf 0 0 4 4 0.0s
T 14284 1214 5620 78.42% 1690.169125 2849 40.68% 39 5 9987 17146 1.5s
T 21917 1000 8515 86.43% 1736.378236 2113 17.82% 36 5 9873 24182 2.2s
T 26514 250 10328 96.20% 1778.832142 1854 4.05% 31 5 4853 28216 2.5s
26903 0 10609 100.00% 1854 1854 0.00% 39 11 3699 28606 2.5s
Solving report
Status Optimal
Primal bound 1854
Dual bound 1854
Gap 0% (tolerance: 0.01%)
P-D integral 0.332196201182
Solution status feasible
1854 (objective)
0 (bound viol.)
9.63673585375e-14 (int. viol.)
0 (row viol.)
Timing 2.50 (total)
0.00 (presolve)
0.00 (solve)
0.00 (postsolve)
Max sub-MIP depth 3
Nodes 26903
Repair LPs 0 (0 feasible; 0 iterations)
LP iterations 28606 (total)
240 (strong br.)
77 (separation)
2156 (heuristics)
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.
为了进行比较,使用初始可行点求得解。
x0 = [16 60 12 0 0 86 34 219]; [x2,fval2,exitflag2,output2] = intlinprog(f,intcon,[],[],Aeq,beq,lb,[],x0);
Running HiGHS 1.11.0: Copyright (c) 2025 HiGHS under MIT licence terms
MIP has 4 rows; 8 cols; 32 nonzeros; 8 integer variables (0 binary)
Coefficient ranges:
Matrix [3e+00, 4e+01]
Cost [2e+00, 2e+01]
Bound [0e+00, 0e+00]
RHS [8e+03, 1e+04]
Assessing feasibility of MIP using primal feasibility and integrality tolerance of 1e-06
Solution has num max sum
Col infeasibilities 0 0 0
Integer infeasibilities 0 0 0
Row infeasibilities 0 0 0
Row residuals 0 0 0
Presolving model
4 rows, 8 cols, 32 nonzeros 0s
4 rows, 8 cols, 27 nonzeros 0s
MIP start solution is feasible, objective value is 2113
Objective function is integral with scale 1
Solving MIP model with:
4 rows
8 cols (0 binary, 8 integer, 0 implied int., 0 continuous, 0 domain fixed)
27 nonzeros
Src: B => Branching; C => Central rounding; F => Feasibility pump; J => Feasibility jump;
H => Heuristic; L => Sub-MIP; P => Empty MIP; R => Randomized rounding; Z => ZI Round;
I => Shifting; S => Solve LP; T => Evaluate node; U => Unbounded; X => User solution;
z => Trivial zero; l => Trivial lower; u => Trivial upper; p => Trivial point
Nodes | B&B Tree | Objective Bounds | Dynamic Constraints | Work
Src Proc. InQueue | Leaves Expl. | BestBound BestSol Gap | Cuts InLp Confl. | LpIters Time
0 0 0 0.00% 0 2113 100.00% 0 0 0 0 0.0s
0 0 0 0.00% 1554.047531 2113 26.45% 0 0 4 4 0.0s
T 3313 105 1293 95.83% 1687.4271 1854 8.98% 56 6 9402 6902 0.5s
3996 0 1630 100.00% 1854 1854 0.00% 30 6 9989 8272 0.6s
Solving report
Status Optimal
Primal bound 1854
Dual bound 1854
Gap 0% (tolerance: 0.01%)
P-D integral 0.111476662697
Solution status feasible
1854 (objective)
0 (bound viol.)
1.13686837722e-13 (int. viol.)
0 (row viol.)
Timing 0.57 (total)
0.00 (presolve)
0.00 (solve)
0.00 (postsolve)
Max sub-MIP depth 3
Nodes 3996
Repair LPs 0 (0 feasible; 0 iterations)
LP iterations 8272 (total)
240 (strong br.)
79 (separation)
565 (heuristics)
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.
如果没有初始点,
intlinprog需要大约 25,000 次 LP 迭代和 25,000 个分支定界节点。使用一个初始点时,
intlinprog所需的线性规划迭代次数不到 1/3,所占节点比例则更小。解问题的时间也大大缩短了。
给出初始点并非始终有帮助。对于此问题,给出初始点可以节省时间和计算步骤。但是,对于某些问题,给定初始点可能会导致 intlinprog 采用更多步骤。
求解问题
而不显示迭代输出。
指定求解器输入。
f = [-3;-2;-1];
intcon = 3;
A = [1,1,1];
b = 7;
Aeq = [4,2,1];
beq = 12;
lb = zeros(3,1);
ub = [Inf;Inf;1]; % enforces x(3) is binary
x0 = [];指定无显示。
options = optimoptions("intlinprog",Display="off");
运行求解器。
x = intlinprog(f,intcon,A,b,Aeq,beq,lb,ub,x0,options)
x = 3×1
0
6
0
此示例说明如何使用基于问题的方法设立问题,然后使用基于求解器的方法求解问题。问题是
创建名为 prob 的 OptimizationProblem 对象来表示此问题。要指定二元变量,请创建一个下界为 0、上界为 1 的整数类型优化变量。
x = optimvar("x",2,LowerBound=0); xb = optimvar("xb",LowerBound=0,UpperBound=1,Type="integer"); prob = optimproblem(Objective=-3*x(1)-2*x(2)-xb); cons1 = sum(x) + xb <= 7; cons2 = 4*x(1) + 2*x(2) + xb == 12; prob.Constraints.cons1 = cons1; prob.Constraints.cons2 = cons2;
将问题对象转换为问题结构体。
problem = prob2struct(prob);
求解生成的问题结构体。
[sol,fval,exitflag,output] = intlinprog(problem)
Running HiGHS 1.11.0: Copyright (c) 2025 HiGHS under MIT licence terms
MIP has 2 rows; 3 cols; 6 nonzeros; 1 integer variables (1 binary)
Coefficient ranges:
Matrix [1e+00, 4e+00]
Cost [1e+00, 3e+00]
Bound [1e+00, 1e+00]
RHS [7e+00, 1e+01]
Presolving model
2 rows, 3 cols, 6 nonzeros 0s
0 rows, 0 cols, 0 nonzeros 0s
Presolve: Optimal
Src: B => Branching; C => Central rounding; F => Feasibility pump; J => Feasibility jump;
H => Heuristic; L => Sub-MIP; P => Empty MIP; R => Randomized rounding; Z => ZI Round;
I => Shifting; S => Solve LP; T => Evaluate node; U => Unbounded; X => User solution;
z => Trivial zero; l => Trivial lower; u => Trivial upper; p => Trivial point
Nodes | B&B Tree | Objective Bounds | Dynamic Constraints | Work
Src Proc. InQueue | Leaves Expl. | BestBound BestSol Gap | Cuts InLp Confl. | LpIters Time
0 0 0 0.00% -12 -12 0.00% 0 0 0 0 0.0s
Solving report
Status Optimal
Primal bound -12
Dual bound -12
Gap 0% (tolerance: 0.01%)
P-D integral 0
Solution status feasible
-12 (objective)
0 (bound viol.)
0 (int. viol.)
0 (row viol.)
Timing 0.00 (total)
0.00 (presolve)
0.00 (solve)
0.00 (postsolve)
Max sub-MIP depth 0
Nodes 0
Repair LPs 0 (0 feasible; 0 iterations)
LP iterations 0 (total)
0 (strong br.)
0 (separation)
0 (heuristics)
Optimal solution found.
Intlinprog stopped at the root node 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.
sol = 3×1
0
6
0
fval = -12
exitflag = 1
output = struct with fields:
relativegap: 0
absolutegap: 0
numfeaspoints: 1
numnodes: 0
constrviolation: 0
message: 'Optimal solution found.↵↵Intlinprog stopped at the root node 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.'
sol(1) 和 sol(3) 都是二元值。哪个值对应于二元优化变量 xb?
prob.Variables
ans = struct with fields:
x: [2×1 optim.problemdef.OptimizationVariable]
xb: [1×1 optim.problemdef.OptimizationVariable]
变量 xb 出现在 Variables 显示结果的最后,因此 xb 对应于 sol(3) = 1。请参阅转换为求解器形式。
带更多输出调用 intlinprog 以查看解的详细信息和过程。
目标是求解问题
指定求解器输入。
f = [-3;-2;-1];
intcon = 3;
A = [1,1,1];
b = 7;
Aeq = [4,2,1];
beq = 12;
lb = zeros(3,1);
ub = [Inf;Inf;1]; % enforces x(3) is binary带所有输出调用 intlinprog。
[x,fval,exitflag,output] = intlinprog(f,intcon,A,b,Aeq,beq,lb,ub)
Running HiGHS 1.11.0: Copyright (c) 2025 HiGHS under MIT licence terms
MIP has 2 rows; 3 cols; 6 nonzeros; 1 integer variables (1 binary)
Coefficient ranges:
Matrix [1e+00, 4e+00]
Cost [1e+00, 3e+00]
Bound [1e+00, 1e+00]
RHS [7e+00, 1e+01]
Presolving model
2 rows, 3 cols, 6 nonzeros 0s
0 rows, 0 cols, 0 nonzeros 0s
Presolve: Optimal
Src: B => Branching; C => Central rounding; F => Feasibility pump; J => Feasibility jump;
H => Heuristic; L => Sub-MIP; P => Empty MIP; R => Randomized rounding; Z => ZI Round;
I => Shifting; S => Solve LP; T => Evaluate node; U => Unbounded; X => User solution;
z => Trivial zero; l => Trivial lower; u => Trivial upper; p => Trivial point
Nodes | B&B Tree | Objective Bounds | Dynamic Constraints | Work
Src Proc. InQueue | Leaves Expl. | BestBound BestSol Gap | Cuts InLp Confl. | LpIters Time
0 0 0 0.00% -12 -12 0.00% 0 0 0 0 0.0s
Solving report
Status Optimal
Primal bound -12
Dual bound -12
Gap 0% (tolerance: 0.01%)
P-D integral 0
Solution status feasible
-12 (objective)
0 (bound viol.)
0 (int. viol.)
0 (row viol.)
Timing 0.01 (total)
0.00 (presolve)
0.00 (solve)
0.00 (postsolve)
Max sub-MIP depth 0
Nodes 0
Repair LPs 0 (0 feasible; 0 iterations)
LP iterations 0 (total)
0 (strong br.)
0 (separation)
0 (heuristics)
Optimal solution found.
Intlinprog stopped at the root node 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.
x = 3×1
0
6
0
fval = -12
exitflag = 1
output = struct with fields:
relativegap: 0
absolutegap: 0
numfeaspoints: 1
numnodes: 0
constrviolation: 0
message: 'Optimal solution found.↵↵Intlinprog stopped at the root node 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.'
输出结构体显示 numnodes 是 0。这意味着 intlinprog 在分支之前已求出问题的解。这是结果可靠的一个标志。此外,absolutegap 和 relativegap 字段是 0。这是结果可靠的另一个标志。
输入参数
系数向量,指定为实数向量或实数数组。系数向量表示目标函数 f'*x。该表示法假设 f 是列向量,但您也可以使用行向量或数组。linprog 在内部将 f 转换为列向量 f(:)。
如果您指定 f = [],intlinprog 会尝试在不试图最小化目标函数的情况下找到可行点。
示例: f = [4;2;-1.7];
数据类型: double
整数变量索引,指定为正整数的向量或使用 integerConstraint 函数创建的 IntegerConstraint 对象。intcon 中的值表示决策变量 x 的分量,这些分量为整数值或扩展整数值(参阅 扩展整数变量)。intcon 中的索引值从 1 到 numel(f)。
intcon 可以是整数数组。intlinprog 在内部将数组 intcon 转换为向量 intcon(:)。
注意
半整数和半连续变量必须具有严格正的界限,且不超出 1e5。
示例: intcon = [1,2,7] 表示 x(1)、x(2) 和 x(7) 仅取整数值。
示例: intcon = integerConstraint(SemiContinuous=[1,4],Integer=[2,3]) 指定 x(1) 和 x(4) 为半连续型,而 x(2) 和 x(3) 为整数型。
线性不等式约束,指定为实矩阵。A 是 M×N 矩阵,其中 M 是不等式的数目,而 N 是变量的数目(x0 中的元素数)。对于大型问题,将 A 作为稀疏矩阵传递。
A 以如下形式编写 M 个线性不等式
A*x <= b,
其中 x 是 N 个变量 x(:) 组成的列向量,而 b 是一个包含 M 个元素的向量。
当 b 是一个包含两个元素的元胞数组 {bl,b} 时,A 表示以下线性不等式:
bl <= A*x <= b. | (1) |
例如,假设有以下不等式:
x1 + 2x2 ≤ 10
3x1 + 4x2 ≤ 20
5x1 + 6x2 ≤ 30。
通过输入以下约束来指定不等式。
A = [1,2;3,4;5,6]; b = [10;20;30];
同样地,如果您还有以下额外约束条件:
| 4 x1 – x2 ≥2, | (2) |
然后指定
bb = {[-inf;-inf;-inf;2] [b;inf]};
AA = [A;[4 -1]];并将 AA 和 bb 作为线性不等式约束。
示例: 要指定 x 分量总和等于或小于 1,请使用 A = ones(1,N) 和 b = 1。
数据类型: single | double
线性不等式约束,指定为一个实数向量或一个由两个元素组成的、包含实数数组的元胞数组。
如果
b是一个由M个元素组成的向量,那么b表示M个线性不等式A*x <= b,(3) 其中,
x是由N个变量组成的列向量x(:),A是大小为M×N的矩阵。如果
b是一个包含两个元素的元胞数组{bl,b},则bl或b(或两者)必须是非空的。b中非空的条目包含M元素,这些元素编码了线性不等式bl <= A*x <= b,(4) 其中,
x是由N个变量组成的列向量x(:),A是大小为M×N的矩阵。
如果将 b 或 bl 作为行向量传入,求解器会在内部将其转换为列向量 b(:) 或 bl(:)。
例如,假设有以下不等式:
x1 + 2x2 ≤ 10
3x1 + 4x2 ≤ 20
5x1 + 6x2 ≤ 30。
通过输入以下约束来指定不等式。
A = [1,2;3,4;5,6]; b = [10;20;30];
请考虑这一额外约束条件
| 4 x1 – x2 ≥2, | (5) |
将约束条件指定为线性不等式矩阵 AA 和 bb,它们是 A 和 b 的扩展。
bb = {[-inf;-inf;-inf;2] [b;inf]};
AA = [A;[4 -1]];示例: 要指定 x 分量总和等于或小于 1,请使用 A = ones(1,N) 和 b = 1。
数据类型: single | double
线性等式约束,指定为实矩阵。Aeq 是 Me×N 矩阵,其中 Me 是等式的数目,而 N 是变量的数目(f 的长度)。对于大型问题,将 Aeq 作为稀疏矩阵传递。
Aeq 以如下形式编写 Me 个线性等式
Aeq*x = beq,
其中,x 是由 N 个变量组成的列向量 x(:),beq 是具有 Me 个元素的列向量。
例如,请参考以下等式:
x1 + 2x2 + 3x3 = 10
2x1 + 4x2 + x3 = 20。
通过输入以下约束来指定等式。
Aeq = [1,2,3;2,4,1]; beq = [10;20];
示例: 要指定 x 分量之和为 1,请指定 Aeq = ones(1,N) 和 beq = 1。
数据类型: double
线性等式约束,指定为实数向量。beq 是与 Aeq 矩阵相关的包含 Me 个元素的向量。如果将 beq 作为行向量传入,求解器会在内部将其转换为列向量 beq(:)。
beq 以如下形式编写 Me 个线性等式
Aeq*x = beq,
其中,x 是由 N 个变量组成的列向量 x(:),Aeq 是大小为 Me×N 的矩阵。
例如,请参考以下等式:
x1 + 2x2 + 3x3 = 10
2x1 + 4x2 + x3 = 20。
通过输入以下约束来指定等式。
Aeq = [1,2,3;2,4,1]; beq = [10;20];
示例: 要指定 x 分量总和为 1,请使用 Aeq = ones(1,N) 和 beq = 1。
数据类型: single | double
下界,指定为双精度值组成的向量或数组。lb 按元素表示下界,形如 lb ≤ x ≤ ub。
intlinprog 在内部将数组 lb 转换为向量 lb(:)。
示例: lb = [0;-Inf;4] 表示 x(1) ≥ 0,x(3) ≥ 4。
数据类型: double
上界,指定为双精度值组成的向量或数组。ub 按元素表示上界,形如 lb ≤ x ≤ ub。
intlinprog 在内部将数组 ub 转换为向量 ub(:)。
示例: ub = [Inf;4;10] 表示 x(2) ≤ 4,x(3) ≤ 10。
数据类型: double
初始点,指定为实数数组。当 f 存在时,x0 中的元素数与 f 中的元素数相同。否则,该数字与 A 或 Aeq 的列数相同。求解器在内部将数组 x0 转换为向量 x0(:)。
intlinprog 会尝试使用任何给定的 x0,并在必要时调整该点以确保可行性。
提供 x0 会改变 intlinprog 收敛所需的时间量。很难预测 x0 如何影响求解器。
示例: x0 = 100*rand(size(f))
数据类型: double
intlinprog 的选项,指定为 optimoptions 的输出。
optimoptions 显示中缺少某些选项。这些选项在下表中以斜体显示。有关详细信息,请参阅查看优化选项。
| 选项 | 描述 | 默认值 |
AbsoluteGapTolerance | 非负实数。如果内部计算的目标函数的上界 (
| 1e-6 |
ConstraintTolerance |
| 1e-6 |
Display | 显示级别(请参阅迭代输出):
| "iter" |
MaxFeasiblePoints | 严格正整数。intlinprog 在找到 MaxFeasiblePoints 个整数可行点时停止。 | Inf |
MaxNodes | 严格正整数,它是 intlinprog 在分支定界过程中探查的最大节点数。 | 1e7 |
MaxTime | 非负实数,它是 intlinprog 运行的最长时间(以秒为单位)。 | 7200 |
ObjectiveCutOff | 大于 -Inf 的实数。在分支定界计算过程中,intlinprog 丢弃那些线性规划解所对应目标函数值超过 ObjectiveCutOff 的节点。 | Inf |
OutputFcn | 优化函数在事件中调用的一个或多个函数。指定为
有关编写自定义输出函数的信息,请参阅intlinprog 输出函数和绘图函数语法。 | [] |
PlotFcn | 对算法执行过程中的各种进度测量值绘图,可以选择预定义的绘图,也可以自行编写绘图函数。传递
有关编写自定义绘图函数的信息,请参阅intlinprog 输出函数和绘图函数语法。 | [] |
RelativeGapTolerance |
停止测试是
当 注意 虽然您将 | 1e-4 |
示例: options = optimoptions("intlinprog",MaxTime=120)
封装输入和选项的结构体,用下列字段指定。
f | 表示目标 f'*x 的向量(必需) |
intcon | 表示取整数值的变量的向量,或指定扩展整数约束的 integerConstraint 对象(必填) |
Aineq | 线性不等式约束 Aineq*x ≤ bineq 中的矩阵 |
| 线性不等式约束中的向量 bcons = {bl b};
problem.bineq = {bcons}; |
| 线性等式约束 Aeq*x = beq 中的矩阵 |
| 线性等式约束 Aeq*x = beq 中的向量 |
lb | 由下界组成的向量 |
ub | 由上界组成的向量 |
x0 | 初始点 |
solver | 'intlinprog'(必需) |
| 使用 optimoptions 创建的选项(必需) |
您必须在问题结构体中至少指定以下字段。其他字段是可选的:
fintconsolveroptions
小心
problem 参量必须是一个标量结构体。如果将线性约束定义为元胞数组 {bl,b},则生成的问题结构可以是非标量结构体数组。为确保 problem 是标量,请传入 {{bl,b}}。
示例: problem.f = [1,2,3];
problem.intcon = [2,3];
problem.options = optimoptions('intlinprog');
problem.Aineq = [-3,-2,-1];
problem.bineq = -20;
problem.lb = [-6.1,-1.2,7.3];
problem.solver = 'intlinprog';
数据类型: struct
输出参量
解,以向量形式返回,它在所有边界、整数约束和线性约束的限制下最小化 f'*x。
当问题不可行或无界时,x 为 []。
目标函数值,以解 x 处的标量值 f'*x 形式返回。
当问题不可行或无界时,fval 为 []。
算法停止条件,以整数形式返回,标识算法停止的原因。下面列出 exitflag 的值以及相应的 intlinprog 停止原因。
| 解关于相对 |
|
|
|
|
|
|
|
|
| 找不到可行点。 |
| 根 LP 问题无界。 |
| 求解器失去可行性。 |
退出消息可以提供关于 intlinprog 停止原因的更详细信息,例如超出容差。
退出标志 3 和 -9 与不可行性较大的解相关。此类问题通常源于具有较大条件数的线性约束矩阵,或源于具有较大解分量的问题。要纠正这些问题,请尝试缩放系数矩阵,消除冗余线性约束,或对变量给出更严格的边界。
求解过程摘要,以包含优化过程信息的结构体形式返回。
|
如果 注意 虽然您将 |
|
如果 |
| 找到的整数可行点的数量。 如果 |
| 分支定界算法中的节点数。如果在预处理或初始切割过程中找到了解,则 如果 |
| 约束违反值,在违反约束时为正值。
|
| 退出消息。 |
限制
通常,解
x(intCon)中一些应为整数值的分量并不是精确的整数。intlinprog将处在整数容差ConstraintTolerance内的所有解值视为整数。要将所有应为整数的解值舍入为精确的整数,请使用
round函数。x(intcon) = round(x(intcon));
小心
舍入解可能导致解变得不可行。舍入后检查可行性:
max(A*x - b) % See if entries are not too positive, so have small infeasibility max(abs(Aeq*x - beq)) % See if entries are near enough to zero max(x - ub) % Positive entries are violated bounds max(lb - x) % Positive entries are violated bounds
intlinprog不强制将绝对值超过2.1e9的解分量转化为整数值。当您的解包含此种分量时,intlinprog会发出警告。如果您收到此警告,请检查该解,确认该解中应为整数值的分量是否接近整数。intlinprog不允许问题的分量(例如f中的系数)、b或ub中的系数,其绝对值不得超过1e20;同时,线性约束矩阵A和Aeq的绝对值不得大于或等于1e15。如果您尝试对这样的问题运行intlinprog,intlinprog会出错。
详细信息
扩展整数变量是整数值、半连续或半整数的变量。
整数值变量可以取标准双精度变量表示的任何整数值,例如 –12 或 1234567。您无需为整型变量指定任何边界。
半连续变量可以取值
0或下界到上界之间的任何实数值。边界值必须严格为正且不超过1e5。半整数变量是整数值,可以取值
0或从下界到上界的任何整数值。边界值必须严格为正且不超过1e5。
intlinprog 求解器支持整数变量和扩展整数变量,它们均具有 MATLAB® 类型 double。使用 integerConstraint 函数指定变量类型。使用以下名称指定变量索引中为整数或扩展整数的索引:
Integer- 整数变量索引SemiContinuous- 半连续变量索引SemiInteger- 半整数变量索引
未指定变量索引的默认类型为连续,这意味着变量可以取任何实数值。
例如,要指定变量 1 至 5 为整数,11 至 20 为半连续,其余为连续:
intcon = integerConstraint(Integer=1:5,SemiContinuous=11:20);
接下来的几项列出了可能增强的退出消息 intlinprog。增强的退出消息在消息的第一句中给出了详细信息的链接。
intlinprog 不一定找到了最优解。但它确实至少找到了一个整数可行点。整数可行点是满足所有约束的点,包括边界、线性约束和整数约束。
intlinprog 采用分支定界算法(请参阅 分支定界)。算法中的每个分支都会创建一个新节点。intlinprog 使用 MaxNodes 选项(容差)作为停止条件。
您可以使用圆点表示法来更改选项的值:
options.MaxNodes = 5e4;
您也可以使用 optimoptions 来更改该值:
options = optimoptions(options,'MaxNodes',5e4);intlinprog 使用 MaxTime 选项 (容差) 作为停止标准。
您可以使用圆点表示法来更改选项的值:
options.MaxTime = 5e4;
您也可以使用 optimoptions 来更改该值:
options = optimoptions(options,'MaxTime',5e4);intlinprog 超出了迭代限制。intlinprog 使用 LPMaxIterations 选项 (容差) 作为停止标准。
您可以使用圆点表示法来更改选项的值:
options.LPMaxIterations = 5e4;
您也可以使用 optimoptions 来更改该值:
options = optimoptions(options,'LPMaxIterations',5e4);intlinprog 找到了至少 MaxNumFeasPoints 个整数可行点。intlinprog 不一定找到了最优解。
整数可行点是满足所有约束的点,包括边界、线性约束和整数约束。
intlinprog 使用 MaxNumFeasPoints 选项 (容差) 作为停止标准。
您可以使用圆点表示法来更改选项的值:
options.MaxNumFeasPoints = 5e4;
您也可以使用 optimoptions 来更改该值:
options = optimoptions(options,'MaxNumFeasPoints',5e4);intlinprog 在内部计算目标函数值在解处的上界和下界。这些内部计算的边界之间的间隙是上界和下界之间的差。相对间隙是间隙与 1 加上下界绝对值的比值。intlinprog 使用 TolGapAbs 选项(间隙的容差)和 TolGapRel 选项(相对间隙的容差)作为停止条件。
intcon 参量为空,因此 intlinprog 求解了一个线性规划问题。
intlinprog 没有找到任何整数可行点,因此无法继续。这并不一定意味着问题不可行,只是 intlinprog 未能找到整数可行点。整数可行点是满足所有约束的点,包括边界、线性约束和整数约束。
intlinprog 无法解决放松的 LP,因为它达到了 RootLPMaxIterationsRootLPMaxIterationsintlinprog (容差) 作为停止标准。
intlinprog 导致内存不足。重新表示问题可能会得到一个解;请参阅 Williams [1]。
intlinprog 已停止,因为该问题没有解。可能因为边界约束和线性约束不一致,也可能因为整数约束与边界约束和线性约束不一致。
要确定原因,请使用 intcon = [] 重新运行该问题。如果得到的线性规划无解,则边界约束和线性约束不一致。否则就是原问题中的整数约束与边界约束和线性约束不一致。
根线性规划 (LP) 问题是原始 MILP 问题,但没有整数约束。intlinprog 停止,因为根 LP 问题是无界的。
原始问题可能不可行。当根 LP 问题无界时,intlinprog 不检查可行性。
intlinprog 停止,因为线性规划问题没有解。对于任何目标值,都有目标函数值小于该目标的可行点。
接下来的几项包含以下术语的定义 intlinprog 退出消息。
一般来说,容差是一个阈值,超过阈值时将终止求解器的迭代。有关容差的详细信息,请参阅容差和停止条件。
分支定界树或分支定界树中的节点是 x 的值,以及 x 的分量 j,其中 x(j) 有小数部分。分支定界节点有两个子问题:评估带有限制 x(j) ≥ ceil(x(j)) 的线性规划问题,以及评估带有限制 x(j) ≤ floor(x(j)) 的线性规划问题。有关详细信息,请参阅分支定界。
intlinprog 无法保证您在 intcon 中指定的变量恰好是整数,只能保证它们在整数值的 TolInteger 容差范围内。请参阅有些“整数”解不是整数。
当 intlinprog 在根节点停止时,它不必执行任何分支定界搜索。intlinprog 或者在预解决期间解决了问题,或者在后续处理期间解决了问题,但无需分支。
根节点是基于原始 MILP 的松驰线性规划问题。有关详细信息,请参阅分支定界。
提示
要指定二元变量,请在
intcon中将变量设置为整数,并指定其下界为0,上界为1。通过指定稀疏线性约束矩阵
A和Aeq来节省内存。但是,您无法对b和beq使用稀疏矩阵。如果提供的是整数分量的逻辑索引,即用
1指示整数的进制向量,请使用find将其转换为intcon形式。例如,logicalindices = [1,0,0,1,1,0,0]; intcon = find(logicalindices)
intcon = 1 4 5intlinprog取代bintprog。要更新使用bintprog的旧代码以使用intlinprog,请进行以下更改:将
intcon设置为1:numVars,其中numVars是问题中变量的数目。将
lb设置为zeros(numVars,1)。将
ub设置为ones(numVars,1)。更新任何相关选项。使用
optimoptions为intlinprog创建选项。按以下方式更改您对
bintprog的调用:[x,fval,exitflag,output] = bintprog(f,A,b,Aeq,Beq,x0,options) % Change your call to: [x,fval,exitflag,output] = intlinprog(f,intcon,A,b,Aeq,Beq,lb,ub,x0,options)
替代功能
App
优化实时编辑器任务为 intlinprog 提供了一个可视化界面。
版本历史记录
在 R2014a 中推出intlinprog "legacy" 算法已删除。"legacy" 算法特有的所有选项也已删除:
BranchRuleCutGenerationCutMaxIterationsHeuristicsHeuristicsMaxNodesIntegerPreprocessIntegerToleranceLPMaxIterationsLPOptimalityToleranceLPPreprocess
NodeSelectionObjectiveImprovementThresholdRootLPAlgorithmRootLPMaxIterations
此外,由于只有一种 intlinprog 算法,Algorithm 选项也已删除。类似地,intlinprog output 结构体不再包含 algorithm 字段。
optimValues 结构体用于输出函数或绘图函数(请参阅intlinprog 输出函数和绘图函数语法),由于只在一种 "legacy" 算法中用到,该结构体中不再包含 phase 字段。
intlinprog 与 "highs" 算法支持半连续和半整数变量,您可以使用 integerConstraint 函数来指定这些变量。例如,要指定变量 10 至 20 为半整数,变量 1 至 9 为半连续,请输入:
intcon = integerConstraint(SemiInteger=10:20,SemiContinuous=1:9);
有关详细信息,请参阅扩展整数变量。
"highs" 算法现在支持输出函数和绘图函数。有关详细信息,请参阅intlinprog 输出函数和绘图函数语法。有关使用内置绘图函数的示例,请参阅工厂、仓库、销售分配模型:基于求解器。
这optimValues 结构体输出函数和绘图函数现在使用字段名称 dualbound 而不是 lowerbound。对 dualbound 的含义是,最小化问题的全局下界,或者最大化问题的全局上界。optimplotmilp 绘图函数现在使用标签 Primal Bound 和 Dual Bound 而不是 Branch/bound UB 和 Branch/bound LB。
"highs" 算法现在支持 MaxFeasiblePoints 选项。"highs" 算法的 output 结构体现在支持 numfeaspoints 字段。
intlinprog 增加了一种算法、一个Algorithm 选项和一种新的默认算法。"highs" 算法基于开源 HiGHS 代码。"highs" 算法目前不支持输出函数或绘图函数。
要使用先前的算法,请使用 optimoptions 设置 Algorithm="legacy"。
现在这两种算法 ConstraintTolerance 选项值的允许范围都是 1e-10 到 1e-3,"legacy" 算法 IntegerTolerance 选项值的允许范围也是这个范围。
BranchRule 选项的默认值为 'reliability',而不再是 'maxpscost'。在测试中,此值在许多问题中表现出更好的性能,无论是在求解时间方面还是在探查的分支节点数量方面。
对于一部分问题,以前的默认分支规则性能更好。要获得以前版本的行为,请将 BranchRule 选项设置为 'maxpscost'。
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)