Thanks Thomas<div> In the rhs I am doing some calculations and then inserting Proven objects. The calculations are significant so I would prefer to prevent the rule fires from occurring. My inclusion of</div><div><span class="Apple-style-span" style="font-size: 15px; color: rgb(31, 73, 125); ">Piton(predicate == $sentence, rule=”uniquerulename”)</span></div>
<div><font class="Apple-style-span" color="#1F497D" size="4"><span class="Apple-style-span" style="font-size: 15px;"><br></span></font></div><div><font class="Apple-style-span" color="#1F497D" size="4"><span class="Apple-style-span" style="font-size: 15px;">does work, but its quite a lot of work to handcode a name which is unique to the particular activation of the rule.</span></font></div>
<div><br></div><div>thanks for your help!</div><div>Tracey<br><br><div class="gmail_quote">2010/3/22 Swindells, Thomas <span dir="ltr">&lt;<a href="mailto:TSwindells@nds.com">TSwindells@nds.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">






<div lang="EN-GB" link="blue" vlink="purple">
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D">Presumably all your RHS do is insert your Proven objects.  If this is the case then my first question is do you actually need to put in an optimisation here? 
 How much is the work of evaluating a few extra rule nodes compared to the work and memory that will be required to evaluate the shadow facts and prevent the rules from firing.</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D"> </span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D">If you do want to try suppress rules firing couldn’t you have the following LHS?</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D">Piton(predicate == $sentence, rule=”uniquerulename”) or not Proven(predicate == $sentence)</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D"> </span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D">What I would recommend is lots of reading up about performance, testing, trying different combinations and generating the rete graph that drools produces
 to see whether you have added more or less complexity to the graph.  Also make sure you order your conditions so that the ones which are most likely to stop processing are placed first.</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D"> </span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D">Thomas</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D"> </span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D"> </span></p>
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:10.0pt">From:</span></b><span lang="EN-US" style="font-size:10.0pt"> <a href="mailto:rules-users-bounces@lists.jboss.org" target="_blank">rules-users-bounces@lists.jboss.org</a> [mailto:<a href="mailto:rules-users-bounces@lists.jboss.org" target="_blank">rules-users-bounces@lists.jboss.org</a>]
<b>On Behalf Of </b>Tracey Lall<br>
<b>Sent:</b> 20 March 2010 20:55<br>
<b>To:</b> <a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
<b>Subject:</b> [rules-users] Mechanism to prevent redundant inferences</span></p>
</div>
</div><div><div></div><div class="h5">
<p class="MsoNormal"> </p>
<div>
<p><span lang="EN-US" style="font-size:10.0pt">Hi folks</span><span style="font-size:10.0pt"></span></p>
<p><span lang="EN-US" style="font-size:10.0pt">  I am writing a logical inference engine in <span><span style="background:#FFFFCC">drools.</span></span></span><span><span lang="EN-US" style="font-size:10.0pt;background:#FFFFCC"> </span></span><span><span lang="EN-US" style="font-size:10.0pt;background:#FFFFCC">Logical
 sentences</span></span><span><span lang="EN-US" style="font-size:10.0pt;background:#FFFFCC"> (class Sentence) </span></span><span><span lang="EN-US" style="font-size:10.0pt;background:#FFFFCC">which
 are proven are indicated by the fact Proven( sentence = $sentence )</span></span><span style="font-size:10.0pt"></span></p>
<p><span lang="EN-US" style="font-size:10.0pt">All Proven(sentence) facts are asserted using the <span><span style="background:#FFFFCC">drools</span></span> logical mechanism (since logical backtracking is required).</span><span style="font-size:10.0pt"></span></p>

<p><span><span lang="EN-US" style="font-size:10.0pt">For efficiency purposes</span></span><span><span lang="EN-US" style="font-size:10.0pt"> I </span></span><span><span lang="EN-US" style="font-size:10.0pt">want
 to be able to suppress firing any</span></span><span><span lang="EN-US" style="font-size:10.0pt"> </span></span><span><span lang="EN-US" style="font-size:10.0pt">rules</span></span><span><span lang="EN-US" style="font-size:10.0pt"> </span></span><span><span lang="EN-US" style="font-size:10.0pt">which assert proof
 of a</span></span><span><span lang="EN-US" style="font-size:10.0pt"> </span></span><span><span lang="EN-US" style="font-size:10.0pt">logical
 sentence</span></span><span><span lang="EN-US" style="font-size:10.0pt"> </span></span><span><span lang="EN-US" style="font-size:10.0pt">which
 has already been proven (there may be multiple</span></span><span><span lang="EN-US" style="font-size:10.0pt"> </span></span><span><span lang="EN-US" style="font-size:10.0pt">inferences
 which prove the same sentence).</span></span><span style="font-size:10.0pt"></span></p>
<p><span><span lang="EN-US" style="font-size:10.0pt">If the non existence of a proof of a</span></span><span><span lang="EN-US" style="font-size:10.0pt"> </span></span><span><span lang="EN-US" style="font-size:10.0pt">sentence</span></span><span><span lang="EN-US" style="font-size:10.0pt"> (not
 exists Proven(sentence=$sentence) </span></span><span><span lang="EN-US" style="font-size:10.0pt">is included in the lhs conditions then that causes problems when the rule logically asserts Proven(sentence)
 since the insertion invalidates the lhs conditions and hence the rule causes its own retraction (the inserted fact handle return is null).</span></span><span style="font-size:10.0pt"></span></p>
<p><span><span style="font-size:10.0pt">As a way around this I created a class Piton() to record whether a particular rule has fired. The lhs conditions then become:</span></span><span style="font-size:10.0pt"></span></p>

<p><span style="font-size:10.0pt">(Proven( predicate == $sentence ) or Piton( fireName == $descriptor ) )</span></p>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt">And then in the body of the rule the first thing it asserts is the fact:</span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt"> </span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt">Piton( fireName == $descriptor )</span></p>
</div>
<p><span style="font-size:10.0pt">Where $descriptor is a string built from the rulename  + the set of facts which matched the lhs (ie a descriptor which is unique to the rule fire)</span><span style="font-size:10.0pt"></span></p>

<p><span style="font-size:10.0pt">With this approach when a rule asserts Proven(sentence) because it has also asserted  Piton( fireName == descriptor ) ) the lhs of the rule still matches the the rule fire is not retracted.</span><span style="font-size:10.0pt"></span></p>

<p><span style="font-size:10.0pt">This approach works, but it is rather tedious to implement since the descriptor must be defined in such as way to make it unique (or as far as possible unique) to the particular rule activation.
 Since the drools variable is not accessible in the lhs of a rule (and hence the activation details are not accessible in the lhs), this means that the descriptor must be handcoded to consist of all matching facts for that lhs.</span><span style="font-size:10.0pt"></span></p>

<p><span style="font-size:10.0pt">Is this approach the only way to prevent multiple rule firings for the same proof, or is there a simpler way to achieve this?</span><span style="font-size:10.0pt"></span></p>
<p><span style="font-size:10.0pt">Any advice greatly appreciated!</span><span style="font-size:10.0pt"></span></p>
<p><span><span style="font-size:10.0pt">thanks</span></span><span style="font-size:10.0pt"></span></p>
<p><span style="font-size:10.0pt">Tracey</span><span style="font-size:10.0pt"></span></p>
<p><span style="font-size:10.0pt"> </span></p>
<div>
<p class="MsoNormal"><span style="font-size:10.0pt"> </span></p>
</div>
</div>
</div></div></div>
</div>
<br>
<hr>
<font face="Arial" color="Gray" size="1"><br>
**************************************************************************************<br>
This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the <a href="mailto:postmaster@nds.com" target="_blank">postmaster@nds.com</a> and delete it from your system as well as any copies. The content of e-mails as well as traffic data
 may be monitored by NDS for employment and security purposes. To protect the environment please do not print this e-mail unless necessary.<br>
<br>
NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603 8808 40-00<br>
**************************************************************************************<br>
</font><br>
<hr>
<font face="Arial" color="Gray" size="1">This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the <a href="mailto:postmaster@nds.com" target="_blank">postmaster@nds.com</a> and delete it from your system as well as any copies. The
 content of e-mails as well as traffic data may be monitored by NDS for employment and security purposes.<br>
To protect the environment please do not print this e-mail unless necessary.<br>
<br>
An NDS Group Limited company. <a href="http://www.nds.com" target="_blank">www.nds.com</a><br>
</font>
</div>

<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br></div>