14.4 Alternation

In section , we discussed the representing parallel activities from a given domain. This included activities that may take place in paralle i.e. at the same time, but we also mention situations where an agent may alternate betwee two or more different activities.

When performing one activity, the agent may decide to suspend it temporarily and resume another activity. This form of pseudo-parallel activities is called alternation and may be supported by coroutines as described in the previous sections.

An example of alternation is a travel agent in a travel agency who may be alternating between ‘updating web pages’, ‘booking service’, and ‘invoicing’. 

An agent ‘Making a flight booking’ may switch to another activity like ‘Invoicing’. Later he/she may resume ‘Making a flight booking. 

When an agent shifts to a new activity, the current activity is temporarily suspended. Later when the agent returns to this activity it is resumed at the the point of suspension. Note that such activities do not take place in parallel – at most one of them takes place at a given point in time. 

Another example of alternation is a cook making dishes. This involves several ongoing activities by the cook who constantly shifts between those requiring his attention. 

Deterministic alternation is the situation where the agent plans by itself how to alternate between the different activites. Nondeterministic alternation is the situation where external events cause the agent to shift to another activity.

In the travel agency example, each agent serves a number of customers and has a file for each customer. An activity for an agent is to process a customer file. During a working day the agent alternates between the activities processing the customer files. Most of the time the agent will decide the order of the activities. However, external events such as telephone calls may force the agent to change activity.

For the purpose of creating a computer-based model of some domain, we need to be able to model parallel activities, deterministic alternation and nondeterministic alternation.

Cooperative coroutines described in the previous sections may be used to represent deterministic alternation. In a later section, we describe how to represent nondeterministic alternation.