Skip to content

Expressions

An expression is a formula ProcessModel works out while the model runs. Anywhere you could type a plain number, a processing time, a quantity, a route condition, an attribute value, you can type an expression instead, and it is calculated fresh each time from attributes, variables, and functions.

A numeric expression returns a number. Combine values with the usual arithmetic:

  • +, -, *, / for add, subtract, multiply, and divide. Division gives a real result, so 7 / 2 is 3.5.
  • % (or the function MOD) for the remainder.
  • Parentheses to group: (a_Cost + a_Tax) * a_Qty.

There is no ^ for powers; use POW(base, exponent). Many functions are built in, including ROUND, ABS, SQRT, EXP, LN, MIN, MAX, and CLAMP:

a_Cost * 1.10
ROUND(Entity.Age, 1)
CLAMP(a_Qty, 1, 100)
POW(a_Side, 3)
MIN(a_Requested, a_Available)

A condition returns true or false. Compare two values with =, <> (not equal), <, >, <=, or >=, and combine conditions with AND, OR, and NOT:

a_Severity = "Critical" AND Entity.Age > 30
a_Region = "US" OR a_Region = "CA"
NOT Resource("Doctor").OnShift

A few things to know:

  • Test a range with two comparisons joined by AND, for example a_Score >= 70 AND a_Score <= 90.
  • Test membership with OR, for example a_Type = "A" OR a_Type = "B".
  • Test for a piece of text with FIND, for example FIND(a_Status, "Error") > 0.
  • Text comparisons ignore case, so a_Tier = "gold" matches Gold.

The same expression language is used across the model:

  • Processing time: N(15, 3) for a normally distributed time.
  • Arrival interval or quantity: E(v_Rate), or IF(WIP('Plant') < 50, 1, 0).
  • Attribute assignment: SET a_Level TO a_Score / 10.
  • Route and gate conditions: WIP("Plant") < 100 AND Resource("Doctor").FreeUnits > 0.

In action logic you can use the block form IF ... THEN ... ENDIF. In a route, arrival, or gate field, use the function form IF(condition, valueIfTrue, valueIfFalse) instead, since those fields return a single value.

An expression can mix:

  • Attributes (a_Name): a value carried by each entity.
  • Variables (v_Name): a value shared by the whole model.
  • Array cells (r_Name[i]): a value looked up by position.
  • Entity properties such as Entity.Age and Entity.TotalCost.
  • Numbers like 5 or 1.10, and text in quotes like "Critical".

For a random value rather than a fixed one, use a distribution such as T(1,3,5) or N(10,2) (see Distributions).

LegacyHow this worked in the previous version

An expression provides a value based on an evaluation of the names, constants, and symbols in the expression. Some expressions provide a numeric value; these are called numeric expressions. Others provide a true/false value; these are called Boolean expressions.

Expressions allow you to introduce variability into your model. They let you track, control, and respond to events. To create an expression you may use any combination of constants, probability distributions, attributes, and variables. These elements allow you to expand the scope and improve the credibility of your model.

This section shows you how to create expressions and how to use distributions, attributes, and variables in your model to accurately reflect the variability and randomness of the real world.

Unless otherwise stated in this manual, expressions refer to numeric expressions which consist of elements (attributes, variables, distributions, and constants) combined with normal mathematical operators ( + , - , etc.) that result in a numeric value. A numeric expression may be as simple as a variable name or as complex as a formula.

The following table illustrates the expression elements.

Element Meaning Examples

attribute name Attribute’s current value a_Weight a_Pkg_Qty a_SerialNumber

variable name Variable’s current value v_Num_In_System v_Qty_To_Go v_Total_Pieces

distribution A probability distribution N(34, 3) U(50, 5)

constant A specific number 5 10.25 19.01

The following table illustrates the use of mathematical operators.

Item Meaning Examples

addition a_Weight + 2.5 a_Pkg_Qty + 3.4

subtraction v_Num_In_System - 5 100 - v_Qty_To_Go

multiplication 5 * v_Total_Pieces a_Weight * 0.98

/ division v_Total_Pieces / 100 a_Pkg_Qty / v_Bin_Qty

() parentheses (v_Total_Pieces - v_Total) / 100 a_Pkg_Qty / (v_Bin_Qty - 100)

** exponentiation a_Pkg_Qty ** v_Total_Pieces 2 ** v_Bin_Qty

modulus a_Value1 = 10 a_Value2 = 4 a_Div = a_Value1 / a_Value2 v_Remainder = a_Value1 - (a_Div * a_Value2)// Where a_Div is an integer.

You may combine items to form a compound expression. Parentheses may be used to set off parts of the expression to be evaluated first. For information on the order in which operators are evaluated to determine the expression’s value, see Operator Precedence below.

a_Attr1 50.91 v_Var1 + 5 v_Total_Pieces + 5 * a_Pkg_Qty (a_Weight + 5) * (a_Pkg_Qty / 2) N(25, 4.8) + a_Weight * (v_Total_Pieces - 10)

In addition to numeric expressions, you may use logical operators to create Boolean expressions that compare two numeric expressions yielding a result of True or False. These expression may be used in IF…THEN statements and condition fields to make specific decisions in the model based on the values of two numeric expressions.

The following table lists and illustrates the use of Boolean operators to create Boolean expressions.

Item Meaning Examples

= equal to a_Weight = 2.5 v_Total_Pieces = 50

greater than a_Weight > 2.5 v_Total_Pieces > 50

< less than a_Weight < 2.5 v_Total_Pieces < 50

<> not equal to a_Weight <> 2.5 v_Total_Pieces <> 50

= greater than or equal to a_Weight >= 2.5 v_Total_Pieces >= 50

<= less than or equal to a_Weight <= 2.5 v_Total_Pieces <= 50

AND both expressions a_Weight = 25 AND v_Total = 30 v_Total >= 20 AND v_Total <= 30

OR Done or both expressions a_Weight > 5 OR v_Total <= 20 v_Total = 30 OR a_Weight =15

You may use simple or compound numeric expressions on either side of the Boolean operator.

**IF **v_Total_Pieces > 5 * a_Pkg_Qty THEN

**IF **(a_Weight + 5) <= (a_Pkg_Qty / 2) THEN

**IF **N(25, 4.8) + a_Weight = v_Total_Pieces - 10 THEN

**IF **a_Weight >= v_Total_Pieces AND a_Pkg_Qty > 20 THEN

**IF **v_Total_Pieces = a_Pkg_Qty OR a_Pkg_Qty > 35 THEN

As in conventional mathematics, ProcessModel evaluates expressions with more than one operator according to certain rules of precedence. Expressions with more than one operator are evaluated from left to right in the following order:

  • Terms inside parenthesis: ( )
  • Multiplication: *; and Division: /
  • Addition: +; and Subtraction: -
  • Equalities and Inequalities: =, <>, >, >=, <, <=

When I place an action logic line that contains the word TIME (e.g. VATIME) before my actual TIME statement, I get a message saying “Missing ’)’ in expression”.

This error is caused by a very specific set of conditions.

  • You must have an action logic line that contains the word TIME (e.g. v_CheckTime)
  • That same line of code must also include parentheses following the word “time”
  • That line must appear before an actual TIME statement

For example:

dl9DaGVja19UaW1lID0gQ2xvY2soKSDigJMgQ3ljbGVTdGFydApUaW1lKDEgTWluKQ==

The TIME statement is being parsed for proper syntax. But because of a bug where only the first occurrence of the word TIME is being checked, the actual time statement is misinterpreted, producing the syntax error.

If possible, move the action logic containing the word TIME (prior to the actual TIME statement) to the route or activity prior to the problem location. Or, if you can, change the name of the variable or attribute containing the word TIME.