maps

30
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.

Upload: daryl-rosales

Post on 01-Jan-2016

11 views

Category:

Documents


0 download

DESCRIPTION

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; - PowerPoint PPT Presentation

TRANSCRIPT

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.

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.

Aaron

Yalmaz

Nkumu

Rajneet

VDM

Apple

Coffee

DOMAIN RANGE

Name Password

Using the map type in VDM-SL

To declare a variable to be of type Map we use a special arrow ;

m

For example, to declare a variable m that maps characters to natural numbers we would write:

DomainType RangeType

m : Char m

To declare a variable, users, that maps names to passwords we could write

users : Name m Password

Notation A look-up table for a set of sensors

Sensor Condition

A low

B normal

C normal

D high

E normal

F normal

sensors = {A <low>, B <normal>, C <normal>,

D <high>, E <normal>, F <normal>}

We can express this table as a map, which we will call sensors:

sensors : Sensor m Condition

sensors = { }

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:

dom m1 = { a, b, c, d, e }

rng m1 = { 1, 2, 3, 4 }

dom m2 = { a, f, c }

rng m2 = { 1, 2, 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 union operator,

m1 m3 = { a 1, b 2, c 2, d 3, e 4, f 2, g 6}

m1 m2 =

m2 m3 =

undefined

undefined

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, †

m1 † m2 = { a 2, b 2, c 7, d 3, e 4, f 1}

m3 † m2 = { f 1, g 6, a 2, c 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}

{ a 1, c 2, e 4}

a domain restriction operator,

{a, c, e} m1 =

{ e,f } m2 =

{ } m3 =

{ f 1}

{ }

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}

a domain deletion operator,

{ f 2, g 6 } { } m3 =

{ e,f } m2 =

{a, c, e} m1 =

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 }

a range restriction operator,

m1 { 2 } =

{ f 1} 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}

a range restriction operator,

m3 { } =

m1 { 2 } =

m2 {1, 4 } =

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 ) =

m2( f ) =

m3( f ) =

m3( x ) =

3

1

2

undefined

Specifying a high-security building

User name

+

Password

UML Diagrams

SecuritySys

authorized : Employee[*]inside : String[*]

addEmployee(String, String)removeEmployee(String)enter(String, String) : Signalleave(String) : Signal

Employee

name: String

password: String

<<enumeration>>

SignalOPEN_DOORACTIVATE_ALARM

SecuritySys

authorized : Employee[*]inside : Name[*]

addEmployee(Name, Password)removeEmployee(Name)enter(Name, Password) : Signalleave(Name) : Signal

Employee

name: Name

password: Password

The VDM-SL state specification types

Name = TOKENPassword = TOKENSignal = <open_door>|< activate_alarm>

state SecuritySys of

Employee

authorized :

:: name: Name password: Password

Employee-set ?Name Password m

inv mk-SecuritySys(a,i) Only authorised employees can be inside the buildingi dom a

init mk-SecuritySys(a,i) a = { } i = { }

inside : Name-set

addEmployee( )

ext

pre

post

nameIn : Name, passwordIn : Password

authorized : Name m Password wr

authorized = {nameIn passwordIn}authorized

nameIn dom authorized

removeEmployee( )

ext

pre

post

nameIn : Name

wr

nameIn dom authorized

inside : Name-set rd

authorized = {nameIn} authorized

nameIn inside

authorized : Name m Password

enter( )

ext

pre

post

nameIn : Name, passwordIn : Password signal : Signal

rd

inside : Name-set wr

(inside = {nameIn} signal = <open_door>) inside

(inside = signal = <activate_alarm>) inside

(authorized(nameIn) = passwordIn nameIn ) inside

authorized(nameIn) passwordIn nameIn ) inside

TRUE

( nameIn dom authorised

authorized : Name m Password

leave ( )

ext

pre

post

nameIn : Name signal : Signal

inside : Name-set wr

signal = <open_door>

signal = <activate_alarm>

nameIn inside

nameIn inside

TRUE

insideinside = \ {nameIn}

insideinside =

A robot monitoring system

Sector A Sector B

IDLEBROKEN

WORKING

RobotMonitor

robots: Robot[*]

addRobot (String)removeRobot (String)setToWork (String, Sector)finishWork (String)needsRepair (String)fixed(String)inSector (Sector): String [*]numberToRepair (): Integer

<<enumeration>>Sector

AB

Robot

name: Stringmode: Modesector: Sector

<<enumeration>>Mode

workingidle

broken

RobotMonitor

robots: Robot[*]

addRobot (Name)removeRobot (Name)setToWork (Name, Sector)finishWork (Name)needsRepair (Name)fixed(Name)inSector (Sector): Name [*]numberToRepair (): Integer

Robot

name: Namemode: Modesector: Sector

typesName = TOKENModeSectorRobot

= <working>|<idle>| <broken> = <A>|< B> :: name mode sector

: Name : Mode : [Sector]

inv mk-Robot(-, m, s) m = <working> s nil

state RobotMonitor of

robots: Name Robot m

inv mk-RobotMonitorSys(r) n dom r n = r(n).name

init mk-RobotMonitorSys(r) r = { }

end

addRobot ( )

ext

pre

post

nameIn: Name

robots: Name Robot m wr

robots = robots

{ nameIn mk-Robot (nameIn, <idle>, nil) }

nameIn dom robots

removeRobot ( )

ext

pre

post

nameIn: Name

robots: Name Robot m wr

nameIn dom robots

robots = {nameIn } robots

robots(nameIn).mode <working>

setToWork ( )

ext

pre

post

robots: Name Robot m wr

nameIn dom robots

robots = robots

robots(nameIn).mode = <idle>

nameIn: Name, sectorIn Sector

{ nameIn mk-Robot(nameIn, <working>, sectorIn )}

finishWork ( )

ext

pre

post

robots: Name Robot m wr

nameIn dom robots

robots = robots

robots(nameIn).mode = <working >

nameIn: Name

{ nameIn mk-Robot(nameIn, <idle>, nil )}

needsRepair ( )

ext

pre

post

robots: Name Robot m wr

nameIn dom robots

robots = robots

nameIn: Name

{ nameIn mk-Robot(nameIn, <broken>, nil )}

fixed ( )

ext

pre

post

robots: Name Robot m wr

nameIn dom robots

robots = robots

nameIn: Name

{ nameIn ( (nameIn), mode <idle>) } robots

robots(nameIn).mode = <broken >

inSector ( )

ext

pre

post

sectorIn: Sector

robots: Name Robot m rd

TRUE

result : Name-set

result =

{ ? | ? ? } r.sector = sectorInr rng robotsr.name

numberToRepair ( )

ext

pre

post

robots: Name Robot m rd

TRUE

number :

result =

card { ? | ? ? } r.mode = <broken> r rng robotsr