Find the Number of Entities in Servers

This example illustrates ways that you can use information from one command as an input to another command. Suppose your system includes several server blocks and you want to see how many entities are in each server block that is currently busy serving an entity. The following code inspects the event calendar to locate service completion events, uses the events to locate server blocks that are currently busy, and inspects server blocks to find out how many entities are in them. An entity in the server might be in service or waiting to depart.

  1. Begin a debugger session for a particular model by entering this command at the MATLAB® command prompt:

    sedebug('sedemo_star_routing')
  2. Proceed in the simulation. At the sedebug>> prompt, enter:

    tbreak 5
    cont
    

    The output ends with a message describing the context of the simulation shortly after T = 5:

    Hit b1 : Breakpoint for first operation at or after time 5.000000
    
    %==============================================================================%
    Executing ServiceCompletion Event (ev29)              Time = 5.189503930558476
    : Entity = en4                                        Priority = 5
    : Block  = Distribution Center/Infinite Server
  3. To find out how many entities are in each server that is currently busy serving, use a series of state inspection and variable manipulation commands:

    % Get the event calendar.
    eventcalendar = evcal;
    
    % Combine executing and pending events, to search both.
    allevents = [eventcalendar.ExecutingEvent; eventcalendar.PendingEvents];
    
    % Find service completion events.
    idx = cellfun(@(x) isequal(x,'ServiceCompletion'), {allevents.EventType});
    svc_completions = allevents(idx);
    
    % Find the unique server blocks.
    svrs = unique({svc_completions.Block});
    
    % Compute the number of server blocks.
    num = length(svrs);
    % Preallocate an array for the results.
    n = zeros(1,num);
    
    % Loop over the server blocks and find the number of entities
    % in each block.
    for jj=1:num
       s = blkinfo(svrs{jj});
       n(jj)=length(s.Entities);
       disp(sprintf('%s: %d',svrs{jj},n(jj)))
    end
    

    The output is:

    sedemo_star_routing/Distribution Center/Infinite Server: 1
    sedemo_star_routing/Service Station 3/Infinite Server3: 1
    sedemo_star_routing/Service Station 4/Infinite Server4: 2
  4. End the debugger session. At the sedebug>> prompt, enter:

    sedb.quit
Was this topic helpful?