Absence of events can only be detected by checking the past.<br>This means that a trigger must be inserted whenever it&#39;s time<br>to check the last two minutes. This check cannot be done in<br>a uniform way for all players because the arrival of an EventB<br>
is the start of another 2 minute interval. The solution is based<br>on a ticker which inserts the trigger (Checker) whenever 120<br>seconds have gone by. (There are also other techniques to do this.)<br><br>declare EventB<br>
&nbsp; @role( event )<br>end<br><br>declare Checker<br>&nbsp; @role( event )<br>end<br><br>rule &quot;ticker 120&quot;<br>&nbsp; no-loop true<br>&nbsp; timer(int:0s 1s)<br>when<br>&nbsp;&nbsp;&nbsp; $p: Player( $index: index, $ticks: ticks )<br>then<br>&nbsp;&nbsp;&nbsp; if( $ticks == 120 ){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; modify( $p ){ setTicks( 1 ) }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; insert( new Checker( $index ) );<br>&nbsp;&nbsp;&nbsp; } else {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; modify( $p ){ setTicks( $ticks + 1 ) }<br>&nbsp;&nbsp;&nbsp; }<br>end<br><br>rule &quot;no B for 2 minutes&quot;<br>when<br>&nbsp;&nbsp;&nbsp; $c : Checker( $index: index )<br>
&nbsp;&nbsp;&nbsp; not EventB( index == $index, this before[0s,2m] $c )<br>then<br>&nbsp;&nbsp;&nbsp; System.out.println( &quot;at &quot; + Main.getClock() + &quot;: no B:&quot; + $index + &quot; in last 2 minutes&quot; );<br>&nbsp;&nbsp;&nbsp; retract( $c );<br>end<br>
<br>rule &quot;B arrives&quot;<br>when<br>&nbsp;&nbsp;&nbsp; $p : Player( $index: index )<br>&nbsp;&nbsp;&nbsp; $b : EventB( index == $index )<br>then<br>&nbsp;&nbsp;&nbsp; System.out.println( &quot;at &quot; + Main.getClock() + &quot;: B:&quot; + $index + &quot;, reset ticks&quot; );<br>
&nbsp;&nbsp;&nbsp; modify( $p ){ setTicks( 0 ) }<br>&nbsp;&nbsp;&nbsp; retract( $b );<br>end<br><br><div class="gmail_quote">2010/10/31 ÕÔ٩٩ <span dir="ltr">&lt;<a href="mailto:kevin223@gmail.com">kevin223@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>&nbsp;&nbsp; &nbsp;<span style="white-space: pre-wrap;">        </span>this.session = createSession();</div><div>&nbsp;&nbsp; &nbsp;<span style="white-space: pre-wrap;">        </span>SessionPseudoClock clock = session.getSessionClock();</div><div class="im">
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;session.insert( new Player( 1 ) );</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;session.insert( new Player( 2 ) );</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;clock.advanceTime( 3*60, TimeUnit.SECONDS );</div></div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;session.insert(new EventB(1));</div>

<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;session.fireAllRules();</div><div class="im"><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;clock.advanceTime( 3*60, TimeUnit.SECONDS );</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;session.fireAllRules();</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;session.dispose();</div>

<div><br></div></div><div>The above code gives the following output:</div><div><br></div><div><div>no B:2 in last 2 minutes</div><div>no B:1 in last 2 minutes</div></div><div><br></div><div>what I expect is:</div><div><br>
</div>
<div>no B:2 in last 2 minutes</div><div><div>no B:2 in last 2 minutes</div><div>no B:1 in last 2 minutes</div></div><div><br></div><div>Any ideas?</div><div><br></div><div>Best Regards,</div><div>Kevin Zhao</div><br><div>
<div></div><div class="h5"><div class="gmail_quote">
2010/10/29 Wolfgang Laun <span dir="ltr">&lt;<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

&nbsp;&nbsp;&nbsp; System.out.println( &quot;Test no B&quot; );<br>&nbsp;&nbsp;&nbsp; session = kBase.newStatefulKnowledgeSession( config, null );<br>&nbsp;&nbsp;&nbsp; clock = session.getSessionClock();<br>&nbsp;&nbsp;&nbsp; session.insert( new Player( 1 ) );<br>&nbsp;&nbsp;&nbsp; clock.advanceTime( 3*60, TimeUnit.SECONDS );<br>


&nbsp;&nbsp;&nbsp; session.fireAllRules();<br>&nbsp;&nbsp;&nbsp; session.dispose();<br><br>The rule fires with this test, (kBase in STREAM mode).<br>-W<br><br><div class="gmail_quote">2010/10/29 ÕÔ٩٩ <span dir="ltr">&lt;<a href="mailto:kevin223@gmail.com" target="_blank">kevin223@gmail.com</a>&gt;</span><div>

<div></div><div><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">The&nbsp;&quot;no B:x for 2 minutes&quot; will not fire if nothing comes in even after 2minutes. e.g. if no characters get killed then no events will come in.<div>


If I add a timer to this rule, say like&nbsp;timer (2m 1s), then the rule will fire every second after 2 minutes.</div>
<div><br></div><div>Best Regards,</div><div>Kevin<br><br><div class="gmail_quote">2010/10/29 Wolfgang Laun <span dir="ltr">&lt;<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>&gt;</span><br>


<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
OK; your original version somehow put me off the right track.<br>This rule will fire as soon as there is no B:n according to the<br>Player index for 2 minutes.<br><br>rule &quot;no B:x for 2 minutes&quot;<br>
when<br>
&nbsp;&nbsp;&nbsp; $b : Player( $index: index )<br>
&nbsp;&nbsp;&nbsp; not ( EventB( index == $index) over window:time( 2m ) )<br>
then<br>
&nbsp;&nbsp;&nbsp; System.out.println( &quot;no B:&quot; + $index + &quot; in last 2 minutes&quot; );<br>
end<br><br>This would fire whenever there&#39;s no B at all for 2 minutes:<br><br>
rule &quot;no B for 2 minutes&quot;<br>
when<br>
&nbsp;&nbsp;&nbsp; not ( EventB() over window:time( 2m ) )<br>
then<br>
&nbsp;&nbsp;&nbsp; System.out.println( &quot;no B:&quot; + $index + &quot; in last 2 minutes&quot; );<br>
end<div><div></div><div><br>
<br><br><div class="gmail_quote">2010/10/28 ÕÔ٩٩ <span dir="ltr">&lt;<a href="mailto:kevin223@gmail.com" target="_blank">kevin223@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">




My last mail should actually read:<div><br></div><div>A player may have multiple characters and the rule should fire when <b>ALL</b> of its characters live longer than 2 minutes. &nbsp;that&#39;s why &quot;characters&quot; do not have a unique identification and&nbsp;&nbsp;there isn&#39;t any event representing a character birth.<div>





<div></div><div><div><br></div><div>Best Regards,</div><div>Kevin Zhao</div></div></div><br><div class="gmail_quote">ÔÚ 2010Äê10ÔÂ28ÈÕ ÏÂÎç9:50£¬ÕÔ٩٩ <span dir="ltr">&lt;<a href="mailto:kevin223@gmail.com" target="_blank">kevin223@gmail.com</a>&gt;</span>дµÀ£º<div>




<div></div><div><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">A player may have multiple characters and the rule should fire when any of its characters live longer than 2 minutes. &nbsp;that&#39;s why &quot;characters&quot; do not have a unique identification and&nbsp;&nbsp;there isn&#39;t any event representing a character birth.<div>





<div></div><div><div>
<br></div><div>Best Regards,</div><div>Kevin Zhao<br><br><div class="gmail_quote">2010/10/28 Wolfgang Laun <span dir="ltr">&lt;<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>&gt;</span><br>





<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
If EventB( index == 3 ) signifies that the &quot;character&quot; owned by player 3 has been killed: what is the event that this character has been born? Life is the time between birth and death; these two are well-defined (well, mostly) events, and they ought to be represented by clean-cut events in any application. Then it&#39;s no problem to write rules firing when a &quot;character&quot; lives longer or shorter than any time. Also, &quot;characters&quot; may have to have a unique identification beyond their player-owner.<br>







<br>If you are constantly shifting your specs, we won&#39;t be getting any closer to a solution, though.<div><div></div><div><br><br>-W<br><br><br><div class="gmail_quote">2010/10/28 ÕÔ٩٩ <span dir="ltr">&lt;<a href="mailto:kevin223@gmail.com" target="_blank">kevin223@gmail.com</a>&gt;</span><br>







<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">To be honest, I don&#39;t quite understand the rules you wrote. Let me explain this a little bit with a real world scenario.<div>







Assume this is an on-line game that EventB indicates a &#39;kill&#39; event that a player is losing its character who might be killed by some other player.</div>
<div>The property index points to the player who owns this character. What I&#39;m looking for here is to find out when a player&#39;s character survives in 2 minutes. The number of players in a game is at least 2 but can be up to any number.</div>







<div><div></div><div>
<div><br></div><div>Best Regards,</div><div>Kevin Zhao<br><br><div class="gmail_quote">2010/10/28 Wolfgang Laun <span dir="ltr">&lt;<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>&gt;</span><br>







<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br><br><div class="gmail_quote"><div>2010/10/28 ÕÔ٩٩ <span dir="ltr">&lt;<a href="mailto:kevin223@gmail.com" target="_blank">kevin223@gmail.com</a>&gt;</span><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">









<div>Hello&nbsp;Wolfgang,</div><div><div><br></div>Index is just like the index in an array. the value can be any from 0 to the array length.&nbsp;<div>for the previous example, the length is 1 so index can be either 0 or 1. but in the real case, the length can be an arbitrary number.</div>










<div><br></div><div>another question, there are 2 rules here, do both of them have to be applied?</div></div></blockquote><div><br>One creates and inserts the PatternConsumer which blocks repeated usage of the pair of EventB facts that have been successfully paired. Otherwise a sequence EventB:0, EventB:1, EventB:2 would fire 2 times.<br>









<br>If the positive condition is more complex, e.g., you need *all* index values 0,...,L-1 within 2m, then other conditions will be required (and that&#39;s what I meant with &quot;more precisesly&quot;). If any pair a,b from [0..L-1] will do, then the modified version (!=) should be OK.<br>








<font color="#888888">
<br>-W<br><br>&nbsp;</font></div><div><div></div><div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><br></div><div>Best Regards,</div>
<div>Kevin Zhao<br><br><div class="gmail_quote">
2010/10/28 Wolfgang Laun <span dir="ltr">&lt;<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>&gt;</span><div><div></div><div><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Kindly state your requirements precisely.<br><br>Perhaps <br>&nbsp;&nbsp; not ( EventB ( index != $index,... )<br>









is what you need.<br>
-W<br><br><div class="gmail_quote">2010/10/28 ÕÔ٩٩ <span dir="ltr">&lt;<a href="mailto:kevin223@gmail.com" target="_blank">kevin223@gmail.com</a>&gt;</span><div><div></div><div><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I haven&#39;t tested this rule, but what about the case that property index would have arbitrary number of possible values?<br>











<br><div class="gmail_quote">2010/10/27 Wolfgang Laun <span dir="ltr">&lt;<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>&gt;</span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Omitting the Entry &nbsp;Points:<br>
<br>
rule &quot;B-0-1-not OK&quot;<br>
when<br>
 &nbsp; &nbsp;$b : EventB( $index: index )<br>
 &nbsp; &nbsp;not ( PatternConsumer( id == &quot;B01&quot;, events contains $b ) )<br>
 &nbsp; &nbsp;not ( EventB( index == (1 - $index), this after[0s,2m] $b ) )<br>
then<br>
 &nbsp; &nbsp;System.out.println( &quot;B:&quot; + $index + &quot;, but no B:&quot; + (1-$index) );<br>
end<br>
<br>
rule &quot;B-0-1&quot;<br>
when<br>
 &nbsp; &nbsp;$b1 : EventB( $index: index )<br>
 &nbsp; &nbsp;$b2 : EventB( index == (1 - $index), this after[0s,2m] $b1 )<br>
then<br>
 &nbsp; &nbsp;insert( new PatternConsumer( &quot;B01&quot;, $b1, $b2 ) );<br>
 &nbsp; &nbsp;System.out.println( &quot;B:&quot; + $index + &quot;+B:&quot; + (1-$index) );<br>
end<br>
<br>
-W<br>
<br>
2010/10/27 ÕÔ٩٩ &lt;<a href="mailto:kevin223@gmail.com" target="_blank">kevin223@gmail.com</a>&gt;:<br>
<div><div></div><div>&gt; Hello,<br>
&gt; With the help from the community I managed to get my first rule working, and<br>
&gt; I&#39;m trying to write my second rule on my own but it just doesn&#39;t seem to<br>
&gt; work correctly.<br>
&gt; Here is the scenario, what I want is to identify a pattern that there&#39;s no<br>
&gt; EventB coming in within 2 minutes with a particular index value.<br>
&gt; For example, EventB would have a property named index and assume the value<br>
&gt; of index would be either 0 or 1.<br>
&gt; Before firing the rules, I would manually insert facts of possibleIndex with<br>
&gt; value 0 and 1 into the workingMemory.<br>
&gt; Within 2 minutes, if there only comes one EventB with index valued 0 then<br>
&gt; the system should report no EventB coming in with index value 1 in last 2<br>
&gt; minutes.<br>
&gt; Vice versa, in the case of only coming one EventB with index valued 1 then<br>
&gt; the system should report no EventB coming in with index value 0 in last 2<br>
&gt; minutes.<br>
&gt; If within 2 minutes, there comes 2 EventB with both value 0 and 1 then<br>
&gt; nothing should report.<br>
&gt; Here is what I wrote, but it doesn&#39;t seem to work correctly.<br>
&gt; I used a timer to fire this rule every 10 seconds because I don&#39;t think the<br>
&gt; rule would run automatically if I don&#39;t add that. (not too sure though)<br>
&gt; rule &quot;no B in 2 minutes&quot;<br>
&gt; timer (0 10s)<br>
&gt; when<br>
&gt; possibleIndex( $index : index ) from entry-point &quot;Event stream&quot;<br>
&gt; $p : PatternConsumer ( name == &#39;no B&#39; &amp;&amp; index == $index )<br>
&gt; not ( EventB( index == $index &amp;&amp; this after[0ms,2m] $p) over window:time(2m)<br>
&gt; from entry-point &quot;Event stream&quot; )<br>
&gt; then<br>
&gt; PatternConsumer pc = new PatternConsumer( &quot;no B&quot;, $index );<br>
&gt; insert(pc);<br>
&gt; System.out.println(&quot;no B in 2 minutes &quot; + $index);<br>
&gt; end<br>
&gt; Best Regards,<br>
&gt; Kevin Zhao<br>
</div></div>&gt; _______________________________________________<br>
&gt; rules-users mailing list<br>
&gt; <a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;<br>
&gt;<br>
<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">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>
</blockquote></div><br>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">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></div></div><br>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">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></div></div><br></div>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">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></div></div><br>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">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>
</div></div><br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">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></div><br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">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>
</div></div></blockquote></div></div></div><br></div>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">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></div><br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">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>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">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></div></div><br>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">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></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>