请将以下lingo语言转换成matlab
时间: 2023-05-29 16:02:12 浏览: 323
应用LINGO和MATLAB软件求解线性规划.ppt
我不确定您指的是什么样的lingo语言,因为这个词在不同的领域中有不同的含义。但是,这里是一个例子,将一段简单的lingo语言转换成matlab语言。
Lingo语言:
```
SETS:
PRODUCTS / P1*P2*P3*P4*P5*P6*P7*P8*P9*P10 /;
LOCATIONS / W1*L1 /;
DATA:
COMMANDER / P1*W1 10, P1*L1 15, P2*W1 6, P2*L1 18, P3*W1 8, P3*L1 16, P4*W1 12, P4*L1 14 /;
VARS:
X(PRODUCTS, LOCATIONS);
BINARY VARIABLES:
Z(PRODUCTS, LOCATIONS);
MIN = SUM((P,I), COMMANDER(P,I) * X(P,I));
SUBTO PROFIT_CONS:
FOR(P IN PRODUCTS):
SUM(I,COMMANDER(P,I)*Z(P,I))<=200;
ENDFOR;
SOLVE;
DISPLAY X;
```
Matlab语言:
```
%SETS
PRODUCTS = ["P1","P2","P3","P4","P5","P6","P7","P8","P9","P10"];
LOCATIONS = ["W1","L1"];
%DATA
COMMANDER = containers.Map(...
{"P1W1","P1L1","P2W1","P2L1","P3W1","P3L1","P4W1","P4L1"},...
[10,15,6,18,8,16,12,14]);
%VARS
X = zeros(length(PRODUCTS),length(LOCATIONS));
Z = zeros(length(PRODUCTS),length(LOCATIONS));
%MIN
MIN = 0;
for i = 1:length(PRODUCTS)
for j = 1:length(LOCATIONS)
MIN = MIN + COMMANDER(string(PRODUCTS(i)) + string(LOCATIONS(j))) * X(i,j);
end
end
%SOLVE
for i = 1:length(PRODUCTS)
for j = 1:length(LOCATIONS)
if Z(i,j) == 1
PROFIT_CONS(i,j) = COMMANDER(string(PRODUCTS(i)) + string(LOCATIONS(j)));
else
PROFIT_CONS(i,j) = 0;
end
end
end
for i = 1:length(PRODUCTS)
if sum(PROFIT_CONS(i,:)) <= 200
PROFIT_CONS(i,:) = [];
end
end
%SOLVE
X = linprog(MIN,[],[],PROFIT_CONS,200*ones(1,size(PROFIT_CONS,1)),zeros(size(X)));
%DISPLAY
disp(X);
```
阅读全文