1

在我们的 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);
4

1 回答 1

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

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

于 2015-10-08T04:52:23.657 回答