1 / 30

Maps

Maps. Learning Outcomes. At the end of this lecture you should be able to:. provide a definition of a VDM map; utilize and interpret map notation; make appropriate use of the VDM map operators; identify situations in which a map is an appropriate data type;

Download Presentation

Maps

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Maps Learning Outcomes At the end of this lecture you should be able to: • provide a definition of a VDM map; • utilize and interpret map notation; • make appropriate use of the VDM map operators; • identify situations in which a map is an appropriate data type; • write VDM specifications using maps.

  2. Introduction Computing systems often involve relating 2 types of value together; A map is a special sort of set, one which contains a set of maplets; Each maplet connects an element of one set to an element of another set; The first set is referred to as the domain, the second is referred to as the range. Yalmaz Coffee Aaron VDM Password Name Rajneet Apple Nkumu RANGE DOMAIN

  3. Using the map type in VDM-SL To declare a variable to be of type Map we use a special arrow ; DomainType RangeType For example, to declare a variable m that maps characters to natural numbers we would write: m : Char  To declare a variable, users, that maps names to passwords we could write users : Name Password

  4. Notation We can express this table as a map, which we will call sensors: sensors : Sensor Condition sensors = {A  <low>, B  <normal>, C  <normal>, D  <high>, E  <normal>,F  <normal>} sensors = {  }

  5. Map operators m1 = { a 1, b2, c2, d 3, e 4} m2 = { a 2, f 1, c  7} The domain operator and the range operators: { a, b, c, d, e } domm1 = { 1, 2, 3, 4 } rngm1 = { a, f, c } domm2 = { 1, 2, 7 } rngm2 =

  6. Map operators m1 = { a 1, b2, c2, d 3, e 4} m2 = { a 2, f 1, c  7} m3 = { f  2, g  6} The union operator,  { a 1, b 2, c 2, d  3, e  4,f  2, g  6} m1m3 = m1m2 = undefined undefined m2m3 =

  7. Map operators m1 = { a 1, b2, c2, d 3, e 4} m2 = { a 2, f 1, c  7} m3 = { f  2, g  6} The override operator, † { a  2, b  2, c  7, d  3, e  4, f  1} m1 † m2= m3 † m2= { f  1, g  6, a  2, c  7}

  8. a domain restriction operator, {a, c, e} m1 = { e,f } m2 = { } m3 = Map operators m1 = { a 1, b2, c2, d 3, e 4} m2 = { a 2, f 1, c  7} m3 = { f  2, g  6} { a  1, c  2, e  4} { f  1} { }

  9. a domain deletion operator, {a, c, e} m1 = { e,f } m2 = { } m3 = Map operators m1 = { a 1, b2, c2, d 3, e 4} m2 = { a 2, f 1, c  7} m3 = { f  2, g  6} { b  2, d  3 } { a  2, c  7} { f  2, g  6 }

  10. a range restriction operator, m1 { 2 } = m2 {1, 4 } = m3 {} = Map operators m1 = { a 1, b2, c2, d 3, e 4} m2 = { a 2, f 1, c  7} m3 = { f  2, g  6} { b2, c2 } { f  1} {  }

  11. a range restriction operator, m1 { 2 } = m2 {1, 4 } = m3 {} = Map operators m1 = { a 1, b2, c2, d 3, e 4} m2 = { a 2, f 1, c  7} m3 = { f  2, g  6} { a 1, d 3, e 4 } { a 2, c  7} { f  2, g  6}

  12. Map operators m1 = { a 1, b2, c2, d 3, e 4} m2 = { a 2, f 1, c  7} m3 = { f  2, g  6} Map Application m1( d ) = 3 m2( f ) = 1 m3( f ) = 2 m3( x ) = undefined

  13. Specifying a high-security building User name + Password

  14. Employee name: String password: String Employee name: Name password: Password SecuritySys authorized : Employee[*] inside : String[*] addEmployee(String, String) removeEmployee(String) enter(String, String) : Signal leave(String) : Signal SecuritySys authorized : Employee[*] inside : Name[*] addEmployee(Name, Password) removeEmployee(Name) enter(Name, Password) : Signal leave(Name) : Signal <<enumeration>> Signal OPEN_DOOR ACTIVATE_ALARM UML Diagrams

  15. Name Password The VDM-SL state specification types Name = TOKEN Password = TOKEN Signal = <open_door>|< activate_alarm> Employee :: name: Name password: Password state SecuritySys of authorized : Employee-set ? : Name-set inside Only authorised employees can be inside the building inv mk-SecuritySys(a,i)  i doma init mk-SecuritySys(a,i)  a = { } i = { }

  16. authorized : Name Password authorized =  {nameIn passwordIn} addEmployee() ext pre post nameIn : Name, passwordIn : Password wr nameIn  domauthorized

  17. authorized : Name Password authorized = {nameIn} nameIn : Name removeEmployee() ext pre post wr rd inside : Name-set nameIn domauthorized nameIninside

  18. authorized : Name Password authorized(nameIn) passwordIn nameIn ) (authorized(nameIn) = passwordIn nameIn ) (inside = signal = <activate_alarm>) (inside = {nameIn}signal = <open_door>) enter() ext pre post signal : Signal nameIn : Name, passwordIn : Password rd wr inside : Name-set TRUE   ( nameIn  dom authorised  

  19. nameIn inside = \ {nameIn} nameIn inside = leave () ext pre post nameIn : Name signal : Signal wr inside : Name-set TRUE  signal = <open_door>   signal = <activate_alarm>

  20. A robot monitoring system WORKING Sector A Sector B BROKEN IDLE

  21. RobotMonitor robots: Robot[*] addRobot (String) removeRobot (String) setToWork (String, Sector) finishWork (String) needsRepair (String) fixed(String) inSector (Sector): String [*] numberToRepair (): Integer RobotMonitor robots: Robot[*] addRobot (Name) removeRobot (Name) setToWork (Name, Sector) finishWork (Name) needsRepair (Name) fixed(Name) inSector (Sector): Name [*] numberToRepair (): Integer Robot name: String mode: Mode sector: Sector Robot name: Name mode: Mode sector: Sector <<enumeration>> Mode working idle broken <<enumeration>> Sector A B

  22. Name Robot types Name = TOKEN Mode Sector Robot = <working>|<idle>| <broken> = <A>|< B> :: name mode sector : Name : Mode : [Sector] m = <working> snil inv mk-Robot(-, m, s)  stateRobotMonitorof robots: invmk-RobotMonitorSys(r) n domr n = r(n).name initmk-RobotMonitorSys(r)  r = { } end

  23. robots: robots =  Name Robot addRobot () ext pre post nameIn: Name wr nameIndom robots { nameIn mk-Robot (nameIn, <idle>, nil) }

  24. robots: robots = {nameIn } Name Robot removeRobot () ext pre post nameIn: Name wr  nameIndom robots robots(nameIn).mode  <working>

  25. robots: robots = Name Robot setToWork() ext pre post nameIn: Name, sectorIn Sector wr  nameIndom robots robots(nameIn).mode = <idle> † { nameIn mk-Robot(nameIn, <working>, sectorIn )}

  26. robots: robots = Name Robot finishWork() ext pre post nameIn: Name wr  nameIndom robots robots(nameIn).mode = <working> † { nameIn mk-Robot(nameIn, <idle>,nil )}

  27. robots: robots = Name Robot needsRepair() ext pre post nameIn: Name wr nameIndom robots † { nameIn mk-Robot(nameIn, <broken>,nil )}

  28. robots: { nameIn ( (nameIn), mode<idle>) } robots = Name Robot fixed() ext pre post nameIn: Name wr  nameIndom robots robots(nameIn).mode = <broken> †

  29. robots: Name Robot inSector () ext pre post sectorIn: Sector result : Name-set rd TRUE result = { ? | ?  ? } r.name r rng robots r.sector = sectorIn

  30. robots: Name Robot numberToRepair () ext pre post number :  rd TRUE result = r card { ? | ?  ? } r rng robots r.mode = <broken>

More Related