比较 2 个列表的内容与顺序不同的值

问题描述 投票:0回答:1

我有这些模板,

(deftemplate classroom
    (slot classroom_number (type INTEGER))
    (multislot students (type SYMBOL))
)

(deftemplate students_to_classroom_lookup
    (multislot students (type SYMBOL))
)

这些事实代表了教室和属于该教室的学生。

(deffacts classrooms
    (classroom (classroom_number 1) (students Paul Lucy Peter Sebastian))
    (classroom (classroom_number 2) (students Peter Paul Lucy Sebastian Arthur))
    (classroom (classroom_number 3) (students Paul Lucy Peter))
    (classroom (classroom_number 4) (students Lucy Peter Paul))
)

然后我有这个事实,它遵循“students_to_classroom_lookup”模板,并在程序运行时通过键盘输入。

(students_to_classroom_lookup (students Paul Peter Sebastian Lucy))

我想找到恰好有这些且只有这些学生的教室号。

请注意,

的内容

(students_to_classroom_lookup (students Paul Peter Sebastian Lucy))

基于用户输入,在程序的另一次运行中,“学生”的内容可能是 Paul Sebastian Lucy Peter 或只是 Lucy Peter Paul。

我已经尝试过这个规则:

(defrule match_classroom_and_students
    (classroom (classroom_number ?number) (students $?students))
    (students_to_classroom_lookup (students $?students_lookup&:(subsetp $?students $?students_lookup)))
=>
    (printout t "Classroom number " ?number crlf)
)

输出:

Classroom number 1
Classroom number 3
Classroom number 4

预期输出:

Classroom number 1

我感谢所有帮助。

clips expert-system
1个回答
0
投票

对于集合 A 和 B 的精确匹配,A 必须是 B 的子集,B 必须是 A 的子集:

(defrule match_classroom_and_students
    (classroom (classroom_number ?number) (students $?students))
    (students_to_classroom_lookup (students $?students_lookup&:(subsetp $?students $?students_lookup)
                                                             &:(subsetp $?students_lookup $?students)))
=>
    (printout t "Classroom number " ?number crlf)
)
© www.soinside.com 2019 - 2024. All rights reserved.