Dear friends,
When I run the following code, GAMS does not compile this code in its written order. Could you pls help me out how I can force it to do so?
$onmulti
Variable Z;
$GDXIN Name1.gdx
$LOAD Z *** the value of Z here is equal to a***
$GDXIN
Display Z.l;
$GDXIN Name2.gdx
$LOAD Z *** the value of Z here is equal to b***
$GDXIN
Display Z.l;
But GAMS displays these values as follows:
Z => b
Z => b
How can I force GAMS to compile this code in its written order?
-
- User
- Posts: 31
- Joined: 6 years ago
-
- User
- Posts: 108
- Joined: 7 years ago
Re: How can I force GAMS to compile this code in its written order?
GAMS makes two different "passes" of the file when "preparing" the model, they are usually referred to as "compile" and "execution" phase or time.
"compile" comes first, then "execution".
As you can see in https://www.gams.com/latest/docs/UG_GDX.html $gdxin works at "compile" time, while "display" is interpreted at "execution" time.
Therefore, your code is actually executed in this way by gams:
This is the WHY of the behaviour you observe. How to obtain a different behaviour depends on what you are trying to achieve, if you let us know then we can suggest a different design.
Best
Claudio
"compile" comes first, then "execution".
As you can see in https://www.gams.com/latest/docs/UG_GDX.html $gdxin works at "compile" time, while "display" is interpreted at "execution" time.
Therefore, your code is actually executed in this way by gams:
Code: Select all
$GDXIN Name1.gdx
$LOAD Z *** the value of Z here is equal to a***
$GDXIN
$GDXIN Name2.gdx
$LOAD Z *** the value of Z here is equal to b***
$GDXIN
Display Z.l;
Display Z.l;
Best
Claudio
-
- User
- Posts: 31
- Joined: 6 years ago
Re: How can I force GAMS to compile this code in its written order?
Dear Claudio,
First of all, I have to thank you very much for your time.
In fact, I want the first display Z.l shows the value "a" and the second display Z.l shows the value of "b". For more clarification, pls look at the following code:
$GDXIN Name1.gdx
$LOAD Z *** the value of Z here is equal to a***
$GDXIN
$GDXIN Name2.gdx
$LOAD Z *** the value of Z here is equal to b***
$GDXIN
Display Z.l; ==> shows the value of a
Display Z.l; ==> shows the value of b
If my clarification is not clear, pls let me know. If you think it would be helpful, I will upload both the GDX files and written code.
Plus, if I want to write these values in an Excel file, I encounter the same problem. Considering the rule you beautifully mentioned, i.e., "compile" comes first, then "execution". , I think the solution to the problem mentioned earlier would solve the later one.
Anyway, THX a Galaxy
First of all, I have to thank you very much for your time.
In fact, I want the first display Z.l shows the value "a" and the second display Z.l shows the value of "b". For more clarification, pls look at the following code:
$GDXIN Name1.gdx
$LOAD Z *** the value of Z here is equal to a***
$GDXIN
$GDXIN Name2.gdx
$LOAD Z *** the value of Z here is equal to b***
$GDXIN
Display Z.l; ==> shows the value of a
Display Z.l; ==> shows the value of b
If my clarification is not clear, pls let me know. If you think it would be helpful, I will upload both the GDX files and written code.
Plus, if I want to write these values in an Excel file, I encounter the same problem. Considering the rule you beautifully mentioned, i.e., "compile" comes first, then "execution". , I think the solution to the problem mentioned earlier would solve the later one.
Anyway, THX a Galaxy
- Gideon Kruseman
- User
- Posts: 24
- Joined: 6 years ago
Re: How can I force GAMS to compile this code in its written order?
$gdxin is a compile time statement
display is an execute time statement
trying to link them is bound to give you problems, unless this is the only thing you are doing in the model.
The two $gdxin statements basically mean that that the second overrules the first.
unless you assign the values of z to a different GAMS item, which you obviously will have to declare first. Since I have no clue of the dimensions, I leave it up to you to figure that one out.
$GDXIN Name1.gdx
$LOAD a=Z *** the value of Z here is equal to a***
$GDXIN
$GDXIN Name2.gdx
$LOAD b=Z *** the value of Z here is equal to b***
$GDXIN
Display a.l; ==> shows the value of a
Display b.l; ==> shows the value of b
display is an execute time statement
trying to link them is bound to give you problems, unless this is the only thing you are doing in the model.
The two $gdxin statements basically mean that that the second overrules the first.
unless you assign the values of z to a different GAMS item, which you obviously will have to declare first. Since I have no clue of the dimensions, I leave it up to you to figure that one out.
$GDXIN Name1.gdx
$LOAD a=Z *** the value of Z here is equal to a***
$GDXIN
$GDXIN Name2.gdx
$LOAD b=Z *** the value of Z here is equal to b***
$GDXIN
Display a.l; ==> shows the value of a
Display b.l; ==> shows the value of b
Gideon Kruseman
ex-ante and foresight lead @CIMMYT, big data focal point @CIMMYT, coordinator CoP socio-economic data @CGIAR_BigData
ex-ante and foresight lead @CIMMYT, big data focal point @CIMMYT, coordinator CoP socio-economic data @CGIAR_BigData
-
- User
- Posts: 108
- Joined: 7 years ago
Re: How can I force GAMS to compile this code in its written order?
To make it more clear from my post and Gideon's: you can't.moosavi_69 wrote: ↑6 years ago In fact, I want the first display Z.l shows the value "a" and the second display Z.l shows the value of "b".
I think you missed my line opening the code example:
i.e. What we've tried to portray by reordering your code is that "$gdxin" statements will be always executed first than "display" statements, no matter where they are actually written in the file.Therefore, your code is actually executed in this way by gams:
Best