%% Comparing Routing Using Path Combiner and Input Switch

% Copyright 2008-2011 The MathWorks, Inc.

%% Description
% This example shows the differences between the Path Combiner block and the Input Switch block.
% The *Path Combiner* block accepts entities as they arrive at any port.
% The *Input Switch* accepts entities only from the port that is selected,
% where the selection changes in a round-robin fashion with the passage of
% each entity.
%
% In the upper part of the model, entities from the high-priority entity
% generator arrive at the Path Combiner block before simultaneously
% generated entities having a lower priority. The plots from the Path
% Combiner block reflect the prioritized order in which the entities arrive
% at and pass through the Path Combiner block.
%
% In the lower part of the model, the Input Switch block permits arrival
% only at the selected port. The prioritization of entity generation events
% does not influence the switch block. The plots from the Input Switch block
% reflect the ascending (round-robin) order in which the entities are
% selected by the Input Switch block.

modelname = 'sedemo_ipswitch_v_pathcombiner';
open_system(modelname);
set_param([modelname '/Path Combiner  Arrival Port  vs. Time'],'OpenScopeAtSimStart', 'off' );
set_param([modelname '/Input Switch  Selected Port  vs. Time'],'OpenScopeAtSimStart', 'off' );



%% Results and Displays
% *Selected Ports vs. Index*
sim(modelname);

%%
% *Selected Ports vs. Time*
des.scope.CallbackSupport('CloseFig',[modelname '/Path Combiner  Arrival Port vs. Index']);
des.scope.CallbackSupport('CloseFig',[modelname '/Input Switch  Selected Port vs. Index']);
set_param([modelname '/Path Combiner  Arrival Port vs. Index'],'OpenScopeAtSimStart', 'off' );
set_param([modelname '/Input Switch  Selected Port vs. Index'],'OpenScopeAtSimStart', 'off' );
set_param([modelname '/Input Switch  Selected Port  vs. Time'],'OpenScopeAtSimStart', 'on' );
set_param([modelname '/Path Combiner  Arrival Port  vs. Time'],'OpenScopeAtSimStart', 'on' );
sim(modelname);


%% Related Examples
% * <matlab:helpview(fullfile(docroot,'toolbox','simevents','helptargets.map'),'doc_releasegate_warmup'); First Entity as a 
% Special Case> 
% * <matlab:helpview(fullfile(docroot,'toolbox','simevents','helptargets.map'),'doc_packet_switch'); A Packet Switch> 
% * <matlab:helpview(fullfile(docroot,'toolbox','simevents','helptargets.map'),'doc_roundrobin'); Round-Robin Approach to Choosing Inputs>
% * <matlab:helpview(fullfile(docroot,'toolbox','simevents','helptargets.map'),'doc_race_conditions_switch'); Choices of Values for Event Priorities>


%% 
%cleanup
bdclose(modelname);
clear modelname;
displayEndOfDemoMessage(mfilename)
