Previous Page | Next Page

Formulas

Formulas

The Router, Switch, and Modifier components use formulas to control routing and set attributes. Formulas are specified in a Formula Manager window. Figure 7.6 shows one such window with the formula 5.0 + x, where x is a random variable with distribution {\cal e}(1), exponentially distributed with mean 1.

cpformul.gif (9751 bytes)

Figure 5.1: Formula Manager Window

Formulas are built using an interface that is similar to that used when building models. The palette has a set of icons that can be dragged and dropped into the Formula Manager window. You use these to build expressions. The following list shows some of the elements that are used to build expressions.

IconDescription
formula imageanother formula
formulat imagea transaction attribute
formulac imagethe simulation clock
formulm2 imagea component in the model
formulad imagean observation of a variable in a SAS data set
formulan imagea number constant
formuls2 imagea string constant

As with components, each of these elements has a pop-up menu associated with it. For example, the random variable icon formular image shown in Figure 7.6 has a pop-up menu, shown in Figure 5.2.

popupfor.gif (4744 bytes)

Figure 5.2: Pop-up Menu on the Random Variable Formula Element

If you select Edit, the window shown in Figure 5.3 is displayed. From this window, you select the distribution for the random variable. When the formula is evaluated (to set an attribute or determine transaction routing, for example), an observation of the random variable is made.

cpformur.gif (2956 bytes)

Figure 5.3: Control Panel for the Random Variable Formula Element

Another important formula element is the model element, formulm2 image. Recall the example discussed in the section "Switch Component". There, the model in Figure 3.11 routes transactions to the shortest queue. The control panel on the Switch shown in Figure 3.10 has TRUE as a case for routing to component Queue 1. This means that you want the formula associated with this switch to return TRUE if Queue 1 is shorter than Queue 2. To accomplish this, you compare the sizes of the two queues and return TRUE if the size of Queue 1 is less than the size of Queue 2.

formulaq.gif (1217 bytes)

Figure 5.4: Formula for Comparing the Size of Two Queues

Figure 5.4 shows the formula for accomplishing this. The edit window for the left-hand model element is shown in Figure 5.5.

cpformum.gif (4550 bytes)

Figure 5.5: The Model Element Edit Window

The Model list box contains the simulation components. When you select one of these components, the Query list box displays query messages for that component. When the formula is evaluated, the result of the query of the identified component will be used. For example, when the formula shown in Figure 5.4 is evaluated, the model element will query Queue 1 with the message size, which will return the number of elements in its queue. Similarly, if you edit the model element on the right-hand side of the > and set it to query size of Queue 2, the formula will evaluate to TRUE if Queue 1 has fewer elements than Queue 2. In this case, the switch will send the transaction to Queue 1.

You should be careful when validating your models that they are behaving as you want them. There is a great amount of error-checking done when formulas are evaluated, particularly with regard to type, but not every error will be detected. For example, a Router may expect a TRUE or FALSE returned from a formula, but you could enter a valid formula that evaluates to a number or a string. The QSIM Application would not detect this type of error but would function as if a nonzero number were TRUE.

The formula syntax is standard with two exceptions. First, functions of one argument, such as the trigonometric functions, are specified in reverse polish style. Thus, an expression like \log(x) would be displayed as in Figure 5.6.

formulal.gif (1109 bytes)

Figure 5.6: A Formula for the Log of a Random Variable

Functions of two arguments, such as max and min, are specified between the arguments. So, an expression like \max(x,\pi) would be displayed as in Figure 5.7.

formulam.gif (1421 bytes)

Figure 5.7: A Formula for the Maximum of a Random Variable and \pi

Previous Page | Next Page | Top of Page