200 likes | 345 Views
Tray allocation for a sortation system Concurrent version Iteration II. TI-VDM2 Project by José Antonio Esparza and Kim Bjerge. Contents of presentation. Simulation scenario in time (ms) The concurrent version of the system (Class) Object diagram concurrent version (Object)
E N D
Tray allocation for a sortation systemConcurrent versionIteration II TI-VDM2 Project by José Antonio Esparza and Kim Bjerge Sortation System, TrayAllocation
Contents of presentation • Simulation scenario in time (ms) • The concurrent version of the system (Class) • Object diagram concurrent version (Object) • Behavior of sequential model (Sequence) • Behavior of concurrent model (Sequence) • VDM - Concurrent model (Vs. sequential) • 10 slides • Introduction to RT model (Deployment) Sortation System, TrayAllocation
Simulation in time (ms) instead of TraySteps Concurrent simulation scenario (time in ms) mk_(7200,[mk_(40,1,100), mk_(70,2,200), mk_(100,3,300), mk_(200,1,400), mk_(210,2,500), mk_(220,3,100) Sequential simulation scenario (TraySteps) mk_(21,[mk_(0,1,100), mk_(0,2,200), mk_(0,3,300), mk_(1,1,400), mk_(1,2,500), mk_(1,3,100), Sortation System, Tray Allocation
1.- The concurrent version of the system Sortation System, Tray Allocation
2.- Object diagram concurrent version Sortation System, Tray Allocation
4. Behavior of sequential model (Sequence) Sortation System, Tray Allocation
5.- Behavior of concurrent model (Sequence) Sortation System, Tray Allocation
VDM - World -- Concurrent model public static timerRef : TimeStamp := new TimeStamp(); start(env); -- Start thread in enviroment -- Sequential model for all t in set {0,...,loader.GetNumTimeSteps()} do env.TimeStep(t); Sortation System, Tray Allocation
VDM - SorterEnviromentstartingthreads busy : bool := true; public static trayStep : TrayStep := new TrayStep(Speed); ….. public isFinished : () ==> () isFinished() == skip; sync per isFinished => not busy; thread ( -- Start all threads in the system start (trayStep); start (sc.allocator); for all i in set {1,...,TrayAllocator`NumOfInductions} do start (inductionGroup(i)); Sortation System, TrayAllocation
VDM - SorterEnviromentfeedinductions whilebusy do ( for all i in set {1,...,TrayAllocator`NumOfInductions} do ( let size = itemLoader.GetItemAtTimeStep(World`timerRef.GetTime(), i) in if(size > 0) then ( itemId:= itemId + 1; inductionGroup(i).FeedItem(new Item(size, itemId)); ); ); Sortation System, Tray Allocation
VDM - SorterEnviromentadvance time World`timerRef.WaitRelative(0); World`timerRef.NotifyAndIncTime(); World`timerRef.Awake(); -- Check if simulation is finish if(World`timerRef.GetTime() >= itemLoader.GetNumTimeSteps()) then busy:= false; ); Sortation System, Tray Allocation
VDM –TrayStepsync and thread public WaitSteps : nat ==> () WaitSteps(steps) == ( AddToMap(threadid, counts + steps); Wait(); ); Wait: () ==> () Wait() == skip; sync per Wait => threadid not in set domwaitTrayStepMap; thread whiletrue do ( IncCounts(); NotifyWatingThreads(); World`timerRef.WaitRelative(stepTime); World`timerRef.NotifyAll(); World`timerRef.Awake(); ) Sortation System, Tray Allocation
VDM - InductionControllerthread and sync -- Enviroment and TrayAllocatorthreads mutex (FeedItem, InductFirstItem); -- TrayAllocator and InductionControllerthreads mutex (InductFirstItem); mutex (IncrementPriority); mutex (GetFirstItem, IncrementPriority, InductFirstItem); -- Block thread if no items to induct per InductNextItem => len items > 0; per ItemsToInduct => len items > 0; thread ( while (ItemsToInduct()) do ( allocator.RequestTray(threadid, selfIC, GetFirstItem()); allocator.Wait(); SorterEnviroment`trayStep.WaitSteps(InductionRate); -- World`timerRef.WaitRelative(InductionRateInMs); -- World`timerRef.Awake(); ); ); Sortation System, Tray Allocation
VDM - InductionController new operations GetFirstItem: () ==> Item GetFirstItem() == returnhd items pre len items <> 0; public InductFirstItem: () ==> () InductFirstItem() == atomic -- Due to invariant ( items := tl items; priority := 0 ) prelen items <> 0; public IncrementPriority: () ==> () IncrementPriority() == priority := priority + 1; -- Increment priority wait counter ItemsToInduct: () ==> bool ItemsToInduct () == return len items <> 0; Sortation System, Tray Allocation
TrayAllocatorthread and sync -- Map of waiting inductions with an item to be inducted itemsToInduct : map nat to (InductionController * Item) := {|->}; ….. mutex(RequestTray); -- Only allows one induction at a time to induct items -- Mutex to ensure syncronization between InductionController and TrayAllocator mutex(RequestTray, CheckItemsToInduct); -- Permission predicate on Wait operation per Wait => threadid not in set domitemsToInduct; thread while (true) do ( -- Wait time equal to one tray step SorterEnviroment`trayStep.WaitSteps(1); CardReader(TrayStep`GetCounts() mod TrayAllocator`NumOfTrays + 1, <Empty>); -- Induct items for all waiting inductions CheckItemsToInduct(); ); Sortation System, Tray Allocation
VDM - TrayAllocatorCheckItemsToInduct CheckItemsToInduct: () ==> () CheckItemsToInduct () == ( -- Induct items for all waiting inductions for all t in set domitemsToInduct do let mk_(ic, item) = itemsToInduct(t) in ifInductItem(ic, item) then ( ic.InductFirstItem(); RemoveItem(t); ) else ic.IncrementPriority(); ); Sortation System, Tray Allocation
VDM - TrayAllocator new operations -- Called by InductionController thread requesting to induct item public RequestTray: nat * InductionController * Item ==> () RequestTray (t, ic, item) == AddItem(t, ic, item) pre t not in set domitemsToInduct; -- Thread blocked until removed from Map itemsToInduct public Wait: () ==> () Wait() == skip; -- Add induction waiting with item to induct AddItem: nat * InductionController * Item ==> () AddItem (t, ic, item) == itemsToInduct := itemsToInductmunion {t |-> mk_(ic, item)} pre t not in set domitemsToInduct; -- Remove induction waiting with item to induct RemoveItem: nat ==> () RemoveItem (t) == itemsToInduct := {t} <-: itemsToInduct pre t in set domitemsToInduct; Sortation System, Tray Allocation
VDM – SC prepared for RT model class SC instancevariables public static ic1 : InductionController := new InductionController(1); public static ic2 : InductionController := new InductionController(2); public static ic3 : InductionController := new InductionController(3); public static inductionGroup : seq of InductionController := [ic1, ic2, ic3]; public static allocator : TrayAllocator := new TrayAllocator(inductionGroup); operations public SC: () ==> SC SC() == ( ); -- Create assignments releations between objects public CreateAssignments: SorterEnviroment ==> () CreateAssignments (env) == ( ic1.AssignAllocator(allocator); ic2.AssignAllocator(allocator); ic3.AssignAllocator(allocator); env.AssignInductionGroup(inductionGroup); ); Sortation System, Tray Allocation
Next step for RT model • Deploythreads to CPU’s • CPU for eachinduction • TrayAllocatoron a central CPU controller • Firstdeployed RT version ready Outstanding for RT model – nexttodo • RemoveTimeStamp and TrayStep • Makeperiodicthread for eg. TrayAllocator • Still need time somehow? • Look at how to useasyn operations? Sortation System, Tray Allocation
First RT version made for SC – system instance variables cpuIC1 : CPU := new CPU (<FCFS>,1E6); cpuIC2 : CPU := new CPU (<FCFS>,1E6); cpuIC3 : CPU := new CPU (<FP>,1E9); cpuTA4 : CPU := new CPU (<FCFS>,1E6); bus1 : BUS := new BUS (<FCFS>,1E3,{cpuIC1,cpuTA4}); bus2 : BUS := new BUS (<FCFS>,1E3,{cpuIC2,cpuTA4}); bus3 : BUS := new BUS (<FCFS>,1E3,{cpuIC3,cpuTA4}); …. operations public SC: () ==> SC SC() == ( cpuIC1.deploy(ic1); cpuIC2.deploy(ic2); cpuIC3.deploy(ic3); cpuTA4.deploy(allocator); ); Sortation System, Tray Allocation