【问题标题】:Accumulate function does not accumulate fact累积函数不累积事实
【发布时间】:2018-05-13 17:14:44
【问题描述】:

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

(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 视为串行连接。这个问题有解决办法吗?

【问题讨论】:

    标签: clips expert-system jess


    【解决方案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)
    )
    

    【讨论】:

    • 我写的代码的问题是规则触发,它不应该触发。我的问题是为什么当有两个分支时节点 B 是 1 个分支的 node1。我会尝试你给的方法。
    • 我已经设法使用给定的代码解决了一个问题,并进行了额外的名称检查,因为此规则不会检测具有相同 ?n1 和 ?n2 的并行分支。谢谢!
    猜你喜欢
    • 2012-07-18
    • 2012-05-31
    • 1970-01-01
    • 2016-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-15
    • 1970-01-01
    相关资源
    最近更新 更多