GAMS


  • Adding a new environment for code listings in LaTeX

    Documentation of code in LaTeX is easy: Just use the package listings. To be able to refer to those code snippets, you can define a new environment as follows:

    The name of the environment is {listing} and the name used for the caption is [Listing]. It was not necessary to add the name as the default is to take the name of the environment with the first character capitalized. … Read the rest “Adding a new environment for code listings in LaTeX”

  • DRY: Some useful macros in Gams

    DRY stands for “Don’t repeat yourself” and is one of the main principles of efficient programming. In Gams, I use some checks over and over again. Instead of rewriting the code or searching for a file with the existing code and copying it, I use macros in Gams. Macros aren’t difficult to write. You can find more on them here in the documentation.

    Here is a simple example from the Gams documentation defining and using a macro that calculates the reciprocal of a number:

    Read the rest “DRY: Some useful macros in Gams”

  • Checking Mappings in GAMS

    In my previous post, I showed an easy way to aggregate a matrix using mappings in GAMS. If you use a small mapping, you probably won’t make any errors, but if the sets in the mappings have many elements, the chance of an error rises. For example, you forget to map one of the elements on either side, or you map one element twice.

    Tom Rutherford wrote a nice piece of code to check your mappings. This code raises an error as soon as you make one of the mistakes mentioned above.

    Let us first set up a simple … Read the rest “Checking Mappings in GAMS”

  • Aggregating tables in Gams in a flexible way using mappings and compile-time variables

    Gams makes aggregating tables quite easy. Imagine you a table with data for 100 sectors but you want to run your model in the testing phase for an aggregation of these sectors (e.g. an aggregate the 100 sectors to the three sector groups “agriculture”, “industry”, and “services”). This is a typical situation in CGE (computable general equilibrium modeling): you have a social accounting matrix for your country and you want to start with a simple model having only a few sectors, one household, no taxes, and no government).
    In Gams you simply introduce a mapping that maps the 100 sectors … Read the rest “Aggregating tables in Gams in a flexible way using mappings and compile-time variables”

  • 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 … Read the rest “Looking for infeasibilities in Gams”


Categories

Name *

Email *