<br> What is probably hurting you now is the number of updates you have in your rules.... :) you can tweak that and you will probably end up being faster than the accumulate.<br><br> []s<br> Edson<br><br><div><span class="gmail_quote">
2008/1/21, Geoffrey De Smet <<a href="mailto:ge0ffrey.spam@gmail.com">ge0ffrey.spam@gmail.com</a>>:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Thanks Edson, it was indeed an infinite loop.<br><br>I 've made it an normal insert and fixed the room != room (instead of<br>room != $room) bug.<br><br>Still, it turns out worse:<br><br>Solved in 500 steps and 30297 time millis spend.
<br>While before I had:<br>Solved in 500 steps and 13078 time millis spend.<br><br>Looks the exists and/or contains might be hurting me a lot?<br><br><br><br>// More seating required during a period in a room than available in
<br>that room.<br>rule "existExamSeating"<br> when<br> $period : Period();<br> $room : Room();<br> exists Exam(period == $period, room == $room);<br> not ExamSeating(period == $period, room == $room);
<br> then<br> insert(new ExamSeating($period, $room));<br>end<br>rule "addExamToExamSeating"<br> when<br> $exam : Exam($period : period, $room : room);<br> $examSeating : ExamSeating(period == $period, room == $room,
<br>examSet not contains $exam);<br> then<br> $examSeating.getExamSet().add($exam);<br> update($examSeating);<br>end<br>rule "removeExamFromExamSeatingPeriod"<br> when<br> $exam : Exam($period : period, $room : room);
<br> $examSeating : ExamSeating(examSet contains $exam, period !=<br>$period);<br> then<br> $examSeating.getExamSet().remove($exam);<br> update($examSeating);<br>end<br>rule "removeExamFromExamSeatingRoom"
<br> when<br> $exam : Exam($period : period, $room : room);<br> $examSeating : ExamSeating(examSet contains $exam, room != $room);<br> then<br> $examSeating.getExamSet().remove($exam);<br> update($examSeating);
<br>end<br>rule "roomCapacityTooSmall"<br> when<br> $examSeating : ExamSeating(studentSize > roomCapacity, $period<br>: period, $room : room);<br> then<br> insertLogical(new<br>IntConstraintOccurrence("roomCapacityTooSmall",
<br>ConstraintType.NEGATIVE_HARD,<br> $period, $room));<br>end<br><br><br>With kind regards,<br>Geoffrey De Smet<br><br><br>Edson Tirelli wrote:<br>><br>> Ge0ffrey,<br>><br>> Isn't the bellow rule causing an infinite loop for you?
<br>><br>> rule "existExamSeating"<br>> when<br>> $period : Period();<br>> $room : Room();<br>> exists Exam(period == $period, room == $room);<br>> not ExamSeating(period == $period, room == $room);
<br>> then<br>> insertLogical(new ExamSeating($period, $room));<br>> end<br>><br>> You see, the insertLogical in the consequence will cause the LHS<br>> condition:<br>><br>> not ExamSeating(period == $period, room == $room);
<br>><br>> To fail. When it fails, it automatically retreats the logical insert,<br>> what causes the condition to be true again and fire the rule again. And<br>> you have an infinite loop... don't you?
<br>><br>> []s<br>> Edson<br>><br>> 2008/1/20, Geoffrey De Smet <<a href="mailto:ge0ffrey.spam@gmail.com">ge0ffrey.spam@gmail.com</a><br>> <mailto:<a href="mailto:ge0ffrey.spam@gmail.com">ge0ffrey.spam@gmail.com
</a>>>:<br>><br>> Hi,<br>><br>> In my statefull working memory on which I fireAllRules over a 1000 timse<br>> per second, I have rule which hurts performance because it gets<br>> backwards chained (which is bad in my use case):
<br>><br>><br>> // More seating required during a period in a room than available<br>> // in that room.<br>> rule "roomCapacityTooSmall" // TODO improve performance, as it takes 50%<br>
> of the performance<br>> when<br>> $period : Period();<br>> $room : Room($capacity : capacity);<br>> $totalStudentListSize : Number(intValue > $capacity)
<br>> from accumulate(<br>> Exam(period == $period, room == $room,<br>> $studentListSize : topicStudentListSize),<br>> sum($studentListSize)
<br>> );<br>> then<br>> insertLogical(new IntConstraintOccurrence(<br>> "roomCapacityTooSmall", ConstraintType.NEGATIVE_HARD,<br>> $period, $room));
<br>> end<br>><br>><br>> In an effort to turn this into a statefull insertLogical,<br>> I 've tried this:<br>><br>> // More seating required during a period in a room than available
<br>> // in that room.<br>> rule "existExamSeating"<br>> when<br>> $period : Period();<br>> $room : Room();<br>> exists Exam(period == $period, room == $room);
<br>> not ExamSeating(period == $period, room == $room);<br>> then<br>> insertLogical(new ExamSeating($period, $room));<br>> end<br>> rule "addExamToExamSeating"
<br>> when<br>> $exam : Exam($period : period, $room : room);<br>> $examSeating : ExamSeating(period == $period, room == $room,<br>> examSet not contains $exam);
<br>> then<br>> $examSeating.getExamSet().add($exam);<br>> update($examSeating);<br>> end<br>> rule "removeExamFromExamSeatingPeriod"<br>> when
<br>> $exam : Exam($period : period, $room : room);<br>> $examSeating : ExamSeating(examSet contains $exam,<br>> period != $period);<br>> then<br>> $examSeating.getExamSet().remove($exam);
<br>> update($examSeating);<br>> end<br>> rule "removeExamFromExamSeatingRoom"<br>> when<br>> $exam : Exam($period : period, $room : room);<br>> $examSeating : ExamSeating(examSet contains $exam,
<br>> room != room);<br>> then<br>> $examSeating.getExamSet().remove($exam);<br>> update($examSeating);<br>> end<br>> rule "roomCapacityTooSmall"
<br>> when<br>> $examSeating : ExamSeating(studentSize > roomCapacity, $period<br>> : period, $room : room);<br>> then<br>> insertLogical(new IntConstraintOccurrence(
<br>> "roomCapacityTooSmall", ConstraintType.NEGATIVE_HARD,<br>> $period, $room));<br>> end<br>><br>><br>><br>> However, this turns out to be so slow it's at least 100 times slower
<br>> (and probably a lot more as I had no time to let the benchmark finish).<br>><br>> What could explain this?<br>> Is "exists" or "contains" backwards chained?<br>> Am I missing something?
<br>><br>> Thanks for any and all help.<br>><br>> --<br>> With kind regards,<br>> Geoffrey De Smet<br>><br>> _______________________________________________<br>> rules-users mailing list
<br>> <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a> <mailto:<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">
https://lists.jboss.org/mailman/listinfo/rules-users</a><br>><br>><br>><br>><br>> --<br>> Edson Tirelli<br>> JBoss Drools Core Development<br>> Office: +55 11 3529-6000<br>> Mobile: +55 11 9287-5646
<br>> JBoss, a division of Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a> <<a href="http://www.jboss.com">http://www.jboss.com</a>><br>><br>><br>> ------------------------------------------------------------------------
<br>><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">
https://lists.jboss.org/mailman/listinfo/rules-users</a><br><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">https://lists.jboss.org/mailman/listinfo/rules-users</a><br></blockquote></div><br><br clear="all"><br>-- <br> Edson Tirelli<br> JBoss Drools Core Development
<br> Office: +55 11 3529-6000<br> Mobile: +55 11 9287-5646<br> JBoss, a division of Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a>