Main Content

resourceSpecification

Class: matlab.DiscreteEventSystem
Namespace: matlab

Create specifications for a resource acquisition or a resource release event

Syntax

resRequest = resourceSpecification(resource,amount)

Description

resRequest = resourceSpecification(resource,amount) specifies the names and the amount of the resources for the eventAcquireResource or the eventReleaseResource requests.

For example, this code specifies one unit of Resource1 and two units of Resource2.

resRequest = obj.resourceSpecification('Resource1', 1);
resRequest = [resReq obj.resourceSpecification('Resource2', 2)];

If you specify an amount for the eventReleaseResource larger than the amount that was acquired earlier, all the previously acquired resources are released.

For example, suppose that an entity previously acquired three resources of type Resource1 and four resources of type Resource2. This code specifies the amounts for eventReleaseResource.

resRequest = obj.resourceSpecification('Resource1', 2);
resRequest = [resReq obj.resourceSpecification('Resource2', 5)];
     event = eventReleaseResource(resReq, ‘relinquish’);

After the release, the entity has one resource of type Resource1 and zero resources of type Resource2.

You can specify the release of all previously acquired resources by using eventReleaseAllResources.

Input Arguments

expand all

Specify the name of the resources for the eventAcquireResource or the eventReleaseResource requests. You can specify more than one resource.

Specify the amount of resources for the eventAcquireResource or the eventReleaseResource requests.

Output Arguments

expand all

Resource request for an acquisition or a release event specified as a vector of MATLAB structures.

Examples

A Simple Resource Specification Example

When an entity enters the storage element, it acquires resources. The entity acquires one resource of type Resource1 and one resource of type Resource2, which are defined as specifications. The specifications are then used for eventAcquireResource with tag MyResourceAcquireEvent.

  function [entity,events] = entry(obj, storage, entity, source)
            % On entry, acquire one resource of type Resource1 and one resource of type Resource2.
            resRequest(1) = obj.resourceSpecification('Resource1', 1);
            resRequest(2) = obj.resourceSpecification('Resource2', 1);
            events = obj.eventAcquireResource(resRequest, 'MyResourceAcquireEvent');       
  end

Resource Specification in a Custom Resource Acquirer Block

This example shows how to use resource management methods to create a custom entity storage block in which entities acquire resources from specified Resource Pool blocks.

Suppose that you manage a facility that produces parts from two different materials, material 1 and material 2, to fulfill orders. After a part is produced, it is evaluated for quality assurance.

Two testing methods for quality control are:

  • Test 1 is used for parts that are produced from material 1.

  • Test 2 is used for parts that are produced from material 2

After the production phase, parts are tagged based on their material to apply the correct test.

For more information, see Create a Custom Resource Acquirer Block.

classdef CustomBlockAcquireResources < matlab.DiscreteEventSystem
    % Custom resource acquire block example.
    
    methods(Access = protected)
        
        function num = getNumInputsImpl(obj)
            num = 1;
        end
        

        function num = getNumOutputsImpl(obj)
            num = 1;
        end

      
        function entityTypes = getEntityTypesImpl(obj)
            entityTypes(1) = obj.entityType('Part');
        end
        
        function [input, output] = getEntityPortsImpl(obj)
            input  = {'Part'};
            output = {'Part'};
        end
        
        function [storageSpec, I, O] = getEntityStorageImpl(obj)
            storageSpec(1) = obj.queueFIFO('Part', 1);
            I = 1;
            O = 1;
        end
        
        function resNames = getResourceNamesImpl(obj)
            % Define the names of the resources to be acquired.
            resNames = obj.resourceType('Part', {'Test1', 'Test2'}) ;
        end
       
    end
        
    methods
        
        function [entity,events] = entry(obj, storage, entity, source)
            % On entity entry, acquire a resource from the specified pool. 
            if entity.data.Test == 1
            % If the entity is produced from Material1, request Test1.    
            resReq = obj.resourceSpecification('Test1', 1);
            else
            % If the entity is produced from Material2, request Test2.     
            resReq = obj.resourceSpecification('Test2', 1);
            end
            % Acquire the resource from the corresponding pool.
            events = obj.eventAcquireResource(resReq, 'TestTag');
        end
        
        function [entity,events] = resourceAcquired(obj, storage,...  
                                   entity, resources, tag)
        % After the resource acquisition, forward the entity to the output.                    
            events = obj.eventForward('output', storage, 0.0);
        end
        
    end

end

Version History

Introduced in R2019a