Real-Time Behavioral Semantics of DSMLs
7.3 Real-time Behavioral Semantic Mappings
7.3.5 Encoding of Ongoing Rules
Ongoing rules are used to model actions that progress with time. Since the delta function defines the effect of time over the model objects, we will encode ongoing rules into thedelta function itself. However, the maximal duration and time upper bounds of current executions of ongoing rules also affect the maximal time elapse (mte) of the system (see Section 7.3.7). Since the maximal time elapse is computed before thedeltaoperation is, we also include a rewrite rule per each ongoing rule that creates an object at the triggering of the ongoing action that represent a possible execution of the action. This object will gather all the information about the rule instantiation (including its maximal duration), which will make it accessible when the mteoperation is invoked (and in fact before the corresponding ongoing rule is realized).
7.3.5.1 The Initial Rule
The initial rule of an ongoing action is encoded as the triggering rule of an atomic action. When the rule precondition is satisfied, an object of theOngoingActionExecclass (which inherits from theActionExecclass) is created, indicating that the corresponding ongoing rule can be executed at that moment of time. This object gathers all the information about its instantiation, including the OCL expression that represents the maximal duration (maxTimerattribute), and a new timer that represents a countdown to the rule’s upper bound (upperBoundTimer at-tribute). This upperBoundTimer timer is only needed in ongoing action executions: since ongoing rules do not have a specific duration, their upper bound also act as a maximal bound for their duration.
As an example, the following Maude specification corresponds to the encoding of the Bat-teryConsumptionaction’s initial rule (see Figure 7.10):
1 c r l [ BatteryConsumption@Triggering ] :
2 MM@ { --- LHS elements
13 < ACTEXC@ : OngoingActionExec | action : "BatteryConsumption",
14 maxTimer : freeze ( p . battery / p . bps ) , variables : Set{mt} ,
15 startingTime : TIME@CLK@ , endingTime : null ,
16 participants : Set{OR1@} , upperBoundTimer : null >
17 < OR1@ : ObjectRole | actualObject : p , role : "p" >
24 /\ not currentExec@BatteryConsumption ( Set{p} , MODEL@ )
25 /\ toRat ( eval ( p . battery / p . bps , env ( empty ) , MODEL@ ) ) > 0
26 /\ ON@p@ATT := eval ( true , env ( self <− p ) , MODEL@ )
27 /\ ACTEXC@ := newId ( VALUE@ids@ )
28 /\ OR1@ := newId ( VALUE@ids@ + 1) .
Ongoing rules’ maximal duration expressions are frozen (i.e., maintained unevaluated with thefreezeoperation in themaxTimerattribute) to be later computed in themtefunction to
get the current (real) values of the elements involved in the expression at that moment of time.
However, they are also computed in the rule (see line 25) to forbid its triggering in case the maximal duration is not greater than zero. In the above rule, theupperBoundTimerattribute is set tonull, since theBatteryConsumptionrule’s upper bound is not specified.
op freeze : OCL−Exp −> OCL−Type .
--- No equations, so the operation is not evaluated
Finally, note that Maude rules are applied in a non-deterministic order. Therefore, the realization rule of an atomic action can be applied, e.g., after the execution of the initial rule of an ongoing action. This application can make anOngoingActionExecobject to represent an invalid action execution: since the state of the system may change from the moment of the generation of anOngoingActionExecobject to the moment in which the ongoing action is in fact realized (the moment in which the delta operation is applied), the precondition of the action that represents the OngoingActionExec object may be violated. These invalid OngoingActionExecobjects will be removed from the specifications, as we shall see below.
7.3.5.2 The applyOngoingRules Operator
In the following time elapse, the delta equation calls the applyOngoingRules function.
One applyOngoingRules equation defining the operator is added for each ongoing rule.
This equation checks whether the ongoing rule’s precondition is satisfied (note that the system state may have changed from the moment on which the OngoingActionExec object was created), and if so, it substitutes the LHS matching by its RHS and sets the ending time and maximal duration of theOngoingActionExecobject.
op applyOngoingRules : @Model Time−> @Model . ce q applyOngoingRules(
MM@ { --- LHS elements
< p : PHONE@p@CLASS | on : ON@p@ATT # battery : BATTERY@p@ATT # p@SFS >
--- Ongoing action execution element
< ACTEXEC@ : OngoingActionExec | action : "BatteryConsumption" # endingTime : null # participants : Set{OR1@} # variables : Set{mt} # maxTimer : freeze ( MAXDURATION@ ) # ACTEXC@@SFS >
< OR1@ : ObjectRole | actualObject : p # role : "p">
--- Further elements
< CLK@ : Clock | time : TIME@CLK@ >
< ’ids@ : Counter | value : VALUE@ids@ >
< ’rdm@ : Counter | value : VALUE@rdm@ >
OBJSET } , T)
= applyOngoingRules ( readjust( Set{mt} ,
MM@{ < p : PHONE@p@CLASS | on : ON@p@ATT #
battery : eval ( p . battery− T ∗ p . bps , env ( self <− p ) , MODEL@ ) # p@SFS >
--- Ongoing action execution element
< ACTEXEC@ : OngoingActionExec | action : "BatteryConsumption" # endingTime : ( T plus TIME@CLK@ ) # participants : Set{OR1@} #
variables : Set{mt} # maxTimer : toRat ( eval ( MAXDURATION@ , env ( empty ) ) # ACTEXC@@SFS>
< OR1@ : ObjectRole | actualObject : p # role : "p">
< CLK@ : Clock | time : TIME@CLK@ >
< ’ids@ : Counter | value : VALUE@ids@ >
< ’rdm@ : Counter | value : VALUE@rdm@ >
OBJSET } ,
= joinOngoingActionExecs ( deleteInvalidActionExecs ( MODEL ) ) [ owise ] .
The current system time elapse Tis provided by thedeltaoperation (see the second ar-gument of the applyOngoingRule operation). This value is used to perform the attribute computations that depend on it (such as the above expression (p . battery - T * p . bps)), and set the rule’s ending time. TheapplyOngoingRuleoperation is recursively called until every possible execution of an ongoing action is realized, and thus theendingTimeof the OngoingActionExecobjects that represent them are set. RemainingOngoingActionExec objects with an undefinedendingTimerepresent current invalid actions, i.e., actions that can-not be performed in that moment of time. These invalid applyOngoingRules objects are deleted (including the Variableand ObjectRole objects referred by them) in the owise equation.
op deleteInvalidActionExecs : @Model−> @Model .
eq deleteInvalidActionExecs( MM { < O : OngoingActionExec | endingTime : null # participants : SET # variables : SET ’ # SFS ) >
OBJSET })
= deleteInvalidActionExecs ( deleteEls ( << SET−> union ( SET ’ ) >>, MM { OBJSET }) ) . eq deleteInvalidActionExecs( MODEL ) = MODEL [ owise ] .
ThejoinOngoingActionExecsoperation joins ongoing action execution elements that represent consecutive executions of the same ongoing action with the same set of participants.
In particular, it refines the information gathered by a previous-in-timeOngoingActionExec object with the information provided by the new occurrence. This operation has been defined to prevent the model from being flooded withOngoingActionExecobjects with short execution times.
va r ST : String . v a r s MAXT MAXT’ : Time .
op joinOngoingActionExecs : @Model −> @Model . ce q joinOngoingActionExecs(
MM { < O : OngoingActionExec | action : ST # participants : SET # maxTimer : MAXT # endingTime : T # SFS >
< O ’ : OngoingActionExec | action : ST # participants : SET ’ # maxTimer : MAXT ’ # startingTime : T # variables : SET ’ ’ # endingTime : T ’ # SFS ’ >
OBJSET })
= joinOngoingActionExecs (
deleteEls( << SET−> union ( SET ’ ) >>,
MM { < O : OngoingActionExec | action : ST # participants : SET # maxTimer : i f ( ( MAXT = / = null ) and−then ( MAXT ’ =/= null ) )
then ( MAXT plus MAXT ’ ) else MAXT fi # endingTime : T ’ # SFS >
OBJSET }) )
i f sameParticipantsAndRoles( SET , SET ’ , MM { . . . OBJSET }) . eq joinOngoingActionExecs( MODEL ) = MODEL [ owise ] .
ThesameParticipantsAndRoles operation checks whether two set ofObjectRole ele-ments refer to the same set of action participants playing the same role.