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
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

Reply via email to