## GUSS issue for parallel computing

Problems with syntax of GAMS
GabrielYin
User Posts: 57
Joined: 1 year ago
Location: Dallas, TX, USA

### GUSS issue for parallel computing

Hi All,

Gather-Update-Solve-Scatter (GUSS) (link:https://www.gams.com/latest/docs/S_GUSS.html)gives me a very good insight to solve multiple models with different parameters efficiently. However when I was going to implement my own model, it has some problems which I cannot figure out. I tried to solve one model with 64 different parameters, i.e.64 LPs via GUSS modeling like follows.

Code: Select all

``````Set      i       /1*4/
j       /1*3/
s       /1*64/;

**** Scenario Data ****

parameter rhsy(s,j);

loop(s\$(ord(s)<=16),
rhsy(s,'1') = 0;
);

loop(s\$(ord(s)<=32 and ord(s)>16),
rhsy(s,'1') = 1;
);

loop(s\$(ord(s)<=48 and ord(s)>32),
rhsy(s,'1') = 2;
);

loop(s\$(ord(s)>49),
rhsy(s,'1') = 3;
);

loop(s\$(ord(s)=1 or ord(s)=17 or ord(s)=32 or ord(s)=49),
rhsy(s,'2') = 0;
rhsy(s+1,'2') = 0;
rhsy(s+2,'2') = 0;
rhsy(s+3,'2') = 0;
);

loop(s\$(ord(s)=5 or ord(s)=21 or ord(s)=36 or ord(s)=53),
rhsy(s,'2') = 1;
rhsy(s+1,'2') = 1;
rhsy(s+2,'2') = 1;
rhsy(s+3,'2') = 1;
);

loop(s\$(ord(s)=9 or ord(s)=25 or ord(s)=40 or ord(s)=57),
rhsy(s,'2') = 2;
rhsy(s+1,'2') = 2;
rhsy(s+2,'2') = 2;
rhsy(s+3,'2') = 2;
);

loop(s\$(ord(s)=13 or ord(s)=29 or ord(s)=44 or ord(s)=61),
rhsy(s,'2') = 3;
rhsy(s+1,'2') = 3;
rhsy(s+2,'2') = 3;
rhsy(s+3,'2') = 3;
);

loop(s\$(ord(s)=1 or ord(s)=5 or ord(s)=9 or ord(s)=13 or ord(s)=17 or ord(s)=21 or ord(s)=25 or ord(s)=29 or ord(s)=33 or ord(s)=37 or ord(s)=41 or ord(s)=45 or ord(s)=49 or ord(s)=53 or ord(s)=57 or ord(s)=61),
rhsy(s,'3') = 0;
rhsy(s+1,'3') = 1;
rhsy(s+2,'3') = 2;
rhsy(s+3,'3') = 3;
);

display rhsy;

parameter prob(s);
prob(s)=0.25*0.25*0.25;

**** Model Data ****

Parameter coefy(i,j),x(i);
coefy('1','1')=40;
coefy('2','1')=45;
coefy('3','1')=32;
coefy('4','1')=55;
coefy('1','2')=24;
coefy('2','2')=27;
coefy('3','2')=19.2;
coefy('4','2')=33;
coefy('1','3')=4;
coefy('2','3')=4.5;
coefy('3','3')=3.2;
coefy('4','3')=5.5;
x('1') = 0; x('2') = 0; x('3') = 0; x('4') = 12;

equation obj,s2c2,s2d2;
variable objective;
positive variable y(i,j);

parameter rhsy2(j);

parameter Ds2c2p(s,i);
parameter Ds2d2p(s,j);

obj..         sum(i,sum(j,coefy(i,j)*y(i,j))) =e= objective;
s2c2(i)..        sum(j,y(i,j))-x(i) =l= 0;
S2d2(j)..        sum(i,y(i,j)) =g=  rhsy2(j);

model mymodel /all/;

Set dict /s.      scenario.       ''
rhsy2.  param.          rhsy
s2c2.   marginal.       Ds2c2p
s2d2.   marginal.       Ds2d2p
/;

* GUSS Method
solve mymodel min objective use lp scenario dict;

\$ontext
loop(s,
rhsy2(j) = rhsy(s,j);
solve mymodel use lp min objective;
Ds2c2p(s,i) = s2c2.m(i);
Ds2d2p(s,j) = s2d2.m(j);
);
\$offtext
``````
When compiled it, it gave an error saying "Symbol rhsy2 in dimension one in scenario dictionary has no data". However, parameter rhsy is not empty.

If you delete the solving code of GUSS method, and the \$ontext \$offtext in the very end, which is going to solve the problem traditionally, it works fine.

I have gone through the GUSS documentation but found nothing useful for this issue. Does anybody have any idea?

BTW you might find the way I created the rhsy parameter a little bit tedious, but I do not have any other idea to do this. My another topic is relevant to this.
viewtopic.php?f=9&t=10428

Best,
Gabriel

bussieck
Moderator Posts: 373
Joined: 3 years ago

### Re: GUSS issue for parallel computing

Hi,
GUSS solves the base case first, i.e. the model with the given values for parameter rhsy2. This parameter has not been filled with data hence GUSS or better GAMS complains. Just remove the "scenario dict" from the solve statement and you get a very similar compilation error. Even though GUSS allows you to skip solving the base case GAMS still requires you to initialize the variable parameters in the model because it uses this to instantiate the model. Hence you have two alternatives:

- set rhsy2 to some useful value or
- set rhsy2 to something (e.g. 0) and skip the base case:

Here is the code for the latter:

Code: Select all

``````...
Set mattrib / system.GUSSModelAttributes /;
Parameter
srep(s, mattrib)  'model attibutes like modelstat etc'
o(*)              'GUSS options' / SkipBaseCase 1 /;

Set dict /s.      scenario.       ''
o.      opt.            srep
rhsy2.  param.          rhsy
s2c2.   marginal.       Ds2c2p
s2d2.   marginal.       Ds2d2p
/;

* GUSS Method
rhsy2(j) = 0;
solve mymodel min objective use lp scenario dict;
``````
After implementing this I got another issues:

Code: Select all

``````**** The following LP errors were detected in model mymodel:
**** 795 Domain violation for symbol Ds2c2p in scenario dictionary
``````
Trouble is that you declared the equation as

Code: Select all

``````equation obj,s2c2,s2d2;
``````
This means that they are declared over the universe (*) but you declared the parameters over the domains i and j:

Code: Select all

``````parameter Ds2c2p(s,i);
parameter Ds2d2p(s,j);
``````
GUSS needs matching or at least consistent domain of the symbols in the model and the reporting symbols. So you either change the second domain in the Ds2.2p to * or better declare the equations with a proper domain:

Code: Select all

``````equation obj,s2c2(i),s2d2(j);
``````
-Michael

GabrielYin
User Posts: 57
Joined: 1 year ago
Location: Dallas, TX, USA

### Re: GUSS issue for parallel computing

bussieck wrote:
1 year ago
Hi,
GUSS solves the base case first, i.e. the model with the given values for parameter rhsy2. This parameter has not been filled with data hence GUSS or better GAMS complains. Just remove the "scenario dict" from the solve statement and you get a very similar compilation error. Even though GUSS allows you to skip solving the base case GAMS still requires you to initialize the variable parameters in the model because it uses this to instantiate the model. Hence you have two alternatives:

- set rhsy2 to some useful value or
- set rhsy2 to something (e.g. 0) and skip the base case:

Here is the code for the latter:

Code: Select all

``````...
Set mattrib / system.GUSSModelAttributes /;
Parameter
srep(s, mattrib)  'model attibutes like modelstat etc'
o(*)              'GUSS options' / SkipBaseCase 1 /;

Set dict /s.      scenario.       ''
o.      opt.            srep
rhsy2.  param.          rhsy
s2c2.   marginal.       Ds2c2p
s2d2.   marginal.       Ds2d2p
/;

* GUSS Method
rhsy2(j) = 0;
solve mymodel min objective use lp scenario dict;
``````
After implementing this I got another issues:

Code: Select all

``````**** The following LP errors were detected in model mymodel:
**** 795 Domain violation for symbol Ds2c2p in scenario dictionary
``````
Trouble is that you declared the equation as

Code: Select all

``````equation obj,s2c2,s2d2;
``````
This means that they are declared over the universe (*) but you declared the parameters over the domains i and j:

Code: Select all

``````parameter Ds2c2p(s,i);
parameter Ds2d2p(s,j);
``````
GUSS needs matching or at least consistent domain of the symbols in the model and the reporting symbols. So you either change the second domain in the Ds2.2p to * or better declare the equations with a proper domain:

Code: Select all

``````equation obj,s2c2(i),s2d2(j);
``````
-Michael
Thank you Michael! It works!

Gabriel