【问题标题】:Equivalent Drools syntax for setting a variable from an object within a collection in ILOG用于从 ILOG 中的集合中的对象设置变量的等效 Drools 语法
【发布时间】:2016-01-05 08:39:36
【问题描述】:

在我们的 ILOG 规则 irl 文件中,我们多次从集合中设置一个变量并从集合中设置另一个不等于第一个对象的变量

student1: com.company.bom.Student() in all_students;
student2: com.company.bom.Student(!(?this.equals(student2))) in all_students;

在 ILOG 中,这些行是否只返回集合中的第一个和第二个对象?

以下是在 Drol 规则文件中的 Drools 中执行相同操作的最佳方法吗?

student1: com.company.bom.Student() from all_students.get(0);
student2: com.company.bom.Student() from all_students.get(1);

【问题讨论】:

    标签: drools ilog jrules


    【解决方案1】:

    你应该能够检查你的 ILOG 做了什么,所以我只是回答 Drools 部分。

    在 Drools 中,可以使用 from <expression> 从某个可到达的集合中获取对象。因此,你确实可以写

    University( $roster: roster )
    $student1: Student() from $roster.get(0)
    $student2: Student() from $roster.get(1)
    

    此规则对名册集合中的前两名学生触发一次,但如果少于两名学生,它必然会引发异常。

    University( $roster: roster )
    $student1: Student() from $roster
    $student2: Student( this != $student1 ) from $roster
    

    此规则会针对每对有序的不同学生触发,其中一对会触发两次规则触发。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-21
      • 1970-01-01
      • 1970-01-01
      • 2015-01-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多