【问题标题】:How to define Linear program in matlab?如何在matlab中定义线性程序?
【发布时间】:2018-03-12 01:36:35
【问题描述】:

我无法在 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),所以我知道这是可能的。

谢谢。

【问题讨论】:

  • 您可能想要修正您的描述,因为您所拥有的不是线性程序。如果你所有的变量都是二进制的,那么它们都需要在整数约束中列出。否则它优化一个线性程序,其中每个变量在闭区间 [0, 1] 上取任何实数值。

标签: matlab linear-programming


【解决方案1】:

如果指定下限和上限约束,则不能省略AeqBeq,因为此函数使用位置参数。

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多