%% Reduce a Variant Model for Selected Variant Configuration
% A variant model can have multiple variant configurations associated with
% it. Each configuration represents a combination of variant control values
% that activates a specific variant choice. You can generate a reduced
% version of a variant model that represents a single variant configuration
% using the Variant Reducer. A Simulink(R) Design Verifier(TM)
% license is required to reduce your model. This example shows how to reduce a model
% programmatically and using the Variant Manager.

% Copyright 2020 The MathWorks, Inc.

%% Explore the Model
% Open the model |slexVariantReducer|. The model contains a Variant Source
% block, a Variant Sink block, and a Variant Subsystem block with these
% variant choices:
%%
% * Variant Source: |V|==1 and |V|==2
% * Variant Sink: |W|==1, |W|==2, and |W|==3
% * Variant Subsystem: |V|==1 and |V|==2
%%
% On the *Modeling* tab of the Simulink(R) toolstrip, select *Model
% Explorer* > *Model Properties* > *Callbacks*. The |PostLoadfn| callback
% function of the model defines the variant control variables |V| and |W|
% and loads the |slexVariantReducer_config.mat| file.
%%
% The model has two predefined variant configurations, named |config1|
% (|V|==1 && |W|==2) and |config2| (|V|==2 && |W|==2). These configurations
% are saved in a variant configuration data object,
% |slexVariantReducer_config|, which is in turn saved in the
% |slexVariantReducer_config.mat| file.
open_system('slexVariantReducer');
%% Reduce the Model from Variant Manager
% * To open the Variant Manager, right-click the variant badge on any of the
% variant blocks and select *Open in Variant Manager*. The Variant Manager
% shows the predefined variant configurations.
%%
% <<../variant_manager_reducemodel.png>>
%%
% * Click *Reduce Model*. The Variant Reducer dialog box opens. Select the 
% *Specify variant configurations* option and select the
% configuration to be retained in the reduced model from *Named Configurations*.
%%
% <<../variant_reducer_dialog.png>>
%%
% * Click *Reduce*. The reduced model for the required configuration is 
% created. If the model contains resolved library links or referenced
% models, the corresponding parent is reduced for the specified
% configuration and is referenced in the model. The reduced model, reduced
% referenced model, and the reduced library get their names from the
% corresponding model, referenced model, or the library with _r (model
% suffix) appended to it.
%% Reduce Model Programmatically
% To reduce the model programmatically, execute these steps in the MATLAB(R) Command Window:

% %Generate the reduced model for the configuration config1 to the default
% %output folder, reducedModel.
  Simulink.VariantManager.reduceModel...
  ('slexVariantReducer','NamedConfigurations', {'config1'});
  cd ./reducedModel;
  open_system('slexVariantReducer_r');
%% See Also
% * <docid:simulink_ug.bu8p9f8 Reduce Models Containing Variant Blocks>
% * <docid:simulink_ref#mw_6c09d7d0-3b71-42a2-8cd3-c0f4ba121ea6 Simulink.VariantManager.reduceModel>
% * <docid:simulink_ref#btyoygu Simulink.VariantConfigurationData>