Main Content

Create 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.

To generate the custom behavior, you create a discrete-event System object™ using the matlab.DiscreteEventSystem class methods for resource management.

Create the Discrete-Event System Object

Generate a custom entity storage block with one input, one output, and one storage element.

Graphical representation of a Discrete-Event system showing a rectangle with one input port and one output port containing a storage element. In its first cell, the storage element has one entity in the form of a grey square, and a resource in the form of a red square.

The block accepts an entity of type Part to its storage with capacity 1. The entity has an attribute Test to indicate the material from which the part is produced. Based on the value of the attribute, the entity acquires a resource from the specified Resource Pool block and departs the block to be tested.

 See the Code to Generate the Custom Block to Acquire Resources

Custom Block Behavior

  1. Define Test1 and Test2 type resources to be acquired by the entity type Part.

    function resNames = getResourceNamesImpl(obj)
        % Define the names of the resources to be acquired.
        resNames = obj.resourceType('Part', {'Test1', 'Test2'}) ;
    end
  2. The entity enters the storage. If its entity.data.Test value is 1, the entity is produced from Material1. The entity acquires 1 resource from the Resource Pool block with resources of type Test1. Similarly, If its entity.data.Test value is 2, the entity acquires one resource from the Resource Pool block with resources of type Test2.

    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, it acquires resource of type Test1.    
            resReq = obj.resourceSpecification('Test1', 1);
            else
            % If the entity is produced from Material2, it acquires resource of type 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

    After the resource is successfully acquired, the resourceAcquired invokes the forwarding of the entity.

Implement the Custom Block

  1. Save the .m file as CustomBlockAcquireResources. Link the System object to a SimEvents® model by using a MATLAB Discrete-Event System block. For more information about linking, see Create Custom Blocks Using MATLAB Discrete-Event System Block.

  2. Create a SimEvents model using a MATLAB Discrete-Event System block, an Entity Generator block and an Entity Terminator block, and two Resource Pool blocks. Connect the blocks as shown in the diagram.

    Label Entity Generator block as Part Generator and Entity Terminator block as Departure for Testing.

    Block diagram showing an Entity Generator block named Part Generator connected to a MATLAB Discrete-Event System with System Object name CustomBlockAcquireResources. The MATLAB Discrete-Event System block is connected to an Entity Terminator block named Departure for Testing. Separately, a Resource Pool block named Resource Pool1 containing resource Test1 is connected to a Scope named Available Test1 Tag. A Resource Pool block named Resource Pool2 containing resource Test2 is connected to a Scope named Available Test2 Tag

  3. In the Part Generator:

    1. In the Entity generation tab, set the Generate entity at simulation start to off.

    2. In the Entity type tab, set the Entity type name as Part and Attribute Name to Test.

    3. In the Event Actions tab, in the Generate action field enter:

      entity.Test= randi([1 2]);

      Parts are generated with intergeneration time 1 and their Test attribute value is 1 or 2 to indicate the material type.

  4. In the Resource Pool block:

    1. Set the Resource name to Test1 and the Reusable upon release parameter to off.

    2. In the Statistics tab, output the Amount available, avail statistic and connect it to a scope.

  5. In the Resource Pool1 block:

    1. Set the Resource name to Test2 and the Reusable upon release parameter to off.

    2. In the Statistics tab, output the Amount available, avail statistic and connect it to a scope.

  6. Right-click the entity path from Part Generator to the MATLAB Discrete-Event System block and select Log Selected Signals.

  7. Simulate the model.

    • Observe the Test attribute values of the incoming entities to the custom block. Three entities require test 1 and seven entities requires test 2.

      Simulink Data Inspector representing Test attribute values of incoming entities, graphically.

    • Observe that three resources of type Test1 are acquired by entities.

      Available Test1 Tag Scope block representing resources acquired by entities, graphically.

    • Observe that seven resources of type Test2 are acquired by entities.

      Available Test2 Tag Scope block representing resources acquired by entities, graphically.

See Also

| | | | | | |

Related Topics