100 likes | 212 Views
VIP Elevator – second model. A VDM++ Project Made By: Sune Wolff. Agenda. Summary of First Model Desired Improvements Class Diagram Mapping Intelligent Elevator Intelligent Queue Achieved Improvements. Summary of First Model. Basic first model FIFO queue for placing orders
E N D
VIP Elevator – second model A VDM++ Project Made By: Sune Wolff
Agenda • Summary of First Model • Desired Improvements • Class Diagram • Mapping • Intelligent Elevator • Intelligent Queue • Achieved Improvements
Summary of First Model • Basic first model • FIFO queue for placing orders • Using ordered sequence of floors • Elevator moved between floors in atomic fashion
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
Mapping class EC instance 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 Elevator operations 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
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>;
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;
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;
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 ?