******************************************************************************** $ontext GGIG project GAMS file : EXAMPLES.GMS @purpose : Show some examples how to use globals e.g. found in include file generated by GGIG @author : Wolfgang Britz @date : 24.02.16 @since : @refDoc : @seeAlso : @calledBy : $offtext ******************************************************************************** $offlisting * * ---- these are pseuo-examples of code generated by GGIG * They would be found in an included file * $setglobal animals on $setglobal nYears 10 * ---------------------------------------------------------- * * Example 1: map a global to a scalar * * ---------------------------------------------------------- * * --- variant one with acronyms * acronyms on,off; scalar p_animals "Flag=on if animals are part of the model" / %animals% /; if ( p_animals, display p_animals ); * * --- variant two with if statements, no acronym * scalar p_animals2 "Flag=1 if animals are part of the model" / 0 /; $$if "%animals%"=="on" p_animals2 = 1; if ( p_animals2, display p_animals2 ); * ---------------------------------------------------------- * * Example 2: Let a global define which variant of code * to use * * ---------------------------------------------------------- $iftheni.animals "%animals%" == on * * --- here comes the code with the feed module swtiched on * display "Animals switched on" $else.animals * * --- here comes the code for the feed module switched off * display "Animals switched off" $endif.animals * ---------------------------------------------------------- * * Example 3: Let a global define a file to include * * (preferred over 2 especially if several * ifthen clauses are nested) * * Note: "typo" "%animals1%" prevents compilation error * as "somefile.gms" does not exist * * ---------------------------------------------------------- $ifi.animals "%animals1%" == on $include 'someFile.gms' * ---------------------------------------------------------- * * Example 4: Calculate a number from a global * and define a set from it * * ---------------------------------------------------------- $eval lastYear 1990 + %nYears% set years / 1990*%lastYear% /; display years; * ---------------------------------------------------------- * * Example 5: Introduce elements into a set * depending on a global * * Note: double $$ which allows to move the preprocessor * command away from first column available since * GAMS 24.0 * * ---------------------------------------------------------- $onempty set acts "Activities" / $$if "%animals%"==on pigs,cattle /; $offempty display acts; * ---------------------------------------------------------- * * Example 6: Calculate parameters * depending on a global, * using an acronym * * ---------------------------------------------------------- parameter p_requirements(acts); * * --- code is only an example, calculation does not make sense * p_requirements(acts) $ ( %animals% eq on) = acts.pos; display p_requirements;