a rule to determine if at least 3 of 4 tests pass

26 views
Skip to first unread message

cariaso

unread,
Jan 27, 2008, 5:48:23 PM1/27/08
to CLIPSESG
Imagine a classroom. I want to determine if Alice, Bob, Charles and
Dave are all in the classroom

(defrule has-student-set-1
(student Alice)
(student Bob)
(student Charles)
(student Dave)
=> (print out t "has 4 of 4" crlf))

That was easy enough, but how can I ask if at least 3 of those
students are in the class?

In reality I'm trying to score if at least 20 of 30 students are
present.

CLIPS Support

unread,
Jan 27, 2008, 8:57:16 PM1/27/08
to CLIPSESG
Put all of the students into a list and then you can count the number
of students in the list:

(defrule create-list
(not (student-list $?))
(student ?name)
=>
(assert (student-list ?name)))

(defrule add-student
?f <- (student-list $?students)
(student ?name)
(test (not (member$ ?name ?students)))
=>
(retract ?f)
(assert (student-list ?name ?students)))

(defrule more-than-2-students
(declare (salience -10))
(student-list $?students)
(test (> (length$ ?students) 2))
=>
(printout t "3 or more students" crlf))
Reply all
Reply to author
Forward
0 new messages