Main Content

resourceAcquired

Class:matlab.DiscreteEventSystem
Package:matlab

Event action upon successful resource acquisition

Syntax

[entity,event,out1,...] = resourceAcquired(obj,storage,entity,resources,tag,in1,...)

Description

[entity,event,out1,...] = resourceAcquired(obj,storage,entity,resources,tag,in1,...)specifies event action for a discrete-event System object™ upon successful acquisition of a resource. Resource acquisition is successful only if all of the specified resources are acquired.

Input Arguments

expand all

Discrete-event System object.

Index of the storage element.

Entity that acquires the resource. Entity has these fields:

  • sys(MATLABstructure) consisting of:

    • id(double) — Entity ID

    • priority(double) — Entity priority

  • data— Entity data

An array of structures that specifies the resources that have been acquired.

Tag of the currently executing resource acquisition event.

First data input.

Output Arguments

expand all

Entity acquiring the resource.

Events to be scheduled. Usematlab.DiscreteEventSystemclass methods to create events. Each event has these fields:

  • type(character vector) — Type of the event

  • delay(double) — Delay before the event

  • priority(double) — Priority of the event

  • storage(double) — Index of the storage element

  • tag(character vector) — Event tag

  • location(MATLABstructure) — Source or destination (seesource)

第一个数据输出。

Examples

Event Action on Resource Acquisition

Suppose that an entity acquires resources successfully with a scheduledeventAcquireResource和这个事件的标记MyResourceAcquireEvent. Then this acquisition invokes theresourceAcquiredmethod to forward entities to the output.

function[entity,events] = entry(obj, storage, entity, source)% On entry, acquire one resource of type Resource1.resRequest = obj.resourceSpecification('Resource1', 1); events = obj.eventAcquireResource(resRequest,'MyResourceAcquireEvent');endfunction[entity,events] = resourceAcquired(obj, storage,...entity, resources, tag)% After resource acquisition, forward the entity to the output.events = obj.eventForward('output', storage, 0.0);end

Custom Resource Acquirer

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, material1and material2,履行订单。后产生的一部分,它is evaluated for quality assurance.

Two testing methods for quality control are:

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

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

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(Access = protected)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

Version History

Introduced in R2019a