Difference between revisions of "Tips on model design"

(Created page with "Here some tips and best practices for models that are easier to build, understand, debug, and extend. == Don't embed numbers in expressions == In models build by novice mode...")
 
 
Line 1: Line 1:
 
Here some tips and best practices for models that are easier to build, understand, debug, and extend.
 
Here some tips and best practices for models that are easier to build, understand, debug, and extend.
  
== Don't embed numbers in expressions ==
+
== Use constants: Avoid numbers in expressions ==
  
In models build by novice modelers, you often see variables like this:
+
In models by novice modelers, you often see variables with definitions that contain numbers like this:
  
Variable Energy_consumption := Gas_consumption * 239.2972
+
Variable Energy_consumption := Gas_consumption * 239.2972
  
It might not be clear from looking at the Definition what the number 239.2972 means. It is actually the energy units conversion factor from million BTU per Kilowatt-hours. It's much better to create a separate Constant for that number:
+
You may wonder what the number 239.2972 means -- unless you happen to know it is units conversion factor from million BTU to Kilowatt-hours. It's much clearer if you create a separate [[Constant]] for that number:
 
  Constant KWH_per_MMBTU := 239.2972
 
  Constant KWH_per_MMBTU := 239.2972
 
  Variable Energy_consumption := Gas_consumption * KWH_per_MMBTU  
 
  Variable Energy_consumption := Gas_consumption * KWH_per_MMBTU  
  
Hopefully, you remembered to specify the units for each quantity:
+
Using a named Constant like this makes it obvious what the number means. Plus you can use this Constant KWH_per_MMBTU wherever you need it --  without having to look up and retype the number each time.
 +
 
 +
Remembered to specify the units for each quantity:
 
  Units OF Gas_consumption := 'MMBtu'
 
  Units OF Gas_consumption := 'MMBtu'
 
  Units OF Energy_consumption := 'kWh'
 
  Units OF Energy_consumption := 'kWh'
  
Using a named constant makes it much clearer what the number means. Plus you can use this Constant KWH_per_MMBTU wherever you need it without having to look it up and retype it each time.
+
If the number is a not a constant, but a model input value, like the population of the city, or a date, it's even more important to put it in its own variable, with a description explaining what it is and where it came from -- rather than embedding it into a definition.
  
 
== Don't repeat expressions in cells of a table ==
 
== Don't repeat expressions in cells of a table ==

Latest revision as of 21:27, 26 November 2019

Here some tips and best practices for models that are easier to build, understand, debug, and extend.

Use constants: Avoid numbers in expressions

In models by novice modelers, you often see variables with definitions that contain numbers like this:

Variable Energy_consumption := Gas_consumption * 239.2972

You may wonder what the number 239.2972 means -- unless you happen to know it is units conversion factor from million BTU to Kilowatt-hours. It's much clearer if you create a separate Constant for that number:

Constant KWH_per_MMBTU := 239.2972
Variable Energy_consumption := Gas_consumption * KWH_per_MMBTU 

Using a named Constant like this makes it obvious what the number means. Plus you can use this Constant KWH_per_MMBTU wherever you need it -- without having to look up and retype the number each time.

Remembered to specify the units for each quantity:

Units OF Gas_consumption := 'MMBtu'
Units OF Energy_consumption := 'kWh'

If the number is a not a constant, but a model input value, like the population of the city, or a date, it's even more important to put it in its own variable, with a description explaining what it is and where it came from -- rather than embedding it into a definition.

Don't repeat expressions in cells of a table

If you find yourself entering the same or similar expressions into some or all the cells of an edit table -- there's almost certainly a simpler and clearer way to do what you want. Consider this table:

Variable
Comments


You are not allowed to post comments.