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.
Generate a custom entity storage block with one input, one output, and one storage element.
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
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
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.
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.
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.
In the Part Generator:
In the Entity generation tab, set the
Generate entity at simulation start to
off
.
In the Entity type tab, set the
Entity type name as Part
and Attribute Name to
Test
.
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.
In the Resource Pool block:
Set the Resource name to
Test1
and the Reusable upon
release parameter to off
.
In the Statistics tab, output the Amount available, avail statistic and connect it to a scope.
In the Resource Pool1 block:
Set the Resource name to
Test2
and the Reusable upon
release parameter to off
.
In the Statistics tab, output the Amount available, avail statistic and connect it to a scope.
Right-click the entity path from Part Generator to the MATLAB Discrete-Event System block and select Log Selected Signals.
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.
Observe that three resources of type Test1
are
acquired by entities.
Observe that seven resources of type Test2
are
acquired by entities.
cancelAcquireResource
| entry
| eventAcquireResource
| getResourceNamesImpl
| matlab.DiscreteEventSystem
| matlab.System
| resourceAcquired
| resourceSpecification