state Metro of
doors: <Open> | <Closed>
train: <Moving> | <Stopped> inv mk_Metro(doors,train) == not (doors = <Open> and train = <Moving>) init metro == metro = mk_Metro(<Closed>,<Stopped>) end
The following variant of Metro1 has booleans instead of enumeration typesand
implicit instead of explicit functions (note that these are not executable).
\begin{vdm_al} module Metro1a
exportsall
definitions
state Metro of
doorsopen: bool
trainmoving: bool inv mk_Metro(doorsopen,trainmoving) == not (doorsopen and trainmoving) init metro == metro = mk_Metro(false,false) end
operations
Accelerate() extwr trainmoving rd doorsopen prenot doorsopen post trainmoving;
Break() extwr trainmoving postnot trainmoving;
Open() extwr doorsopen rd trainmoving prenot trainmoving post doorsopen;
Close() extwr doorsopen postnot doorsopen
end Metro1a
\end{vdm_al}
\section{Adding the Bell Warning andTime}
There is a requirement that a bell must ring three seconds before
doors closes. The close button must remain depressed for this period.
This kind of requirement is a bit problematic to handle, but I believe
that the suggestion below works fairly well. Timeis handled almost
entirely by the environment, so it isnot part of the state. However,
the time when the bell goes on, i.e.\ starts ringing, is recorded in
the state. The operation Close is split into two operations, one for
depressing the close button and one for releasing it. The operations
CloseDepress and CloseRelease have current timeas a parameter.
\begin{vdm_al} module Metro2
exportsall
definitions
state Metro of
doors: <Open> | <Closed>
train: <Moving> | <Stopped>
bellon: [Time] -- The bell is not ringing if bellon is nil inv mk_Metro(doors,train,bellon) == not (doors = <Open> and train = <Moving>) init metro == metro = mk_Metro(<Closed>,<Stopped>,nil) end
CloseDepressed: Time ==> ()
CloseDepressed(t) ==
(bellon:= t) pre bellon = nil;
CloseReleased: Time ==> ()
CloseReleased(t) ==
(if t+3 >= bellon then doors:= <Closed> elseskip;
bellon:= nil) pre bellon <> nil
end Metro2
\end{vdm_al}
Note that my interpretation here is that the bell rings as long as the
close button is depressed and that the doors close when it is
released. Hence, I have abstracted away from the closing assistance,
but this is included in the next version.
\section{Formalizing the Requirements}
Finally I have taken a radically different approach. The idea isto
model a system scenario, or a system ``life-time''. Here
I view the systemas five sequences oftime intervals, denoting when
the close button is depressed, the bell is ringing, the doors are
open, the train is moving, and the closing assistance is
activated. The correct behaviour and safety requirements of the system
are defined asfunctions on these sequences included in the invariant of the System datatype. Note that I have abstracted away from the
accelerate and break buttons. Perhaps more surprisingly we don't need
the open button.
However the model includes the doors closing assistance, which must be
activated when the bell has been ringing for 3 seconds.
\begin{vdm_al} module Metro3
exportsall
definitions
types Time = real inv t == t>0;
Interval:: start: Time
stop: Time inv mk_Interval(s,e) == s < e;
LifeTime = seqof Interval inv s == forall i inset {1,...,len s - 1} & s(i).stop < s(i+1).start;
System::
train : LifeTime -- intervals for moving
doors : LifeTime -- intervals for open
bell : LifeTime -- intervals for ringing
closebut: LifeTime -- intervals for depressed
closeassist: LifeTime -- intervals for activated inv mk_System(train,doors,bell,closebut,closeassist) ==
NotMovingAndOpen(train,doors) and
BellOnWhenCloseBut(bell,closebut) and
CloseAssistAfter3Secs(closeassist,bell);
functions
NotMovingAndOpen: LifeTime * LifeTime -> bool
NotMovingAndOpen(train,doors) == forall t inseq train, d inseq doors & not OverlappingIntervals(t,d);
CloseAssistAfter3Secs: LifeTime * LifeTime -> bool
CloseAssistAfter3Secs(closeassist,bell) == forall c inseq closeassist & exists b inseq bell &
b.stop >= b.start+3 and
c.start = b.start+3;
BellOnWhenCloseBut: LifeTime * LifeTime -> bool
BellOnWhenCloseBut(bell,closebut) == forall b inseq bell & exists c inseq closebut &
SubInterval(b,c) -- Too loose, correct?
end Metro3
\end{vdm_al}
I have left the last two functionsas an exercise! You could probably
find more requirements to model here.
A lot of questions arised during the development of this last
specification, for example, when does the bell go on and off in
relation to the close assistance and the close button, does the bell
sound for longer than 3 secs while doors are closing?
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.