Object Oriented Simulation with OOSimL Models with Resources Fall 2015 Resources Processes are the active components of system Resources are passive components of a system In the process-interaction approach to simulation, resource pools are defined and created. Processes can acquire a number of resource items from a resource pool. (C) J. M. Garrido 2 Types of Resources Standard resources that are accessed in a mutually exclusive manner by processes. These resource objects represent a finite pool of resource units and are created with the Res class. Detachable resources that are consumed by the processes. These resource objects represent infinite pools of resource units and are created with the Bin class. (C) J. M. Garrido 3 Resource Pools A system can include zero or more resource pools Each resource pool has a number of resource items A number of these resource items can be acquired by one or more processes (C) J. M. Garrido 4 Resource Allocation and Deallocation Every process follows the sequence: Request a number of resource items from a resource pool, wait until these become available Acquire a number of items from a resource pool Use the resource items for a finite period Release the some or all resource items acquired (C) J. M. Garrido 5 Standard Resources A resource pool is an passive object A simulation model must declare a resource pool and create the resource pool object with a number of resource items A specific number of items of a resource pool can be used by at most one process (C) J. M. Garrido 6 Resource Contention Mechanism Processes compete for a limited number of resource items. When there are not sufficient resource items for a request, the requesting process is suspended and placed in an internal queue by priority. The processes waiting for resource items are reactivated when another process releases sufficient items. (C) J. M. Garrido 7 Resource Classes in OOSimL A resource pool is an object of class Res The resource pool object is created with a number of resource items The resource pool object includes mechanism for processes to compete in a mutual exclusive manner for resources by (C) J. M. Garrido 8 Using Resources in OOSimL For example, to declare and create a resource with 50 chairs: define chairs of class Res // chairs as a resource pool .... create chairs of class Res using “Wood chairs”, 50 A process acquires 15 chairs then releases 10: acquire 15 from chairs … release 10 of chairs // acquire 15 chairs // release 10 chairs (C) J. M. Garrido 9 (C) J. M. Garrido 10 Get Available Resources The following lines of code get the current number of available resource units in the resource pool chairs, which was defined above, and assigns this value to variable num_res. define num_res of type integer ... assign available units of chairs to num_res (C) J. M. Garrido 11 Checking for Available Items A process may want to first check the number of available resource items before attempting to acquire items. assign available units of chairs to items_left if items_left >= 15 then acquire 15 from chairs else // carry out some other activity endif (C) J. M. Garrido 12 A Simple Model of a Warehouse Trucks arrive periodically to a busy warehouse to unload goods Trucks need to wait for an unloading bay Small trucks need two workers for unloading Big trucks need three workers for unloading (C) J. M. Garrido 13 Resources and Processes in the Warehouse Model Warehouse resources: 2 unloading bays 5 workers for unloading Processes: small trucks big trucks arrivals for small trucks arrivals for big trucks (C) J. M. Garrido 14 (C) J. M. Garrido 15 Workload and Performance Both types of trucks have different mean arrival rates and different mean unloading periods. Some of the performance measures calculated for this model are: Average wait period for each type of truck Number of trucks serviced of each type Resource utilization (C) J. M. Garrido 16 Executing The Warehouse Model (C) J. M. Garrido 17 Executing The Warehouse Model (C) J. M. Garrido 18 Executing The Warehouse Model (C) J. M. Garrido 19 Executing The Warehouse Model (C) J. M. Garrido 20 Executing The Warehouse Model (C) J. M. Garrido 21 Executing The Warehouse Model (C) J. M. Garrido 22 Executing The Warehouse Model (C) J. M. Garrido 23 Output of a Simulation Run of The Warehouse Model End Simulation of Busy Warehouse System date: 6/17/2009 time: 15:42 Elapsed computer time: 907 millisec Total small trucks serviced: 42 Average period small truck spends in warehouse: 23.981 Small truck average wait period: 16.285 Total number of big trucks serviced: 54 Big truck average wait period: 20.659 Avg per btruck in warehouse: 33.006 (C) J. M. Garrido 24 Allocating Resources with Priorities Priorities are assigned to every process that needs resources Processes compete for resources based on their priorities To implement priorities, use an integer value for the priority (C) J. M. Garrido 25 Using Priorities with OOSimL Invoke method set_prio with an integer argument in the class definition for the processes define my_prio = 3 of type integer // priority … fix priority my_prio // set priority … assign priority my_prio // get priority of this process In OOSimL, priority 0 is the highest priority. (C) J. M. Garrido 26 Deadlock When processes compete for resources, deadlock may occur. Deadlock is a situation in which a set processes are waiting indefinitely for each other to release resources. Good synchronization is necessary to prevent or avoid deadlock. (C) J. M. Garrido 27 Deadlock Example Processes P1 and P2 are waiting for each other Process P1 holds on item of resource R2 and is requesting one item of resource R1, which is held by P2 Process P2 holds one item of resource R1 and is requesting one item of resource R2, which is held by P1 (C) J. M. Garrido 28
© Copyright 2026 Paperzz