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