Looking for infeasibilities in Gams

A good CGE modelers always checks the calibration of a CGE model using a simple trick: If you set the iteration limit of the model to zero and you try to solve the model, GAMS should find a solution if you correctly initialized and wrote down your model equations with the use of the benchmark data. Often, the calibration is not done properly and this can be seen (using the iteration set to zero) by looking at the infeasibilities of the equations and the variables.

If you use MPSGE to write down your model, the infeasibilities are easily interpreted. If the activity variables show infeasibilities the corresponding zero-profit condition is not met, if the price variables show infeasibilities the corresponding market clearing condition is not met. Either the equation, the initialization or the data is wrong.

Looking for infeasibilities in the listing can be daunting. A simple model can have hundreds of variables and finding the infeasibilities can become time consuming. Therefore, I wrote a small Python script that uses some regular expression magic to find the infeasibilities and show them. Below is an example. It shows all variables with an infeasibility greater than 1E-5. The script runs very fast.

Feel free to use and/or improve the code (I just started learning Python). The script looks like this (assuming that the listing file is called “BenchF.lst”):