[rules-users] Help write rule drools
My structure is composed of 2 classes (Node, Link) class Node { List Link out; List Link in; } class Link { Source node; Target node; } they are inserted as facts in working memory. I have to write a rule that will unite for each node joins the links that have the same destination, and if there is then the inverse must also join the latter. eg. A - link1 - B A - link2 - B A - link3 - C C - link4 - D B - link5 - A result A - link1 + link2 +link5 - B A - link3 - C C - link4 - D Can anyone help me? -- View this message in context: http://drools.46999.n3.nabble.com/Help-write-rule-drools-tp4029841.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Help write rule drools
How do you want the result? Printed lines on standard output? One for each pair of connected nodes, as you have shown it below result? Or collected in another fact? -W On 4 June 2014 10:09, nill nill...@hotmail.com wrote: My structure is composed of 2 classes (Node, Link) class Node { List Link out; List Link in; } class Link { Source node; Target node; } they are inserted as facts in working memory. I have to write a rule that will unite for each node joins the links that have the same destination, and if there is then the inverse must also join the latter. eg. A - link1 - B A - link2 - B A - link3 - C C - link4 - D B - link5 - A result A - link1 + link2 +link5 - B A - link3 - C C - link4 - D Can anyone help me? -- View this message in context: http://drools.46999.n3.nabble.com/Help-write-rule-drools-tp4029841.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Help write rule drools
One for each pair of connected nodes. -- View this message in context: http://drools.46999.n3.nabble.com/Help-write-rule-drools-tp4029841p4029848.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Help write rule drools
On 04/06/2014, nill nill...@hotmail.com wrote: One for each pair of connected nodes. One what? Where? With what content? -W -- View this message in context: http://drools.46999.n3.nabble.com/Help-write-rule-drools-tp4029841p4029848.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Help write rule drools
I try to explain. I have a graph where each node can have only one connection to the other. If I check the presence of n links between two nodes then delete n-1 connections. -- View this message in context: http://drools.46999.n3.nabble.com/Help-write-rule-drools-tp4029841p4029869.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Help write rule drools
To remove all redundant Link objects and assuming that class Link is declared as class Link { Node source; Node target; } (and not as given in the original post), the rule: rule kill redundant links when $l1: Link( $s: source, $t: target ) $l2: Link( this != $l1, source == $s target == $t || source == $t target == $s ) $n1: Node( out contains $l2 ) $n2: Node( in contains $l2 ) then retract( $l2 ); modify( $n1 ){ getOut().remove( $l2 ) } modify( $n2 ){ getIn().remove( $l2 ) } end removes all redundant Link facts and updates the out and in fields of the Nodes at either end of these links. -W On 04/06/2014, nill nill...@hotmail.com wrote: I try to explain. I have a graph where each node can have only one connection to the other. If I check the presence of n links between two nodes then delete n-1 connections. -- View this message in context: http://drools.46999.n3.nabble.com/Help-write-rule-drools-tp4029841p4029869.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Help write rule drools
Thank you very much! -- View this message in context: http://drools.46999.n3.nabble.com/Help-write-rule-drools-tp4029841p4029873.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users