TIVDM1Modelling relationships1 Peter Gorm Larsen.

Slides:



Advertisements
Similar presentations
ML Lists.1 Standard ML Lists. ML Lists.2 Lists A list is a finite sequence of elements. [3,5,9] ["a", "list" ] [] Elements may appear more than once [3,4]
Advertisements

Hierarchical Task Network (HTN) Planning Hai Hoang 4/17/2007.
1 Modelling using sets Sets: The finite set type constructor Value definitions: enumeration, subrange, comprehension Operators on sets Case Study: the.
12 April 2009Instructor: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Formal.
1-1 An Introduction to Scheme March Introduction A mid-1970s dialect of LISP, designed to be a cleaner, more modern, and simpler version than.
A Lightning Tour of Haskell Lecture 1, Designing and Using Combinators John Hughes.
1 Introducing ASML Sequences, Parallel evaluation, Maps, Non-Determinism Lecture 12 Software Engineering COMP201.
1 Functions Chapter 10 Formal Specification using Z.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Kernel language semantics Carlos Varela RPI Adapted with permission.
Vienna Development Method SIM5104. one of the longest-established Formal Methods for the development of computer- based systemsFormal Methods Originating.
1 Predicates and quantifiers Chapter 8 Formal Specification using Z.
Functions. A function between two sets is a relation between those sets that has a special property, namely that each member of the from-set is related.
Programming Concepts MIT - AITI. Variables l A variable is a name associated with a piece of data l Variables allow you to store and manipulate data in.
The Z Notation: relations and functions Compiled By Tariq R. Soomro, Ph.D. Reference: Text Book Week-7.
Functional Programming Element of Functional Programming.
Math 002 College Algebra Final Exam Review.
Data Structures in Python By: Christopher Todd. Lists in Python A list is a group of comma-separated values between square brackets. A list is a group.
PRACTICAL COMMON LISP Peter Seibel 1.
SWBAT… define and evaluate functions Agenda 1. Warm-Up (5 min) 2. Quiz – piecewise functions (6 min) 3. Notes on functions (25 min) 4. OYO problems (10.
Functional Programming in Scheme and Lisp. Overview In a functional programming language, functions are first class objects. You can create them, put.
Michaelmas Term 2004 Discrete Mathematics CSC 141 Discrete Mathematics Dr. Corina Sas and Ms. Nelly Bencomo
Formal Methods in SE Lecture 20. Agenda 2  Relations in Z Specification Formal Methods in SE.
Algorithms and their Applications CS2004 ( ) Dr Stephen Swift 3.1 Mathematical Foundation.
INM175 Topic 7 1 Module INM175 Discrete Mathematics Topic 7 Set Theoretic Models.
Functional Programming and Lisp. Overview In a functional programming language, functions are first class objects. In a functional programming language,
TIVDM1Modelling ordered collections1 Peter Gorm Larsen.
TIVDM1Modelling ordered collections1 Peter Gorm Larsen.
TIVDM2Real-Time and Distributed Development in VDM++1 Peter Gorm Larsen
Equations, Inequalities, and Mathematical Models 1.2 Linear Equations
TIVDM1Modelling unordered collections1 Peter Gorm Larsen.
TIVDM1Modelling unordered collections1 Peter Gorm Larsen.
Built-in Data Structures in Python An Introduction.
1 Relational Algebra and Calculas Chapter 4, Part A.
REVIEW A relation is a set of ordered pairs. {(2,3), (-1,5), (4,-2), (9,9), (0,-6)} This is a relation The domain is the set of all x values.
F28PL1 Programming Languages Lecture 13: Standard ML 3.
Python uses boolean variables to evaluate conditions. The boolean values True and False are returned when an expression is compared or evaluated.
Chapter 7 Selection Dept of Computer Engineering Khon Kaen University.
Albert Gatt LIN3021 Formal Semantics Lecture 4. In this lecture Compositionality in Natural Langauge revisited: The role of types The typed lambda calculus.
CS201: Data Structures and Discrete Mathematics I
MATH 224 – Discrete Mathematics
LISP Data Types Functional Programming Academic Year Alessandro Cimatti
Naïve Set Theory. Basic Definitions Naïve set theory is the non-axiomatic treatment of set theory. In the axiomatic treatment, which we will only allude.
Formal Methods in SE Lecture 16 Formal Methods in SE Qaisar Javaid Assistant Professor.
8. The set types The set types are one of the compound types available in SOFL, and usually used for the abstraction of data items that have a collection.
Sets Definition: A set is an unordered collection of objects, called elements or members of the set. A set is said to contain its elements. We write a.
Semantics of Predicate Calculus For the propositional calculus, an interpretation was simply an assignment of truth values to the proposition letters of.
TIVDM1Sortation System, Tray Allocation1 Tray allocation for a sortation system Iteration III TI-VDM1 Project by José Antonio Esparza and Kim Bjerge.
1 Logic Our ability to state invariants, record preconditions and post- conditions, and the ability to reason about a formal model depend on the logic.
1 FP Foundations, Scheme In Text: Chapter Chapter 14: FP Foundations, Scheme Mathematical Functions Def: A mathematical function is a mapping of.
1 Modelling using Sequences Sequences The finite sequence constructor Value definitions: enumeration, subsequence Operators on Sequences Case Study: the.
CSE 425: Functional Programming I Programs as Functions Some programs act like mathematical functions –Associate a set of input values from the function’s.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
11 Making Decisions in a Program Session 2.3. Session Overview  Introduce the idea of an algorithm  Show how a program can make logical decisions based.
CMSC201 Computer Science I for Majors Lecture 05 – Comparison Operators and Boolean (Logical) Operators Prof. Katherine Gibson Prof. Jeremy.
Sets Page 746.
Functional Programming Languages
Principles of programming languages 12: Functional programming
Formal Methods in SE Lecture 21.
Types CSCE 314 Spring 2016.
VDM: Vienna Development Method
Relations and Functions
A lightening tour in 45 minutes
MATH 224 – Discrete Mathematics
Chapter 2 Sets and Functions.
Haskell.
Component 1 – 2A, B, C Binary Logic
Instructor: Alexander Stoytchev
Functions Computers take inputs and produce outputs, just like functions in math! Mathematical functions can be expressed in two ways: We can represent.
From now on: Combinatorial Circuits:
Relations/Sequences Objective: Students will learn how to identify if a relation is a function. They will also be able to create a variable expression.
Presentation transcript:

TIVDM1Modelling relationships1 Peter Gorm Larsen

TIVDM1Modelling relationships2 Agenda  Mapping Characteristics and Primitives The MSAW Example Revisited The Congestion Warning System Revisited

TIVDM1Modelling relationships3 Mapping Characteristics Mappings are unordered collections of pairs of elements (a maplet) with a unique relationship There can be many copies of each maplet The elements themselves can be arbitrary complex, e.g. they can be mappings as well Mappings in VDM++ are finite Mapping types in VDM++ are written as: map Type1 to Type2 inmap Type1 to Type2 (for injective mappings)

TIVDM1Modelling relationships4 Mapping Enumeration A maplet is written with curly brackets: “ { domv |-> rngv } ” A mapping enumeration consists of a comma-separated list of maplets enclosed between curly brackets, ”{…}” For example {1 |-> 5,8 |->1,3|-> 9} {true|->1, false|->0,false|->0} {“Peter”|->{}, “Frodo”|->{4,3},”John”|->{2,4}} {‘g’|->1,’o’|->0,’d’|->1} {3.567|->3, |->0,7|->7,7|->,7|->7,7|->7} Are all mappings The empty mapping can be written as “ { |-> } ”

TIVDM1Modelling relationships5 Mapping Domain The domain of a mapping is the collection of the first elements in the maplets of a mapping Multiple occurrences of the same value does not count The domain of a mapping M is written as “ dom M” Quick examples: dom {“Peter”|->1,”Nico”|->2,”Paul”|->3} dom { |-> } dom {3|->2,3|->2,1|->8}

TIVDM1Modelling relationships6 Mapping Range The range of a mapping is the collection of the second elements in the maplets of a mapping Multiple occurrences of the same value does not count The range of a mapping M is written as “rng M” Quick examples: rng {“Peter”|->1,”Nico”|->2,”Paul”|->3} rng { |-> } rng {3|->2,3|->2,1|->8}

TIVDM1Modelling relationships7 Mapping Equality Two mappings are equal if both have the same domain and for all elements in the domain the corresponding range values are equal Quick examples: {2|->4,1|->2} = {1|->2,2|->4} {true|->1, true|->1, false|->0} = {false|->1, true|->1} {1|->3,3|->8,8|->1} = {8|->3,3|->1,1|->8} {1|->{3,4,5},2|->{4}} = {3|->{3,5,4},2|->{4,4,4}}

TIVDM1Modelling relationships8 Mapping Application Looking up in a mapping for a given domain value yields the corresponding range value Mapping application is written as function application, i.e. mapping(domain expression) Quick examples: {1|->2,3|->4,5|->6}(3) {true|->1,false|->2,}(true) {[5]|->1,[6,1]|->2,[4,4,4]|->3}([6,1]) {5|->[5],6|->[6,1],4|->[4,4,4]}(6)

TIVDM1Modelling relationships9 Mapping Domain Restrictions It is possible to restrict the domain of a mapping to or by a given set of elements Domain restrictions are written as: s <: m (restricting domain to the set s) s <-: m (restricting domain by the set s) Quick examples: {1,2,2} 5,4|->2} {3,4} 7,2|->4} {1,3} 8,5|->1} {2,4} 4,3|->6}

TIVDM1Modelling relationships10 Mapping Range Restrictions It is possible to restrict the range of a mapping to or by a given set of elements Range restrictions are written as: m :> s (restricting range to the set s) m :-> s (restricting range by the set s) Quick examples: {1 |->5,4|->2} :> {1,2,2} {1|->7,2|->4} :> {3,4} {3|->8,5|->1} :-> {1,3} {8|->4,3|->6} :-> {6,4}

TIVDM1Modelling relationships11 Mapping Override and Merge It is possible to combine two mappings by either merging them together (similar to set union) or by letting one mapping override another mapping Merging is written with munion using infix notation munion requires mappings to be conformant, i.e. if domains have common elements they map to the same range value Overriding is written with ++ using infix notation and the mapping from the second argument overrides the maplets from the first argument Quick examples: {1|->2,3|->4} munion {2|->3,4|->1} {5|->7,8|->0} munion {6|->3,5|->7} {1|->2,3|->4,2|->8} ++ {2|->3,4|->1} {5|->7,8|->0,6|->9} ++ {6|->3,5|->9}

TIVDM1Modelling relationships12 Distributed Mapping Merge Given a set of mappings it is possible to take a distributed merge if all the mappings are conformant Distributed mapping merge is written as “ merge ms ” where ms is a set of mappings Quick examples merge {{2|->4},{3|->4,1|->2},{2|->4,7|->3}} merge {{5|->”me”,7|->”too”},{6|->”what”,8|->”now”}} merge {}

TIVDM1Modelling relationships13 Mapping Inverse A mapping is injective if all its domain elements map to different range elements For injective mappings it is possible to construct the inverse mapping (swapping domain and range elements) This is written as “ inverse m ” using prefix notation Quick examples: inverse {1|->2,3|->4,2|->3,4|->1} inverse {5|->7,8|->0,6|->3,5|->7} inverse {1|->2,3|->4,2|->8,6|->3,4|->1} inverse {|->}

TIVDM1Modelling relationships14 Map Operators dom m Domain (map A to B) -> set of A rng m Range (map A to B) -> set of B m1 munion m2 Merge (map A to B) * (map A to B) -> (map A to B) m1 ++ m2 Override (map A to B) * (map A to B) -> (map A to B) merge ms Distr. merge set of (map A to B) -> map A to B s map A to B m :> s Rng. restr. to (map A to B) * set of A -> map A to B m :-> s Rng. restr. by (map A to B) * set of A -> map A to B m(d) Map apply (map A to B) * A -> B inverse m Map inverse inmap A to B -> inmap B to A m1 = m2 Equality (map A to B) * (map A to B) -> bool m1 <> m2 Inequality (map A to B) * (map A to B) -> bool

TIVDM1Modelling relationships15 Mapping Comprehensions Using predicates to define mappings implicitly In VDM++ formulated like: {maplet | list of bindings & predicate} The predicate part is optional Quick examples {i |-> i*i | i: nat1 & i <= 4} {i**2 |-> i/2 | i in set {1,…,5}}

TIVDM1Modelling relationships16 Questions What are the mapping enumerations for: {x |-> x|x in set {8,…,1} & x < 3} {x |-> 2*x|x in set {1,…,10} & x > 3 and x < 6} {{y} |-> y - 8| y in set {3,1,7,3}} {x |-> x+6| x in set {1,2}} {x|->mk_(x,8)| x in set {1,2,7} & x > 4} {y|->y|y in set {0,1,2} & exists x in set {0,…,3} & x = 2 * y} {x|->x = 7| x in set {1,…,10} & x < 6}

TIVDM1Modelling relationships17 Agenda Mapping Characteristics and Primitives  The MSAW Example Revisited The Congestion Warning System Revisited

TIVDM1Modelling relationships18 Making use of FO Identification In the set version of the MSAW model we had: class AirSpace is subclass of GLOBAL instance variables airspace : set of FO := {}; inv forall x,y in set airspace & x <> y => x.getId() <> y.getId(); If we use mappings this can be done simpler class AirSpace is subclass of GLOBAL instance variables airspace : map FOId to FO := {|->};

TIVDM1Modelling relationships19 An Updated Class Diagram

TIVDM1Modelling relationships20 Adding and Removing Flying Objects class AirSpace is subclass of GLOBAL operations public addFO : FO ==> () addFO(fo) == airspace := airspace munion {fo.getId() |-> fo} pre forall x in set rng airspace & fo.getId() <> x.getId(); public removeFO : FOId ==> () removeFO(id) == airspace := {id} <-: airspace; …

TIVDM1Modelling relationships21 Getting Hold of a FO and Airspace class AirSpace … public getFO : FOId ==> FO getFO(id) == return airspace(id) pre id in set dom airspace; public getAirspace : () ==> set of FO getAirspace() == return rng airspace;

TIVDM1Modelling relationships22 Can Radars use Mappings? class Radar is subclass of GLOBAL instance variables location : Coordinates; range : nat1; detected : map FOId to FO; priority : seq of FO := []; operations public Scan : AirSpace ==> () Scan(as) == (detected := { x.getId() |-> x | x in set as.getAirspace() & InRange(x) }; UpdatePriorityList() );

TIVDM1Modelling relationships23 Removing and Adding FOs removeNotDetected : set of FO ==> () removeNotDetected(fos) == priority := [priority(i) | i in set inds priority & priority(i) in set fos]; addNewlyDetected : map FOId to FO ==> () addNewlyDetected(newlyDetect) == priority := priority ^ set2seqFO(rng newlyDetect); functions set2seqFO : set of FO -> seq of FO set2seqFO(fos) == if fos = {} then [] else let fo in set fos in [fo] ^ set2seqFO(fos\{fo})

TIVDM1Modelling relationships24 Updating Priority List UpdatePriorityList : () ==> () UpdatePriorityList() == let notDetect = elems priority \ rng detected, newlyDet = detected :-> elems priority in ( removeNotDetected(notDetect); addNewlyDetected(newlyDet) );

TIVDM1Modelling relationships25 Overview in Air Traffic Controller class Radar … public getDetectedMap : () ==> map FOId to FO getDetectedMap() == return detected; end Radar class AirTrafficeController operations OverviewAllRadars: () ==> map FOId to FO OverviewAllRadars() == merge {r.getDetectedMap() | r in set radars} end AirTrafficeController

TIVDM1Modelling relationships26 Agenda Mapping Characteristics and Primitives The MSAW Example Revisited  The Congestion Warning System Revisited

TIVDM1Modelling relationships27 The CWS Revisited Introducing a more realistic road network Introducing the notion of lanes Introducing name servers Adding sensors and actuators gradually

TIVDM1Modelling relationships28 The Revised CWS System

TIVDM1Modelling relationships29 Two Injective Mappings at VDM++ Level class CWS instance variables roadNetwork: inmap Location to CongestionMonitor := {|->} sensors: inmap Location to (inmap Lane to PassageSensor) := {|->}; types public Location = nat1; public Lane = nat1 … end CWS

TIVDM1Modelling relationships30 Class Diagram for Revised CWS

TIVDM1Modelling relationships31 Adding a new Sensor class CWS … operations public AddSensor: Location * Lane ==> () AddSensor(loc, lane) == def passageSensor = new PassageSensor(loc, lane) in let sensorAtLane = {lane |-> passageSensor} in if loc in set dom sensors then sensors(loc) := sensors(loc) munion sensorAtLane else sensors := sensors munion {loc |-> sensorAtLane}; end CWS

TIVDM1Modelling relationships32 Dealing with Name Servers Control over the actuation managers Each control manager control multiple locations class NameServer instance variables am: map ActuatorManager to (set of CWS`Location) := {|->} … end NameServer

TIVDM1Modelling relationships33 Setting Actuation Managers in control class NameServer operations public SetActuatorManager: ActuatorManager * set of CWS`Location ==> () SetActuatorManager(actuatorManager, locations) == am := am ++ {actuatorManager |-> locations}; end NameServer

TIVDM1Modelling relationships34 Getting an Actuation Manager class NameServer operations public GetActuatorManager: [CWS`Location] ==> [ActuatorManager] GetActuatorManager(loc) == if loc = nil then return nil else let locations = inverse am in let locationSet in set dom locations be st loc in set locationSet in return locations (locationSet); end NameServer

TIVDM1Modelling relationships35 Message Logs inside Congestion Sensors class CongestionSensor is subclass of Sensor … instance variables passageSensors: map CWS`Lane to PassageSensor := {|->} end CongestionSensor Notice that the first box on page 180 in the book is wrong. This is the right version.

TIVDM1Modelling relationships36 Issue Congestion Warnings class CongestionSensor is subclass of Sensor public IssueCongestionStatus: () ==> CongestionSensor`CongestionStatus IssueCongestionStatus() == def averagespeed = min ({passageSensors(lane). AverageSpeed(NoPassages) | lane in set dom passageSensors}) in if averagespeed < CongestionThreshold then return elseif averagespeed > NoCongestionThreshold then return else return end CongestionSensor

TIVDM1Modelling relationships37 Managing Actuators class ActuationManager … instance variables as: inmap CWS`Location to Actuator := {|->}; ns: NameServer end ActuationManager

TIVDM1Modelling relationships38 Adding Actuator at a given Location class ActuationManager … operations public AddActuator: CWS`Location ==> () AddActuator(loc) == def actuator = new Actuator() in (as := merge {as, {loc |-> actuator}}; ns.SetLocation(self, loc) ) pre loc not in set dom as; end ActuationManager

TIVDM1Modelling relationships39 Removing Actuators class ActuationManager … operations public RemoveActuator: Actuator ==> () RemoveActuator(actuator) == as := as :-> {actuator}; end ActuationManager

TIVDM1Modelling relationships40 Replacing Actuators class ActuationManager … operations public ReplaceActuator: Actuator * Actuator ==> () ReplaceActuator(actuator, newActuator) == as := as ++ {(inverse as)(actuator) |-> newActuator}; end ActuationManager

TIVDM1Modelling relationships41 Showing Signal at a given Location class OperatorControl … public ShowSignal: CWS`Location * CongestionMonitor`Signal ==> () ShowSignal(location, signal) == ( def downstreamLocation = Downstream(location, ns.GetLocations()); downstreamManager = ns.GetActuatorManager(downstreamLocation); downstreamSignal = if downstreamManager <> nil then downstreamManager.GetSignal(downstreamLocation) else nil; actuator = as(location); upstreamLocation = Upstream(location, ns.GetLocations()); upstreamManager = ns.GetActuatorManager(upstreamLocation); upstreamSignal = if upstreamManager <> nil then upstreamManager.GetSignal(upstreamLocation) else nil in ( ShowSignalAtLoc(signal,downstreamLocation, downstreamSignal,actuator); ShowSignalUpstream(signal,upstreamLocation,upstreamManager,upstreamSignal) ) ) pre location in set dom as; end OperatorControl

TIVDM1Modelling relationships42 Operator Utilities class OperatorControl … operations public WriteLog: seq1 of char * CWS`Location ==> () WriteLog(message, location) == let newMessage = message ^ int2String(location), messages = if location in set dom messageLog then messageLog(location) ^ [ newMessage ] else [ newMessage ] in messageLog := messageLog ++ {location |-> messages}; public CongestionSpots: () ==> set of CWS`Location CongestionSpots() == return dom messageLog; end OperatorControl

TIVDM1Modelling relationships43 Summary What have I presented today? The notion of mappings as ordered collections The basic operations in VDM++ for manipulating mappings The MSAW example again The congestion warning system example again What do you need to do now? Complete your project Provide report and source model to me Fill out evaluation form Tell me whether you would like an exam trial session

TIVDM1Modelling relationships44 Quote of the day By Herbert Hoover ( ) Engineering is a great profession. There is the satisfaction of watching a figment of the imagination emerge through the aid of science to a plan on paper. Then it moves to realization in stone or metal or energy. Then it brings homes to men or women. Then it elevates the standard of living and adds to the comforts of life. This is the engineer's high privilege.