On 12 December 2010 10:17, Greg Barton <span dir="ltr">&lt;<a href="mailto:greg_barton@yahoo.com">greg_barton@yahoo.com</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-size: inherit; line-height: inherit; font-size-adjust: inherit; font-stretch: inherit;" valign="top">
The benefits of an OO RBMS don&#39;t matter when you&#39;re incompletely constraining the type as you were in your original rules.  The constraint you want is &quot;the id is the same AND they&#39;re of corresponding types&quot; which you couldn&#39;t get by just specifying the supertypes as you were.  </td>
</tr></tbody></table></blockquote><div><br>The moral of the story is that you can&#39;t use a mixture of leaf and non-leaf class nodes from the same hierarchy for distinct matches. Use supertypes in patterns only if you &quot;really mean it&quot;.<br>
<br>Or, I can also use<br>   rule &quot;track state for unknown element&quot;<br>   when<br>       $s: TrackState(  $id: id, <b>eval( $s.getClass() == TrackState.class)</b> )<br>       not Track( id == $id )<br>   then<br>
 </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-size: inherit; line-height: inherit; font-size-adjust: inherit; font-stretch: inherit;" valign="top">
<div><br></div><div>As for your testing comment, I agree.  The best I&#39;ve ever done is to set up a random dataset I know should pass a test, including random setup conditions, and run the test until I&#39;m reasonably confident the code works properly.  That doesn&#39;t work if the input data is too &quot;safe,&quot; but that&#39;s always a problem with unit tests.</div>
</td></tr></tbody></table></blockquote><div><br>Even a set of exhaustive tests of individual SwitchState facts succeeds:<br>        for( String e: new String[]{ &quot;1&quot;, &quot;2&quot;, &quot;3&quot;, &quot;4&quot;, &quot;5&quot;, &quot;6&quot; } ){<br>
            insert( new SwitchState( e, true, SwitchPosition.RIGHT, false ) );<br>            fireAllRules();<br>        }<br>Only moving fireAllRules() out of the loop produces the effect.<br><br>-W<br><br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-size: inherit; line-height: inherit; font-size-adjust: inherit; font-stretch: inherit;" valign="top">
<div><div class="im"><br><br>--- On <b>Sun, 12/12/10, Wolfgang Laun <i>&lt;<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>&gt;</i></b> wrote:<br></div><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;">
<div class="im"><br>From: Wolfgang Laun
 &lt;<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>&gt;<br></div>Subject: Re: [rules-dev] A remarkable flop<div class="im"><br>To: &quot;Rules Dev List&quot; &lt;<a href="mailto:rules-dev@lists.jboss.org" target="_blank">rules-dev@lists.jboss.org</a>&gt;<br>
</div>Date: Sunday, December 12, 2010, 2:48 AM<div><div></div><div class="h5"><br><br><div>Ah, yes, and I&#39;d actually be interested to learn why the indeterminism of rule firings not only depends on two or more rules matching the fact set but also on the order and/or number of facts being inserted.<br>
<br>Notice that with three SwitchState facts inserted, id&#39;s 1, 2 and 5 match and fire the &quot;correct&quot; (i.e., expected) rule. Adding a fourth fact with id 4 suddenly fires the match of no. 5 with the &quot;wrong&quot; (i.e., unexpected) rule.<br>

<br>Actually, this means that you cannot rely on tests of rule sets, as you could if a potentially multiple match between two rules would always first activate A or always first B.<br><br>-W<br><br><div>
On 12 December 2010 09:28, Wolfgang Laun <span dir="ltr">&lt;<a rel="nofollow" href="http://mc/compose?to=wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>&gt;</span> wrote:<br><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

The solution I adopted is to make SwitchState not a subclass of TrackState but of ElementState, which means that the field(s) to be inherited from TrackState have to be duplicated in SwitchState. (Luckily, here it is only one field.)<br>


<br>Adding a type-identifying field goes against the (my) idea of classes for identifying categories and using them as an implicit constraint in rules, making them more readable. That&#39;s one of the benefits of having an OO RBS, isn&#39;t it?<br>


<br>Anyway, I just wanted to draw people&#39;s attention to this hidden trap; working around it is no problem once you know it is there.<br><font color="#888888"><br>-W</font><div><div></div><div><br><br><br><div>
On 12 December 2010 05:06, Greg Barton <span dir="ltr">&lt;<a rel="nofollow" href="http://mc/compose?to=greg_barton@yahoo.com" target="_blank">greg_barton@yahoo.com</a>&gt;</span> wrote:<br>
<blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-size: inherit; line-height: inherit; font-size-adjust: inherit; font-stretch: inherit;" valign="top">


Well, seeing as you&#39;re already maintaining two parallel type hierarchies, and it&#39;s a mismatch between the two that&#39;s causing the problem, you might as well use that in the rules.<br><br><div><div>   rule &quot;Xyz state update&quot;  <br>


   when<br></div>       $s: XyzState( $id: id, $type: type ... )<br>       $e: Xyz( id == $id, type == $type )<div><br>   then<br>     //...update $e, retract $s<br>   end<br><br></div></div><div><div>
   rule &quot;Xyz state for unknown element&quot;<br>   when<br></div>      $s: XyzState( $id: id, $type: type )</div><div>      not Xyz( id == $id, type == $type )</div><div><div>  then<br>      //... diagnostic, retract $s<br>


  end</div><div><br></div></div><div>That oughter do
 it, and it avoids salience.<br>--- On <b>Sat, 12/11/10, Wolfgang Laun <i>&lt;<a rel="nofollow" href="http://mc/compose?to=wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>&gt;</i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;">


<br>From: Wolfgang Laun &lt;<a rel="nofollow" href="http://mc/compose?to=wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>&gt;<br>Subject: [rules-dev] A remarkable flop<br>To: &quot;Rules Dev List&quot; &lt;<a rel="nofollow" href="http://mc/compose?to=rules-dev@lists.jboss.org" target="_blank">rules-dev@lists.jboss.org</a>&gt;<br>


Date: Saturday, December 11, 2010, 10:23 AM<div><div></div><div><br><br><div><br>
Given classes Switch and Track, and the &quot;natural&quot; class hierarchy representing state changes for these two elements:<br>
   ElementState<br>
   TrackState extends ElementState (&quot;free/occupied&quot;)<br>
   SwitchState extends TrackState (adds &quot;left/right/moving&quot;)<br>Now we have rules for updating Switch and Track elements, like this one:<br>
   rule &quot;Xyz state update&quot;  <br>
   when<br>
       $s: XyzState( $id: id, ... )<br>
       $e: Xyz( id == $id )<br>
   then<br>
     //...update $e, retract $s<br>
   end<br>
and, since we want to catch bad ids, also<br>
   rule &quot;Xyz state for unknown element&quot;<br>
   when<br>
      $s: XyzState( $id: id )<br>
      not Xyz( id == $id )<br>
  then<br>
      //... diagnostic, retract $s<br>
  end<br>
<br>
Best practice, wouldn&#39;t you say?<br><br>Testing by inserting a few of SwitchState objects works fine:<br>   updated: Switch 5 RIGHT occupied<br>   updated: Switch 2 RIGHT<br>   updated: Switch 1 RIGHT occupied<br> so everything is allright, wouldn&#39;t you say? <br>




<br>Add another SwitchState for Switch &quot;4&quot; to the test, and suddenly:<br>  updated: Switch 4 RIGHT<br>  track state for unknown element 5<br>  updated: Switch 2 RIGHT<br>  updated: Switch 1 RIGHT occupied<br>What&#39;s this?!<br>



<br>After some headscratching I realized that the negative rule for the SwitchState&#39;s superclass TrackState produces another activation, since, for any Switch element with an id x there clearly isn&#39;t a Track element with id x! This activation <i>occasionally </i>precedes the activation for the match in the &quot;update&quot; rule.<br>



<br>This is annoying. Of course, negative salience for the &quot;not&quot; rules fixes this, but who would have thought that you need it with conditions (seemingly!) describing disjoint situations. And the negative salience is counter-intuitive, since normally you&#39;d perform the check &quot;no such element&quot; <i>before </i>permitting any update action.<br>



<br>Remarkable.<br>Wolfgang<br><br><br><br> <br> <br><br><br>
</div><br></div></div>-----Inline Attachment Follows-----<br><br><div>_______________________________________________<br>rules-dev mailing list<br><a rel="nofollow" href="http://mc/compose?to=rules-dev@lists.jboss.org" target="_blank">rules-dev@lists.jboss.org</a><br>


<a rel="nofollow" href="https://lists.jboss.org/mailman/listinfo/rules-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-dev</a><br></div></blockquote></div></td></tr></tbody></table><br>

      <br>_______________________________________________<br>
rules-dev mailing list<br>
<a rel="nofollow" href="http://mc/compose?to=rules-dev@lists.jboss.org" target="_blank">rules-dev@lists.jboss.org</a><br>
<a rel="nofollow" href="https://lists.jboss.org/mailman/listinfo/rules-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-dev</a><br>
<br></blockquote></div><br>
</div></div></blockquote></div><br>
</div><br>-----Inline Attachment Follows-----<br><br><div>_______________________________________________<br>rules-dev mailing list<br><a href="http://mc/compose?to=rules-dev@lists.jboss.org" target="_blank">rules-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-dev</a><br></div></div></div></blockquote></div></td></tr></tbody></table><br>

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