流口水明显
多个具有相同显着性的规则会产生什么结果?它们的执行顺序只是它们列出的顺序,还是该行为未定义 - 也就是说,它们是否以任意顺序检查?我似乎找不到有关内部如何处理此问题的文档。
What is the outcome of several rules having the same salience? Is their order of execution just the order that they're listed in, or is that behaviour undefined - that is, are they checked in arbitrary order? I can't seem to find documentation of how this is handled internally.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
简而言之,您不应该依赖具有相同显着性的规则触发顺序 - 如果它们“冲突”(即两者都有资格触发)。顺便说一句,没有显着性的规则只是显着性为零。
当然,它是确定性的 - 只是算法可能会在版本之间发生变化(尽管不太可能)。
这是“冲突解决”的一般领域,并且已经有很多关于它的文章。我找不到关于 Drools 策略的当前文章 - 但我相信其中大部分是“新近度” - 即最近修改/插入的事实“获胜” - 或者更确切地说,引用最新事实的规则将获胜。如果毕竟它无法决定 - 这通常是它们规则的加载顺序(通常与它们在文件中的写入方式一致)。如果你必须有一个顺序 - 使用显着性,或使用规则流或类似的,最好不要再次猜测它会如何工作。
The short answer is that you shouldn't rely on the order of rules firing of the same salience - if they are "in conflict" (ie both are eligible to fire). Rules with no salience are just salience of zero, BTW.
Of course it is deterministic - its just that the algorithm is subject to change between versions (not very likely though).
This is under the general area of "conflict resolution" and much has been written about it. I can't find a current article on Drools strategy - but I believe most of it is "recency" - ie the most recently modified/inserted fact "wins" - or rather the rules that refer to the most recent fact will win. If after all that it can't decide - it is usually the order in which they rules are loaded (which usually co-incides with how they are written in the file). If you have to have an order - use salience, or use rule-flow or similar, best not to second guess how it will work.
Rete 算法使用条件的新近度和特异性。
The Rete algorithm used recency and specificity of conditions.
我对 Drools 5.1 的体验是它是后进先出。也就是说,您的 drl 中最后定义的规则将首先执行。
但是,是的,依赖这种行为并不是最好的主意:)
My experience with Drools 5.1 is that it's last in, first out. That is, the rule defined last in your drl will be executed first.
But yes, relying on such behavior wouldn't be the best idea :)