18/5 - 20071 VIP Elevator – second model A VDM++ Project Made By: Sune Wolff.

10
18/5 - 2007 1 VIP Elevator – second model A VDM++ Project Made By: Sune Wolff

Transcript of 18/5 - 20071 VIP Elevator – second model A VDM++ Project Made By: Sune Wolff.

Page 1: 18/5 - 20071 VIP Elevator – second model A VDM++ Project Made By: Sune Wolff.

18/5 - 2007 1

VIP Elevator – second model

A VDM++ Project

Made By: Sune Wolff

Page 2: 18/5 - 20071 VIP Elevator – second model A VDM++ Project Made By: Sune Wolff.

18/5 - 2007 2

Agenda

Summary of First Model Desired Improvements Class Diagram Mapping Intelligent Elevator Intelligent Queue Achieved Improvements

Page 3: 18/5 - 20071 VIP Elevator – second model A VDM++ Project Made By: Sune Wolff.

18/5 - 2007 3

Summary of First Model

Basic first model FIFO queue for placing orders

Using ordered sequence of floors Elevator moved between floors in

atomic fashion

Page 4: 18/5 - 20071 VIP Elevator – second model A VDM++ Project Made By: Sune Wolff.

18/5 - 2007 4

Desired Improvements

Introduce classes for buttons and sensors Make use of mapping

Make elevator more intelligent Keep track of direction Choose next floor based on direction and distance

Introduce automatic test Read test sequence from file

Make sure the VIP receives special treatment No neighbours in elevator when VIP wants to use it Execute VIP order as soon as possible

Page 5: 18/5 - 20071 VIP Elevator – second model A VDM++ Project Made By: Sune Wolff.

18/5 - 2007 5

Class DiagramWorld

Run()World()

Environment

Environment()

-environment

Elevator

VipExit()VipEnter()Elevator()MoveElevator()NeighbourExit()NeighbourEnter()ActivateSensor()PushOuterButton()UpdateCurrent()PushInnerButton()UpdateDir()

Queue

Queue()QueueFull()QueueEmpty()PutInQueue()GetNextFromQueue()

EC

EC()

-ec

+$elevator

+$vipQueue

+$innerQueue

+$outerQueue

Turnstile

locked : bool

Turnstile()LockTurnstile()UnlockTurnstile()IsTurnstileLocked()

+$tsController

Page 6: 18/5 - 20071 VIP Elevator – second model A VDM++ Project Made By: Sune Wolff.

18/5 - 2007 6

Mapping

class ECinstance variables public static floorMap : map Elevator`Floor to nat :=

{<none> |-> -1, <ground> |-> 0, <one> |-> 1, <two> |-> 2, <three> |-> 3, <penthouse> |->

4}; public static invFloorMap : map nat to Elevator`Floor := inverse floorMap;end EC

class Elevatoroperations public UpdateCurrent: Dir * Floor ==> Floor UpdateCurrent(dir, cur) == (dcl curNum : nat := EC`floorMap(cur); if (dir = <up> and cur <> <penthouse>) then curNum := curNum + 1 elseif (dir = <down> and cur <> <ground>) then curNum := curNum – 1; return EC`invFloorMap (curNum); );end Elevator

Page 7: 18/5 - 20071 VIP Elevator – second model A VDM++ Project Made By: Sune Wolff.

18/5 - 2007 7

Intelligent Elevator

public MoveElevator: () ==> Floor MoveElevator() == (if (not EC`vipQueue.QueueEmpty() and EC`innerQueue.QueueEmpty()) then (nextFloor := EC`vipQueue.GetNextFromQueue(direction, currentFloor, nextFloor); currentFloor := UpdateCurrent(direction, currentFloor); return nextFloor) elseif (not EC`innerQueue.QueueEmpty()) then (nextFloor := EC`innerQueue.GetNextFromQueue(direction, currentFloor, nextFloor); currentFloor := UpdateCurrent(direction, currentFloor); return nextFloor) elseif (not EC`outerQueue.QueueEmpty()) then (nextFloor := EC`outerQueue.GetNextFromQueue(direction, currentFloor, nextFloor); currentFloor := UpdateCurrent(direction, currentFloor); return nextFloor) else (UpdateDir(direction); return <none>;

Page 8: 18/5 - 20071 VIP Elevator – second model A VDM++ Project Made By: Sune Wolff.

18/5 - 2007 8

Intelligent Queue

public GetNextFromQueue: Elevator`Dir * Elevator`Floor * Elevator`Floor ==> [Elevator`Floor]

GetNextFromQueue(dir, cur, next) == (dcl nextFloor : Elevator`Floor := next; dcl nextSet : set of Elevator`Floor := {}; dcl top : Elevator`Floor := <penthouse>; dcl bottom : Elevator`Floor := <ground>; for all f in set elevatorQueue do (if (dir = <up> and EC`floorMap(f) > EC`floorMap(cur)) then (nextSet := nextSet union {f}; for all nextF in set nextSet do (if (next = <none>) then (if (EC`floorMap(nextF) < EC`floorMap(top)) then (nextFloor := nextF; top := nextF;) elseif (EC`floorMap(nextF) < EC`floorMap(nextFloor)) then nextFloor := nextF;

Page 9: 18/5 - 20071 VIP Elevator – second model A VDM++ Project Made By: Sune Wolff.

18/5 - 2007 9

Intelligent Queue #2

if (nextFloor <> next and next <> <none>)then (elevatorQueue := elevatorQueue union {next}; elevatorQueue := {y | y in set elevatorQueue & y <> nextFloor};

)elseif (next = <none>)then elevatorQueue := {y | y in set elevatorQueue & y <> nextFloor};return nextFloor;

Page 10: 18/5 - 20071 VIP Elevator – second model A VDM++ Project Made By: Sune Wolff.

18/5 - 2007 10

Achieved Improvements

Introduce classes for buttons and sensors Make use of mapping

Make elevator more intelligent Keep track of direction Choose next floor based on direction and distance

Introduce automatic test Read test sequence from file

Make sure the VIP receives special treatment No neighbours in elevator when VIP wants to use it Execute VIP order as soon as possible

??

VDMUnit