eventAcquireResource
Class:matlab.DiscreteEventSystem
Package:matlab
Syntax
event = eventAcquireResource(resourceSpec,tag)
Description
creates an event to acquire resources from existingResource Poolblocks. You can specify names and amount of resources to acquire. For more details, seeevent
= eventAcquireResource(resourceSpec
,tag
)resourceSpecification
.
If all the requested resources are not available during the event execution, the acquisition event remains active. When the requested resources become available, the event is rescheduled for immediate execution.
Input Arguments
Output Arguments
Examples
Acquire Resources upon Entry
On entity entry to a storage element, an entity acquires one resource of typeTest1
. The tag of this resource acquisition event isTestTag
.
function[entity,events] = entry(obj, storage, entity, source)% On entity entry, acquire a resource from the specified pool.resourceSpec = obj.resourceSpecification('Test1', 1); event = obj.eventAcquireResource(resourceSpec,'TestTag');end
Custom Block to Acquire Resources
This example shows how to use resource management methods to create a custom entity storage block in which entities acquire resources from specifiedResource Poolblocks.
Suppose that you manage a facility that produces parts from two different materials, material1
and material2
, 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, seeCreate a Custom Resource Acquirer Block.
classdefCustomBlockAcquireResources < matlab.DiscreteEventSystem% Custom resource acquire block example.methods(访问=亲tected)functionnum = getNumInputsImpl(obj) num = 1;endfunctionnum = getNumOutputsImpl(obj) num = 1;endfunctionentityTypes = getEntityTypesImpl(obj) entityTypes(1) = obj.entityType('Part');endfunction[input, output] = getEntityPortsImpl(obj) input = {'Part'}; output = {'Part'};endfunction[storageSpec, I, O] = getEntityStorageImpl(obj) storageSpec(1) = obj.queueFIFO('Part', 1); I = 1; O = 1;endfunctionresNames = getResourceNamesImpl (obj)% Define the names of the resources to be acquired.resNames = obj.resourceType('Part', {'Test1','Test2'}) ;endendmethodsfunction[entity,events] = entry(obj, storage, entity, source)% On entity entry, acquire a resource from the specified pool.ifentity.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');endfunction[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);endendend
版本历史
Introduced in R2019a