<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Well, seeing as you're already maintaining two parallel type hierarchies, and it's a mismatch between the two that's causing the problem, you might as well use that in the rules.<br><br><div>&nbsp;&nbsp; rule "Xyz state update"&nbsp;&nbsp;<br>&nbsp;&nbsp; when<br>&nbsp;&nbsp; &nbsp; &nbsp; $s: XyzState( $id: id, $type: type ... )<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $e: Xyz( id == $id, type == $type )<br>&nbsp;&nbsp; then<br>&nbsp;&nbsp;&nbsp;&nbsp; //...update $e, retract $s<br>&nbsp;&nbsp; end<br><br></div><div>&nbsp;&nbsp; rule "Xyz state for unknown element"<br>&nbsp;&nbsp; when<br>&nbsp;&nbsp; &nbsp;&nbsp; $s: XyzState( $id: id, $type: type&nbsp;)</div><div>&nbsp;&nbsp; &nbsp;&nbsp; not Xyz( id == $id, type == $type&nbsp;)</div><div>&nbsp; then<br>&nbsp; &nbsp; &nbsp; //... diagnostic, retract $s<br>&nbsp; end</div><div><br></div><div>That oughter do
 it, and it avoids salience.<br>--- On <b>Sat, 12/11/10, Wolfgang Laun <i>&lt;wolfgang.laun@gmail.com&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;wolfgang.laun@gmail.com&gt;<br>Subject: [rules-dev] A remarkable flop<br>To: "Rules Dev List" &lt;rules-dev@lists.jboss.org&gt;<br>Date: Saturday, December 11, 2010, 10:23 AM<br><br><div id="yiv413986284"><br>
Given classes Switch and Track, and the "natural" class hierarchy representing state changes for these two elements:<br>
&nbsp;&nbsp; ElementState<br>
&nbsp;&nbsp; TrackState extends ElementState ("free/occupied")<br>
&nbsp;&nbsp; SwitchState extends TrackState (adds "left/right/moving")<br>Now we have rules for updating Switch and Track elements, like this one:<br>
&nbsp;&nbsp; rule "Xyz state update"&nbsp; <br>
&nbsp;&nbsp; when<br>
&nbsp;&nbsp; &nbsp; &nbsp; $s: XyzState( $id: id, ... )<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $e: Xyz( id == $id )<br>
&nbsp;&nbsp; then<br>
&nbsp;&nbsp;&nbsp;&nbsp; //...update $e, retract $s<br>
&nbsp;&nbsp; end<br>
and, since we want to catch bad ids, also<br>
&nbsp;&nbsp; rule "Xyz state for unknown element"<br>
&nbsp;&nbsp; when<br>
&nbsp;&nbsp; &nbsp;&nbsp; $s: XyzState( $id: id )<br>
&nbsp;&nbsp; &nbsp;&nbsp; not Xyz( id == $id )<br>
&nbsp; then<br>
&nbsp; &nbsp; &nbsp; //... diagnostic, retract $s<br>
&nbsp; end<br>
<br>
Best practice, wouldn't you say?<br><br>Testing by inserting a few of SwitchState objects works fine:<br>&nbsp;&nbsp; updated: Switch 5 RIGHT occupied<br>&nbsp;&nbsp; updated: Switch 2 RIGHT<br>&nbsp;&nbsp; updated: Switch 1 RIGHT occupied<br>&nbsp;so everything is allright, wouldn't you say? <br>

<br>Add another SwitchState for Switch "4" to the test, and suddenly:<br>&nbsp; updated: Switch 4 RIGHT<br>&nbsp; track state for unknown element 5<br>&nbsp; updated: Switch 2 RIGHT<br>&nbsp; updated: Switch 1 RIGHT occupied<br>What's this?!<br>
<br>After some headscratching I realized that the negative rule for the SwitchState's superclass TrackState produces another activation, since, for any Switch element with an id x there clearly isn't a Track element with id x! This activation <i>occasionally </i>precedes the activation for the match in the "update" rule.<br>
<br>This is annoying. Of course, negative salience for the "not" 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'd perform the check "no such element" <i>before </i>permitting any update action.<br>
<br>Remarkable.<br>Wolfgang<br><br><br><br>&nbsp;<br>&nbsp;<br><br><br>
</div><br>-----Inline Attachment Follows-----<br><br><div class="plainMail">_______________________________________________<br>rules-dev mailing list<br><a ymailto="mailto:rules-dev@lists.jboss.org" href="/mc/compose?to=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></div></blockquote></div></td></tr></table><br>