0

Now,I have the GAMS code like the sample below. The statement binary variables x(i,j) indicates that the GAMS will creat one hundred variables x with index(i,j). How Can I do to let GAMS creats variables x(i,j) only when r(i,j) exists to reduce the number of variable x?

set i nodes /1*10/;
alias (i, j);
parameter r(i,j) factor /1.2 1 ......  7.8 1/;
binary variables x(i,j);
Jiawei Lu
  • 509
  • 6
  • 16

1 Answers1

0

You need to use $-condition when you use the variables. The declaration

binary variables x(i,j);

itself does not generate any variables. They are created when they are used, e.g., in an equation. Look for example at this dummy equation:

equation dummy(i);
dummy(i).. sum(j, x(i,j)) =l= 5;

This would generate 100 x variables as you said, but now lets modify this using a $-condition:

dummy(i).. sum(j$r(i,j), x(i,j)) =l= 5;

This would create only those x variables where r is not 0. You would have to use the same $-condition wherever x is used.

Hope that helps! Lutz

Lutz
  • 2,197
  • 1
  • 10
  • 12
  • Thanks a lot! I thought that the GAMS creats all variables as soon as the declaration is made. Now, I have got it. Thank you again. – Jiawei Lu Mar 15 '18 at 14:41