Banker’s Algorithm Implementation in CPN Tools Michal Žarnay Department of Transportation Networks University of Žilina, Slovakia
University of Žilina Dept. of Transportation Networks CPN'08 Workshop 2 Outline Background Banker’s algorithm: modifications and implementation Analysis results and conclusion
University of Žilina Dept. of Transportation Networks CPN'08 Workshop 3 Background Simulation of large and complex logistic nodes using ABAsim architecture Deadlock states occur Over one hundred resources Automatic instead of human control Tenths of processes at the same time
University of Žilina Dept. of Transportation Networks CPN'08 Workshop 4 Resource Allocation System (RAS) ProcessesResources Limited number Used repeatedly Running concurrentlyAllocated exclusively
RAS: Modelling in CPN
Process Subnet
Resource Subnet
University of Žilina Dept. of Transportation Networks CPN'08 Workshop 8 Used Category of RAS Processes have properties: Flexible routing Use of multiple resource types at once Concurrent processing
Branches of Concurrent Processing
University of Žilina Dept. of Transportation Networks CPN'08 Workshop 10 Variants of Flexible Routing
University of Žilina Dept. of Transportation Networks CPN'08 Workshop 11 Process and Resource Instances
University of Žilina Dept. of Transportation Networks CPN'08 Workshop 12 Deadlock-Avoidance Policy (DAP) Processes combine concurrent processing and flexible routing Chosen: Banker’s algorithm DAP for such a RAS not found
University of Žilina Dept. of Transportation Networks CPN'08 Workshop 13 Banker’s Algorithm (BA) Using information about current system state it attempts to order running process instances in a sequence, so they can be finished State is not ordered State may (not) be safe State is safe State is ordered Success? +–
Assigning at T7 Request of P2: (0,-1,1) AllocatedNeededAvailable R1R2R3R1R2R3R1R2R3 P P AllocatedNeededAvailable R1R2R3R1R2R3R1R2R3 P P Ordered state:
University of Žilina Dept. of Transportation Networks CPN'08 Workshop 15 Unsafe states BA Principle Deadlock states Safe states States ordered by BA
University of Žilina Dept. of Transportation Networks CPN'08 Workshop 16 Tasks 1.Modify an available version of BA to suit the needs 2.Implement it 3.Test the BA on a model with outlined properties
University of Žilina Dept. of Transportation Networks CPN'08 Workshop 17 Why Choosing CPN Tools? Fast construction of the model in Petri nets Facilities for qualitative analysis of the model Availability of language for the BA implementation
University of Žilina Dept. of Transportation Networks CPN'08 Workshop 18 Outline Background Banker’s algorithm: modifications and implementation Analysis results and conclusion
University of Žilina Dept. of Transportation Networks CPN'08 Workshop 19 Original Data Structures For process instances: –Allocated resource units to process instances –Needed resource units to finish process instances –Available resource units in the system Overall –Set of all process instances –Set of all resource instances
University of Žilina Dept. of Transportation Networks CPN'08 Workshop 20 Original Algorithm On entering, each process instance declares the maximum number of units of each resource type needed for its execution Elaborated versions: supportive routines update the number of remaining needed resources on the run – information related to process stages
University of Žilina Dept. of Transportation Networks CPN'08 Workshop 22 Modifications of BA Needed renamed to RemainingNeeded Change information not fixed to process stages, but relative to it => Change – vector of relative changes for all resource types –Bits encoding –Primary and other descriptions
University of Žilina Dept. of Transportation Networks CPN'08 Workshop 23 Bits Encoding –18 – – 12– 3 released 2 planned for re-allocation assigned
BA: 12 Functions in CPN ML Links represent calls to functions
University of Žilina Dept. of Transportation Networks CPN'08 Workshop 25 Adding BA to CPN Model Adding one place Adding arcs Editing transition guards
A dedicated fusion place linked to transitions via a pair of arcs
input data output data after the change
Allocation No allocation BA is called only by an allocation request (7 from 9 transitions)
Change from primary to secondary variant Specific update, when changing the variants
University of Žilina Dept. of Transportation Networks CPN'08 Workshop 30 Outline Background Banker’s algorithm: modifications and implementation Analysis results and conclusion
University of Žilina Dept. of Transportation Networks CPN'08 Workshop 31 Analysis via CPN Tools Main criterion: number of deadlock states in the occurrence graphs of 2 models: –without BA –with BA Validation and verification phases: –All transitions occurring in the model without BA must occur in the model with BA –All reachable markings must form a home space Restriction of state space by BA
University of Žilina Dept. of Transportation Networks CPN'08 Workshop 32 Analysis Results Banker’s algorithm –Avoids deadlock states –Does not influence behaviour of the model inappropriately –Restricts the state space Model version State space Deadlock statesStatesTransitions Without BA With BA
University of Žilina Dept. of Transportation Networks CPN'08 Workshop 33 Benefits Banker’s algorithm works for the outlined RAS with processes containing at the same time: –Concurrent processing –Flexible routing –Use of multiple resource types at once CPN Tools – integration of the properties: –Fast construction of the model in Petri nets –Facilities for qualitative analysis of the model –Availability of language for the BA implementation
University of Žilina Dept. of Transportation Networks CPN'08 Workshop 34 Shortcomings Implementation of BA in 12 CPN ML functions is rather complicated compared to sequential programming Use of external routines? Maintaining information about global states makes the CPN more difficult to read Use of hierarchy
University of Žilina Dept. of Transportation Networks CPN'08 Workshop 35 Further Issues Complex models produce too large state spaces –Algorithm should be effective – verify it! –Challenge: How to make its run more effective for such systems? More complicated way of allocation and release of resources – already implemented and requires further testing More complicated versions of BA – are they effective and beneficial for our purpose?
Thank you for your attention!
University of Žilina Dept. of Transportation Networks CPN'08 Workshop 37 AllocatedNeededAvailable R1R2R3R1R2R3R1R2R3 P P P P