[rules-users] transitive closure
Paul Fodor
paul.i.fodor at gmail.com
Thu Jul 3 15:56:03 EDT 2008
Dear Sir,
I am new to Drools and I want to ask how can I implement the classical
transitive closure in Drools. For instance we have a bunch of facts
edge/2 and the transitive closure:
reach(X,Y):- edge(X,Y).
reach(X,Y):- edge(X,Z),reach(Z,Y).
Should I create classes Edge and Reach with attributes source and target?
rule "reachDirect"
when
exists( Edge(X,Y) )
then
insertLogical( new Reach(X,Y) );
end
rule "reachIndirect"
when
exists( Edge(X,Z) )
exists( Reach(Z,Y) )
then
insertLogical( new Reach(X,Y) );
end
Regards,
Paul Fodor
More information about the rules-users
mailing list