GAMS calling GAMS, compilation & Execution phases

Problems with syntax of GAMS
Post Reply
Abhi140
User
User
Posts: 29
Joined: 3 years ago

GAMS calling GAMS, compilation & Execution phases

Post by Abhi140 »

Hi,

I have a main GAMS program that iteratively calls different GAMS programs. It needs to process the data from these programs. These programs take processed data as input from the main program.

The following code portion will help to understand the problem more clearly.

Since Dollar control statements are processed during compilation and NOT during execution. So, the Hfeasible_data.gdx file (generated from NG_nonConvex.gms) can't be opened as it will be available only after executing NG_nonConvex.gms. The same goes for RelaxedNG_output.gdx file. Now, I can't use parameter err (and others) from RelaxedNG_output.gdx file. So, it can't process any data.
Is there any way to do this? or is any material available that I can use to understand such scenarios?


Code: Select all

Set k        'Heating Network nodes';

Alias(k,l);


$GDXIN  F:\MES 13 bus Code\ginput_data.gdx
$LOAD k
$GDXIN 

*initial bounds
$call gdxxrw MES_Data.xlsx output = massflowBounds.gdx par=LineHydroBounds rng=HSSystemdata!B1:F30 cDim=1 rDim=2 ignoreColumns=D par=ioHydroBounds rng=HSLoadData!B1:H18 cDim=1 rDim=1 ignoreColumns=C,F

Set 
   mhb       'line flow bounds'       /Mkl_low, Mkl_up/
   mhlb      'In/out flow bounds'     /Mk_inLow, Mk_outUp, Mk_inUP, Mk_outlow/;
   
Parameter LineHydroBounds(k,l, mhb);
Parameter ioHydroBounds(k, mhlb);
$gdxin massflowBounds.gdx
$load LineHydroBounds, ioHydroBounds 
$gdxin

Parameters m_in, m_out, m_kl;

[b]execute.checkErrorLevel  'gams NG_nonConvex.gms lo=4';[/b]

[b]$GDXIN  F:\MES 13 bus Code\Hfeasible_data.gdx
$LOAD m_in=mw_in.l, m_out=mw_out.l, m_kl=mw_kl.l
$GDXIN[/b]

Parameter err, tol;
tol = 0.001;

Scalar del1 /0.5/
       del2 /0.2/;

scalar stopped /0/
       counter /1/;

Set count /1*10/;
       
loop(count$(not stopped),

   put_utility 'exec.checkErrorLevel' / 'gams NGsystem.gms lo=4';
   put_utility 'exec.checkErrorLevel' / 'gams DHS_directional.gms lo=4';

$GDXIN  F:\MES 13 bus Code\RelaxedNG_output.gdx
$LOAD err
$GDXIN

   
if(err < tol,
   stopped = 1;
   
else

Parameter m_in(k), m_out(k), m_kl(k,l);

$GDXIN  F:\MES 13 bus Code\Hfeasible_data.gdx
$LOAD m_in=mw_in.l, m_out=mw_out.l, m_kl=mw_kl.l
$GDXIN

display m_in, m_out, m_kl;

ioHydroBounds(k, 'Mk_inLow') = (1-del2)*ioHydroBounds(k, 'Mk_inLow')+del2*m_in(k);
LineHydroBounds(k,l,'Mkl_up') = (1-del1)*LineHydroBounds(k,l,'Mkl_up')+del1*m_kl.l(k,l);

execute_unload 'massflowBounds', LineHydroBounds, ioHydroBounds;
);

counter = counter + 1;
display counter, err;
);
GFA
User
User
Posts: 50
Joined: 5 years ago

Re: GAMS calling GAMS, compilation & Execution phases

Post by GFA »

Hi Abhi,

You might want to use the $call-statement to run NG_nonConvex.gms instead of execute-statement. Have a look here: https://support.gams.com/gams:call_gams_within_gams

Cheers,
GFA
Abhi140
User
User
Posts: 29
Joined: 3 years ago

Re: GAMS calling GAMS, compilation & Execution phases

Post by Abhi140 »

Hi,

Thank you for your response. Your input helped me a lot.
Abhi140
User
User
Posts: 29
Joined: 3 years ago

Re: GAMS calling GAMS, compilation & Execution phases

Post by Abhi140 »

Hi,

Actually, we can't use $call conditions inside the loop statement. It wouldn't open gdx file generated by another gams program which is called inside the loop. I don't if there any other way to do this.
GFA
User
User
Posts: 50
Joined: 5 years ago

Re: GAMS calling GAMS, compilation & Execution phases

Post by GFA »

Hi Abhi,

It is impossible to run your code as you didn't provide all the necessary files, so best one can do is give some guesses. For a lot of commands in compile time there is also an equivalent command for execution time. Maybe you want to use execute_load (which is in execute time) instead of $gdxin (compile time). See also: https://www.gams.com/mccarlGuide/execute_load.htm

Regards,
GFA
Abhi140
User
User
Posts: 29
Joined: 3 years ago

Re: GAMS calling GAMS, compilation & Execution phases

Post by Abhi140 »

Hi,

Yes, I have tried execute_loaddc. Inside the loop, I am calling first NGsystem gams code & then opening gdx file & then again calling DHS_directional gams code. But now, the problem is that it's not generating the RelaxedNG_output gdx file (should be generated from NGsystem gams code). Isn't it weird if I am executing NGsystem gams code first & in the next line it should open the gdx file generated from this code?

Code: Select all

put_utility 'exec.checkErrorLevel' / 'gams NGsystem.gms lo=4';   
execute_loaddc 'RelaxedNG_output', err;
put_utility 'exec.checkErrorLevel' / 'gams DHS_directional.gms lo=4';
Abhi140
User
User
Posts: 29
Joined: 3 years ago

Re: GAMS calling GAMS, compilation & Execution phases

Post by Abhi140 »

Shall I share a code reproducing the same problem?
Abhi140
User
User
Posts: 29
Joined: 3 years ago

Re: GAMS calling GAMS, compilation & Execution phases

Post by Abhi140 »

I think I got it. I will try to repost the problem with the solution.
Post Reply