Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Make_notes always follows Listen_to_instructor which can be concurrent with Check_your_email_during_a_pause.   Remember, spaces indicate precedence and commas indicate concurrence.  To be able to see the concurrence clearly on the GUI, pulling to the side to separate the IN from the FOLLOWS is needed.  Note as shown by the highlighting that the parallel paths (concurrence) is now shown clearly on the GUI.

Optional Events

 

Now suppose we want to model the possibility that after class you might want to proceed to the library to study more, but you also might want to just go home.  It also might be that you skip class and just go the library.  So, we add the event Go_to_library  to the prior example (.  Note that Go_to_library is made optional  by the [ ] syntax and that it is added as an event separate from Attend_class.  In this example precedence between the two upper level events is set with Attend_class always before Go_to_library which is indicated by the space between them.

 

Notice that this is a different way of framing the problem than many other programming languages which would use an explicit if-then-else structure and would have to explicitly specify the conditions under which you went to the library (or not). In MP the focus is on the possibility of this behavior happening rather than understanding the exact conditions under which it might happen (which is, of course, important at the end of the day and can be specified in MP, but not right now).  If I really want to specify reasoning for deciding library or not library, conditionals, as explained in Example 2 Weather With Conditionals, would be appropriate.

 

Example 4 Optional Events

ROOTStudentAttend_class  [Go_to_library];

 

/* this is a composite event definition */

Attend_class: Find_a_good_seat

               Plug_in_laptop

 

/* these activities may happen in parallel */

{ Listen_to_instructor,

Make_notes,

   Check_your_email_during_a_pause }

 

Leave_the_classroom;

 

This generates four traces total: no class,  library only, class+library, class only.    Notice that class and library happen in a sequence (i.e. precedence), but are independent events.   In contrast, all the elements inside the composite event Attend_class always happen (whever Attend_class happens).  The reason for generating only a single trace for Attend_class despite showing three events is that the { } confers the meaning that order does not matter, so there is only one trace necessary.

 

Now let’s add an optional event Ask_prof_a_question before leaving the classroom.

 

Example 5 More Optional Events

ROOTStudent:  Attend_class[Go_to_library];

 

/* this is a composite event definition */

Attend_class: Find_a_good_seat

               Plug_in_laptop

 

/* these activities may happen in parallel */

{ Listen_to_instructor,

Make_notes,

   Check_your_email_during_a_pause }

 

        [Ask_prof_a_question]

 

Leave_the_classroom;

 

The placement outside { } indicates that you can't interupt the Prof to ask your question.

.Image Added

 

Figure 8 Example 5 Trace 1

Attend_class is collapsed (by clicking on the pencil icon) to hide the atomic events.  You can see this on the GUI by the bars on the left of the Attend_class.

 

 

Figure 9 Example 5 Trace 2

In this sequence of events (trace) you went to the library after class.  Dragging the Go_to_library on the GUI allows you to see that library follows attending class (solid arrow). 

 

 

Figure 10 Example 5 Trace 3

The collapsed Attend_class makes this look just like trace #1 because the two alternatives within Attend_class (ask question or don't) are hidden.   Using the event collapse on the GUI can be a good way to reduce clutter, but just be aware of what you are looking at.

 

Trace 4 is similar to trace #2 shown above. 

Figure 11 Example 5 trace 4

 

Simplify Visuals Through Decomposition

As you can see this example has a lot of different atomic events shown in each trace, which can easily become hard to digest visually.   An alternative way to think about the problem by using more decomposition can help with this.  The decomposition in this example is specifically chosen in a way which keeps all non-optional events together inside a single parent event.  Now, when the parent nodes are collapsed you can easily see that the four event traces come from the inclusion/exclusion of the two optional events (library and question) with all other things being equal.

 

 

ROOT Student:  Attend_class [Go_to_library];

 

/* this is a composite event definition */

Attend_class:             

              get_ready lecture [Ask_prof_a_question]

                             Leave_the_classroom;

 

get_ready: Find_a_good_seat Plug_in_laptop;

 

lecture:

              /* these activities may happen in parallel */

              {             Listen_to_instructor,

                            Make_notes,

                             Check_your_email_during_a_pause };

 

Example 6 Attend_class with more decomposition

 

 

 

 

 

 

 

 

 

 

 

Now let us say that sometimes you go Visit_with_friends instead of going to the library.  This is included as an alternative event as shown.   Note that the ( ) syntax must be used, not just the |, to indicate “or”.  This allows sequences of events to be included in the or construct.  Also note that since the first line

is getting a bit long, you can just continue to the next line with no special continuation character.  Indentation is good coding practice for readability, but is NOT enforced by MP.

 

Example 7 Optional And Alternative and Line Continuation

 

ROOTStudent: Attend_class

  [(Go_to_library|Visit_with_friends)];

 

/* this is a composite event definition */

Attend_class:              Find_a_good_seat

               Plug_in_laptop

 

/* these activities may happen in parallel */

{ Listen_to_instructor,

Make_notes,

   Check_your_email_during_a_pause }

 

        [Ask_prof_a_question]

 

Leave_the_classroom;

 

You now have another option (Visit_with_friends) and there is also Visit_with_friends option if you do not attend class since library and friends are independent (and mutually exclusive in this case) events.

Iterating With MP (Repetitive Event Patterns)