Hi,
is it possible (or wise ;-) to use drools in a scheduling application?
I want to place Tasks into Timeslots. Placement is dependant on certain
constraints (hard or maybe soft) and ressources. Each slot can contain
one task.
E.g. I have some tasks {t1,t2,t3} to place on slots {s1,s2,s3,s4}.
Constraints are defining which slots a task may be placed into
(c1{t1;s1..s4}, c2{t2;s1,s4}) or define a task sequence
(task1.slotNumber < task2.slotNumber).
My naive "newbie approach" is to define two rules like this:
<rule name="Assign Next" no-loop="yes">
<parameter identifier="task">
<class>Task</class>
</parameter>
<parameter identifier="slot">
<class>Slot</class>
</parameter>
<java:condition>
slot.getTask() == null
</java:condition>
<java:condition>
task.getSlot() == null
</java:condition>
<java:consequence>
System.out.println("Placing "+task.getName()+" on
"+slot.getName());
task.setSlot(slot);
slot.setTask(task);
drools.modifyObject(slot);
drools.modifyObject(task);
</java:consequence>
</rule>
<rule name="Reset">
<parameter identifier="task">
<class>Task</class>
</parameter>
<parameter identifier="constraint">
<class>Constraint</class>
</parameter>
<java:condition>
task.getSlot() != null
</java:condition>
<java:condition>
!constraint.isOK(task)
</java:condition>
<java:consequence>
System.out.println("Resetting ... ");
Slot slot = task.getSlot();
task.setSlot(null);
drools.modifyObject(task);
slot.setTask(null);
drools.modifyObject(slot);
</java:consequence>
</rule>
It assigns tuples of "Slot" and "Task" first and checks if they are ok
(constraint.isOK) second. This leads to an infinite loop flipping
between the two rules.
Do I have to use a more "Miss Manners"ish approach of implementing some
sort of backtracking mechanism by myself? I think I have to use some
kind of depth search to avoid wasting huge quantities of workingMemory ..?
Any help would be appreaciated! ;-)
TIA,
Robert