Suppose the following list of facts in a deffacts construct:
(deffacts ss-and-ts-edges
(ss-pair (ss 1 2)) (ss-pair (ss 2 3))(ss-pair (ss 3 4))(ss-pair (ss 4 5))
(ss-pair (ss 8 9)) (ss-pair (ss 9 10))
(ss-pair (ss 11 12)) (ss-pair (ss 12 13))(ss-pair (ss 13 14))(ss-pair (ss 14 15))
(ts-pair (ts 4 9))(ts-pair (ts 6 11))(ts-pair (ts 8 13)))
We want to know if at most an element of ts-pair is NOT IN ss-pair through the following rule:
(defrule connexion-directe
(ts-pair (ts $? ?u $?))
(ts-pair (ts $? ?v $?))
(ss-pair (ss $?ss))
(test (and
(or
(not (member$ ?u ?ss))
(not (member$ ?v ?ss))
)
(neq ?u ?v)))
=>
(or
(printout t "u: " ?u ": NOT IN ss-pair" crlf))
(printout t "v: " ?v ": NOT IN ss-pair" crlf)))
But when this rule is implemented, obtained result is:
u: 4: NOT IN ss-pair
u: 6: NOT IN ss-pair
u: 8: NOT IN ss-pair
u: 9: NOT IN ss-pair
u: 11: NOT IN ss-pair
u: 13: NOT IN ss-pair
while the expected result should be:
u: 6: NOT IN ss-pair
because only node 6 in (ts-pair (ts 6 11)) not belong to any ss-pair in ss-and-ts-edges deffacts list.
The question is: how to achieve the expected result.
Suppose the following list of facts in a deffacts construct:
(deffacts ss-and-ts-edges
(ss-pair (ss 1 2)) (ss-pair (ss 2 3))(ss-pair (ss 3 4))(ss-pair (ss 4 5))
(ss-pair (ss 8 9)) (ss-pair (ss 9 10))
(ss-pair (ss 11 12)) (ss-pair (ss 12 13))(ss-pair (ss 13 14))(ss-pair (ss 14 15))
(ts-pair (ts 4 9))(ts-pair (ts 6 11))(ts-pair (ts 8 13)))
We want to know if at most an element of ts-pair is NOT IN ss-pair through the following rule:
(defrule connexion-directe
(ts-pair (ts $? ?u $?))
(ts-pair (ts $? ?v $?))
(ss-pair (ss $?ss))
(test (and
(or
(not (member$ ?u ?ss))
(not (member$ ?v ?ss))
)
(neq ?u ?v)))
=>
(or
(printout t "u: " ?u ": NOT IN ss-pair" crlf))
(printout t "v: " ?v ": NOT IN ss-pair" crlf)))
But when this rule is implemented, obtained result is:
u: 4: NOT IN ss-pair
u: 6: NOT IN ss-pair
u: 8: NOT IN ss-pair
u: 9: NOT IN ss-pair
u: 11: NOT IN ss-pair
u: 13: NOT IN ss-pair
while the expected result should be:
u: 6: NOT IN ss-pair
because only node 6 in (ts-pair (ts 6 11)) not belong to any ss-pair in ss-and-ts-edges deffacts list.
The question is: how to achieve the expected result.
Share Improve this question asked Mar 30 at 14:14 Honoré De MarseilleHonoré De Marseille 116 bronze badges1 Answer
Reset to default 0CLIPS>
(deftemplate ss-pair
(multislot ss))
CLIPS>
(deftemplate ts-pair
(multislot ts))
CLIPS>
(deffacts ss-and-ts-edges
(ss-pair (ss 1 2))
(ss-pair (ss 2 3))
(ss-pair (ss 3 4))
(ss-pair (ss 4 5))
(ss-pair (ss 8 9))
(ss-pair (ss 9 10))
(ss-pair (ss 11 12))
(ss-pair (ss 12 13))
(ss-pair (ss 13 14))
(ss-pair (ss 14 15))
(ts-pair (ts 4 9))
(ts-pair (ts 6 11))
(ts-pair (ts 8 13)))
CLIPS>
(defrule connexion-directe
(ts-pair (ts $? ?u $?))
(not (ss-pair (ss $? ?u $?)))
=>
(printout t "u: " ?u ": NOT IN ss-pair" crlf))
CLIPS> (reset)
CLIPS> (run)
u: 6: NOT IN ss-pair
CLIPS>