制定线性规划问题

发布于 2024-10-31 19:52:53 字数 705 浏览 1 评论 0原文


对于了解线性规划的人来说,这可能是一个非常基本的问题。
我在 LP 上看到的大多数问题都与以下格式有些相似

max            3x+4y  
subject to     4x-5y = -34
               3x-5y = 10      (and similar other constraints)

。换句话说,我们在目标函数和约束函数中具有相同数量的未知数。

我的问题是目标函数中有 1 个未知变量,约束函数中有 3 个未知变量。
问题是这样的

Objective function:  min w1
subject to:
w1 + 0.1676x + 0.1692y >= 0.1666 
w1 - 0.1676x - 0.1692y >= -0.1666 
w1 + 0.3039x + 0.3058y >= 0.3  
w1 - 0.3039x - 0.3058y >= -0.3  
x + y = 1
x >= 0
y >= 0

可以看出,目标函数只有一个未知数,即 w1 ,约束函数有 3 个(或者说 2)个未知数,即 w1, xy
有人可以指导我如何解决这个问题,特别是使用 R 或 MATLAB 线性编程工具箱。

This may be quite a basic question for someone who knows linear programming.
In most of the problems that I saw on LP has somewhat similar to following format

max            3x+4y  
subject to     4x-5y = -34
               3x-5y = 10      (and similar other constraints)

So in other words, we have same number of unknown in objective and constraint functions.

My problem is that I have one unknown variable in objective function and 3 unknowns in constraint functions.
The problem is like this

Objective function:  min w1
subject to:
w1 + 0.1676x + 0.1692y >= 0.1666 
w1 - 0.1676x - 0.1692y >= -0.1666 
w1 + 0.3039x + 0.3058y >= 0.3  
w1 - 0.3039x - 0.3058y >= -0.3  
x + y = 1
x >= 0
y >= 0

As can be seen, the objective function has only one unknown i.e. w1 and constraint functions have 3 (or lets say 2) unknown i.e w1, x and y.
Can somebody please guide me how to solve this problem, especially using R or MATLAB linear programming toolbox.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

枕头说它不想醒 2024-11-07 19:52:53

您的目标仅涉及 w1,但您仍然可以将其视为 w1,x,y 的函数,其中 w1 的系数为 1,并且 x,y 的系数为零:

min w1*1 + x*0 + y*0

一旦您看到这一点,您就可以按照通常的方式将其表示为“标准”LP。

Your objective only involves w1 but you can still view it as a function of w1,x,y, where the coefficient of w1 is 1, and the coeffs of x,y are zero:

min w1*1 + x*0 + y*0

Once you see this you can formulate it in the usual way as a "standard" LP.

套路撩心 2024-11-07 19:52:53

普拉萨德是正确的。目标函数中未知数的数量并不重要。您可以将不存在的未知数视为具有零系数。

使用Matlab 的linprog 函数可以轻松求解该LP。了解更多
有关 linprog 的详细信息,请参阅此处的文档

% We lay out the variables as X = [w1; x; y]
c = [1; 0; 0]; % The objective is w1 = c'*X
% Construct the constraint matrix
% Inequality constraints will be written as Ain*X <= bin
%       w1      x        y
Ain = [ -1 -0.1676 -0.1692;
        -1  0.1676  0.1692;
        -1 -0.3039 -0.3058;  
        -1  0.3039  0.3058; 
      ];
bin =  [ -0.166; 0.166; -0.3; 0.3];

% Construct equality constraints Aeq*X == beq
Aeq = [ 0 1 1];
beq = 1;

%Construct lower and upper bounds l <= X <= u
l = [ -inf; 0; 0];
u = inf(3,1);

% Solve the LP using linprog
[X, optval] = linprog(c,Ain,bin,Aeq,beq,l,u);

% Extract the solution
w1 = X(1);
x  = X(2);
y  = X(3); 

Prasad is correct. The number of unknowns in the objective function does not matter. You can view unknowns that are not present as having a zero coefficient.

This LP is easily solved using Matlab's linprog function. For more
details on linprog see the documentation here.

% We lay out the variables as X = [w1; x; y]
c = [1; 0; 0]; % The objective is w1 = c'*X
% Construct the constraint matrix
% Inequality constraints will be written as Ain*X <= bin
%       w1      x        y
Ain = [ -1 -0.1676 -0.1692;
        -1  0.1676  0.1692;
        -1 -0.3039 -0.3058;  
        -1  0.3039  0.3058; 
      ];
bin =  [ -0.166; 0.166; -0.3; 0.3];

% Construct equality constraints Aeq*X == beq
Aeq = [ 0 1 1];
beq = 1;

%Construct lower and upper bounds l <= X <= u
l = [ -inf; 0; 0];
u = inf(3,1);

% Solve the LP using linprog
[X, optval] = linprog(c,Ain,bin,Aeq,beq,l,u);

% Extract the solution
w1 = X(1);
x  = X(2);
y  = X(3); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文