A Quantity Resource represents discrete elements which are stored in a resource pool when not in use, and are allocated to MLDesigner data structures as they move through a system.
Typically, a data structure will enter an Allocate block to request resource units. Any quantity of units can be requested. The Allocate block provides queuing if the resource units cannot be allocated immediately. When the resource units can be allocated, the data structure exits the Allocate block and continues its journey through the model. At some later point in the processing of the data structure (and usually at a later time), the resource units may be returned to the resource pool for allocation to other requests.
When using nonaddressed resources, units can be identical and indistinguishable, in which case the resource represents a token pool. On the other hand, the addressed resources are distinguishable and each has an integer address. Requests for an addressed Quantity Resource require a contiguous block of units, which is allocated using either a first-fit or best-fit policy.
The two fundamental blocks for manipulation of quantity resources are the Allocate and Free blocks. The Allocate block is used to make a request for resource units. When the units are available, the output ports on the right side of the Allocate block are enabled to indicate that the resource units have been granted. The Free block is used to release resource units when they are no longer needed.
A quantity resource begins a simulation with an initial capacity, the number of resource units in the pool at the beginning of the simulation. The initial capacity is specified with the Initial Capacity resource attribute. During simulation, requests for quantities of the resource are made by enabling all of the inputs of an Allocate block. Input values, which includes one data structure of any type, are collectively called the transaction. The other inputs specify the attributes of the transaction. One attribute of the transaction is the number of units of the resource requested. If there is an unused quantity of the resource greater than or equal to the number of units requested and there are no transactions with a higher priority waiting in the queue, that number of units of the resource will be removed from the pool and granted to the transaction.
Any time resource units are granted to a transaction, the outputs of the Allocate block where the request was made are enabled. One of the outputs is the data structure which is associated with the transaction. The other outputs are the number of units granted and the starting index if the resource is addressed. Resource units can then be held for an arbitrary amount of time (as the data structure is delayed by other blocks in your model). The resource units can be freed by enabling the inputs of a Free block. One of the inputs specifies the number of units of the resource to free. Normally, you will need a field in your data structure to store the number of resource units held by each resource that can be possessed. If you use addressed resources, you may also need a field to store the starting index.
If the Addressing Mode is NonIndexed, the capacity of the resource may be increased or decreased during the simulation by using the ChangeCap block. If the capacity is increased, new resource units are immediately placed in the resource pool, and the resource queue is checked. If any waiting transactions can be granted their requested number of units, they are immediately given the requested units.
If the capacity is decreased, the resource units are removed from the pool, provided the pool contains at least that number of units. If the pool does not contain the number to be removed, all unused units in the pool are removed, and the remaining units are removed when they become freed. The capacity of the resource cannot be less than zero. If you attempt to set the capacity below zero, the capacity of the resource is not changed, the output of the ChangeCap block is not enabled, but the simulation continues executing.
Attribute |
Description |
Possible values |
---|---|---|
Number of Dimensions |
The number of dimensions which can be modeled with each grouping of resource blocks and arguments. |
|
Initial Capacity |
The number of resource units in the pool when the simulation starts. |
|
Blocking Mechanism |
The action to be taken if a transaction cannot be granted the requested number of resource units when it enters the Allocate block. This attribute must be set to Wait_for_Resource for the values of the next three resource attributes to be used (Maximum Occupancy, Queue Discipline and Queue Reject Mechanism). |
Wait_for_Resource, Exit_without_any_Resource_Units, Seize_Available_Units |
Maximum Occupancy |
The maximum number of transactions which can wait in the queue at any one time. |
|
Queue Discipline |
The ordering of transactions in the queue which have the same priority. |
First_In_First_Out, Last_In_First_Out |
Queue Reject Mechanism |
The way a transaction is chosen for rejection when a new transaction would cause the overall occupancy to exceed the Maximum Occupancy. |
Incoming_DS_Rejected, Lowest_Priority_Rejected |
Addressing Mode |
This attribute determines whether each resource unit has a unique integer identifier (Indexed) or if resource units are indistinguishable. |
Indexed, NonIndexed |
Addressed Fit Policy |
The policy by which available resource units are searched for when the Addressing Mode is Indexed. The value of this attribute is ignored if the Addressing Mode is NonIndexed. |
FirstFit, BestFit |
One of the resource attributes, Number of Dimensions, allow a single set of resource block arguments to represent a collection of identical resources distinguished by an integer index, called the dimension. The Allocate, Free, and other resource models have an input (or parameter) which is the dimension of the resource to be accessed. The dimension is zero-based, with valid values between zero, inclusive, and the number of dimensions attribute of the resource, exclusive.
When you use multiple dimensions, separate queues and resource pools are created for each dimension. The resource attributes are the same for every dimension.