在 CLIPS 中访问多个(?)值

Accessing multiple (?) values in CLIPS

假设我有以下一组定义,它们显示了电路各个阶段的输入和输出。我不包括所有 类 和实例,因为我认为它与我的问题无关。我将附上一张照片,帮助您了解此问题的工作原理。

此处输入 1 作为两个输入进入加法器 A1。 Input3 和 input4 作为输入进入 Π2 乘法器。

definstances facts(      
([command_10_inp1] of  command_data

    (clock 10)
    (object [input_1])
    (value 6))

([command_10_inp2] of  command_data

    (clock 10)
    (object [input_2])
    (value 4))

([command_10_inp3] of  command_data

    (clock 10)
    (object [input_3])
    (value 25))

([command_10_inp4] of  command_data

    (clock 10)
    (object [input_4])
    (value 12))

([command_1_inp1] of  command_data

    (clock 1)
    (object [input_1])
    (value 21))

([command_1_inp2] of  command_data

    (clock 1)
    (object [input_2])
    (value 28))

([command_1_inp3] of  command_data

    (clock 1)
    (object [input_3])
    (value 10))

([command_1_inp4] of  command_data

    (clock 1)
    (object [input_4])
    (value 25))

([command_2_inp1] of  command_data

    (clock 2)
    (object [input_1])
    (value 7))

([command_2_inp2] of  command_data

    (clock 2)
    (object [input_2])
    (value 25))

([command_2_inp3] of  command_data

    (clock 2)
    (object [input_3])
    (value 13))

([command_2_inp4] of  command_data

    (clock 2)
    (object [input_4])
    (value 15))

([command_3_inp1] of  command_data

    (clock 3)
    (object [input_1])
    (value 11))

([command_3_inp2] of  command_data

    (clock 3)
    (object [input_2])
    (value 17))

([command_3_inp3] of  command_data

    (clock 3)
    (object [input_3])
    (value 24))

([command_3_inp4] of  command_data

    (clock 3)
    (object [input_4])
    (value 31))

([command_4_inp1] of  command_data

    (clock 4)
    (object [input_1])
    (value 18))

([command_4_inp2] of  command_data

    (clock 4)
    (object [input_2])
    (value 11))

([command_4_inp3] of  command_data

    (clock 4)
    (object [input_3])
    (value 28))

([command_4_inp4] of  command_data

    (clock 4)
    (object [input_4])
    (value 21))

([command_5_inp1] of  command_data

    (clock 5)
    (object [input_1])
    (value 25))

([command_5_inp2] of  command_data

    (clock 5)
    (object [input_2])
    (value 24))

([command_5_inp3] of  command_data

    (clock 5)
    (object [input_3])
    (value 30))

([command_5_inp4] of  command_data

    (clock 5)
    (object [input_4])
    (value 10))

([command_6_inp1] of  command_data

    (clock 6)
    (object [input_1])
    (value 12))

([command_6_inp2] of  command_data

    (clock 6)
    (object [input_2])
    (value 19))

([command_6_inp3] of  command_data

    (clock 6)
    (object [input_3])
    (value 11))

([command_6_inp4] of  command_data

    (clock 6)
    (object [input_4])
    (value 19))

([command_7_inp1] of  command_data

    (clock 7)
    (object [input_1])
    (value 1))

([command_7_inp2] of  command_data

    (clock 7)
    (object [input_2])
    (value 31))

([command_7_inp3] of  command_data

    (clock 7)
    (object [input_3])
    (value 7))

([command_7_inp4] of  command_data

    (clock 7)
    (object [input_4])
    (value 22))

([command_8_inp1] of  command_data

    (clock 8)
    (object [input_1])
    (value 0))

([command_8_inp2] of  command_data

    (clock 8)
    (object [input_2])
    (value 31))

([command_8_inp3] of  command_data

    (clock 8)
    (object [input_3])
    (value 3))

([command_8_inp4] of  command_data

    (clock 8)
    (object [input_4])
    (value 23))

([command_9_inp1] of  command_data

    (clock 9)
    (object [input_1])
    (value 31))

([command_9_inp2] of  command_data

    (clock 9)
    (object [input_2])
    (value 1))

([command_9_inp3] of  command_data

    (clock 9)
    (object [input_3])
    (value 6))

([command_9_inp4] of  command_data

    (clock 9)
    (object [input_4])
    (value 8))


([reading_10_m1] of  reading_data

    (clock 10)
    (object [m1])
    (value 12))

([reading_10_m2] of  reading_data

    (clock 10)
    (object [m2])
    (value 31))

([reading_10_m3] of  reading_data

    (clock 10)
    (object [m3])
    (value 12))

([reading_10_out] of  reading_data

    (clock 10)
    (object [out1])
    (value 28))

([reading_1_m1] of  reading_data

    (clock 1)
    (object [m1])
    (value 10))

([reading_1_m2] of  reading_data

    (clock 1)
    (object [m2])
    (value 24))

([reading_1_m3] of  reading_data

    (clock 1)
    (object [m3])
    (value 26))

([reading_1_out] of  reading_data

    (clock 1)
    (object [out1])
    (value 18))

([reading_2_m1] of  reading_data

    (clock 2)
    (object [m1])
    (value 0))

([reading_2_m2] of  reading_data

    (clock 2)
    (object [m2])
    (value 0))

([reading_2_m3] of  reading_data

    (clock 2)
    (object [m3])
    (value 3))

([reading_2_out] of  reading_data

    (clock 2)
    (object [out1])
    (value 3))

([reading_3_m1] of  reading_data

    (clock 3)
    (object [m1])
    (value 22))

([reading_3_m2] of  reading_data

    (clock 3)
    (object [m2])
    (value 6))

([reading_3_m3] of  reading_data

    (clock 3)
    (object [m3])
    (value 8))

([reading_3_out] of  reading_data

    (clock 3)
    (object [out1])
    (value 14))

([reading_4_m1] of  reading_data

    (clock 4)
    (object [m1])
    (value 4))

([reading_4_m2] of  reading_data

    (clock 4)
    (object [m2])
    (value 12))

([reading_4_m3] of  reading_data

    (clock 4)
    (object [m3])
    (value 12))

([reading_4_out] of  reading_data

    (clock 4)
    (object [out1])
    (value 0))

([reading_5_m1] of  reading_data

    (clock 5)
    (object [m1])
    (value 18))

([reading_5_m2] of  reading_data

    (clock 5)
    (object [m2])
    (value 16))

([reading_5_m3] of  reading_data

    (clock 5)
    (object [m3])
    (value 12))

([reading_5_out] of  reading_data

    (clock 5)
    (object [out1])
    (value 12))

([reading_6_m1] of  reading_data

    (clock 6)
    (object [m1])
    (value 8))

([reading_6_m2] of  reading_data

    (clock 6)
    (object [m2])
    (value 24))

([reading_6_m3] of  reading_data

    (clock 6)
    (object [m3])
    (value 17))

([reading_6_out] of  reading_data

    (clock 6)
    (object [out1])
    (value 9))

([reading_7_m1] of  reading_data

    (clock 7)
    (object [m1])
    (value 2))

([reading_7_m2] of  reading_data

    (clock 7)
    (object [m2])
    (value 0))

([reading_7_m3] of  reading_data

    (clock 7)
    (object [m3])
    (value 26))

([reading_7_out] of  reading_data

    (clock 7)
    (object [out1])
    (value 26))

([reading_8_m1] of  reading_data

    (clock 8)
    (object [m1])
    (value 0))

([reading_8_m2] of  reading_data

    (clock 8)
    (object [m2])
    (value 0))

([reading_8_m3] of  reading_data

    (clock 8)
    (object [m3])
    (value 0))

([reading_8_out] of  reading_data

    (clock 8)
    (object [out1])
    (value 0))

([reading_9_m1] of  reading_data

    (clock 9)
    (object [m1])
    (value 30))

([reading_9_m2] of  reading_data

    (clock 9)
    (object [m2])
    (value 30))

([reading_9_m3] of  reading_data

    (clock 9)
    (object [m3])
    (value 12))

([reading_9_out] of  reading_data

    (clock 9)
    (object [out1])
    (value 28))
)
)

通过使用以下断言规则,我可以获得所有事实的列表以及它们属于哪个输入或传感器:

(defrule assert-inputs
    (object (is-a command_data) (clock ?clock) (object ?object) (value ?value))
    =>
    (assert (fact ?clock ?object ?value)))

(defrule assert-outputs
    (object (is-a reading_data) (clock ?clock) (object ?object) (value ?value))
    =>
    (assert (fact ?clock ?object ?value)))

我想以某种方式能够处理事实中的所有输入,并能够看到它们通过加法器或乘法器后会发生什么。我设法为 A1 做到了这一点,因为它只接受 input1 两次这样的输入:

(defrule check_a1
    (fact ?clock ?object ?value)
    (test (eq ?object [input_1]))
    =>
    (assert (fact ?clock [m1t] (mod(+ ?value ?value)(** 2 5)))))

然而Π2乘法器将两个不同的值input3和input4作为输入。通过使用以下内容,我可以打印出所有属于 input3 或 input4 的事实。问题是我不知道如何以与我在上面使用它们时相同的方式使用它们,因为对于我想创建的每个新事实,我都有两个不同的值。有没有一种简单的方法来访问这些值?我试图将它们绑定到不同的变量并像 nth$ 1 和 nth$ 2 一样访问它们,但我无法使其工作。

 (defrule check_p2
    (fact ?clock ?object ?value)
    (test (or (eq ?object [input_3]) (eq ?object [input_4])))
    =>
    (printout t ?clock " " ?object " " ?value crlf))

如果你想抓取两个具有相同时钟值、不同值和对象 [input_3] 和 [input_4] 的不同事实,请使用此规则:

(defrule check_p2
   (fact ?clock [input_3] ?value3)
   (fact ?clock [input_4] ?value4)
   =>
   ; Your action here
)