2010/11/2 ��٩٩ <span dir="ltr"><<a href="mailto:kevin223@gmail.com">kevin223@gmail.com</a>></span><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;">
I get the following errors:<div><br></div><div><div>Rule Compilation error : [Rule name='no B for 2 minutes']</div><div><span style="white-space: pre-wrap;"> </span>com/sample/Rule_no_B_for_2_minutes_0.java (7:571) : Main cannot be resolved</div>
<div>Rule Compilation error : [Rule name='B arrives']</div><div><span style="white-space: pre-wrap;"> </span>com/sample/Rule_B_arrives_0.java (7:632) : Main cannot be resolved</div><div><br></div><div>
It seems that 'Main.getClock()' can't be resolved. </div></div></blockquote><div><br>Well, it's obvious that you can omit the println, or use some function returning the pseudo-time.<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><div><br></div><div>Besides, is it possible not to retract EventB when it arrives? Those events might be checked against other rules.</div><div><br></div></div></blockquote><div><br>You can omit the retract, but then you must add no-loop true as in "ticker 120".<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><div></div>
<div>Out of interest in the last, what are <span style="font-family: arial,sans-serif; font-size: 13px; border-collapse: collapse;">other possible techniques?</span></div><div><br></div></div></blockquote><div>Run a separate timer thread, i.e., a ticker written in Java.<br>
<br>-W<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><div></div><div>Best Regards,</div>
<div>Kevin Zhao</div><br><div class="gmail_quote">2010/11/1 Wolfgang Laun <span dir="ltr"><<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>></span><div><div></div><div class="h5">
<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Absence of events can only be detected by checking the past.<br>This means that a trigger must be inserted whenever it'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>
@role( event )<br>end<br><br>declare Checker<br> @role( event )<br>end<br><br>rule "ticker 120"<br> no-loop true<br> timer(int:0s 1s)<br>when<br> $p: Player( $index: index, $ticks: ticks )<br>then<br> if( $ticks == 120 ){<br>
modify( $p ){ setTicks( 1 ) }<br> insert( new Checker( $index ) );<br> } else {<br> modify( $p ){ setTicks( $ticks + 1 ) }<br> }<br>end<div><br><br>rule "no B for 2 minutes"<br>
when<br></div> $c : Checker( $index: index )<br>
not EventB( index == $index, this before[0s,2m] $c )<br>then<br> System.out.println( "at " + Main.getClock() + ": no B:" + $index + " in last 2 minutes" );<br> retract( $c );<br>end<br>
<br>rule "B arrives"<br>when<br> $p : Player( $index: index )<br> $b : EventB( index == $index )<br>then<br> System.out.println( "at " + Main.getClock() + ": B:" + $index + ", reset ticks" );<br>
modify( $p ){ setTicks( 0 ) }<br> retract( $b );<br>end<br><br><div class="gmail_quote">2010/10/31 ��٩٩ <span dir="ltr"><<a href="mailto:kevin223@gmail.com" target="_blank">kevin223@gmail.com</a>></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;">
<div> <span style="white-space: pre-wrap;"> </span>this.session = createSession();</div><div> <span style="white-space: pre-wrap;"> </span>SessionPseudoClock clock = session.getSessionClock();</div><div>
<div> session.insert( new Player( 1 ) );</div><div> session.insert( new Player( 2 ) );</div><div> </div><div> clock.advanceTime( 3*60, TimeUnit.SECONDS );</div></div><div> session.insert(new EventB(1));</div>
<div> session.fireAllRules();</div><div><div> </div><div> clock.advanceTime( 3*60, TimeUnit.SECONDS );</div><div> session.fireAllRules();</div><div> </div><div> 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><div class="gmail_quote">
2010/10/29 Wolfgang Laun <span dir="ltr"><<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
System.out.println( "Test no B" );<br> session = kBase.newStatefulKnowledgeSession( config, null );<br> clock = session.getSessionClock();<br> session.insert( new Player( 1 ) );<br> clock.advanceTime( 3*60, TimeUnit.SECONDS );<br>
session.fireAllRules();<br> 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"><<a href="mailto:kevin223@gmail.com" target="_blank">kevin223@gmail.com</a>></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 "no B:x for 2 minutes" 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 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"><<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>></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 "no B:x for 2 minutes"<br>
when<br>
$b : Player( $index: index )<br>
not ( EventB( index == $index) over window:time( 2m ) )<br>
then<br>
System.out.println( "no B:" + $index + " in last 2 minutes" );<br>
end<br><br>This would fire whenever there's no B at all for 2 minutes:<br><br>
rule "no B for 2 minutes"<br>
when<br>
not ( EventB() over window:time( 2m ) )<br>
then<br>
System.out.println( "no B:" + $index + " in last 2 minutes" );<br>
end<div><div></div><div><br>
<br><br><div class="gmail_quote">2010/10/28 ��٩٩ <span dir="ltr"><<a href="mailto:kevin223@gmail.com" target="_blank">kevin223@gmail.com</a>></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. that's why "characters" do not have a unique identification and there isn'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"><<a href="mailto:kevin223@gmail.com" target="_blank">kevin223@gmail.com</a>></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. that's why "characters" do not have a unique identification and there isn'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"><<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>></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 "character" 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's no problem to write rules firing when a "character" lives longer or shorter than any time. Also, "characters" may have to have a unique identification beyond their player-owner.<br>
<br>If you are constantly shifting your specs, we won'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"><<a href="mailto:kevin223@gmail.com" target="_blank">kevin223@gmail.com</a>></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'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 'kill' 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'm looking for here is to find out when a player'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"><<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>></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"><<a href="mailto:kevin223@gmail.com" target="_blank">kevin223@gmail.com</a>></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 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. <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's what I meant with "more precisesly"). 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> </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"><<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>></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> not ( EventB ( index != $index,... )<br>
is what you need.<br>
-W<br><br><div class="gmail_quote">2010/10/28 ��٩٩ <span dir="ltr"><<a href="mailto:kevin223@gmail.com" target="_blank">kevin223@gmail.com</a>></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'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"><<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>></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 Points:<br>
<br>
rule "B-0-1-not OK"<br>
when<br>
$b : EventB( $index: index )<br>
not ( PatternConsumer( id == "B01", events contains $b ) )<br>
not ( EventB( index == (1 - $index), this after[0s,2m] $b ) )<br>
then<br>
System.out.println( "B:" + $index + ", but no B:" + (1-$index) );<br>
end<br>
<br>
rule "B-0-1"<br>
when<br>
$b1 : EventB( $index: index )<br>
$b2 : EventB( index == (1 - $index), this after[0s,2m] $b1 )<br>
then<br>
insert( new PatternConsumer( "B01", $b1, $b2 ) );<br>
System.out.println( "B:" + $index + "+B:" + (1-$index) );<br>
end<br>
<br>
-W<br>
<br>
2010/10/27 ��٩٩ <<a href="mailto:kevin223@gmail.com" target="_blank">kevin223@gmail.com</a>>:<br>
<div><div></div><div>> Hello,<br>
> With the help from the community I managed to get my first rule working, and<br>
> I'm trying to write my second rule on my own but it just doesn't seem to<br>
> work correctly.<br>
> Here is the scenario, what I want is to identify a pattern that there's no<br>
> EventB coming in within 2 minutes with a particular index value.<br>
> For example, EventB would have a property named index and assume the value<br>
> of index would be either 0 or 1.<br>
> Before firing the rules, I would manually insert facts of possibleIndex with<br>
> value 0 and 1 into the workingMemory.<br>
> Within 2 minutes, if there only comes one EventB with index valued 0 then<br>
> the system should report no EventB coming in with index value 1 in last 2<br>
> minutes.<br>
> Vice versa, in the case of only coming one EventB with index valued 1 then<br>
> the system should report no EventB coming in with index value 0 in last 2<br>
> minutes.<br>
> If within 2 minutes, there comes 2 EventB with both value 0 and 1 then<br>
> nothing should report.<br>
> Here is what I wrote, but it doesn't seem to work correctly.<br>
> I used a timer to fire this rule every 10 seconds because I don't think the<br>
> rule would run automatically if I don't add that. (not too sure though)<br>
> rule "no B in 2 minutes"<br>
> timer (0 10s)<br>
> when<br>
> possibleIndex( $index : index ) from entry-point "Event stream"<br>
> $p : PatternConsumer ( name == 'no B' && index == $index )<br>
> not ( EventB( index == $index && this after[0ms,2m] $p) over window:time(2m)<br>
> from entry-point "Event stream" )<br>
> then<br>
> PatternConsumer pc = new PatternConsumer( "no B", $index );<br>
> insert(pc);<br>
> System.out.println("no B in 2 minutes " + $index);<br>
> end<br>
> Best Regards,<br>
> Kevin Zhao<br>
</div></div>> _______________________________________________<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>
><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" 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">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>