В этом примере показано, как использовать simevents.SimulationObserver возразите, чтобы считать отъезды сущности и получить исходные метки времени.
Используйте simevents.SimulationObserver объект наблюдать или визуализировать сущности и реализовать аниматоров, чтобы отладить симуляции модели. Для получения дополнительной информации смотрите Использование Класс SimulationObserver, чтобы Контролировать Модель SimEvents.
В этой модели, simevents.SimulationObserver объект используется, чтобы получить количество сущностей, отбывая из блока или набора блоков в модели и добавить метку времени к их отъездам. Модель имеет два блока Терминатора Генератора и Сущности Сущности и Блок Сервера Сущности. Блоки Scope отображают Количество сущностей, из которых отбывают, d статистика для блоков Сервера Генератора и Сущности Сущности.

Откройте новый скрипт и инициируйте simevents.SimulationObserver объект этим кодом.
classdef myObserverPreexit < simevents.SimulationObserver % Add the observer properties. properties Model % Initialize the property count. count end
properties (Constant, Access=private)
increment = 1;
end
methods
% Observe any model by incorporating its name to MyObserverPreexit.
function this = myObserverPreexit(Model)
% Input model name to the simulation observer.
this@simevents.SimulationObserver(Model);
this.Model = Model;
end % Initialize the count in the simulation start.
function simStarted(this)
this.count = 0;
end % Specify list of blocks to be notified of entity entry and exit
% events.
function Block = getBlocksToNotify(this)
Block = this.getAllBlockWithStorages();
end function preExit(this,evSrc,Data)
% Get the names of all storage blocks that the entities depart.
% This returns the block with its path.
Block = Data.Block.BlockPath;
% Remove the path to display only the
% block name.
Block = regexprep(Block,'ObserverPreexitModel/' ,'');
% Initialize the blocks to observe.
BlockName = 'Entity Server';
% If the block that entity exits contains the block name
% acquire data for exit time and block name.
if contains(Block, BlockName)
% Get time for entity preexit from event calendar.
evCal = this.getEventCalendars;
Time = evCal(1).TimeNow;
% Increase the count for departing entities.
this.count = this.count + this.increment; myInfo = [' At time ',num2str(Time), ...
' an entity departs ', Block, ', Total entity count is ', ...
num2str(this.count)];
disp(myInfo);
end
end
end
endСохраните файл как myObserverPreexit.m файл.
Включите объекту наблюдателя контролировать ObserverPreexitModel модель.
obj = myObserverPreexit('ObserverPreexitModel');
Наблюдатель контролирует блок Entity Server, который определяется BlockName параметр в файле наблюдателя myObserverPreexit.m.
Симулируйте модель. Нажмите View Diagnostics на окне модели и заметьте, что количество сущностей, отбывая из блока Entity Server и отъезда устанавливает метку времени.

Для валидации наблюдайте блок Scope, который отображает Количество сущностей, из которых отбывают, d статистическая величина для блока Entity Server.

Используйте того же наблюдателя, чтобы контролировать отклонения сущности от всех блоков Генератора Сущности в вашей модели.
Измените BlockName параметр в preExit метод к 'Entity Generator'. Блоки Генератора сущности в модели помечены Entity Generator1 и Entity Generator2.
function preExit(this,evSrc,Data) % Get the names of all storage blocks that the entities depart. % returns the block with its path. Block = Data.Block.BlockPath; % Remove the path to display only the block name Block = regexprep(Block,'ObserverPreexitModel/' ,''); % Initialize the common Entity Generator phrase BlockName = 'Entity Generator'; % If the block that the entity exits contains the block name % acquire the exit time and the block name. if contains(Block, BlockName) % Get the time of entity preexit from the event calendar. evCal = this.getEventCalendars; Time = evCal(1).TimeNow; % Increase the count of departing entities. this.count = this.count + this.increment;
myInfo = [' At time ',num2str(Time), ...
' an entity departs ', Block, ', Total entity count is ', ...
num2str(this.count)];
disp(myInfo);
end
endВключите объекту наблюдателя контролировать ObserverPreexitModel модель.
obj = myObserverPreexit('ObserverPreexitModel');
Симулируйте модель. Наблюдайте Диагностическое Средство просмотра, которое отображает информацию для 15 сущности, вылетающие от обоих блоков Генератора Сущности.

Для валидации заметьте, что блоки Scope1 и Scope2 отображают Количество сущностей, из которых отбывают, d статистическая величина для Сущности Generator1 и Сущности Generator2.
Наблюдайте тот 4 сущности отбывают из Сущности Generator1.

Кроме того, 11 сущности отбывают из Сущности Generator2. Всего, 15 сущности вылетели от блоков Генератора Сущности в модели.

getBlocksToNotify | getEventCalendars | preExit | simStarted | simevents.SimulationObserver