3

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?

rkza
  • 53
  • 3

2 Answers2

2

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.

Lutz
  • 2,197
  • 1
  • 10
  • 12
1

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:

enter image description here

And the results are:

enter image description here

I believe that should do it :)

  • But this is a nice question, as I don't really know if there is a way to selectively create the variables in GAMS based on a scope of indexes, as in the python-CPLEX interface. It is not relevant for the size of your problem, though :) – Raquel Aguiar Jun 02 '20 at 08:25