How to add a condition to a variable - GAMS

情到浓时终转凉″ 提交于 2020-06-14 08:34:13

问题


In the model I'm trying to build, I have a variable defined as:

Variables
    x(i,j)  number of motors produced in month i to be delivered in month j ;

In that variable, j must always be equal or greater than i for it to make sense (you can't produce something in this month to be delivered in the previous month). However, I have no clue as to how I can properly model this. I've searched and couldn't find an easy solution to this.

Any ideas?


回答1:


You should use "variables with limited domains" for this, look here for more details, it is a rather new GAMS feature: https://www.gams.com/latest/docs/UG_ModelSolve.html#UG_ModelSolve_LimitedDomain

So, in your example, it would look like this:

Set limX(i,j) limiting domain of x;

limX(i,j) = ord(j) >= ord(i);

Model m /all, x(limX)/;
...

Edit: Corrected syntax of model statement.




回答2:


So, I add this, right after declaring the variable:

x.fx(i,j)$(ord(i)>ord(j))=0; 

It is fixing the values of the variables you are not using to zero. In your model:

And the results are:

I believe that should do it :)



来源:https://stackoverflow.com/questions/62134823/how-to-add-a-condition-to-a-variable-gams

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!