model: sets: p /p1, p2/; w /width, height/; parameters: shapes(p,w); shapes('p1', 'width') = 373; shapes('p1', 'height') = 201; shapes('p2', 'width') = 406; shapes('p2', 'height') = 229; boardSize(w) = 3000; boardSize('height') = 1500; integer variables: x(p,w); binary variables: y(p); equations: total_area: sum((p,w), x(p,w)*shapes(p,w)) =l= boardSize(w)*boardSize('height'); use_shape(p): y(p)*sum(w, x(p,w)) =l= sum((p,w), shapes(p,w)); maximize: utilization: sum((p,w), x(p,w)*shapes(p,w))/(boardSize(w)*boardSize('height')); generate: loop(p, y(p) = 1); solve; display x.l, y.l; 请指出lingo代码错误地方,并给出正确代码
时间: 2024-02-03 14:04:12 浏览: 61
根据您提供的Lingo代码,我注意到您在generate块中使用了"loop"语句,但是Lingo语法中没有这个关键词。在Lingo中,您可以使用一个循环语句来替代。此外,您还没有指定循环的范围和循环变量。下面是修正后的代码:
```lingo
model:
sets:
p /p1, p2/;
w /width, height/;
parameters:
shapes(p,w);
shapes('p1', 'width') = 373;
shapes('p1', 'height') = 201;
shapes('p2', 'width') = 406;
shapes('p2', 'height') = 229;
boardSize(w) = 3000;
boardSize('height') = 1500;
integer variables:
x(p,w);
binary variables:
y(p);
equations:
total_area: sum((p,w), x(p,w)*shapes(p,w)) =l= boardSize(w)*boardSize('height');
use_shape(p): y(p)*sum(w, x(p,w)) =l= sum((p,w), shapes(p,w));
maximize:
utilization: sum((p,w), x(p,w)*shapes(p,w))/(boardSize(w)*boardSize('height'));
generate:
for(p, y(p) = 1);
solve;
display x.l, y.l;
```
请注意,我将"loop"替换为"for"循环,并添加了循环的范围(在这种情况下,是对集合p进行循环)和循环变量(在这种情况下,是变量p)。现在您可以尝试运行修正后的代码。
阅读全文