Page tree
Skip to end of metadata
Go to start of metadata

Boolean Expressions and Operators

  Just to review, a Boolean evaluates to a 'true' or 'false' value (as opposed to a string or a number…).  We have seen this before in the tutorial, even though it wasn't called that.  For instance when " $a AFTER $b " is evaluated by MP in Example 15 (SUCH THAT), it comes out to either true or false.  MP also permits implication  (implies -> and if-and-only-if <->) and AND, OR and NOT which work in a manner similar to other programming languages.

Numeric Expressions and Constants

Numeric constants can just be typed in directly and then used in a way analogous to traditional programming languages.  The number of events of a specific type is accessed by the #event syntax.  The resulting expression can be used with comparison operators ( <, > etc) to form Boolean expressions.   Usage is illustrated several times in Example 16 (Car Race)

Trace annotation with SAY and MARK.

 SAY and Mark are implemented to help the user flag conditions of interest and do not impact the logic of the model.

ROOT Serious_Student: (+ Attend_class +)

  [(Go_to_library|Visit_with_friends)];

ROOT Casual_Student: (* Think_about_class [ Attend_class] *)

                Visit_with_friends;

COORDINATE

               $a: Visit_with_friends FROM Serious_Student

               DO

                              ADD SAY("This example works") PRECEDES $a;

               OD;

/*flag events of interest for easy checking in the traces.*/

IF #Think_about_class < #Attend_class THEN MARK; FI; 

Example 17 SAY and MARK

The results of SAY and MARK are shown below.  The point is to be able to quickly identify conditions of interest for individual scrutiny among the large number of potential traces.  The orange dot in the upper left of the navigation windows indicates a MARKED trace.

In this example, a by-product of having Attend_class defined as a shared event name are illustrated.  In the absence of a qualifier, Attend_class is taken to be from either of the roots.  

 

 

Figure 19 effects of MARK and names shared across roots.

In order to specify the root from which the event should be taken, the FROM qualifier can be used as shown:

IF  #Think_about_class < #Attend_class FROM Casual_Student THEN MARK; FI; 

This produces no marked traces since Think_about_class always occurs at least as many times as attending class for the casual student.   The same construct could be used to identify traces in which the serious student attends more than the casual student, etc.

The SAY in the example was already qualified with FROM so it is applied only to the serious student.

 

 

Figure 20 SAY illustrated

Context conditions with ENSURE

The MP construct ENSURE is used to enforce specified conditions within the traces generated.   This could be conditions within a single ROOT or involving multiple ROOTs

As an example, let's go back to the Attend_class model with one student.  Suppose we want only those traces where the number of times the student listens to the instructor is more than the e-mail checking.  This can be done using a BUILD (which causes the statements inside to be applied to the model) along with ENSURE as shown added onto the original example.

ROOT Student: Attend_class;

/* this is a composite event definition

 events separated by spaces indicates precedence-

meaning that they happen exactly in the order specified */

Attend_class:               Find_a_good_seat

                                             Plug_in_laptop

/* activities in {,, } may happen in parallel – concurrent events*/

{             (*Listen_to_instructor*) Make_notes,

               (*Check_your_email_during_a_pause*) }

Leave_the_classroom;

BUILD{

    ENSURE #Listen_to_instructor > #Check_your_email_during_a_pause;

    }

Example 18 Attend_class with conditions ENSURED

Without the ENSURE 18 traces are generated with all possible combinations of listening and e-mail checking.

With the ENSURE only 6 traces are generated since traces not fulfilling listen > checking are not included.

Any Boolean expression can be used after ENSURE

  • No labels