I would like to use the model and solve status in a conditional statement. My initial thought was to create a global variable based on a condition and then use this global variable in a second condition statement. I am having trouble getting the first condition to work. My code:
$ifthen %solved%==1
run some code
$else
run some other code
$endif
The problem is with the first conditional statement. Even if the conditions are met, the global variable “solved” is never set to 1. Any insight would be appreciated.
GAMS doesn’t work this way as GAMS distinguishes between compiltation and exectution time, see: https://www.gams.com/latest/docs/UG_GamsCall.html#UG_GamsCall_TwoPass
Control variables (e.g. $setglobals) are executed at compile time and the solve statment is executed at execution time. However, there are other possibilities, for example:
Indeed. I was trying to set a compile time global variable with a run time mymodel.solveStatus. Using your second option works great. thanks for your help.
Unfortunately, I was unsuccessful in creating the CSV file. Would it be possible for someone to assist me in identifying the error? Thank you in advance for your help.
Sure, then just put the logic to create CSV files described in the section I linked to in the if statement you already have. Declarations, like file fx /x.csv/, need to be done outside control structures though.