computer science 520/620 consistency is a principal concern

17
CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved Computer Science 520/620 Spring 2011 Prof. L. Osterweil Software Models and Representations Part 2 CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved Consistency is a principal concern Are the diagrams consistent with each other? Top view consistent with elaborations? Arrows consistent Data flows consistent Other semantics? Invitation to subtle errors CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved An Example: Elevator Software Representation Modern elevators are controlled using software Software is usually complex Some issues the software must deal with: Functionality » Respond to all calls » Coordination of multiple elevators » Treat all calls fairly; donʼt make anyone wait too long Speed » Donʼt spend too much time optimizing » Donʼt send people in the wrong direction Safety » Donʼt move elevator with doors open CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved What Representations Support Answering These Stakeholder Concerns Buyer (Elevator Company) Before development: What should it do? » What does it mean to be “fair” to all riders? During development: What will it do? » What scheduling algorithm to use? » How to coordinate multiple elevators? » Is the project on time? After development, before delivery: What does it do? » Does it do what it was intended to do? Software developer: How should it be developed? » What is the system architecture? » What scheduling algorithm to use? User (rider): Why does it take so long? act so weird? Safety Inspector: Is it safe? CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved Answering many of these questions can be facilitated by allowing hierarchical decomposition CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved Data Flow Diagram Current Floor New Floor Turn off Light Button Press Turn on Light Request List Select New Floor Move Elevator New Floor Update Request List New Request Delete Request Just Satisfied Get copy of Request List

Upload: others

Post on 18-Apr-2022

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Computer Science 520/620 Consistency is a principal concern

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Computer Science 520/620 Spring 2011

Prof. L. Osterweil"

Software Models and Representations"

Part 2"

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Consistency is a principal concern"

•  Are the diagrams consistent with each other?"•  Top view consistent with elaborations?"

– Arrows consistent"– Data flows consistent"– Other semantics?"

•  Invitation to subtle errors"

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

An Example: Elevator Software Representation"

•  Modern elevators are controlled using software"•  Software is usually complex"•  Some issues the software must deal with:"

– Functionality"» Respond to all calls"» Coordination of multiple elevators"» Treat all calls fairly; donʼt make anyone wait too

long"– Speed"

» Donʼt spend too much time optimizing"» Donʼt send people in the wrong direction"

– Safety"» Donʼt move elevator with doors open"

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

What Representations SupportAnswering These Stakeholder Concerns"•  Buyer (Elevator Company)"

– Before development: What should it do?"» What does it mean to be “fair” to all riders?"

– During development: What will it do?"» What scheduling algorithm to use?"» How to coordinate multiple elevators?"»  Is the project on time?"

– After development, before delivery: What does it do?"» Does it do what it was intended to do?"

•  Software developer: How should it be developed?"» What is the system architecture?"» What scheduling algorithm to use?"

•  User (rider): Why does it take so long? act so weird?"•  Safety Inspector: Is it safe?"

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Answering many of these questions can be facilitated by

allowing hierarchical decomposition"

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Data Flow Diagram"

Current Floor

New Floor

Turn off Light

Button Press Turn on

Light

Request List

Select New Floor

Move Elevator

New Floor

Update Request List

New Request

Delete Request Just Satisfied

Get copy of Request List

Page 2: Computer Science 520/620 Consistency is a principal concern

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Hierarchical Elaboration (of “Select New Floor”)"

Current Floor

Request List

Process Request List

Do Updates

New Status

Floor to Move to

Floor

Floors in the right direction

Direction

Find Nearest Floor Consider

Other Cars

New Floor

Rejection

Floor

Delete Floor Selected

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Simplified Case"

Check"args."

Check args."

height"

width"

args OK"

args not OK"

height"

width"

args OK"

args not OK"height">0"width"

>0"

valid"width"

valid pair"

height"> width"

valid"height"

no"

no"no"

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Consistency is a principal concern"

•  Are the diagrams consistent with each other?"•  Top view consistent with elaborations?"

– Arrows consistent"– Data flows consistent"– Other semantics?"

•  Invitation to subtle errors"

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Service *"

•  Service Oriented Software "•  Service Science"•  Service-based Development"•  ----"

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Service *"

•  Service Oriented Software "•  Service Science"•  Service-based Development"•  ----"

What do these things mean?"

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Service *"

•  Service Oriented Software "•  Service Science"•  Service-based Development"•  ----"

What do these things mean?"What are the problems in doing them?"

Page 3: Computer Science 520/620 Consistency is a principal concern

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Consistency definitions"•  Let NodeAnnotation(n, somenode) for some n∈ N,

where ParentGraph = (N, E)"•  Let somenode = (Nʼ, Eʼ) "

– This is the DFG elaborating on “somenode”"•  Some consistency properties"

– If {(mi, n)} ≠ ∅ , mi, n ∈ N, "then | INPUT(somenode) | ≠ 0"

– If {(n, mi)} ≠ ∅ , mi, n ∈ N, "then | OUTPUT(somenode) | ≠ 0"

•  Maybe some others(?)"– If | {(mi, n)} | = k, mi, n ∈ N, "then | INPUT(somenode) | = k"

– If {(n, mi)} = k , mi, n ∈ N, "then | OUTPUT(somenode) | = k"

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Data Flow Diagram"

Current Floor

New Floor

Turn off Light

Button Press Turn on

Light

Request List

Select New Floor

Move Elevator

New Floor

Update Request List

New Request

Delete Request Just Satisfied

Get copy of Request List

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Elaboration of “Select New Floor”Suggests Artifact Issues"

Current Floor

Request List

Process Request List

Do Updates

New Status

Floor to Move to

Floor

Floors in the right direction

Direction

Find Nearest Floor Consider

Other Cars

New Floor

Rejection

Floor

Delete Floor Selected

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Data needs precise specification too"• DFD's focus on functionality, using data as a vehicle"

• Data shown as unstructured atomic units--usually unrealistic"

• Complex functions cannot be adequately defined without" delving into the details of how they handle structured data"

• Sub-DFD's can show how the high level data that high " level DFD's deal with is decomposed" --But this is implicit data definition" --Can be hard to read/inconsistent"

• Data specification is worth doing explicitly, carefully"

• Usually using Disciplined Natural Language--eg. templates" --Hierarchical relations" --Function(s) creating and using data" --Possible other attributes: "

" "persistent? where? encoding? ... "

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

IDEF0"

•  Commercial DFD formalism"•  Some formality and rigor behind it"•  Primarily pictorial"•  In wide use"•  Additional semantics in IDEF1, IDEF2, etc."

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Page 4: Computer Science 520/620 Consistency is a principal concern

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Note: The edges here do not comprise a setThey comprise a collection."

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Broadening DFG Semantics"•  Node cannot begin until data arrives along all in-edges"

– DFGNODE is set of nodes, {dfgnodei} such that dfgnodei is a function defined on the set of all artifacts IAi = {iai}, such that iai is an annotation on an edge (dfgnodej, dfgnodei)"

•  How to adapt this for "– any semantics? "– for output semantics?"– exactly one Output node "– Etc."

These sorts of constraints can support additional types of reasoning: Eg. about parallelism

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

More Broadening"• Use of "open boxes" to indicate data store" --A different set, with different semantics" --Not a computation function" --Methods are: put, get, search(?)"

LIBRARY"Buy"new"books" new "

books"

Borrow" a" book"

book"

Page 5: Computer Science 520/620 Consistency is a principal concern

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Still More Broadening"

•  Different shapes of boxes"•  Different pictures instead of boxes"•  Different colors"•  Different lines"•  ……."

Central questions: What are the semantics? Does this really help? Or confuse?

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Kepler--Another DFG Technology"

•  Data Flow diagram notation"•  Has hierarchical decomposition"•  Capability for specifying DFD semantics"

– For each diagram"– Can be different at each level of hierarchy (!)"

•  Based on Ptolemy II system"– P. Baldwin, S. Kohli, E.A. Lee, X. Liu, and Y. Zhao.

“Modeling of Sensor Nets in Ptolemy II. in Proc. of Information Processing in Sensor Networks”, (IPSN), April 26-27, 2004, pp.359-368.

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

What kinds of questions are well addressed by DFGs?"

•  Overall structure of functional capabilities"– What does this piece do?"

•  System outputs and inputs"•  How might changes be made?"•  What functions create what data entities"

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Given that Precision is essential"

•  What about the other three dimensions?"•  Detail"

– Gained from hierarchical elaboration"•  Breadth"

– Comes from different (sub)types of DFG"•  Clarity"

– Seems to be reduced by increased Detail and Breadth"

– With the need for Precision"

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Clarity helps appeal to diverse stakeholders"

•  Users"•  Developers"•  Managers"•  Evolvers"•  Bystanders (?)"

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Final observations"• Very primitive representation"

"--very limited semantics"

• But actually more a family of model types""--different sets of semantics"

• The actual relation(s) are rarely made clear and precise"

• Powerful aid to intuition and efficiency of communication" --Clear advantages over natural language"

• But is intuition misled by ambiguity, misinterpretation?"

• Does not help explain HOW things get done"

Page 6: Computer Science 520/620 Consistency is a principal concern

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Control Flow Diagrams"• Semantics are different from DFD's semantics" --Arrows represent flow of control, rather than flow of data" --Different shapes/types of boxes with different semantics"• Basic control flow graph:" --Boxes represent functions" --Some other shape represents control flow alternation" --Arrows represent control flow: " If there is an arrow from circle A to circle B, it means" ImmFol: "the execution of B can immediately follow " the execution of A for some execution”" --Different semantics for arrows between different shapes" --Still other shapes represent Start and Stop" --Use of hierarchy for elaborating boxes"• Usual enhancements:" --Annotate edges with predicates" --Special symbols for branching, concurrency control...."

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Control Flow Diagrams"• Semantics are different from DFD's semantics" --Arrows represent flow of control, rather than flow of data" --Different shapes/types of boxes with different semantics"• Basic control flow graph:" --Boxes represent functions" --Some other shape represents control flow alternation" --Arrows represent control flow: " If there is an arrow from circle A to circle B, it means" ImmFol: "the execution of B can immediately follow " the execution of A for some execution”" --Different semantics for arrows between different shapes" --Still other shapes represent Start and Stop" --Use of hierarchy for elaborating boxes"• Usual enhancements:" --Annotate edges with predicates" --Special symbols for branching, concurrency control...."

Control flow graphs also address questions like “what does "" "this do” and “how does this do it”"

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Example Control Flow Graph Semantics"

•  Square boxes: Functions"– Any number of inedges"– One outedge"

•  Edges: ImmFol relation"– Function at head executes immediately after

function at tail concludes"•  Round ovals: Branches/decisions"

– Each oval represents a Boolean function"– For each oval there are exactly two outedges,

labeled True and False"

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Example Control Flow Graph Semantics"

•  FG = (FN, FE), where FN = OPS ∪ TEST and "OPS = {opsi} nodes where computation is done "TEST = {testi} nodes where tests are done"

•  Edges: ImmFol relation"if (fei, fek) ∈ FE then there is an execution path for which

the execution of fek immediately follows the execution of fei"•  | {(fei, fek} | where fei ∈ TEST = 2"•  | {(fei, fek} | where fei ∈ OPS = 1"•  FG is a directed, connected graph"•  Maybe(?): FN = OPS ∪ TEST ∪ INPUT ∪ OUTPUT where"

–  fni ∈ OUTPUT ⇒ ∄ ( fni , fnk ) ∈ FE"

–  fni ∈ INPUT ⇒ ∄ ( fnk , fni , ) ∈ FE"– Other semantics?"

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Control Flow Graph" Read Floor, Direction

DB_Read: curr-length, Floors(.), Directions(.)

Direction = Up

incr <-- 1 incr <-- -1 yes no

NFloor <-- Floor;

Directions[NFloor] = incr ?

yes

other car is nearer ? yes

no

output new floor

NFloor out of bounds

Complement Direction (Incr <-- -Incr)

yes

no

increment NFloor

no

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

More Detail throughHierarchical Elaboration"

•  The challenges and solutions here are similar to those for DFGs"

•  Need for consistency between levels"•  Semantics can be hard to define, stick to"

Page 7: Computer Science 520/620 Consistency is a principal concern

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

More Breadth from more (sub)types of CFG"

•  Concurrency"•  Timing"•  Data flow augmentations"•  Etc."

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Concurrency graph with “fork and join”"T1"

1"

2"

3"

4"

5"

call a"

T2

6

7

8

9

10

accept a

1

2

3

5

6

7

8

10

Ra

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Rendezvous Graph"

3 Ra"

2"

10"

T1! T2!

5

7

8

1 6   Rendezvous graph: RG = (N, E), where N = COMP ∪ SYNC"

  S ∈ SYNC ⇒ S executes only after the execution of all C ∈ COMP such that (C, S) ∈ E"

  If (S, C) ∈ E, where S ∈ SYNC,then C cannot execute until S has executed "

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Trace Flow Graph"

3 Ra"

2"

10"

T1! T2!

5

7

8

1 6   Explicitly represents interleaved execution "

  The green edges are the ImmFol relation" Double-headed arrows

represent one arrow in each direction"

  Sync nodes are filled in black"  Synch edges are blue

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Different variations to address differentstakeholders and their needs"

•  More semantic issues"– Different graph types for different issues "

•  More detail"– Hierarchy helps here"

•  More clarity"– Does more elaboration and more graph types

help clarity or impede it?"

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Focus on Clarity"

•  CFG has more procedural detail"•  Does this help?"•  What about combining DFG and CFG?"

– Iconography must be clear (?)"

Page 8: Computer Science 520/620 Consistency is a principal concern

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Control Flow Graph" Read Floor, Direction

DB_Read: curr-length, Floors(.), Directions(.)

Direction = Up

incr <-- 1 incr <-- -1 yes no

NFloor <-- Floor;

Directions[NFloor] = incr ?

yes

other car is nearer ? yes

no

output new floor

NFloor out of bounds

Complement Direction (Incr <-- -Incr)

yes

no

increment NFloor

no

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Control Flow Graph with Data Flow" Read Floor, Direction

DB_Read: curr-length, Floors(.), Directions(.)

Direction = Up

incr <-- 1 incr <-- -1 yes no

NFloor <-- Floor;

Directions[NFloor] = incr ?

yes

other car is nearer ? yes

no

output new floor

NFloor out of bounds

Complement Direction (Incr <-- -Incr)

yes

no

increment NFloor

no

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Control Flow Graph with Data Flow" Read Floor, Direction

DB_Read: curr-length, Floors(.), Directions(.)

Direction = Up

incr <-- 1 incr <-- -1 yes no

NFloor <-- Floor;

Directions[NFloor] = incr ?

yes

other car is nearer ? yes

no

output new floor

NFloor out of bounds

Complement Direction (Incr <-- -Incr)

yes

no

increment NFloor

no

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

What is Control Flow good/not good for?"

•  Sense of what algorithms to use"•  Constraints on data appearing"

– eg. Assuming that the Request List is maintained in sorted order"

•  Can estimate running speed"•  Can reason about functionality"

– Possible to strand requesters"– Possible to take riders in the wrong direction"

•  Drawbacks:"– What about safety?"– What about data?"

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

What Stakeholders does this address?"

•  Developers"•  ???"

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Control Flow vs. Data Flow Graphs"•  Both shed light on similar questions"•  One focuses on data evolution, the other on

functional development"•  Both are useful, neither removes the need for the

other"•  Control flow graphs map closely to

implementation code written in procedural languages. "– Good basis for determining consistency of

code with ideas expressed as data flow"•  Data flow graphs focus more on the product itself,

seem better at helping understand if and how it gets evolved"– Seem better adapted to studying earlier

formulations of the problem to be solved, and ways of solving it"

Page 9: Computer Science 520/620 Consistency is a principal concern

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Finite State Machines (FSM's)"

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Finite State Machines (FSM's)"

• FSM = (Q, I, ∂), where"

"Q = {qi} , the set of all possible system states"

"I = {ij} , the set of all events that can affect the "" " "state of the system"

"∂ is a function, ∂: Q x I ➞ Q such that if the system"" "is in state q and event i occurs, then the system"" "transitions to state ∂(q, i)"

• Use of hierarchy can help add detail""- But presents familiar consistency problems"

• Other definitions:""Start state""Accepting state""Trap state"

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Why FSM's?"• Primary appeal is visualizability--clarity" --Circles represent states" --(Curved) arrows represent transitions" --Arrows are annotated with inputs"

• Intuitively: Can "watch" a stream of inputs "drive"" the behavior of the system as a sequence of movements" from state to state"

Kinds of Questions FSMs seem adept at helping answer: “What is a good way to think about the problem to be solved?” “What is the solution approach?” “How does this program work?”

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Finite State Machine"

Doors Closed, Elevator Idle

Request to Move to new floor

Doors closed Elevator in

Motion

Arrival at New Floor

Doors open, Elevator Stopped

No new request timeout

Request to Move to new floor

Doors open Elevator in

Motion

Queueing new floor request

Arrival at New Floor Getting new

floor request

Request to Move to

new floor

Queue empty

Request to Move to

new floor

Request to Move to

new floor

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Finite State Machine for Digital Watch"

Time display mode

Datebook"mode"

Phone book"mode"

Alarm display"mode"

press button A

press button A

press button A

press button A

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

More Finite State Machine Details"

Time display mode

Datebook"mode"

Phone book"mode"

Alarm display"mode"

press button A

press button A

press button A

press button A

Time set mode

press button B

press button B

Datebook set mode

press button B press

button B

Datebook query mode

press button C

press button C

press button B

Phone book set mode

press button B

Phone book query mode

press button C

press button B

press button B

press button C

Alarm set mode

press button B

press button B

Page 10: Computer Science 520/620 Consistency is a principal concern

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

More Complex FSMs"

•  State also specifies activities"– Leans towards a CFG"

•  Transition may involve computation"– Considered to be “instantaneous”"

•  Transition may be conditional"– Event as well as a condition"

•  Transition may emit events"– To drive other FSMs"

•  FSMs may be hierarchical"– What exactly are semantics?"

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Statecharts: More Complex FSMs"

Initialize do: Initialize course object

do: Assign professor to course

Open

entry: Register a student

Closed do: Report course is full

Canceled do: Send cancellation notices

addStudent/ numStudents = 0

cancelCourse

RegistrationComplete do: Generate class roster

cancelCourse [ numStudents = 10 ]

cancelCourse

registration closed[ numStudents > = 3 ]

registration closed[ numStudents < 3 ]

Unassigned

addStudent

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Statecharts: More Complex FSMs"

Initialize do: Initialize course object

do: Assign professor to course

Open

entry: Register a student

Closed do: Report course is full

Canceled do: Send cancellation notices

addStudent/ numStudents = 0

cancelCourse

RegistrationComplete do: Generate class roster

cancelCourse [ numStudents = 10 ]

cancelCourse

registration closed[ numStudents > = 3 ]

registration closed[ numStudents < 3 ]

Unassigned

addStudent

Activity to be"performed in"

this state"

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Statecharts: More Complex FSMs"

Initialize do: Initialize course object

do: Assign professor to course

Open

entry: Register a student

Closed do: Report course is full

Canceled do: Send cancellation notices

addStudent/ numStudents = 0

cancelCourse

RegistrationComplete do: Generate class roster

cancelCourse [ numStudents = 10 ]

cancelCourse

registration closed[ numStudents > = 3 ]

registration closed[ numStudents < 3 ]

Unassigned

addStudent condition"on this"

transition"

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Statecharts: More Complex FSMs"

Initialize do: Initialize course object

do: Assign professor to course

Open

entry: Register a student

Closed do: Report course is full

Canceled do: Send cancellation notices

addStudent/ numStudents = 0

cancelCourse

RegistrationComplete do: Generate class roster

cancelCourse [ numStudents = 10 ]

cancelCourse

registration closed[ numStudents > = 3 ]

registration closed[ numStudents < 3 ]

Unassigned

addStudent activity"on this"

transition"

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Statechart with Nested States"superstate

substate Initialize Register

Open entry: Register a student

Unassigned do: Assign professor to course

Open

Closed Canceled

RegistrationComplete do: Generate class roster

Add student / numStudents = 0

[ numStudents = 10 ]

cancelCourse

registration closed[ numStudents > = 3 ]

registration closed[ numStudents < 3 ]

addStudent

do: Report course is closed

Page 11: Computer Science 520/620 Consistency is a principal concern

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

What is FSM good/not good for?"

•  Focus on specific issue: safety concern"– Model unsafe state"– Model state transitions"– Can unsafe state be reached?"

•  Drawbacks"– No sense of functionality"

» Unless additional semantics"– No sense of how functionality achieved"

» Except perhaps hierarchy"– Hard to deal with concurrency"

» Without additional semantics"– Impossible to reason about timing"

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Petri Nets"•  More powerful and intuitive depiction of control flow

strong on depiction of parallelism and concurrency"•  A Petri Net structurally consists of"

– A finite number of places"– A finite number of transitions"– A finite set of arrows that connect places to transitions

(or vice versa)"•  If an arrow goes from a place to a transition, then place is

said to be an input place of the transition."•  If an arrow goes from a transition to a place, then place is

said to be an output place of the transition."

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Marking and Firing Petri Nets"•  A Petri Net place can be marked by the presence of a

token"– Any collection of places can be marked. "– Any such marking is said to define a state of the

Petri Net"•  Petri Nets proceed from one state to another by means

of a firing"– Occurs only when every input place of a transition is

marked with a token."•  The effect of the firing of a transition is to"

– Remove all of the tokens from the transition's input places"

–  Put tokens in all of the transition's output places "

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Unmarked Petri Net"

Car going up

Up button Pressed Up button Not pressed

Stop at Floor

Go to Next Floor

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Petri Net Marked "With Up button pressed"

Car going up

Up button Pressed Up button Not pressed

Stop at Floor

Go to Next Floor

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Petri Net Marked "With Up button pressed"

Car going up

Up button Pressed Up button Not pressed

Stop at Floor

Go to Next Floor

Page 12: Computer Science 520/620 Consistency is a principal concern

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Petri Net Marked "With Up button pressed"

Car going up

Up button Pressed Up button Not pressed

Stop at Floor

Go to Next Floor

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Unmarked Petri Net--Two Elevator Cars"

No Press

Stop at Floor

Go to Next Floor

Up

Car 1 approaching Floor n, going up

No Press

Stop at Floor

Go to Next Floor

Up

Up Button Pressed at

Floor n

Car 2 approaching Floor n, going up

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Petri Net--Two Elevator Cars"Car 1 Wins Race"

No Press

Stop at Floor

Go to Next Floor

Up

Car 1 approaching Floor n, going up

No Press

Stop at Floor

Go to Next Floor

Up

Up Button Pressed at

Floor n

Car 2 approaching Floor n, going up

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Petri Net--Two Elevator Cars"Car 1 Wins Race"

No Press

Stop at Floor

Go to Next Floor

Up

Car 1 approaching Floor n, going up

No Press

Stop at Floor

Go to Next Floor

Up

Up Button Pressed at

Floor n

Car 2 approaching Floor n, going up

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Petri Net--Two Elevator Cars"Car 1 Wins Race"

No Press

Stop at Floor

Go to Next Floor

Up

Car 1 approaching Floor n, going up

No Press

Stop at Floor

Go to Next Floor

Up

Up Button Pressed at

Floor n

Car 2 approaching Floor n, going up

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Petri Net--Two Elevator Cars"Car 1 Wins Race"

No Press

Stop at Floor

Go to Next Floor

Up

Car 1 approaching Floor n, going up

No Press

Stop at Floor

Go to Next Floor

Up

Up Button Pressed at

Floor n

Car 2 approaching Floor n, going up

Page 13: Computer Science 520/620 Consistency is a principal concern

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Petri Net--Two Elevator Cars"Car 1 Wins Race"

No Press

Stop at Floor

Go to Next Floor

Up

Car 1 approaching Floor n, going up

No Press

Stop at Floor

Go to Next Floor

Up

Up Button Pressed at

Floor n

Car 2 approaching Floor n, going up

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Petri Net--Two Elevator Cars"Car 2 Wins Race"

No Press

Stop at Floor

Go to Next Floor

Up

Car 1 approaching Floor n, going up

No Press

Stop at Floor

Go to Next Floor

Up

Up Button Pressed at

Floor n

Car 2 approaching Floor n, going up

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Petri Net--Two Elevator Cars"Car 2 Wins Race"

No Press

Stop at Floor

Go to Next Floor

Up

Car 1 approaching Floor n, going up

No Press

Stop at Floor

Go to Next Floor

Up

Up Button Pressed at

Floor n

Car 2 approaching Floor n, going up

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Petri Net--Two Elevator Cars"Car 2 Wins Race"

No Press

Stop at Floor

Go to Next Floor

Up

Car 1 approaching Floor n, going up

No Press

Stop at Floor

Go to Next Floor

Up

Up Button Pressed at

Floor n

Car 2 approaching Floor n, going up

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Petri Net--Two Elevator Cars"Car 2 Wins Race"

No Press

Stop at Floor

Go to Next Floor

Up

Car 1 approaching Floor n, going up

No Press

Stop at Floor

Go to Next Floor

Up

Up Button Pressed at

Floor n

Car 2 approaching Floor n, going up

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Petri Net--Two Elevator Cars"Car 2 Wins Race"

No Press

Stop at Floor

Go to Next Floor

Up

Car 1 approaching Floor n, going up

No Press

Stop at Floor

Go to Next Floor

Up

Up Button Pressed at

Floor n

Car 2 approaching Floor n, going up

Page 14: Computer Science 520/620 Consistency is a principal concern

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Petri Net for a Different Elevator"Car going up

Up button higher No Up Button

Higher

Move up to Nearest Up Button Car going down

Visit floor, Turn off button

Down button lower

No Down Button Lower

Move to nearest Down Button

Visit floor, Turn off button

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Marking for moving up to pick up a passenger"Car going up

Up button higher No Up Button

Higher

Move up to Nearest Up Button Car going down

Visit floor, Turn off button

Down button lower

No Down Button Lower

Move to nearest Down Button

Visit floor, Turn off button

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Marking for moving up to pick up a passenger"Car going up

Up button higher No Up Button

Higher

Move up to Nearest Up Button Car going down

Visit floor, Turn off button

Down button lower

No Down Button Lower

Move to nearest Down Button

Visit floor, Turn off button

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Marking for moving up to pick up a passenger"Car going up

Up button higher No Up Button

Higher

Move up to Nearest Up Button Car going down

Visit floor, Turn off button

Down button lower

No Down Button Lower

Move to nearest Down Button

Visit floor, Turn off button

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Marking for moving up to pick up a passenger"Car going up

Up button higher No Up Button

Higher

Move up to Nearest Up Button Car going down

Visit floor, Turn off button

Down button lower

No Down Button Lower

Move to nearest Down Button

Visit floor, Turn off button

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Marking for moving up to pick up a passenger"Car going up

Up button higher No Up Button

Higher

Move up to Nearest Up Button Car going down

Visit floor, Turn off button

Down button lower

No Down Button Lower

Move to nearest Down Button

Visit floor, Turn off button

Queues at places?

Page 15: Computer Science 520/620 Consistency is a principal concern

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Marking when no passengers higher, but passenger lower"Car going up

Up button higher No Up Button

Higher

Move up to Nearest Up Button Car going down

Visit floor, Turn off button

Down button lower

No Down Button Lower

Move to nearest Down Button

Visit floor, Turn off button

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Marking when no passengers higher, but passenger lower"Car going up

Up button higher No Up Button

Higher

Move up to Nearest Up Button Car going down

Visit floor, Turn off button

Down button lower

No Down Button Lower

Move to nearest Down Button

Visit floor, Turn off button

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Marking when no passengers higher, but passenger lower"Car going up

Up button higher No Up Button

Higher

Move up to Nearest Up Button Car going down

Visit floor, Turn off button

Down button lower

No Down Button Lower

Move to nearest Down Button

Visit floor, Turn off button

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Marking for both up and down buttons"Car going up

Up button higher No Up Button

Higher

Move up to Nearest Up Button Car going down

Visit floor

Down button lower

No Down Button Lower

Move to nearest Down Button

Visit floor

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Marking for neither up nor down buttons"Car going up

Up button higher No Up Button

Higher

Move up to Nearest Up Button Car going down

Visit floor

Down button lower

No Down Button Lower

Move to nearest Down Button

Visit floor

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Evaluation of Petri Nets"

• How do things get done?"

• Especially parallelism and nondeterminism"

• Helps spot races and deadlocks"

• Too little focus on product (tokens represent it)"

• Many extensions:"

--Hierarchical Petri Nets" --Colored tokens" --"Or" transitions" --Queues at places"

• Too many extensions confuse the picture? "

What are Petri Net representations good for?:

What kinds of things are Petri Nets not good for?

Page 16: Computer Science 520/620 Consistency is a principal concern

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Combinations of Representations"•  Different representations give different views, support

providing answers to different questions"•  But different views must all be consistent with each other"•  One way to assure this: superimpose different views

atop each other"– Control/Data flow diagrams"– Call/control flow charts"– FSMs with activities too"– Diagrams augmented with natural language"

» Example: RSL"•  Risk of too much clutter, Can be self defeating"•  Another way: Coordinated sets of representations"

– Need to assure that all the different representations are consistent with each other--represent the same thing "

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Kepler--Another DFG Technology"

•  Data Flow diagram notation"•  Has hierarchical decomposition"•  Capability for specifying DFD semantics"

– For each diagram"– Can be different at each level of hierarchy (!)"

•  Based on Ptolemy II system"– P. Baldwin, S. Kohli, E.A. Lee, X. Liu, and Y. Zhao.

“Modeling of Sensor Nets in Ptolemy II. in Proc. of Information Processing in Sensor Networks”, (IPSN), April 26-27, 2004, pp.359-368.

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

A Kepler Example"

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Kepler Elaboration"

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Multirepresentation Systems"•  Have seen that different representations are of different

uses"•  One diagram may be useful in different ways to

different stakeholders"•  But most stakeholders require a variety of diagrams"•  Several different diagrams can be expected to be

needed to satisfy the different stakeholders"•  Problems with different views/diagrams"

– Are they all representing the same software product?"

– How to assure that they are all consistent with each other?"

– If the product changes, then ALL views must change correspondingly"

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Multiple Views"

Page 17: Computer Science 520/620 Consistency is a principal concern

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Platoʼs Cave"

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

RSL/REVS"• Reference: Bell, Bixler, Dyer, IEEE TSE SE-3 #1 pp. 49-59"• Enhanced DFD's (called RNET's)" --Functions called ALPHA's" --ALPHA's can be defined hierarchically" --Structured English as well as pictorial diagrams" --Diverse set of attributes used to enhance ALPHA defs." --Logical connectives on arrows"• Balanced by facilities for defining data (called DATA's)" --Defined hierarchically" --Output from/Input to specs are dual of ALPHA info."

• Supports consistency checking through redundancy" --Redundancy to check for consistency and quality"

• Designed to help specify reactive systems" --Dataflow diagrams are particularly good at that (?)"

• Other Features (more peripheral to this discussion)" --I/O specifications" --Requirements tracing (why is that requirement here?)"

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

STATEMATE"•  Elaborate enhancement of FSM's"

–  Augmented by other views (e.g. activity Diagrams)"•  Key feature is maintenance of consistency among views"

–  Done by projecting views of text (language)-based model"•  References"

–  Harel et al., "STATEMATE: A Working Environment for the Development of Complex Reactive Systems" Proc. 10th Int'l. Conf. on Software Engineering, Singapore, 1988, pp. 396-406."

–  Harel et al., “STATEMATE: A Working Environment for the Development of Complex Reactive Systems:, IEEE Trans. On Software Engineering (IEEE TSE), v. 16, #4, April 1990, pp. 403-414."

–  Harel and Naamad, “The STATEMATE Semantics of Statecharts”, ACM Trans. On Software Engineering Methodology (TOSEM), v.5 #4, Oct. 1996. "

•  Commercially available software system"–  http://www-01.ibm.com/software/awdtools/statemate/ "

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Multiple Views in Statemate"• Rationale for multiple views: Too much information in a" single diagram creates clutter, confusion, defeats clarity"

• Advantage of multiple views: Each represents a different" viewpoint, different model, with a different diagram--easier" to grasp the model"

• Disadvantage: Reader needs to synthesize views, assure" that they are really consistent with each other"

• Three views in Statemate:" --Module Charts (a hierarchy representing capabilities)" --Activity Charts (hierarchical dataflow charts)" --Statecharts (hierarchical finite state machines)"

• All charts are derived from textual input, facilitated by use of" tools prompting user via forms"• Three Statemate views depict some different views, but also" overlap with each other: facilitates cross-checking for " consistency and easier comprehension"

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Multiple Views in Statemate"

Statechart view

Activity view

Textual view

Module view

CS 520/620 Spring 2011 Univ. of Massachusetts Copyright L. Osterweil, all rights reserved

Multiple Views in Statemate"

Statechart view Activity view

Textual view

Module view