最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

clips - How to express that a node belonging to a particular multislot does not belong to another different multislot - Stack Ov

programmeradmin2浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 0
CLIPS> 
(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> 

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论