190 likes | 299 Views
Reactive Programs Design. Reactive Programs. Initiate actions in response to events. Basic events are: External - generated by the environment. Process - generated by running actions. Thus, typical instruction: when e [ while C] initiate A. action. condition. activating event.
E N D
Reactive Programs • Initiate actions in response to events. • Basic events are: • External - generated by the environment. • Process - generated by running actions. Thus, typical instruction: when e [whileC]initiateA action condition activating event • e can be logical expression of basic events, • C represents a program state (internal variables)
Actions • self-terminating programs. • no internal synchronization with the environment • termination of an action execution is an internal event • Two types: • Synchronous actions - Executed in no time w.r.t. the environment clock. • Asynchronous actions - Their executions may take some time units. a sequence of synchronous actions is synchronous. Synchrony hypothesis: Synchronous actions take zero time.
Reactive Program Design Formalism when e [whileC]initiateA initial actions Execution of async. actions activating event condition actions
Reactive Program Design Formalism asynchronous actions A system under design is specified over: • E - a set of external events. • A – a set of program actions. A = Async Aasync synchronous actions • Async ,Aasync are disjoint sets • Assume actions return no value (extension to finite multiple values {v1,…,vm} is straight forward).
Action Events • With every action aA we define the events: @a – initiate execution of a, a!–termination of an execution ofa a–interrupting a (only for aAasyn ) Notation: • @A = { @a | aA } • A! = {a!, a | aA } • Obs = E A! • For aAsyn @a, a! occur at the same time instant, hence use a as a single event.
Transition System (TS) over E, A , S, T, sinit, A init = 2Obs2@A A init2@A = ,where 2Obs,2@A (-pre(), -post()) sinitS initial state set of states T: S S total on S • A behavior0,1,…is executable by TS iff • 0=, A init • s0 s1 s2 …s.t. s0=sinit andT(si,i)= si+1 i=0,1,… The language accepted by TS isthe set of all executable beaviors.
Example: XR control E={ Tin, Tout }, A={ Open, Close, Go, Stop} Ainit = {@open, stop} Sinit = {Opening } =,{@open, stop}, {open!},, {Tin},{@close}, {close!},{go},… synchronous
Real Time Programs • Initiate actions in response to events. • Specify durations to implement delaysand timeouts. • Basic events are: • External - generated by the environment. • Process - generated by running actions. • Timing - indicate time-periods expiration. Thus, typical instructions are still of the form: when x [whileC]initiateA but there is a special (async’) action:"waitn” action activating event condition time units
Clocks as a Timing Formalism A clockcis a variable over Dc = {} [0,nc] With every clock c, · the term c=ncis a clock event. · the terms reset(c), stop(c) are sync. clock actions. Informal semantics: • c= indicates the clock is disabled (initial value) • reset(c) – enables c and sets it to 0 • Enabled clock increases over [0,nc] at fixed rate c’=1 • stop(c) – disables c (sets it to ) • c=ncis generated when c reaches nc. Then, c becomes disabled, (unless the transition includes an action reset(c))
Timed Transition System (TTS) A Timed Transition System over • E - a set of external events. • A – a set of program actions. • C ={c1,…,ck}– a finite set of clocks. is a TS , S, T, sinit,A initdefined over EC,AC where EC= E {ci=nci| ciC} --clock events over C. AC= A{reset(ci), stop(ci)| ciC} -- clock actions over C. = 2Obs2@(AC)where Obs=EC(AC)! However behaviors are extended to provide time semantics
Example TTS Suppose it is requiredthat if gateopening or closing does not end within9 sec. then thesystem must activate an alarmsignal and stop functioning.
Time Progress Given a set of clocks C ={c1,…,ck}, a C-state is an assignment = (1,2,…, k) s.t.jDcj, j=1,…,k Transition are labeled by: (,’) - reflects clocks update by the time elapsed since last transition occurred. ’- reflects clocks update due to transition timing actions (reset, stop) and events.
a/reset(c) Examples: [, ’] with a single clock c wherenc=7 [-,] [,0] c=7 [-,3] [7,] after 4 t.u. c=7/reset(c) [-,3] [7,0] b/stop(c) [-,2] [4,] after 2 t.u. b/reset(c) [-,2] [4,0]
Timed Behavior A timedsequence: (0,[0, ’0],t0) (1,[1, ’1],t1) … where: • 0,1,… • i, ’i are clock-states • tiN, titi+1, and nN.j s.t. tjn, i=1,2,…
[ij,’ij] [i+1j,’i+1j] i+1j’ij(ti+1ti) ti+1 ti Consistent Behavior Atimed behavior(0,[0, ’0],t0) … is consistent iff: • 0 = , A init , 0j, j=1,…,k , t0=0 0 if reset(cj)post(i) • ’ij= if stop(cj)post(i) or ij = ncj ij otherwise • ti+1ti min{ ncj-’ij | ’ij, j=1..k } • if ’ij theni+1j’ij (ti+1ti) • cj=ncjpre(i) iff ij ncj cj=ncj [ij,’ij] [mj, ’mj 0] [kjncj, ’kj] tm tk ti ncjtktm
Semantics of TTS A consistent behavior(0,[0, ’0],t0) (1,[1, ’1],t1) … of a TTSover EC,AC is executableiff there exists an infinite state sequence: s0 s1 s2 … such that s0=sinit and for every i=0,1,…, T(si, i)= si+1 The language accepted by TTS is the set of all executable beaviors.