9.10 Using Macros

Macros can be used in several ways that can be helpful in maintaining your model; such as defining a specific part of the model into a macro that will enable you to use it repetitively, thus making the model easier to maintain. Macros can also be used to give complex expressions a distinctive name and then refer to these complex expressions throughout the model by the macro. Finally, you can use them to eliminate unnecessary constraints from the model and thereby reduce the size of the problem to be solved by the LP package.

A defined macro can be used in the formula of a constraint as a term. The macro is expanded as it is replaced by the expression it represents. Macro terms can be preceded by coefficients.

Example:

    MACROS
       Revenues  := SUM(product,month:  price * Sales);
       TotalCost := SUM(product,month:  IventoryCost * Inventory
                                      + ProductionCost * Production);

    MODEL

       MAX  Profit  =  Revenues - TotalCost ;

Macros are helpful to aid readability by giving complex expressions a distinctive name. They are also used to eliminate unnecessary constraints from the model and thereby reduce the size of the problem to be solved by the LP package. See Chapter 8.2: Defining Macros for more information.


Back To Top | Maximal Home Page | Table of Contents | Previous Page | Next Page