<html><head><META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>4.3.6. Choose Rule</title><link href="style.css" rel="stylesheet" type="text/css"><meta content="DocBook XSL Stylesheets V1.72.0" name="generator"><link rel="start" href="index.html" title="The VIATRA2 Model Transformation Framework"><link rel="up" href="sec_ASMCompoundRules.html" title="4.3. Compound ASM Rules"><link rel="prev" href="def_LetRule.html" title="4.3.5. Let Rule"><link rel="next" href="def_ForallRule.html" title="4.3.7. Forall Rule"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table summary="Navigation header" width="100%"><tr><th align="center" colspan="3">4.3.6. Choose Rule</th></tr><tr><td align="left" width="20%"><a accesskey="p" href="def_LetRule.html">Prev</a> </td><th align="center" width="60%">4.3. Compound ASM Rules</th><td align="right" width="20%"> <a accesskey="n" href="def_ForallRule.html">Next</a></td></tr></table><hr></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="def_ChooseRule"></a>4.3.6. Choose Rule</h4></div></div></div><div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Tip: Description"><tr><td valign="top" align="center" rowspan="2" width="25"><img alt="[Tip]" src="images/tip.png"></td><th align="left"><a name="def_ChooseRule_Description"></a>Description</th></tr><tr><td valign="top" align="left"><p> | |
The <span class="strong"><strong>choose rule</strong></span><a name="N1170E" class="indexterm"></a> | |
binds its variables to non-deterministically selected elements from the model space (or from an ASM function) | |
fulfilling a condition (existential condition), and then executes its body with those variable bindings. | |
</p></td></tr></table></div><div class="important" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Important: Syntax"><tr><td valign="top" align="center" rowspan="2" width="25"><img alt="[Important]" src="images/important.png"></td><th align="left"><a name="def_ChooseRule_Syntax"></a>Syntax</th></tr><tr><td valign="top" align="left"><pre class="programlisting"> | |
ChooseRuleAST ::= <span class="token">choose</span> <a href="def_ConstrainedVariableList.html" title="5.8.4. Constrained Variable List">ConstrainedVariablesOptAST</a> <span class="token">with</span> ConditionAST <span class="token">do</span> <a href="def_AsmRuleInvoc.html" title="4.1.2. ASM Rule Invocation">AsmRuleAST</a> | |
ConditionAST ::= <a href="def_LogicalTerm.html" title="5.2.1. Logical Term">LogicalTermAST</a> | |
| <a href="def_GTRuleCall.html" title="3.4.1. GTRule Call">GTRuleCallAST</a> | |
</pre><p> | |
The <span class="strong"><strong>choose rule</strong></span> consists of (scoped) variable declarations, a condition | |
part (<span class="emphasis"><em>with</em></span> clause), and an <a href="def_AsmRuleInvoc.html" title="4.1.2. ASM Rule Invocation">ASM rule invocation</a>as body. | |
</p><p> | |
Quantified variables of the <span class="strong"><strong>choose rule</strong></span> may only appear in the condition part in | |
a <a href="def_GraphPatternCall.html" title="2.1.4. Graph Pattern Call">graph pattern call</a>, a <a href="def_GTRuleCall.html" title="3.4.1. GTRule Call">GT rule call</a> or | |
an <a href="def_AsmFunctionLocation.html" title="5.5.3. ASM Function Location">ASM function location</a>. | |
</p></td></tr></table></div><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note: Semantics"><tr><td valign="top" align="center" rowspan="2" width="25"><img alt="[Note]" src="images/note.png"></td><th align="left"><a name="def_ChooseRule_Semantics"></a>Semantics</th></tr><tr><td valign="top" align="left"><p> | |
The <span class="strong"><strong>choose rule</strong></span> tries to find one substitution of variables | |
defined in its head, which satisfies a boolean condition, and then the body | |
rule is executed. If more variable substitutions satisfy the condition, then | |
one is chosen non-deterministically. If there are no such substitutions then | |
the <span class="strong"><strong>choose rule</strong></span> fails. The body ASM rule may use the head | |
variables of the choose construct. | |
</p><p> | |
For a combination of values in the variables that make the formula true, the | |
rule is executed. | |
</p><p> | |
The location in the containment hierarchy of each variable in the | |
<a href="def_ConstrainedVariableList.html" title="5.8.4. Constrained Variable List">constrained variable list</a> can be narrowed to a specific | |
<a href="def_Entity.html" title="2.2.1. Entity">container entity</a>, or to a specific subtree of the model space. With the | |
use of the <code class="computeroutput">in</code> clause users can specify the direct parent which the | |
values of the variables can be taken from. The <code class="computeroutput">below</code> | |
clause means that the values of the corresponding variable have to be taken from the model | |
subtree below the given container. | |
</p><p> | |
If the <span class="strong"><strong>choose rule</strong></span> is used with <a href="def_GTRuleCall.html" title="3.4.1. GTRule Call">GT rule call</a> | |
then the quantified variables have to be | |
<div class="itemizedlist"><ul type="disc"><li><p>output parameters of the <a href="def_GTRuleDef.html" title="3.1.1. Graph Transformation Rule Definition">GT rule</a>, and | |
</p></li><li><p>input parameters of its <span class="emphasis"><em>precondition </em></span> <a href="def_GraphPatternDef.html" title="2.1.1. Graph Pattern Definition">pattern</a>, | |
</p></li></ul></div> | |
</p><p> | |
Variables not quantified explicitly by the <span class="strong"><strong>choose rule</strong></span>, and | |
passed to the pattern matcher with a specific value (either in a | |
<a href="def_GTRuleCall.html" title="3.4.1. GTRule Call">GT rule call</a> or in a <a href="def_GraphPatternCall.html" title="2.1.4. Graph Pattern Call">graph pattern call</a>) are | |
input parameters for the pattern matcher. | |
</p><p> | |
Variables not quantified explicitly by the <span class="strong"><strong>choose rule</strong></span>, and | |
passed to pattern matching with an <span class="strong"><strong>undef</strong></span> value (either in a | |
<a href="def_GTRuleCall.html" title="3.4.1. GTRule Call">GT rule call</a> or in a <a href="def_GraphPatternCall.html" title="2.1.4. Graph Pattern Call">graph pattern call</a>) are | |
always existentially quantified implicitly. | |
</p></td></tr></table></div><div class="caution" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Caution: Constraints"><tr><td valign="top" align="center" rowspan="2" width="25"><img alt="[Caution]" src="images/caution.png"></td><th align="left"><a name="def_ChooseRule_Constraints"></a>Constraints</th></tr><tr><td valign="top" align="left"><p> | |
In the <a href="def_ConstrainedVariableList.html" title="5.8.4. Constrained Variable List">constrained variable list</a>only entities can be constrained. | |
If a containment contraint is applied to a relation, it causes a runtime error. | |
</p></td></tr></table></div><div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Warning: Warning"><tr><td valign="top" align="center" rowspan="2" width="25"><img alt="[Warning]" src="images/warning.png"></td><th align="left">Warning</th></tr><tr><td valign="top" align="left"><p> | |
The <span class="strong"><strong>choose rule</strong></span> is evaluated efficiently when the condition (<span class="emphasis"><em>with</em></span> clause) | |
is either a graph pattern call, or a GT rule call. Evaluating complex logical expressions with ASM function invocations | |
can be highly inefficient. The intended use is to include attribute and other arithmetic constraints as part of a | |
<a href="def_CheckCondition.html" title="2.1.8. Check Condition">check condition</a> of a graph pattern, where it is evaluated more efficiently. | |
</p></td></tr></table></div><div class="highlights"><a name="def_ChooseRule_Remark"></a><p><b>Remark. </b> | |
Note that in a typical model transformation, the <a href="def_ForallRule.html" title="4.3.7. Forall Rule">forall rule</a> | |
and the <span class="strong"><strong>choose rule</strong></span> will drive the execution of elementary | |
graph transformation rules. In this respect, wherever a Boolean condition is | |
expected, we may use a graph pattern as condition, and wherever an ASM rule | |
is executed, we may apply a GT rule. | |
</p></div><div class="example"><a name="def_ChooseRule_Example1"></a><p class="title"><b>Example 2.4. Different invocations of a choose rule</b></p><div class="example-contents"><pre class="programlisting"> | |
// Invoking a graph pattern | |
pattern myPattern(X) = { ... } | |
choose Y with find myPatt(Y) do println(fqn(Y)); | |
// Invoking a graph transformation rule | |
gtrule myGtRule(out X) = { ... } | |
choose Y with find myGtRule(Y) do println(fqn(Y)); | |
// Invoking a logical term with an ASM function (INEFFICIENT) | |
asmfunction myAsmFun/1 = { ... } | |
choose Y with myAsmFun(Y) > 2 do println(Y); | |
</pre></div><p></p></div><br class="example-break"><div class="example"><a name="def_ChooseRule_Example2"></a><p class="title"><b>Example 2.5. Quantification of variables passed to a choose rule</b></p><div class="example-contents"><pre class="programlisting"> | |
let X=uml.mymodel in | |
choose Y with find myPatt(X,Y) do ... | |
</pre><p> | |
In this case, X is an input variable. | |
</p><pre class="programlisting"> | |
let X=undef in | |
choose Y with find myPatt(X,Y) do ... | |
</pre><p> | |
causes a run-time exception as X is unbound. | |
</p></div><p></p></div><br class="example-break"><div class="highlights"><a name="def_ChooseRule_DefinedIn"></a><p><b>Defined In: </b> | |
<a href="def_CompoundRule.html" title="4.3.1. Compound Rule">compound rule</a> | |
</p></div><div class="highlights"><a name="def_ChooseRule_SeeAlso"></a><p><b>See Also: </b> | |
<a href="def_ForallRule.html" title="4.3.7. Forall Rule">forall rule</a> | |
</p></div></div><div class="navfooter"><hr><table summary="Navigation footer" width="100%"><tr><td align="left" width="40%"><a accesskey="p" href="def_LetRule.html">Prev</a> </td><td align="center" width="20%"><a accesskey="u" href="sec_ASMCompoundRules.html">Up</a></td><td align="right" width="40%"> <a accesskey="n" href="def_ForallRule.html">Next</a></td></tr><tr><td valign="top" align="left" width="40%">4.3.5. Let Rule </td><td align="center" width="20%"><a accesskey="h" href="index.html">Home</a></td><td valign="top" align="right" width="40%"> 4.3.7. Forall Rule</td></tr></table></div></body></html> |