Constraint agents can be built by directly
defining their waking behaviour using the notion of a ``guard''.
As an example we take a resource constraint
on two tasks, *t*1 with
duration *d*1 and *t*2 with duration *d*2 forcing them not to overlap.
The variable denotes the start time of *t*1 and
denotes the start time of *t*2.
Suppose we wish to define the agent constraint thus:
if the domain constraints on the start time of *t*1 and *t*2 prevent
*t*1 from
starting after *t*2 has finished, constrain it to finish before *t*2
has started.

This behaviour can be expressed as follows:

agent(ST1,ST2) <==> % agent name and parameters ST1 #< ST2 + d2 | % guard ST1 + d1 #<= ST2 % bodyThe guard will keep the agent suspended until the domains of and are reduced to the point that the inequation holds for every possible value of and . When this is true, it wakes up and executes the body, invoking a new agent

`ST1+d1 #<= ST2`

.
Of course this guard may never become true, in case task agent(ST1,ST2) <==> % agent name and parameters ST1 #< ST2 + d2 | % guard1 ST1 + d1 #<= ST2 ; % body1 ST2 #< ST1 + d2 | % guard2 ST2 + d2 #<= ST1 % body2This agent wakes up as soon as either of the guards are satisfied, and executes the relevant body. As soon as one guard is satisfied, the other guard and body are discarded.

Wed Sep 3 18:36:40 BST 1997