市面上的产品
一、Scene
1.1. func
1.1.1. 规则的数据模型
决策集
- 向导式规则
-
脚本式规则
image.png
决策表
image.png
交叉决策表
image.png
决策树
image.png
评分卡
image.png
复杂评分卡
规则流
image.png
1.1.2. 数据从哪来
调用方拼好传进来(或者以塞进上下文的形式)
1.2. non-func
service/sdk计算
二、Service
https://zhuanlan.zhihu.com/p/51296996
https://martinfowler.com/bliki/RulesEngine.html
image.png
image.png
image.png
image.png
2.1. 原理
就是给一堆规则,一堆fact数据,匹配出符合条件的规则,冲突决策,然后执行。
2.2. 描述规则的方法
a. 结构化的java object
b. dsl
有的系统是把结构化的java object转成dsl字符串,再通过表达式引擎编译dsl、执行。表达式引擎编译dsl时其实也是编译成java object、构造出树或栈,所以这种方案多了编译字符串这步,多了冗余转换。
如果想用GUI配置,除了dsl字符串,还是要有结构化的java object
c. GUI
2.3. 匹配规则模块的算法
a. 暴力循环
问题是有很多冗余,规则、数据都很多的时候性能差;
尤其是执行规则后有级联影响、需要迭代计算的时候,即chaining功能
An important property of rule engines is chaining - where the action part of one rule changes the state of the system in such a way that it alters the value of the condition part of other rules. Chaining sounds appealing, since it supports more complex behaviors, but can easily end up being very hard to reason about and debug.
——https://martinfowler.com/bliki/RulesEngine.html
看描述easy-rules就是这么做的,不支持chaining
b. Rete
https://developer.ibm.com/zh/technologies/artificial-intelligence/articles/os-drools/
You can build a simple rules engine yourself. All you need is to create a bunch of objects with conditions and actions, store them in a collection, and run through them to evaluate the conditions and execute the actions. But mostly when people refer to "rules engine" they mean a product built specifically to help you build and run a rules engine. Techniques to specify rules can vary from an API for people to describe rules as Java objects, a DSL to express rules, or a GUI that allows people enter rules. More efficient execution engines help to quickly evaluate conditions on hundreds of rules using specialized algorithms (such as the Rete algorithm).
——https://martinfowler.com/bliki/RulesEngine.html
网友评论