Main Content

Resource Scheduling Using MATLAB Discrete-Event System and Data Store Memory Blocks

This example shows how to model resource scheduling using data exchange between the MATLAB Discrete-Event System block and the Data Store Memory block.

The example models a facility that generates two types of parts, Part A and Part B, that undergo a heating process. Both parts acquire resources for the heating process from the same resource pool. The resource acquisition for Part A has a higher priority. When Part A acquires a certain number of resources, Part B can acquire only 1 resource. This constraint requires that the total number of resources be shared between the processes and the acquisition scheduled based on the shared data.

Model Description

In the model, an Entity Generator Block generates entities of type PartA. The parts are then sent to a storage unit to acquire resources from the Resource Pool block. A MATLAB Discrete-Event System Block that uses the PartAStorage System Object™ represents the storage unit.

The System Object™ defines the amount of acquired resources and the resource acquisition event for Part A.

function [entity,event] = PartAEntry(obj,storage,entity,source)
    % Define the amount of acquired resources as a random value.
    Amount = randi([1 3]);
    resReq = obj.resourceSpecification('Resources', Amount);
    % Define the resource acquisition event.
    event = obj.eventAcquireResource(resReq, 'ResourceAcq');
end

When Part A acquires the resources successfully, the entity is forwarded to the output. TotalAcquiredByPartA is the data stored in the Data Store memory block representing the total number of acquired resources by Part A. The System Object™ first calls the value stored in Data Store A. It updates and writes the new TotalAcquiredByPartA value by adding the number of acquired resources.

function [entity,events] = resourceAcquired(obj, storage,...
                                entity, resources, tag)
    global TotalAcquiredByPartA;
    % After successful resource acquisition, forward the entity
    % to the output |1|.
    events = obj.eventForward('output', 1, obj.Delay);
    % Update the total number of resources acquired.
    TotalAcquiredByPartA = TotalAcquiredByPartA + resources.amount;
end

The part is sent to Heating Process A, which is represented by an Entity Server block. When the heating process is complete, the parts release the acquired resources and depart the facility.

In the model, another Entity Generator block generates entities of type Part B. The parts are then sent to a storage unit to acquire resources from the Resource Pool block. A MATLAB Discrete-Event System Block that uses the PartBStorage System Object™ represents the other storage unit.

The System Object™ defines the amount of acquired resources and the resource acquisition event for Part B.

function [entity,event] = PartBEntry(obj,storage,entity,source)
    global TotalAcquiredByPartA;
        % If the number of resources acquired by Part A is greater than
        % 30 then Part B acquires only |1| resource.
        if TotalAcquiredByPartA > 30
        Amount = 1;
        else
        % Otherwise, Part B can acquire any number of resources between
        % |1| and |5|.
        Amount = randi([1 5]);
        end
    resReq = obj.resourceSpecification('Resources', Amount);
    % Define the resurce acquisition event.
    event = obj.eventAcquireResource(resReq, 'ResourceAcq');
end

The amount of resources Part B acquires depends on the resources acquired by Part A. This acquisition is achieved by PartBStorage System Object™ that reads the value of TotalAcquiredByPartA stored in Data Store A for each entity entry.

After successfully acquiring the resources, the entity is forwarded to the output. The System Object (TM) updates TotalAcquiredByPartB and writes its new value to Data Store B.

function [entity,events] = resourceAcquired(obj, storage,...
                                 entity, resources, tag)
    global TotalAcquiredByPartB; % After successful resource
    acquisition, forward the entity to the output. events =
    obj.eventForward('output', 1, obj.Delay); % Update the total number
    of resources acquired. TotalAcquiredByPartB = TotalAcquiredByPartB
    + resources.amount;
end

Then the parts are sent to Heating Process B. They release the resources after the process is complete and depart the facility.

Track Resources component in the model, tracks available resources and acquired number of resources by each part. Available resources are measured by the Amount available, avail statistic from the Resource Pool block. Resources acquired by Part A and Part B is observed by the output of the Data Store Read blocks that read values from Data Store A and Data Store B.

Simulation Results

Simulate the model. Observe the Scope block connected to the Data Store Read Part A. The scope shows that Part A acquires 30 resources around the simulation time 40.

Also observe the Scope block connected to Data Store Read Part B. The scope shows that Part B acquires 1 resource after the simulation time 40 due to the prioritization of resources.

Related Topics