Title: Maps
1Maps
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.
2Introduction
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
3Using 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
4Notation
We can express this table as a map, which we will
call sensors
sensors
Sensor
Condition
sensors A ? ltlowgt, B ? ltnormalgt, C ? ltnormalgt,
D ? lthighgt, E ? ltnormalgt, F ? ltnormalgt
sensors ?
5Map 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
dom m1
1, 2, 3, 4
rng m1
a, f, c
dom m2
1, 2, 7
rng m2
6Map 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
7Map 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
8Map 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
?
9Map 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
10Map 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
?
11Map 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
12Map 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
13Specifying a high-security building
User name Password
14UML Diagrams
15The VDM-SL state specification
types
Name TOKEN Password TOKEN Signal
ltopen_doorgtlt activate_alarmgt
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 ? dom a
init mk-SecuritySys(a,i) ?
a ? ? i
16addEmployee(
) ext pre post
nameIn Name, passwordIn Password
wr
nameIn ? dom authorized
17nameIn Name
removeEmployee(
) ext pre post
wr
inside Name-set
rd
nameIn ? dom authorized
? nameIn ? inside
18enter(
) ext pre post
signal Signal
nameIn Name, passwordIn Password
rd
inside Name-set
wr
TRUE
?
?
( nameIn ? dom authorised ?
?
19leave ( ) ext pre post
nameIn Name
signal Signal
inside Name-set
wr
TRUE
signal ltopen_doorgt
?
?
?
signal ltactivate_alarmgt
20A robot monitoring system
WORKING
Sector A
Sector B
BROKEN
IDLE
21(No Transcript)
22types Name TOKEN Mode Sector Robot
ltworkinggtltidlegt ltbrokengt
ltAgtlt Bgt
name mode sector
Name
Mode
Sector
m ltworkinggt ? s ? nil
inv mk-Robot(-, m, s) ?
state RobotMonitor of
robots
inv mk-RobotMonitorSys(r) ?
? n ? dom r ? n r(n).name
init mk-RobotMonitorSys(r) ?
r ?
end
23addRobot (
) ext pre post
nameIn Name
wr
nameIn ? dom robots
nameIn ? mk-Robot (nameIn, ltidlegt, nil)
24removeRobot (
) ext pre post
nameIn Name
wr
?
nameIn ? dom robots
robots(nameIn).mode ? ltworkinggt
25 setToWork (
) ext pre post
nameIn Name, sectorIn Sector
wr
?
nameIn ? dom robots
robots(nameIn).mode ltidlegt
nameIn ? mk-Robot(nameIn, ltworkinggt, sectorIn
)
26 finishWork (
) ext pre post
nameIn Name
wr
?
nameIn ? dom robots
robots(nameIn).mode ltworking gt
nameIn ? mk-Robot(nameIn, ltidlegt, nil )
27 needsRepair (
) ext pre post
nameIn Name
wr
nameIn ? dom robots
nameIn ? mk-Robot(nameIn, ltbrokengt, nil )
28fixed ( ) ext pre post
nameIn Name
wr
?
nameIn ? dom robots
robots(nameIn).mode ltbroken gt
29inSector (
) ext pre post
sectorIn Sector
result Name-set
rd
TRUE
result
? ? ?
?
r.sector sectorIn
r ? rng robots
r.name
30numberToRepair ( ) ext pre post
number ?
rd
TRUE
result
r
card ? ? ?
?
r.mode ltbrokengt
r ? rng robots