Sets for system modelling - PowerPoint PPT Presentation

1 / 58
About This Presentation
Title:

Sets for system modelling

Description:

When a plane arrives to land at the airport it is only allowed to do so if it ... When a plane leaves the airport its permission to land is also removed' ... – PowerPoint PPT presentation

Number of Views:14
Avg rating:3.0/5.0
Slides: 59
Provided by: aaron63
Category:

less

Transcript and Presenter's Notes

Title: Sets for system modelling


1
Sets for system modelling
2
At the end of this lecture you should be able to
  • Identify when it is appropriate to use a set for
    system modelling
  • Define a set using enumeration, number ranges and
    comprehension
  • Use the set operators (union, intersection,
    difference, subset and cardinality)
  • Apply the set type to model systems in VDM-SL

3
A set is an unordered collection of objects in
which repetition is not significant.
When to use a set?
Collection of patients registered on the books of
a doctor's surgery?
?
?
The queue of patients waiting for a doctor?
4
Declaring sets in VDM-SL
5
To indicate a variable to be of the set type
-set
variableName ElementType
For example
Day ltMONgt ltTUEgt ltWEDgt ltTHUgt ltFRIgt
ltSATgt ltSUNgt aNumber ? aDay
Day someNumbers ?-set someOtherNumbers ?
-set importantDays Day-set
6
Defining sets in VDM-SL
Three ways to initialise the values of a set
  • by enumeration
  • by number ranges
  • by comprehension.

7
Defining sets by enumeration
someNumbers 2, 4, 28, 19 ,10
importantDays ltFRIgt, ltSATgt, ltSUNgt
8
Defining sets by number ranges
9
Can be used when a set of continuous integers
required
someRange 5, ,15 equal to someRange
5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
When the second number in the range is smaller
than the first, the empty set is returned.
7,,6
10
Defining a set by comprehension
11
Defining a set by comprehension
12
Allows one set to be defined by means of another
someSet expression (x) x ? someOtherSet ?
test(x)
13
Allows one set to be defined by means of another
someSet expression (x) x ? someOtherSet ?
test(x)
14
Allows one set to be defined by means of another
someSet expression (x) x ? someOtherSet ?
test(x)
15
Allows one set to be defined by means of another
someSet expression (x) x ? someOtherSet ?
test(x)
Examples
someNumbers x x ? 2,,6 ? isEven(x)
2, 3, 4, 5, 6
16
Allows one set to be defined by means of another
someSet expression (x) x ? someOtherSet ?
test(x)
Examples
someNumbers x x ? 2,,6 ? isEven(x)


2, 3, 4, 5, 6
17
Allows one set to be defined by means of another
someSet expression (x) x ? someOtherSet ?
test(x)
Examples
someOtherNumbers x2 x ? 2,,6
2, 3, 4, 5, 6
4,
9,
16,
25,
36
18
Allows one set to be defined by means of another
someSet expression (x) x ? someOtherSet ?
test(x)
Examples
someOtherNumbers x2 x ? 2,,6 ?
isEven(x)


2, 3, 4, 5, 6
4,
16,
36
19
Set operations
Set union j ? k
Returns a set that contains all the elements of
the set j and all the elements of the set k.
if j ltMONgt, ltTUEgt, ltWEDgt, ltSUNgt and
k lt MON gt, ltFRIgt, lt TUE gt then j ? k
ltMONgt, ltTUEgt, ltWEDgt, ltSUNgt , ltFRIgt
20
Set operations. contd
Set intersection j ? k
Returns a set that contains all the elements that
are common to both j and k.
if j ltMONgt, ltTUEgt, ltWEDgt, ltSUNgt and
k lt MON gt, ltFRIgt, lt TUE gt then j ? k
ltMONgt, ltTUEgt
21
Set operations. contd
Set difference j \ k
Returns the set that contains all the elements
that belong to j but do not belong to k.
if j ltMONgt, ltTUEgt, ltWEDgt, ltSUNgt and
k lt MON gt, ltFRIgt, lt TUE gt then j \ k
ltWEDgt, ltSUNgt
22
Set operations. contd
Subset j ? k
Returns true if all elements that belong to j
also belong to k.
a, d, e ? a, b, c, d, e, f a, d, e ? d, a,
e
Proper subset j ? k
Returns true if all elements that belong to j
also belong to k but false if sets j and k are
equal.
a, d, e ? a, b, c, d, e, f a, d, e ? d, a,
e
23
Set operations. contd
Cardinality card j
Returns the number of elements in a given set.
card 7, 2, 12
3
card 7, 2, 2, 12, 12
3
card 4,,10
7
card
0
24
The PatientRegister class
25
PatientRegister reg Patient addPatient
(Patient) removePatient (Patient) getPatients (
) Patient isRegistered (Patient)
Boolean numberRegistered ( )Integer
26
PatientRegister reg Patient addPatient
(Patient) removePatient (Patient) getPatients (
) Patient isRegistered (Patient)
Boolean numberRegistered ( )Integer
27
Modelling the PatientRegister class in VDM-SL
28
types Patient values LIMIT state PatientRegister
of reg init mk-PatientRegister ( ) ?
end
TOKEN
There must be no more than 200 patients on the
register
? 200
Patient
-set
inv mk-PatientRegister (r) ?
card r ? LIMIT
r
r
29
PatientRegister reg Patient addPatient
(Patient) removePatient (Patient) getPatients (
) Patient isRegistered (Patient)
Boolean numberRegistered ( )Integer
30
addPatient (
) ext pre post
patientIn Patient
reg Patient-set
wr
patientIn ? reg
31
addPatient (
) ext pre post
patientIn Patient
reg Patient-set
wr
patientIn ? reg
card reg lt LIMIT
?
32
PatientRegister reg Patient addPatient
(Patient) removePatient (Patient) getPatients (
) Patient isRegistered (Patient)
Boolean numberRegistered ( )Integer
33
removePatient (
) ext pre post
patientIn Patient
wr reg Patient-set
patientIn ? reg
reg \ patientIn
patientIn ? reg
34
PatientRegister reg Patient addPatient
(Patient) removePatient (Patient) getPatients (
) Patient isRegistered (Patient)
Boolean numberRegistered ( )Integer
35
getPatients ( ) ext pre post
output Patient-set
rd reg Patient-set
TRUE
output reg
36
PatientRegister reg Patient addPatient
(Patient) removePatient (Patient) getPatients (
) Patient isRegistered (Patient)
Boolean numberRegistered ( )Integer
37
isRegistered (
) ext pre post
patientIn Patient
query ?
rd reg Patient-set
TRUE
?
query
patientIn ? reg
38
PatientRegister reg Patient addPatient
(Patient) removePatient (Patient) getPatients (
) Patient isRegistered (Patient)
Boolean numberRegistered ( )Integer
39
numberRegistered () ext pre post
total ?
rd reg Patient-set
TRUE
card reg
total
40
The Airport Class
41
"A system is to be developed that keeps track of
planes that are allowed to land at a particular
airport. Planes must apply for permission to
land at the airport prior to landing. When a
plane arrives to land at the airport it is only
allowed to do so if it has previously been given
permission. When a plane leaves the airport its
permission to land is also removed"
42
A UML specification of the Airport class
Airport permission Aircraft landed Aircraft
givePermission(Aircraft) recordLanding(Aircra
ft) recordTakeOff(Aircraft) getPermission( )
Aircraft getLanded( ) Aircraft
numberWaiting() Integer
43
A UML specification of the Airport class
44
Modelling the Airport class in VDM-SL
45
types state Airport of
init mk-Airport ( ) ? end
Aircraft TOKEN
All landed planes must have had permission to
land.
permission
Aircraft -set
Aircraft -set
landed
inv mk-Airport(p,l) ?
l ? p
p, l
p
?
l
46
(No Transcript)
47
craftIn Aircraft
givePermission(
) ext pre post
permission Aircraft - set
wr
craftIn ? permission
48
(No Transcript)
49
recordLanding (
) ext pre post
craftIn Aircraft
landed Aircraft -set
wr
permission Aircraft -set
rd
craftIn ? landed
?
craftIn ? permission
50
(No Transcript)
51
craftIn Aircraft
recordTakeOff (
) ext pre post
permission Aircraft -set
wr
wr
landed Aircraft -set
craftIn ? landed
?
52
(No Transcript)
53
getPermission( ) ext pre post
out Aircraft-set
permission Aircraft -set
rd
TRUE
out permission
54
(No Transcript)
55
out Aircraft -set
getLanded( ) ext pre post
landed Aircraft -set
rd
TRUE
out landed
56
(No Transcript)
57
numberWaiting( ) ext pre post
total ?
permission Aircraft -set
rd
landed Aircraft -set
rd
card (permission \ landed)
total
58
Thats all Folks..
Write a Comment
User Comments (0)
About PowerShow.com