累积功能不累积事实

时间:2017-11-29 21:34:59

标签: clips expert-system jess

我正致力于减少电路并且在串行连接方面遇到困难。我用两个节点建模了分支,为了检测串行连接,我写了以下规则:

(defrule serial
    ?b1 <- (Branch (node2 ?n1) (resistance ?v1))
    ?b2 <- (Branch (node1 ?n1) (resistance ?v2) (node2 ?n3))
    ?c <- (accumulate (bind ?count 0)
          (bind ?count (+ ?count 1))
          ?count
          (Branch (node1 ?n1))
          ) 
    (test (eq ?c 1))
     ?c1 <- (accumulate (bind ?count1 0)
          (bind ?count1 (+ ?count1 1))
          ?count1
          (Branch (node2 ?n1))
          ) 
    (test (eq ?c1 1))
     =>
    (modify ?b1 (node2 ?n3) (resistance (+ ?v1 ?v2)))
    (retract ?b2)
    )

我想计算有多少个分支具有相同的起始节点,如果有多个分支,则这不是串行连接。不幸的是,对于后续分支,此计数返回1:

f-1   (MAIN::Branch (name AB) (node1 A) (node2 B) (resistance 2))
f-2   (MAIN::Branch (name BC) (node1 B) (node2 C) (resistance 2))
f-3   (MAIN::Branch (name BC) (node1 B) (node2 T) (resistance 5.0))

将f-1和f-2视为串行连接。这个问题有解决办法吗?

1 个答案:

答案 0 :(得分:1)

规则不会触发集合AB,BC和BT,我想它不应该,因为B连接到C和T.我认为可以被淘汰的节点不能有多个前身不超过一个继任者。因此我建议这条规则:

(defrule myserial
  ?b1 <- (Branch (node1 ?n1) (node2 ?n2) (resistance ?v1))
  ?b2 <- (Branch (node1 ?n2) (node2 ?n3) (resistance ?v2))
  (not (Branch (node1 ~?n1) (node2 ?n2)))
  (not (Branch (node1 ?n2) (node2 ~?n3)))
=>
  (modify ?b1 (node2 ?n3) (resistance (+ ?v1 ?v2)))
  (retract ?b2)
)