Trading memory for time

Top  Previous  Next

Sometimes an extensive calculation that is repeated in the model many times can be restructured so it is calculated once then saved.  For example, a component of a .. equation specification for a model solved a lot of times can be restructured to be done once and stored then only accessed later as follows.

 

obj.. Z=SUM(( CROP, TILLAGE, LANDTREAT, ROTATION ),

             ACREPLANT( CROP, TILLAGE, LANDTREAT, ROTATION)*

             SUM(INPUT, USAGE(INPUT,  CROP)));

 

Here the code is revised by defining a parameter for the input usage sum and substituting i.e.;

 

INPUTUSE( CROP) = SUM(INPUT, USAGE (INPUT, CROP));

obj.. Z=SUM(( CROP, TILLAGE, LANDTREAT, ROTATION ),

  ACREPLANT( CROP, TILLAGE, LANDTREAT, ROTATION)*

          INPUTUSE (CROP));

 

This can be a huge time saver but one needs to watch out for problems with static calculations as discussed in the calculating items chapter.