On Thu, Jul 24, 2008 at 3:28 PM, Ralph Ammon <ralph.ammon(a)lisytec.de> wrote:
I'd like to get some hints to improve the rules of my simple
planning
system.
My simple planning system is derived from the HelloWorld Drools Project. The
job of my planning system is to calculate startTime and endTime as function
of duration and predecessors for each task. Each task has the fields
long duration;
Set<Task> predesessors;
long startTime;
long endTime;
For each task the rule (endTime = startTime + duration) should hold. If a
task has no predecessors, then its startTime should be 0. If a task has
predecessors, then is should start at the latest endTime of all
predecessors.
Maybe something like this would work?
rule "Calc EndTime"
no-loop true
when
$t : Task(endTime != (startTime+duration))
then
$t.setEndTime( $t.getStartTime() + $t.getDuration() );
System.out.println( "Drools: Set " + $t.getName() + ".EndTime to
"
+ $t.getEndTime() );
update( $t );
end
Afaik, this will also enable Drools to only check this rule if one of
the attributes used in the LHS is changed. So if you change any other
field of your object at some point, this rule will not be evaluated
again.
Please note that I haven't checked the syntax but I think that it
should work like this.
Best regards
Marcus