检查以下LINGO代码的合理性:model: sets: fac/1..3/:A; shop/1..4/:B,T; link(fac,shop):c,x; endsets data: A=7 8 5; B=16 20 12 30; T=45 72 120 48; C= 2 3 4 5 8 9 10 9 2 3 4 7; enddata min=@sum(link:c*x); @for(fac(i): @sum(shop(j):x(i,j))<A(i) ); @for(shop(j): @sum(fac(i):x(i,j))>B(j) ); @for(shop(j): @sum(fac(i):x(i,j)*T(j))<1440 ); @for(fac(i): @for(shop(j): @gin(x(i,j))) ); end
时间: 2023-10-21 08:07:17 浏览: 102
LINGO-JIAOCHENG.rar_lingo_lingo优化_site:www.pudn.com
这是一个LINGO的线性规划模型,经过检查,代码基本合理,但有以下几点建议:
1. 在sets部分,B和T应该分行写,以提高可读性;
2. 在data部分,C的顺序与sets中定义的link顺序不一致,应该保持一致;
3. 在第4个@for循环中,应该为x(i,j)*T(j),而非x(i,j);
4. 在第5个@for循环中,@gin()函数限制x(i,j)为整数,但x(i,j)是变量,应该使用@int()函数将其转换为整数。
下面是修改后的代码:
```
model:
sets:
fac/1..3/: A;
shop/1..4/: B,
T;
link(fac, shop): c, x;
endsets
data:
A = 7 8 5;
B = 16
20
12
30;
T = 45
72
120
48;
C = 2 3 4 5 8 9 10 9 2 3 4 7;
enddata
min = @sum(link: c * x);
@for(fac(i):
@sum(shop(j): x(i, j)) < A(i)
);
@for(shop(j):
@sum(fac(i): x(i, j)) > B(j)
);
@for(shop(j):
@sum(fac(i): x(i, j) * T(j)) < 1440
);
@for(fac(i):
@for(shop(j):
x(i, j) = @int(x(i, j));
)
);
end
```
这样修改后,代码应该可以正确运行。
阅读全文