简体   繁体   English

Lingo中的线性编程

[英]linear programming in Lingo

I want to do a linear programming with Lingo, I have the solution but I want to improve the code. 我想用Lingo进行线性编程,我有解决方案,但我想改善代码。

Here is what I want to do: 这是我想做的:

SETS:
 SEMANA/ 1..12/: D, X, I, Y, Z, R, n;
ENDSETS

X(1)>=D(1); 

X(2)+I(1)>=D(2);

X(3)+I(2)>=D(3);

X(4)+I(3)>=D(4);

X(5)+I(4)>=D(5);

X(6)+I(5)>=D(6);

X(7)+I(6)>=D(7);

X(8)+I(7)>=D(8);

X(9)+I(8)>=D(9);

X(10)+I(9)>=D(10);

X(11)+I(10)>=D(11);

X(12)+I(11)>=D(12);

I have tried this option but there is a mistake that says: Subscript out of range on attribute I. 我已经尝试过该选项,但是有一个错误提示:下标超出属性I的范围。

@FOR (SEMANA(j): 

X(j)+ I(j-1)>= D(j)) ; 

I(j-1) is out of range so I can´t solve the problem. I(j-1)超出范围,所以我无法解决问题。

Thank you 谢谢

Notice that your code will try to get into I(0) when j=1. 请注意,当j = 1时,您的代码将尝试进入I(0)。 I(0) does not defined and that's why it's out of range problem. I(0)没有定义,这就是为什么它超出范围的问题。

You need a index filter 您需要索引过滤器

@FOR (SEMANA(j) | j#GT#1: 
  X(j)+ I(j-1)>= D(j)) ;

This would be equivalent to having I(0)=0, but only implicitly. 这将等效于I(0)= 0,但仅是隐式的。 If you have I(0)>0, eg you have positive initial inventory, then you will need to extend your index set to include '0' and put an additional constraint I(0)=INITIAL_VALUE 如果您的I(0)> 0,例如初始库存为正,那么您将需要扩展索引集以使其包括“ 0”,并附加一个约束I(0)= INITIAL_VALUE

Consequently, your @for loop will have to be 因此,您的@for循环必须为

@FOR (SEMANA(j) | j#GT#0: 
  X(j)+ I(j-1)>= D(j)) ;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM