Context changes

Top  Previous  Next

Consider the optimization example from above (goodoptalgebra.gms) which involved a farming example.  This can be rewritten to another context as follows (newcontext.gms)

 

SET       Products  Items produced by firm

              /Chairs  , Tables , Dressers /

          Resources  Resources limiting firm production

              /RawWood , Labor  , WarehouseSpace/;

PARAMETER Netreturns(products)  Net returns per unit produced

              /Chairs 19  , Tables 50, Dressers 75/

          Endowments(resources) Amount of each resource available

              /RawWood 700 , Labor 1000 , WarehouseSpace 240/;

TABLE     Resourceusage(resources,products) Resource usage per unit produced

                          Chairs   Tables  Dressers

          RawWood            8        20      32

          Labor             12        32      45

          WarehouseSpace     4        12      10   ;

POSITIVE VARIABLES   Production(products) Number of units produced;

VARIABLES            Profit               Total fir summed net returns ;

EQUATIONS            ProfitAcct           Profit accounting equation ,

                     Available(Resources) Resource availability limit;

 ProfitAcct..

      PROFIT

      =E= SUM(products,netreturns(products)*production(products)) ;

 available(resources)..

      SUM(products,

          resourceusage(resources,products) *production(products))

      =L= endowments(resources);

MODEL RESALLOC /ALL/;

SOLVE RESALLOC USING LP MAXIMIZING PROFIT;

 

where only the lines in black changed not those in red relative to the farming example.  So what?  The algebraic structure once built did not need to be altered and GAMS models can easily be changed from one context to another.