On 19.02.2011 16:01, Simon Chen wrote: > The example you gave seems to be the one-hop case. For the two-hop > case, we need something like this > > when > edge(a, b), reach(b, c), not exists reach(a, c) > then > insertLogical( reach(a,c) ) > > So, where do you put your logical around? It should include both > edge(a,b) and reach(b,c), right? > > Another thought, can we have something like > testExistsAndInsertLogical() to replace insertLogical()? But this may > be buggy, as the conditions are all met, so the rule actually fired... > Hi,
from my experience, insertLogical does exactly what testExistsAndInsertLogical would suggest. If the same object is already in the working memory, it keeps this object and does not insert another instance. This behaviour is not stated explicitly in the documentation, but I did a learning test a few weeks ago and IIRC it clearly showed this behaviour (at least for 5.0.1). -- I consider this behaviour a feature and would like it to be kept this way. With this, all which is necessary to implement transitive closure is to remove the contradicting part of the precondition to avoid oscillation. If it turns out that insertLogical does not perform a "does fact already exist" check and thus might potentially insert duplicates, put exists( ) around the two preconditions and also use "exists( reach(x,y) )" to check whether y is reachable from x. Kind regards Ansgar _______________________________________________ rules-users mailing list [email protected] https://lists.jboss.org/mailman/listinfo/rules-users
