サポートされる、およびサポートされないブロックおよびパラメーターのモデル アドバイザー チェックの定義
ブロックが特定のブロックまたはパラメーターの値を使用するかどうかをチェックするモデル アドバイザー チェックを作成できます。次に対する制約を指定できます。
サポートされる、またはサポートされないブロック パラメーター値
サポートされる、またはサポートされないモデル パラメーター値
サポートされる、またはサポートされないブロック
ブロックまたはパラメーターが制約の組み合わせを満たすかどうか
関数addPreRequisiteConstraintIDを使用して、モデル アドバイザーが実際の制約をチェックする前にパスしなければならない前提条件の制約を追加することもできます。編集時に、またはモデル アドバイザーからチェックを実行することで、これらの制約に対してモデルをチェックできます。
例
sldemo_bounce モデルは、地球上でバウンドするボールをシミュレートします。この例では、制約で構成される 2 つのモデル アドバイザー チェックを作成し、それらの制約に対してモデルをチェックします。

サポートされる、またはサポートされないブロック パラメーターのチェックの作成
まず、サポートされる、およびサポートされないブロック パラメーター値を指定する 3 つのブロック パラメーター制約 c1、c2、c3 を含むモデル アドバイザー チェックを作成します。 
1.新しい関数を定義します。
function constraints = createConstraints_Check1() end
2.関数内で、2 つのブロック パラメーター制約 c1 と c2 を作成します。
function constraints = createConstraints_Check1() c1=Advisor.authoring.PositiveBlockParameterConstraint; c1.ID='ID_1'; c1.BlockType='Gain'; c1.ParameterName='Gain'; c1.SupportedParameterValues={'-0.7'}; c1.ValueOperator='eq'; % equal to c2=Advisor.authoring.NegativeBlockParameterConstraint; c2.ID='ID_2'; c2.BlockType='InitialCondition'; c2.ParameterName='Value'; c2.UnsupportedParameterValues={'0'}; c2.ValueOperator='le'; % less than or equal to end
制約 c1 は、Gain ブロックが -0.7 と等しい値をもたなければならないことを指定します。制約 c2 は、ゼロ以下の値をもつ Initial Condition ブロックがサポートされないことを指定します。
3.正のブロック制約 c3 を作成し、制約 c1、c2、c3 の cell 配列に等しい constraints を設定します。
function constraints = createConstraints_Check1() c1=Advisor.authoring.PositiveBlockParameterConstraint; c1.ID='ID_1'; c1.BlockType='Gain'; c1.ParameterName='Gain'; c1.SupportedParameterValues={'-0.7'}; c1.ValueOperator='eq'; % equal to c2=Advisor.authoring.NegativeBlockParameterConstraint; c2.ID='ID_2'; c2.BlockType='InitialCondition'; c2.ParameterName='Value'; c2.UnsupportedParameterValues={'0'}; c2.ValueOperator='le'; % less than or equal to c3=Advisor.authoring.PositiveBlockTypeConstraint; c3.ID='ID_3'; s1=struct('BlockType','Constant','MaskType',''); s2=struct('BlockType','SubSystem','MaskType',''); s3=struct('BlockType','InitialCondition','MaskType',''); s4=struct('BlockType','Gain','MaskType',''); s5=struct('BlockType','Memory','MaskType',''); s6=struct('BlockType','SecondOrderIntegrator','MaskType',''); s7=struct('BlockType','Terminator','MaskType',''); c3.SupportedBlockTypes={s1;s2;s3;s4;s5;s6;s7;}; constraints = {c1,c2,c3}; end
制約 c3 はサポートされるブロックを指定します。constraints はブロック制約の cell 配列です。
4.別の関数 check1 を作成して、新しいモデル アドバイザー チェックを定義します。関数Advisor.authoring.createBlockConstraintCheckを使用して、これらのブロック制約をもつモデル アドバイザー チェック rec を作成します。次に、mdladvRoot.register(rec) を使用して、モデル アドバイザーでブロック制約チェックを登録します。
function check1() rec = Advisor.authoring.createBlockConstraintCheck('mathworks.check_0001',... 'Constraints',@createConstraints_Check1); rec.Title = 'Example 1: Check three block parameter constraints'; rec.TitleTips = 'Example check three block parameter constraints'; mdladvRoot = ModelAdvisor.Root; mdladvRoot.publish(rec,'Example: My Group') end function constraints = createConstraints_Check1() c1=Advisor.authoring.PositiveBlockParameterConstraint; c1.ID='ID_1'; c1.BlockType='Gain'; c1.ParameterName='Gain'; c1.SupportedParameterValues={'-0.7'}; c1.ValueOperator='eq'; % equal to c2=Advisor.authoring.NegativeBlockParameterConstraint; c2.ID='ID_2'; c2.BlockType='InitialCondition'; c2.ParameterName='Value'; c2.UnsupportedParameterValues={'0'}; c2.ValueOperator='le'; % less than or equal to c3=Advisor.authoring.PositiveBlockTypeConstraint; c3.ID='ID_3'; s1=struct('BlockType','Constant','MaskType',''); s2=struct('BlockType','SubSystem','MaskType',''); s3=struct('BlockType','InitialCondition','MaskType',''); s4=struct('BlockType','Gain','MaskType',''); s5=struct('BlockType','Memory','MaskType',''); s6=struct('BlockType','SecondOrderIntegrator','MaskType',''); s7=struct('BlockType','Terminator','MaskType',''); c3.SupportedBlockTypes={s1;s2;s3;s4;s5;s6;s7;}; constraints = {c1,c2,c3}; end
複合制約のチェックの作成
次に、3 つのブロック パラメーター制約 cc1、cc2、および cc を含むモデル アドバイザー チェックを作成します。制約 cc1 と cc2 はサポートされるブロック パラメーターを指定し、制約 cc は cc1 と cc2 を含む複合制約です。 
1.新しい関数を定義します。
function constraints = createConstraints_Check2() end
2.2 つのブロック パラメーター制約 cc1 および cc2 と、1 つの複合制約 cc を作成します。制約 cc1、cc2、cc の cell 配列に等しい constraints を設定します。
function constraints = createConstraints_Check2() cc1=Advisor.authoring.PositiveBlockParameterConstraint; cc1.ID='ID_cc1'; cc1.BlockType='SecondOrderIntegrator'; cc1.ParameterName='UpperLimitX'; cc1.SupportedParameterValues={'inf'}; cc1.ValueOperator='eq'; % equal to cc2=Advisor.authoring.PositiveBlockParameterConstraint; cc2.ID='ID_cc2'; cc2.BlockType='SecondOrderIntegrator'; cc2.ParameterName='LowerLimitX'; cc2.SupportedParameterValues={'0.0'}; cc2.ValueOperator='eq'; % equal to cc=Advisor.authoring.CompositeConstraint; cc.addConstraintID('ID_cc1'); cc.addConstraintID('ID_cc2'); cc.CompositeOperator='and'; % Model Advisor checks multiple constraints constraints = {cc1,cc2,cc}; end
制約 cc1 は、Second-Order Integrator ブロックの [上限 x] パラメーターが inf と等しい値をもたなければならないことを指定します。さらに、制約 cc2 は、[下限 x] パラメーターがゼロと等しい値をもたなければならないことを指定します。制約 cc では、このチェックをパスするには cc1 と cc2 の両方をパスしなければならないことを指定します。constriants はブロック制約の cell 配列です。
3.新しい関数 check2 で、新しいモデル アドバイザー チェックを定義します。関数Advisor.authoring.createBlockConstraintCheckを使用して、関数 createConstraints_Check2 によって定義されるブロック制約のモデル アドバイザー チェックを作成します。
function check2() rec = Advisor.authoring.createBlockConstraintCheck('mathworks.check_0002',... 'Constraints',@createConstraints_Check2); rec.Title = 'Example 2: Check three block parameter constraints'; rec.TitleTips = 'Example check three block parameter constraints'; mdladvRoot = ModelAdvisor.Root; mdladvRoot.publish(rec,'Example: My Group') end function constraints = createConstraints_Check2() cc1=Advisor.authoring.PositiveBlockParameterConstraint; cc1.ID='ID_cc1'; cc1.BlockType='SecondOrderIntegrator'; cc1.ParameterName='UpperLimitX'; cc1.SupportedParameterValues={'inf'}; cc1.ValueOperator='eq'; cc2=Advisor.authoring.PositiveBlockParameterConstraint; cc2.ID='ID_cc2'; cc2.BlockType='SecondOrderIntegrator'; cc2.ParameterName='LowerLimitX'; cc2.SupportedParameterValues={'0.0'}; cc2.ValueOperator='eq'; cc=Advisor.authoring.CompositeConstraint; cc.addConstraintID('ID_cc1'); cc.addConstraintID('ID_cc2'); cc.CompositeOperator='and'; constraints = {cc1,cc2,cc}; end
モデル アドバイザー チェックの作成と実行
1.新しいチェックを登録するには、sl_customization.m ファイルを使用します。この例では、関数 sl_customization_DefineChecks およびファイルの名前を sl_customization に変更します。
function sl_customization(cm) % register custom checks. cm.addModelAdvisorCheckFcn(@check1); cm.addModelAdvisorCheckFcn(@check2);
2.コマンド プロンプトに次のコマンドを入力することで、[Example 1: Check block parameter constraints] チェックと [Example 2: Check block parameter constraints] チェックを作成します。
Advisor.Manager.refresh_customizations
3.コマンド プロンプトで、モデル sldemo_bounce を開きます。
open_system('sldemo_bounce')
4.[モデル化] タブで [モデル アドバイザー] を選択してモデル アドバイザーを開きます。
5.左側のペインで、次を選択します。[製品別]、[Example: My Group]。
6.[チェックの実行] をクリックします。
[Example1: Check three block parameter constraints] チェックでは警告が生成されます。これは、Gain ブロックのもつ値が -0.8 であるためです。[Example2: Check three block parameter constraints] チェックはパスします。Second-Order Integrator ブロックが両方の制約を満たすためです。
制約を使用したモデル アドバイザーの編集時チェックの作成
編集時のチェックを使用して、ブロック制約に違反するブロックをモデル キャンバスで強調表示できます。モデル アドバイザー構成エディターで目的のチェックを選択し、カスタム構成を保存することで、編集時のチェック中にどのモデル アドバイザー チェックを評価するかを選択できます。
1.モデル アドバイザー構成エディターを開くには、モデル アドバイザーを開いて、[開く]、[構成エディターを開く] を選択します。
2.作成したチェックは、次に表示されます。[製品別]、[Example: My Group]。
3.この例では、次を除くすべてのフォルダーを削除します。[Example: My Group] フォルダー。

4.[保存] をクリックし、構成を my_config.json として保存します。
5.この構成を既定の構成としては設定しないため、ダイアログ ボックスで [いいえ] をクリックします。
6.Simulink モデル エディターの [モデル化] タブで、[モデル アドバイザー]、[編集時チェック] をクリックします。
7.[モデル アドバイザー構成ファイル] パラメーターで、[参照] をクリックし、my_config.json を選択します。
8.[編集時チェック] パラメーターを選択し、[コンフィギュレーション パラメーター] ダイアログ ボックスを閉じます。
9.モデル内の強調表示されたブロックをクリックして、編集時の警告を表示します。

[修正] ボタンをクリックするか、サポートされないパラメーターのハイパーリンクをクリックして [ブロック パラメーター] ウィンドウを開いて、編集時のチェック診断ウィンドウからブロック パラメーターの値を編集できます。
参考
PositiveBlockParameterConstraint | NegativeBlockParameterConstraint | PositiveModelParameterConstraint | NegativeModelParameterConstraint | PositiveBlockTypeConstraint | NegativeBlockTypeConstraint | Advisor.authoring.generateBlockConstraintsDataFile