<p>Hi Edson, Greg,<br>I don't think the rule is written wrong. This is how the win-nowin program is written in logic programming: X wins if there is a move from X to some Y and Y doesn't win:</p>
<div>win(X):- move(X,Y), not(win(Y)).</div>
<p>rule "direct" % Drools<br> when<br> m : Move(x : first, y : second)<br> not Win(first == y)<br> then<br> insert(new Win(m.getFirst()));<br>end</p>
<p>I think that it's interesting that, in Jess (another production rule system), the stratified model is always computed right, no matter what was the order of the facts in the database. If you want to take a look, please see the equivalent program in Jess for win-nowin that I attached. Just run it with: <br>
jess test.clp</p>
<p>win_upper1_jess.jess</p>
<p>(move (cur 1) (next 2))<br>(move (cur 1) (next 3))<br>(move (cur 2) (next 4))<br>(move (cur 2) (next 5))<br>...</p>
<p>win_upper2_jess.jess</p>
<p>(move (cur 2) (next 4))<br>(move (cur 2) (next 5))<br>(move (cur 1) (next 2))<br>(move (cur 1) (next 3))<br>...</p>
<p>test.clp:</p>
<p>(deftemplate move (slot cur) (slot next))<br>(deftemplate win (slot val))</p>
<p>(defrule find_win<br> (move (cur ?cur) (next ?next))<br> (not (win (val ?next)))<br> =><br> (assert (win (val ?cur)))<br>)</p>
<p>(defquery query-win<br> (win (val ?val))<br>)<br>(open "win_result.txt" output a)<br>(printout output ./win_upper1_jess.jess crlf)<br>(reset)<br>(load-facts "./win_upper1_jess.jess")<br>(bind ?tmx (call java.lang.management.ManagementFactory getThreadMXBean))<br>
(deffunction cputime () (return (* (?tmx getCurrentThreadCpuTime) 1E-9)))<br>(bind ?starttime_wall (time))<br>(bind ?starttime_cpu (cputime))<br>(run)<br>(bind ?query_result (run-query* query-win))<br>(bind ?count 0)<br>(while (?query_result next)<br>
(++ ?count)<br>)<br>(printout output "solutions: " ?count crlf)<br>(bind ?endtime_cpu (cputime))<br>(bind ?endtime_wall (time))<br>(bind ?walltime (- ?endtime_wall ?starttime_wall))<br>(bind ?cputime (- ?endtime_cpu ?starttime_cpu))<br>
(printout output "computing cputime: " ?cputime crlf)<br>(printout output "computing walltime: " ?walltime crlf)<br>(close output) <br><br>Regards,<br>Paul Fodor.</p>
<div class="gmail_quote">2009/4/16 Edson Tirelli <span dir="ltr"><<a href="mailto:tirelli@post.com">tirelli@post.com</a>></span><br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"><br> Ha, thanks a lot Greg. I need new glasses... he is actually comparing with the parameter "second", but when creating the win fact, using the parameter "first".
<div class="im"><br><br>not Win(first == m.second)<br></div>
<div class="im"> insert(new Win(m.first));<br><br></div> Yes, in this case the engine is working exactly as it should.<br><br> Anyway, I added the (fixed) test case to the codebase, just in case. :)<br><br> Thanks,<br>
Edson<br><br>
<div class="gmail_quote">2009/4/16 Greg Barton <span dir="ltr"><<a href="mailto:greg_barton@yahoo.com" target="_blank">greg_barton@yahoo.com</a>></span>
<div>
<div></div>
<div class="h5"><br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">You don't have to worry. The engine is acting as it should.<br><br>The rule Paul had was this, a bit simplified for clarity:<br>
<br>rule "direct"<br>when<br> m : Move()<br> not Win(first == m.second)<br>then<br> insert(new Win(m.first));<br>end<br><br>If the insertion order is [Move(1,2), Move(2,3)] then the rule matches first on Move(2,3) and Win(2) is inserted. No other rule fires because now Move(1,2) and Win(2) match up, removing the instantiation with Move(1,2) from the agenda.<br>
<br>If the insertion order is [Move(2,3), Move(1,2)] then the order is this:<br><br>matched Move(1,2) insert Win(1)<br>matched Move(2,3) insert Win(2)<br><br>The insertion of Win(1) in the first firing does NOT prevent the instantiation with Move(2,3) from then firing.<br>
<br>So it's all good. :) Sample code and output attached.<br><br>--- On Thu, 4/16/09, Greg Barton <<a href="mailto:greg_barton@yahoo.com" target="_blank">greg_barton@yahoo.com</a>> wrote:<br><br>> From: Greg Barton <<a href="mailto:greg_barton@yahoo.com" target="_blank">greg_barton@yahoo.com</a>><br>
> Subject: Re: [rules-users] Negation semantics in Drools<br>
<div>> To: "Rules Users List" <<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a>><br></div>> Date: Thursday, April 16, 2009, 8:50 PM<br>
<div>
<div></div>
<div>> It is on the latest snapshot release,<br>> 5.0.0.20090417.005612-483<br>><br>> --- On Thu, 4/16/09, Edson Tirelli <<a href="mailto:tirelli@post.com" target="_blank">tirelli@post.com</a>><br>> wrote:<br>
><br>> > We need to investigate if that is still happening<br>> in<br>> > latest trunk.<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>
<br><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 clear="all">
<div>
<div></div>
<div class="h5"><br>-- <br> Edson Tirelli<br> JBoss Drools Core Development<br> JBoss, a division of Red Hat @ <a href="http://www.jboss.com/" target="_blank">www.jboss.com</a><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>