Presentation is loading. Please wait.

Presentation is loading. Please wait.

Sets for system modelling. At the end of this lecture you should be able to: Identify when it is appropriate to use a set for system modelling Define.

Similar presentations


Presentation on theme: "Sets for system modelling. At the end of this lecture you should be able to: Identify when it is appropriate to use a set for system modelling Define."— Presentation transcript:

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. Collection of patients registered on the books of a doctor's surgery? When to use a set? 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: variableName: ElementType For example Day = | | | | | | aNumber: aDay : Day someNumbers: -set someOtherNumbers: -set importantDays : Day-set -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 = {, , }

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

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 = { x 2 | 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 = { x 2 | 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 = { , , , } and k = { < MON >, , < TUE > } then j k = {, , , , }

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 = { , , , } and k = { < MON >, , < TUE > } thenj k = {, }

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 = { , , , } and k = { < MON >, , < TUE > } then j \ k = {, }

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} card { 7, 2, 2, 12, 12} card { 4,…,10} card { } = 3 = 3 = 7 = 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 Patient inv mk-PatientRegister (r) card r LIMIT r = { } = TOKEN : = 200 r -set There must be no more than 200 patients on the register

29 PatientRegister reg: Patient [*] addPatient (Patient) removePatient (Patient) getPatients ( ): Patient [*] isRegistered (Patient): Boolean numberRegistered ( ):Integer

30 addPatient ( ) ext pre post reg = patientIn patientIn: Patient reg: Patient-setwr patientIn reg

31 addPatient ( ) ext pre post reg = { patientIn} patientIn regcard reg < LIMIT patientIn: Patient reg: Patient-setwr

32 PatientRegister reg: Patient [*] addPatient (Patient) removePatient (Patient) getPatients ( ): Patient [*] isRegistered (Patient): Boolean numberRegistered ( ):Integer

33 removePatient ( ) ext pre post patientIn: Patient wrreg: Patient-set reg = \ { patientIn}patientIn reg 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 output = reg TRUE

36 PatientRegister reg: Patient [*] addPatient (Patient) removePatient (Patient) getPatients ( ): Patient [*] isRegistered (Patient): Boolean numberRegistered ( ):Integer

37 isRegistered ( ) ext pre post patientIn: Patient query: rdreg: Patient-set query patientIn reg TRUE

38 PatientRegister reg: Patient [*] addPatient (Patient) removePatient (Patient) getPatients ( ): Patient [*] isRegistered (Patient): Boolean numberRegistered ( ):Integer

39 numberRegistered () ext pre post total: rdreg: Patient-set total = card reg TRUE

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(Aircraft) recordTakeOff(Aircraft) getPermission( ): Aircraft [*] getLanded( ): Aircraft [*] numberWaiting(): Integer

43 Airport permission: Aircraft [*] landed: Aircraft [*] givePermission(Aircraft) recordLanding(Aircraft) recordTakeOff(Aircraft) getPermission( ): Aircraft [*] getLanded( ): Aircraft [*] numberWaiting(): Integer

44 Modelling the Airport class in VDM-SL

45 types state Airport of init mk-Airport ( ) end Aircraft = TOKEN permission: landed: inv mk-Airport(p,l) l p p = { } l = { } p, l Aircraft -set All landed planes must have had permission to land.

46 Airport permission: Aircraft [*] landed: Aircraft [*] givePermission(Aircraft) recordLanding(Aircraft) recordTakeOff(Aircraft) getPermission( ): Aircraft [*] getLanded( ): Aircraft [*] numberWaiting(): Integer

47 givePermission( ) ext pre post craftIn: Aircraft permission: Aircraft - set wr permission = {craftIn } craftIn permission

48 Airport permission: Aircraft [*] landed: Aircraft [*] givePermission(Aircraft) recordLanding(Aircraft) recordTakeOff(Aircraft) getPermission( ): Aircraft [*] getLanded( ): Aircraft [*] numberWaiting(): Integer

49 recordLanding ( ) ext pre post craftIn: Aircraft permission: Aircraft -set landed: Aircraft -set rd wr landed = {craftIn} craftIn permission craftIn landed

50 Airport permission: Aircraft [*] landed: Aircraft [*] givePermission(Aircraft) recordLanding(Aircraft) recordTakeOff(Aircraft) getPermission( ): Aircraft [*] getLanded( ): Aircraft [*] numberWaiting(): Integer

51 recordTakeOff ( ) ext pre post craftIn: Aircraft permission: Aircraft -set landed: Aircraft -set wr wr landed = \ {craftIn }permission = \ { craftIn } craftIn landed

52 Airport permission: Aircraft [*] landed: Aircraft [*] givePermission(Aircraft) recordLanding(Aircraft) recordTakeOff(Aircraft) getPermission( ): Aircraft [*] getLanded( ): Aircraft [*] numberWaiting(): Integer

53 getPermission( ) ext pre post out: Aircraft-set permission: Aircraft -setrd out = permission TRUE

54 Airport permission: Aircraft [*] landed: Aircraft [*] givePermission(Aircraft) recordLanding(Aircraft) recordTakeOff(Aircraft) getPermission( ): Aircraft [*] getLanded( ): Aircraft [*] numberWaiting(): Integer

55 getLanded( ) ext pre post out: Aircraft -set landed: Aircraft -set rd out = landed TRUE

56 Airport permission: Aircraft [*] landed: Aircraft [*] givePermission(Aircraft) recordLanding(Aircraft) recordTakeOff(Aircraft) getPermission( ): Aircraft [*] getLanded( ): Aircraft [*] numberWaiting(): Integer

57 numberWaiting( ) ext pre post total: permission: Aircraft -set landed: Aircraft -set rd rd card (permission \ landed)total =

58 Thats all Folks..


Download ppt "Sets for system modelling. At the end of this lecture you should be able to: Identify when it is appropriate to use a set for system modelling Define."

Similar presentations


Ads by Google