Bab 10 state diagram 2010
-
Upload
donasiilmu -
Category
Education
-
view
1.924 -
download
1
description
Transcript of Bab 10 state diagram 2010
BAB XSTATE DIAGRAM
StatechartStatechart DiagramDiagram
-- BersifatBersifat dinamisdinamis
-- MemperlihatkanMemperlihatkan statestate--state state padapada sistemsistem; ; memuatmemuat state, state, transisitransisi, event, , event, sertasertaaktivitasaktivitas..
-- MemperlihatkanMemperlihatkan sifatsifat dinamisdinamis daridariantarmukaantarmuka, , kelaskelas, , kolaborasikolaborasi dandan terutamaterutamapentingpenting padapada pemodelanpemodelan sistemsistem--sistemsistemyang yang reaktifreaktif
• Setiap objek dapat dikatakan memiliki state ---nilai dari attributnya pada suatu saat tertentu.
• State diagram memodelkan daur hidup sebuahobjek tunggal. Ia menggambarkan macam-macam state yang dimiliki sebuah objek, eventyang mengakibatkan perubahan state selamawaktu tertentu dan aturan-aturan yang mengaturtransisi objek antara satu state dengan state lainnya.
• Perubahan terhadap state objek terjadi ketikaada suatu kejadian atau ketika nilai dari salahsatu atributnya berubah. Perubahan state inidipicu oleh adanya suatu event.
SYSTEMS ANALYSYS AND DESIGN METHODS 5TH Edition Whitten Bentley Dittman
Irwin/McGraw-Hill Copyrighth@2000 The Mcgraw-Hill Companies All Right reserved
Membuat model behavior dari objek-objek
• Sebuah state diagram menunjukkan urut-urutan state dari sebuah objek selama masa hidupnya / lifetimenya, sekaligus dengan event-event yang menyebabkanperubahan dari state tersebut.
• Sebuah state diagram menjelaskan sebuah hypothetical machine (finite automaton) yang pada setiap waktuberada pada satu set finite state, yang terdiri dari:
• a finite, non-empty set of states;• a finite, non-empty set of events;• functions, yg menjelaskan transisi dari satu state ke
state berikutnya;• sebuah initial state;• satu set final state.
Developing Software Woth UML Booch Jacobson Rumbaugh
Addison-Wesley
• On opening the flight, the initial state leads to the NoReservationstate. When the state is entered, the Reset operation is executed. If a reservation is made for this flight, the object changes to the state PartiallyReserved.
• The Reserve event is associated to the homonymous Reserveaction (implemented as an operation).
• In this operation, the actual reservation takes place, and the internal reservation counter is updated. After termination of this action, we will find the object in the PartiallyReserved state.
• Each additional reservation leads to the same action. As long as a free seats are available, the object remains in the PartiallyReservedstate. If only one seat left, it changes into FullyBooked state. Cancellation of reserved seats is carried out in a similar way. Thus, the state diagram describes which actions are triggered by whichevents and under which conditions these (and together with the call of the corresponding operations) are permitted.
Soal:
Developing Software Woth UML Booch Jacobson Rumbaugh
Addison-Wesley
PartiallyReserved
FullyBooked
Closed
entry/reset()
NoReservation
cancelFlight()openFlight()
reserve()
cancel()[ReservedSeats=1]
cancel()[reservedSeats>1]
reserve()[freeSeats>1]
cancel()
reserve()[freeSeats=1]
close()
close()
Developing Software Woth UML Booch Jacobson Rumbaugh
Addison-Wesley
• Sebuah state dimiliki oleh satu buah Class danmerepresentasikan abstraksi atau kombinasi darisatu set nilai atribut yang mungkin terjadi padaobjek tersebut dari class ini.
• Tidak setiap perubahan nilai atribut akan dianggapsebagai perubahan state. Hanya event tertentuyang sangat signifikan mengakibatkan perubahanbehavior dari objek.
• Sebuah state oleh karena itu dapat dilihat jugasebagai rentang waktu (time span) antara duaevent.
• Dua type khusus state yang ada adalah initial state dan final state.
State
Developing Software Woth UML Booch Jacobson Rumbaugh
Addison-Wesley
• Tidak ada transisi yang menuju initial state dan tidak adaevent yang diperbolehkan meninggalkan final state.
• Transisi dari satu state ke state berikutnya di trigger / dipicu oleh event. Sebuah event terdiri dari nama event dan sejumlah argument.
• Event dapat memicu aksi didalam state yang dilakukanmelalui operasi tertentu.
Ada tiga trigger yang sudah predefine:• entry, fires automatically when entering a state• exit, fires automatically when leaving a state• do, fires repeatedly as long as the state is active, that is,
not left.
Developing Software Woth UML Booch Jacobson Rumbaugh
Addison-Wesley
• Sebuah state dapat diuraikan lebih lanjut, baiksekuensial ataupun paralel substate.
• Gambar dibawah ini menunjukkan sebuah sequential nesting. Ketika kontrak asuransi ditetapkan, sebuahproduk dipilih (sebagai contoh, content-nya), yang terdiridari beberapa produk element (Pel), seperti furniture, gelas, dsb. Untuk setiap produk elemen, sebuah cover (istilah asuransi) harus dibuat. Ilustrasi dibawah inimenunjukkan Create covers state dari context ini.
Substate
PElQuantityReset
Create Coverscovers:set=Empty set
DefinecoveraddPEl
addPEl
[isComplete]
Developing Software Woth UML Booch Jacobson Rumbaugh
Addison-Wesley
S1 S2
substates
event1
event2 event3
event4
S4
S3
S5
Gambar dibawah ini menunjukkan notasidari paralel substates.
Developing Software Woth UML Booch Jacobson Rumbaugh
Addison-Wesley
• Sebuah event adalah sebuah kejadian yang memiliki pengaruh khusus dalam suatu context yang dibicarakan, karena ia men-trigger / memicuperubahan state.
• Kebalikan dari state, event bukan milik satu kelastertentu.
• State transition (perubahan state) biasanya dipicuoleh adanya event yang digambarkan dengan anakpanah yang menghubungkan state satu denganstate lainnya.
Event dan transition
Developing Software Woth UML Booch Jacobson Rumbaugh
Addison-Wesley
Copyright © 1997 by Rational Software Corporation
State Transition Diagram
InitializationOpen
entry: Register studentexit: Increment count
Closed
Canceled
do: Initialize course
do: Finalize course
do: Notify registered students
Add Student / Set count = 0
Add student[ count < 10 ]
[ count = 10 ]
Cancel
Cancel
Cancel
Transitionsxx yy
event [guard] | action
The event that triggers the transition
Conditions that must be met for the transition to take place
The action that takes place when the transition is taken
Transitionsxx yy
event [guard] | action
The event that triggers the transition
Conditions that must be met for the transition to take place
The action that takes place when the transition is taken
Events • General Events
– Method calls: received(customer)– Event signals: inventoryReady
• Time event– interval expiry;
tm(3 days), tm(1000 ms)– calendar/clock time; when(11:50)
• Change Event:– Change in value of some entity;
false(hasProblems)true(hasProblems)
createdcreated
sentsent
in gatheringin gathering
is received
inventoryReady
tm(3 days)
false(hasProblems)
received()
in problem
Guards (Conditions)
• Boolean expressions.• Evaluated when the transition is triggered• Types of guards:
– Simple predicate: [hasProblems], [x > 0]– Combined predicates:
[¬hasProblems ∨ (hasProblems ∧ order.sum < 100]– Guards on activities: [active(gatherItems)]– State related (we’ll get back to it later)
sentsent
in gatheringin gathering
gatheringFinished [all items were gathered]
in problemin problemgatheringFinished [items are not found]
Guards - Example
SellingSelling
UnhappyUnhappy
bid [(value >= 100) AND (value < 200)]
HappyHappybid [value >= 200]
bidbid [value < 100]
Intro | Building Blocks | Advanced
Static Conditional Branching
• A graphical shortcut for convenient rendering of decision trees
[(value >= 100) & (value < 200)]
[value >= 200]
[value < 100]
SellingSellingSelling
UnhappyUnhappyUnhappy
HappyHappyHappy
bid
Empty Transitions
• A transition can have any combination (including none) of the events, guards and actions
• When a transition does not have an event, it is taken after all the activities were ended
Cleaningdo: put waterdo: put soap
do: wash soapdo: drain
doing nothing
Employee
rest[break]
work
Workingdo: shovel
Empty Transition
work
Guards and Events
• What’s the difference between the two machines?
S1 S2E1
S3true(C)
S1 S2E1
S3[C]
What happens if C changes to True before E1?
Actions• An executable atomic computation• Types of actions
– Variable assignment:
– Throwing a signal:
– Start, or stop activities (and concatenation of actions):
sentsentsent is receivedis receivedreceived() | status := received
sentsentsent is receivedis receivedreceived() | throw(InventoryUpdate)
sentsentsent is receivedis received| start(sendBill); stop(delivery); x := x+1
Transitions - advanced• Self-transitions: Transitions can be directed to the same
state:
• Un-deterministic states – when two transitions are taken in the same time, one of will be taken in an un-deterministic fashion:
S2 E1 / c:=c+1
/ c=0
S1 S2E1
S3
[C1]
How does a Washing Machine Works?• On / Off button. Start button• (No stop button.)• Feedback is given on the current stage
(soaking, rinsing, draining, drying)• Three plans:
– Regular– Delicate (no soaking)– Super delicate (no soaking, no drying)
• Off can be clicked only before starting, or after finishing
Washing Machineoff
idle
Do: light(soak)
Do: pump(in)
soak
Do: light(rinse)
Do: stir()
rinse
Do: light(drain)
Do: pump(out)
drain
Do: light(dry)
Do: stir()
dry
click(power) click(power)
click(start) [plan=regular]
click(start) [plan=delicate
or super delicate]
tm(30 mins)
tm(30 mins)
Tm(5 mins) [plan=super delicate] | light(off)
tm(5 mins)
[plan=not super
delicate]
Tm(10 mins) | light(off)
State Explosion: An Example
What is the offbutton can be clicked at any time?
What if we want to show how many minutes left to the end of the cycle?
What if we want to come back to the same state we left?
Abstraction in Statechart
Finding Common Behavior
Separating Independent Regions
Composite States Parallel States
The State Explosion Problem
• Let– n: Num of Classes– m: Num of variables (assume equals among classes)
• Number of possible states = 2(nm)
• And...– What if the state space of each variable > 2– What about association between objects?
Class
v1 : {t, f}v2 : {t, f}v3 : {t, f}...
Class
v1 : {t, f}v2 : {t, f}v3 : {t, f}...
Class
v1 : {t, f}v2 : {t, f}v3 : {t, f}......
Composite States
Composite + History
On
off
idle
Do: light(soak)
Do: pump(in)
soak
Do: light(rinse)
Do: stir()
rinse
Do: light(drain)
Do: pump(out)
drain
Do: light(dry)
Do: stir()
dry
click(start) [plan=regular]
click(start) [plan=delicate
or super delicate]
tm(30 mins)
tm(30 mins)
Tm(5 mins) [plan=super delicate] | light(off)
tm(5 mins)
[plan=not super
delicate]
Tm(10 mins) | light(off)
click(power)
click(power)
H
deep and shallow
DiagnosingDiagnosingDiagnosing
Diagnostic1Diagnostic1
setupsetupsetup
Check blood pressure
Check blood Check blood pressurepressure
Diagnostic2Diagnostic2
Find a veinFind a veinFind a vein
Draw BloodDraw BloodDraw Blood
H*H*
HH
StopStopStoppause
return
return-full
Shift ended | clh()
clh() – clears the history
Completion Transitions• Triggered by a completion event
– generated automatically when an immediately nested state machine terminates
CommittingCommittingCommitting
Phase1Phase1Phase1
Phase2Phase2Phase2Commit DoneCommit DoneCommit Done
completion transition (no trigger)
LampFlashingLampFlashing
off/off/
FlashOffFlashOff
FlashOnFlashOn
Triggering Rules
• Two or more transitions may have the same event trigger– inner transition takes precedence– if no transition is triggered, event is discarded
on/on/
on/on/
Order of Actions: Complex Case
• Same approach as for the simple caseS1exit:exS1
S1S1exit:exS1exit:exS1
S11exit:exS11
S11S11exit:exS11exit:exS11
S2entry:enS2
S2S2entry:enS2entry:enS2
S21entry:enS21
S21S21entry:enS21entry:enS21
| initS2| initS2E/E/actEactE
Actions execution sequence:
exS11� exS1 � actE�enS2 � initS2 � enS21
Parallel States• Sometimes, some aspect of an entity are independent of other
aspects
single
married
divorced
Martial
StaffMember
Manager
employee
Parallel States Annotation
• Combine multiple simultaneous descriptions
StaffStaffMemberMember
ManagerManager
employeeemployee
StaffStaffMemberMember
ManagerManager
employeeemployee
singlesingle
marriedmarried
divorceddivorced
MartialMartial
singlesingle
marriedmarried
divorceddivorced
Martial Martial
Intro | Building Blocks | Advanced
Interactions Between Parallel States
On
idle
soak
rinse
drain
idle
Do: pump in
water
in
Regular
Delicate
click(start)
[Plan in Regular]
Entered(soak)
Tm(30)
[Plan not in Super Delicate]
Tm(30)
click(plan)
Pump PlanController
Super
Delicate
click(plan)
click(plan)
click(start)
[Plan not in Regular]
Tm(30)
Tm(30)
[Plan in
Super Delicate]
idle
Rotor
Do: spin(150rpm)
Spin Slow
Do: pump out
water
out
Entered(rinse)
Entered(drain)
Do: spin(400rpm)
Spin Fast
Exited(drain)
Exited(rinse)Tm(entered(rinse),15)
Entered(rinse)
[Plan not in Regular]
off
click(power)
click(power)
H
“Flat” and Parallel Machines
Use of Orthogonal
Regions
No Use of Orthogonal
Regions
B
C
E
G
F
A D
αααα ββββ γγγγ δδδδ
µµµµ
(in G) αααα
C,F
C,E C,G
B,GB,E
B,F
αααα ββββ
γγγγ
γγγγ
δδδδ
δδδδ
µµµµ
µµµµ
αααααααα
αααα
• Every parallel machine can be transformed into a sequential machine:
Transition Forks and Joins
• For transitions into/out of orthogonal regions:
Credit Card verification
Credit Card verification
chargingcharging
ProcessingProcessing SentSent ConfirmedConfirmed
shippingshipping
Receipt SentReceipt Sent
In problemIn problem
[ok]
[not ok] Joinfork