0

I have the following gams program:

Set x_set /1*2/;
variable x(x_set) /1.lo = 0 ,1.up = 1,2.lo = 0,2.up = 1/;
Set y_set /1*3/;
variable y(y_set) /1.lo = 0,1.up = 1,2.lo = 0,2.up = 1, 3.lo = 0, 3.up = 1/;

Set S /1*2/;
variable obj; equation eqobj; eqobj.. obj =e= (x['1']+x['2']+y['1']+y['2']+y['3']);
equation eqcon1; eqcon1(S).. 0.5 =l= x[S];
*if defining S over x_set, the following is not possible anymore
equation eqcon2; eqcon1(S).. 0.7 =l= y[S]; 

model mod /all/;
solve mod minimizing obj using minlp;

Unfortunaly, I will get a domain set violation error Domain violation for set with the program above. This error is caused because I am not using the set I defined the variable above in the indexed equation. Is there any way I can accomplish what I am trying to do, i.e. to iterate the multidimensional variable without using the set it was defined above?

(Note: A new set for every equation is not wanted, as there are a lot of constraints, therefore the same set should be reused).

wittn
  • 298
  • 5
  • 16

1 Answers1

1

Updated reply based on comments below

You could define a common super set for x_set, y_set and s like this:

Set sSuper /1*3/;
Set x_set(sSuper) /1*2/;
variable x(sSuper) /1.lo = 0 ,1.up = 1,2.lo = 0,2.up = 1/;

Set y_set(sSuper) /1*3/;
variable y(sSuper) /1.lo = 0,1.up = 1,2.lo = 0,2.up = 1, 3.lo = 0, 3.up = 1/;

Set S(sSuper) /1*2/;
variable obj; equation eqobj;
eqobj.. obj =e= (x['1']+x['2']+y['1']+y['2']+y['3']);
equation eqcon1;
eqcon1(S).. 0.5 =l= x[S];
equation eqcon2;
eqcon2(S).. 0.7 =l= y[S]; 
Lutz
  • 2,197
  • 1
  • 10
  • 12
  • Yes, but as I said, then I would not be able to use S to iterate over other multidimensional Variables, which is a requirement. – wittn Mar 16 '22 at 11:37
  • Sorry, I don't get that. Could you give an example of something that you also want to do in addition to the code you shared, that would not work? – Lutz Mar 16 '22 at 12:50
  • Sorry, I have edited the question so that (I hope) it is more clear what the problem is. – wittn Mar 16 '22 at 13:26
  • You wrote "if defining S over x_set, the following is not possible anymore". But that is also not possible, if you do not define S over x_set. So what is the actual relation you have in mind for x_set, y_set and s? Should they all be subset of a common super set? I'll adjust my reply to show how that could work. – Lutz Mar 16 '22 at 14:46
  • The code you provided is almost what I intended to do, it is just still a little bit not general enough. I defined my variables and S over the universal set got the result I wanted. – wittn Mar 17 '22 at 15:19