在CLIPS中访问多个(?)值

时间:2019-01-19 16:24:23

标签: artificial-intelligence clips

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

这里,输入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作为输入。通过使用以下内容,我可以打印所有输入3或输入4的事实。问题是我不知道如何以与上面仅使用它们时相同的方式使用它们,因为对于我要创建的每个新事实,我都有两个不同的值。是否有一种简单的方法来访问这些值?我试图将它们绑定到其他变量,并像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))

1 个答案:

答案 0 :(得分:0)

如果要使用相同的时钟值,不同的值以及对象[input_3]和[input_4]来捕获两个不同的事实,请使用以下规则:

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