You are on page 1of 7

Traffic Light for Crossing the Street

Traffic Light Control

InfSci 2511 Information Systems: Advanced Topics


Lecture 8 3/24/2003

Allow Street Crossing

Use Case: Primary Actor: Stakeholders: Description: Pre-Conditions: Post -Conditions:

Allow Street Crossing Pedestrian to cross the street when traffic so permits Pedestrian to cross the street safely and quickly. Car drivers to pass through without offense to traffic regulation
Pedestrian presses the button to make the request to cross the street. The traffic lights will respond accordingly to coordinate traffic for crossing

Pedestrian side showed a Red traffic light. Traffic lights went through sequence as described below.

Main Success Scenario:

Traffic Light for Crossing the Street:Sequence Diagram System Response


:Button
press()

Actor Intention
[1] Pedestrian wishes to cross but sees a Red light; presses the button.

:Control
check_timer()

:Timer

:ATL R:Light Y:Light G:Light

:PTL R:Light G:Light

[2] If the traffic lights for cars have not shown Green for more than 100 seconds, wait until then.

buttonPressed( )

[3] Turn the traffic lights for cars from Green to Yellow while the pedestrian side traffic lights remain Red. Keep the pattern for 5 seconds. [4] Turn the traffic lights for cars from Yellow to Red while the pedestrian side traffic lights turn from Red to Green. Keep the pattern for the pedestrians to cross the street, for 25 seconds. [5] Seeing Green, pedestrian(s) cross the street while the cars are stopped.

YellowRed
check_timer()

turn_yellow() set_alarm(5) on()

o ff()

alarm() turn_red()

RedGreen
set_alarm(25) check_timer() alarm()

off() on() turn_green() off()

on()

RedRed
[6] While the traffic lights for cars remain Red, turn the pedestrian side traffic lights to Red to stop the pedestrians. Hold for 10 seconds. [7] Turn the traffic lights for cars from Red to Green to allow cars to pass through.
check_timer()

turn_red() set_alarm(10) on()

off()

alarm()

GreenRed
set_alarm(100)

turn_green()

off()

on()

Reading
Reference book: The Unified Modeling Language User Guide Booch, Rumbaugh, Jacobson. Chapter 19 Activity Diagrams Chapters 24 Statechart Diagrams more comprehensive.

Reading
Textbook: Applying UML and Patterns: an introduction to OOAD and the UP (2 nd edition) C. Larman Chapter 29 Statechart Diagram Chapter 38 Activity Diagram (last section) not sufficiently in depth

Topics
Statechart Diagrams Activity Diagrams

Modeling Behavior
Modeling a technique for both analysis and design: State Diagram (aka: Statechart Diagram) Activity Diagram To model the behavior of Use Case Class

State Diagram
also called: Statechart Diagram so called after David Harels Statechart
Harel, D. Statecharts: A visual formalism for complex systems. Science of computing programming, Vol.8, 1987.

State Diagram
To model behavior, we recognize the following: event An event is a significant or noteworthy occurrence. EG: A switch is thrown. state A state is the condition of an object (or a system) at a moment in time (the period between events). EG: The light is on. transition A transition is a relationship between two states, indicating when the object (or system) moves from one state to another, and what happens. EG: The light is turned on (it was off).

To model the behavior of complex systems: such as


the system (or portion of) in a Use Case, or the objects of a certain Class.

State Diagram:
of a light with on/off switch
An event: switch(on)
init( )

An arc for state transition

Event which begins the start state

Operation of the State Diagram


The system begins at the start state. At any state, the system is waiting for an event to happen. (Check the out-going arcs from that state.) An event may bring the system through a state transition from one state to another. Upon state transition, the system must invoke other operations known as activities associated with the state transition. These operations may result in other events.

switch(open)

ON
switch(close)

OFF

state: ON

state: OFF
An event: switch(off)

More: Syntax for the Arc Label


On each arc for state transition, we have a label:

State Diagram Example


getFirstItem() [NOT all checked] getNextItem() Arc label with no event and no guard condition, just one action item. Arc label with no event, a compound guard condition, and no action

event [guard] action event: event with arguments [guard]: logical condition(s) to test action: action to take upon state transition Example: button(pressed) [over 100s] setTimerAlarm(10s).

Checking Items for availability

[ALL checked && ALL available]

Dispatching Delivery

[ALL checked && Some not available]

arrived(item, quantity) [ALL are available] preparePackage(orderNum); logistics.arrange(orderNum). dispatched(orderNum) notifyAccounting(orderNum)

arrived(item, quantity) [NOT all available]

Waiting to gather items

Arc label with event, guard condition, and two action items.

Order Dispatched

Arc label with one event and one guard condition, no action.

Arc label with one event, no guard condition, one action item.

Customer Order Delivery Dispatcher

Customer Order Delivery Dispatcher


Consider a system for Customer Order Delivery Dispatching. We model the sequence of operation of the system (use case) in a state diagram

State Diagram Example (1)


getFirstItem() [NOT all checked] getNextItem()

Checking Items for availability

[ALL checked && ALL available]

Dispatching Delivery

[ALL checked && Some not available]

arrived(item, quantity) [ALL are available] preparePackage(orderNum); logistics.arrange(orderNum). dispatched(orderNum) notifyAccounting(orderNum)

arrived(item, quantity) [NOT all available]

Waiting to gather items

Order Dispatched

Customer Order Delivery Dispatcher

State Diagram Example (2)


Upon entering Start State getFirstItem ( ). Start State: Checking items for availability. Three out -going arcs, but not waiting for any specific event. The guard conditions are checked state transition occurs on the arc with the guard condition tested true. If not all items are checked, state transition takes place, the actions are taken getNextItem( ).

State Diagram Example (3)


When are items are checked, if all are available, state transition takes place. System enters the state of Dispatching Delivery. Otherwise, some items are not available. System enters the state of Waiting to gather Items . No action taken in either case.

State Diagram Example (4)


In the state of Waiting to gather Items, there are two out -going arcs. On both arcs, we are waiting for the arrived(item,quantity) event, which signifies the arrival of the specified item in the specified quantity. If some items are still not available, continue to wait. But if all items are available, we move to the state of Dispatching Delivery, taking action to prepare the package, and notifying logistics department.

State Diagram Example (5)


In the state of Dispatching Delivery, there is only one out-going arc. We wait for the event dispatched(orderNum) which indicates the completion of dispatching the delivery for the specified order. Upon dispatching the delivery, state transition takes place to Order Dispatched, notifying Accounting department to collect payment.

State Diagram Example (6)


Now consider the possibility of customer calling in to cancel the order any time. We try to honor the cancellation if the delivery is not yet dispatched At any state before Order Dispatched, allow the event cancelled(orderNum) to signal the order cancelled, moving into the state of Order Cancelled.

State Diagram Example (7)


getFirstItem() [NOT all checked] getNextItem()

Checking Items for availability

[ALL checked && ALL available]

Dispatching Delivery

[ALL checked && Some not available]

arrived(item, quantity) [ALL are available] preparePackage(orderNum); logistics.arrange(orderNum). dispatched(orderNum) notifyAccounting(orderNum)

arrived(item, quantity) [NOT all available] cancelled(orderNum)

Waiting to gather items


cancelled(orderNum)

Order Dispatched

cancelled(orderNum)

Order Cancelled

Super State: the concept


Consider another view of the system for Customer Order Delivery Dispatching. When it has an order to work with, it is ACTIVE. Otherwise, it may have the order delivery cancelled, or dispatched. When it is ACTIVE, it is in a state working on the processing. If we do not care about the details of how it does processing, we may consider it just one state superstate for which we may, if so desired, get into the details.

Super State: illustrated


getFirstItem()

State of Active Processing

[NOT all checked] getNextItem()

Checking Items for availability

[ALL checked && ALL available]

Dispatching Delivery

[ALL checked && Some not available]

arrived(item, quantity) [ALL are available] preparePackage(orderNum); logistics.arrange(orderNum). dispatched(orderNum) notifyAccounting(orderNum)

arrived(item, quantity) [NOT all available] cancelled(orderNum)

Waiting to gather items


cancelled(orderNum)

Order Dispatched

cancelled(orderNum)

Order Cancelled

Super State:
facilitates a simplified view
Active Processing

Super State: fully illustrated


getFirstItem()

Active Processing
[ALL checked && ALL available]

[NOT all checked] getNextItem()

Checking Items for availability

Dispatching Delivery

[ALL checked && Some not available] dispatched(orderNum) notifyAccounting(orderNum) arrived(item, quantity) [NOT all available]

arrived(item, quantity) [ALL are available] preparePackage(orderNum); logistics.arrange(orderNum).

cancelled(orderNum)

Order Dispatched

Waiting to gather items

dispatched(orderNum) notifyAccounting(orderNum)

Order Cancelled

cancelled(orderNum)

Order Cancelled

Order Dispatched

Super State: fully illustrated


An arc may come from or go to a state within the super state the construct of the superstate is not involved. When an arc leads to the superstate, it means that it goes to the start state within the superstate. When an arc leaves from the superstate , it means that any state within the superstate may leave from the arc it is an out-going arc for all states within the super state. Such as the case or order cancellation.

Assignment 6
Given description of behavior. Draw state diagram for the traffic light system, using super states active, idle. Draw state diagram for the controller, not using any super states. Two diagrams would look quite similar! Hand drawn diagram OK if legible. Tools: Visio, Power Point, Word

Topics
Activity Diagram
Purpose Association with what? class/operation/use case Activity and Transition Condition and branches Synchronization Compound Activity Swim lanes (activities in responsibility domains) Send and Receive signals Object flow and transition labels

Topics
Statechart Diagrams Activity Diagrams

Activity Diagram
Purpose to model concurrent events and processing. Per Use Case: activities in the system Per Class: sequence of internal operations

Activity and Transition


Fill Order Activity: a processing step

Transition: done with one step, moving into the next. Send Order

Branch and Merge


Branch: one in-coming transition, multiple out -going ones, each with a condition to guard it only one should take place.

Fork and Join


Fork: one in-coming transition, multiple out -going ones, all take place in parallel action.

[ condition ]

[ else ]

Merge: one out-going transition, multiple in-coming ones, no label necessary only one in-coming transition should take place.

Join: one out -going transition, multiple in-coming ones, waits until all in-coming transitions are there to take place, for synchronization.

Start and End


Start: activities start here. There should be only one start point.

Activity Diagram Example


Traffic Light Control System

End: activities end here. May have multiple end points.

Swim Lanes
Show activities of different objects in the process.

You might also like