如何在matlab中定义线性规划?

How to define Linear program in matlab?

我在 MATLAB 中定义优化问题时遇到问题。

我正在尝试表达 7 个二元决策变量。但是前3个二元决策变量之和不能大于1,后4个二元决策变量之和不能大于1.

A = [1,1,1,0,0,0,0;...
    0,0,0,1,1,1,1];
b = [1;1];

% objective function 
f = [0.1, 0.5, 0.2, 0.2, -2.0, 0.2, 0.6];

lb = zeros(7,1);
ub = ones(7,1); % Enforce all of the decision variables to be binary
intcon = [];  % all of my variables are binary, so I assume this should be blank.

x = intlinprog(f,intcon,A,b,lb,ub);

我想强制所有的决策变量都是二元的,所以我包括了这些行:

lb = zeros(7,1);
ub = ones(7,1); % Enforce all of the decision variables to be binary 
intcon = [];  % all of my variables are binary, so I assume this should be blank.

另外,我没有等式约束,所以我没有在上面的问题中包括Aeqbeq。但是当我尝试 运行 没有像 x = intlinprog(f,intcon,A,b,lb,ub); 这样的参数的求解器时,它告诉我

Error using intlinprog (line 123)
The number of columns in Aeq must be the same as the number of elements of f.

但是如果我没有任何等式约束,我该如何定义呢?

这是文档:https://www.mathworks.com/help/optim/ug/intlinprog.html#bts3gkc-2 页面顶部的示例显示它可以在不使用 Aeqbeq 的情况下调用 x = intlinprog(f,intcon,A,b),所以我知道这是可能的。

谢谢。

如果指定 lower-bound 和 upper-bound 约束,则不能省略 AeqBeq,因为此函数使用位置参数。

但是,您可以传递空矩阵,从而导致零等式约束:

x = intlinprog(f,intcon,A,b,[],[],lb,ub);