9

In the application that I'm working on right now, I need to periodically check eligibility of tens of thousands of objects for some kind of a service. The decision diagram itself is in the following form, just way larger: Decision diagram

In each of the end nodes (circles), I need to run an action (change an object's field, log information etc). I tried using Drool Expert framework, but in that case I'd need to write a long rule for every path in the diagram leading to an end node. Drools Flow doesn't seem to be built for such a use case either - I take an object and then, depending on the decisions along the way, I end up in one of the end nodes; and then again for another object. Or is it? Could you give me some examples/links to such solutions?

UPDATE:

Drools Flow calls might look like this:

// load up the knowledge base
KnowledgeBase kbase = readKnowledgeBase();
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
Map<String, Object> params = new HashMap<String, Object>();

for(int i = 0; i < 10000; i++) {

    Application app = somehowGetAppById(i);

    // insert app into working memory
    FactHandle appHandle = ksession.insert(app);

    // app variable for action nodes
    params.put("app", app);

    // start a new process instance
    ProcessInstance instance = ksession.startProcess("com.sample.ruleflow", params);
    while(true) {
        if(instance.getState() == instance.STATE_COMPLETED) {
            break;
        }
    }

  // remove object from working memory
    ksession.retract(appHandle);
}

That is: I'd take an Application object, start a new process for it, when the process is finished (the final, action node would modify the application somehow), I'd remove the object from working memory and repeat the process for a new App object. What do you think about this solution?

SOLUTION:
I've ended up using Drools Flow and it has been working quite fine. My decision process isn't as straightforward as Drools Expert asks for and depending on where in the decision tree the process is it needs to load lists of objects from the database, transform them, make decisions, log everything etc. I use a Process object that is passed to the process as a parameter and stores all my global variables (for the process) and some convenience methods that are repeated at different points in the tree (as writing Java code in the Script Task nodes isn't very convenient itself). I also ended up using Java to make decisions (and not mvel or rules) - it's faster and I'd say easier to control. All objects that I work with are passed as parameters and used as normal Java variables in the code.

4

3 回答 3

12

流口水专家绝对是要走的路。

如果您想避免为更高的节点重复自己,那么诀窍是使用insertLogical(或者仅insert当您处于无状态会话中时)并了解规则可以触发规则(这不是您父亲的 SQL 查询)。例如:

// we just insert Customer objects in the WM

rule "evaluateRetired"
when
    $c : Customer(age > 65)
then
    insertLogical(new Retiree($c));
end

rule "evaluteRetireeIsFemale"
when
    $r : Retiree(customer.gender == Gender.FEMALE, $c : customer)
then
    ...
end

如果决策图经常更改(并且您希望非程序员编辑它),请查看有关决策表(和DSL)的文档。在这种情况下,您可能会为每个规则重复整个路径,但在大多数情况下这实际上是可以的。

于 2011-02-03T15:33:53.503 回答
0

您可以尝试 iLog 框架兼规则引擎。

于 2011-02-03T15:12:34.833 回答
0

我有一个类似的问题,并使用 Neo4J 节点数据库作为一个简单且非常灵活的规则引擎。您可以将它与 REST 服务接口一起使用,因此它独立于主应用程序。您还可以有一个单独的应用程序来配置规则(甚至由最终用户)。

于 2014-05-26T12:35:20.517 回答