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