Accessing values in CLIPS? - artificial-intelligence

Assume I have the following set of definstances which show the inputs and outputs of various stages of an electric circuit. I don't include all the classes and instances as I don't think it's relevant to my problem. I will include a photo that will help you understand how this problem works.
The code below is from Protege, the code of Ontology.
We have 10 cycles.
(defclass systemEntity
(is-a USER)
(role abstract)
(single-slot suspect
(type SYMBOL)
(allowed-values yes no)
(default no)
(create-accessor read-write))
(single-slot out
(type INTEGER)
(range 0 31)
(create-accessor read-write)))
(defclass command
(is-a systemEntity)
(role concrete))
(defclass component
(is-a systemEntity)
(role abstract))
(defclass sensor
(is-a component)
(role concrete)
(single-slot theoretical
(type INTEGER)
(range 0 31)
(create-accessor read-write))
(single-slot out
(type INTEGER)
(range 0 31)
(create-accessor read-write))
(single-slot reading
(type INTEGER)
(range 0 31)
(create-accessor read-write))
(single-slot input
(type INSTANCE)
(allowed-classes internal-component)
(create-accessor read-write)))
(defclass internal-component
(is-a component)
(role concrete)
(single-slot short-out
(type INTEGER)
(range 0 0)
(default 0)
(create-accessor read-write))
(multislot output
(type INSTANCE)
(allowed-classes component)
(create-accessor read-write))
(single-slot msb-out
(type INTEGER)
(range 0 15)
(create-accessor read-write))
(single-slot input2
(type INSTANCE)
(allowed-classes systemEntity)
(create-accessor read-write))
(single-slot input1
(type INSTANCE)
(allowed-classes systemEntity)
(create-accessor read-write)))
(defclass adder
(is-a internal-component)
(role concrete))
(defclass multiplier
(is-a internal-component)
(role concrete))
(defclass circuit
(is-a systemEntity)
(role concrete)
(multislot outputs
(type INSTANCE)
(allowed-classes sensor)
(create-accessor read-write))
(multislot has-components
(type INSTANCE)
(allowed-classes component)
(create-accessor read-write))
(multislot inputs
(type INSTANCE)
(allowed-classes command)
(create-accessor read-write)))
(defclass data
(is-a USER)
(role abstract)
(single-slot clock
(type INTEGER)
(range 1 ?VARIABLE)
(create-accessor read-write))
(single-slot object
(type INSTANCE)
(allowed-classes systemEntity)
(create-accessor read-write))
(single-slot value
(type INTEGER)
(create-accessor read-write)))
(defclass command_data
(is-a data)
(role concrete)
(single-slot object
(type INSTANCE)
(allowed-classes command)
(create-accessor read-write)))
(defclass reading_data
(is-a data)
(role concrete)
(single-slot object
(type INSTANCE)
(allowed-classes sensor)
(create-accessor read-write)))
(definstances facts
([a1] of adder
(input1 [input_1])
(input2 [input_1])
(output
[m1]
[p1])
(short-out 0)
(suspect no))
([a2] of adder
(input1 [p1])
(input2 [p2])
(output [out1])
(short-out 0)
(suspect no))
([circuit_1] of circuit
(has-components
[m1]
[m2]
[m3]
[out1]
[a1]
[a2]
[p1]
[p2])
(inputs
[input_1]
[input_2]
[input_3]
[input_4])
(outputs [out1])
(suspect no))
([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))
([input_1] of command
(suspect no))
([input_2] of command
(suspect no))
([input_3] of command
(suspect no))
([input_4] of command
(suspect no))
([m1] of sensor
(input [a1])
(suspect no))
([m2] of sensor
(input [p1])
(suspect no))
([m3] of sensor
(input [p2])
(suspect no))
([out1] of sensor
(input [a2])
(suspect no))
([p1] of multiplier
(input1 [input_2])
(input2 [a1])
(output
[m2]
[a2])
(short-out 0)
(suspect no))
([p2] of multiplier
(input1 [input_3])
(input2 [input_4])
(output
[m3]
[a2])
(short-out 0)
(suspect no))
([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 0))
([reading_9_out] of reading_data
(clock 9)
(object [out1])
(value 30))
)
By using the following code i can calculate the A1.
(defrule check_a1
(fact ?clock ?object ?value)
(test (eq ?object [input_1]))
=>
(assert (fact ?clock [m1t] (mod(+ ?value ?value)(** 2 5)))))
How can i calculate the Π1?

If you look through your code, you can see the information for adder and multiplier referenced in your question.
([a1] of adder
(input1 [input_1])
(input2 [input_1])
(output
[m1]
[p1])
(short-out 0)
(suspect no))
([p1] of multiplier
(input1 [input_2])
(input2 [a1])
(output
[m2]
[a2])
(short-out 0)
(suspect no))
It's not clear how your check_a1 rule can correctly calculate anything. It matches facts, but the protege code contains only instances. It's also not clear looking at the protege code where the input/output values for the internal-components are stored.
If you write rules specific rules for each component, you have to change those rules if you run your program with a different circuit. It's better to write generic rules for each component type. For example:
(defrule adder
(object (is-a multiplier)
(name ?name)
(input1 ?input1)
(input2 ?input2)
)
;; Pattern to retrieve input1 value
;; Pattern to retrieve input2 value
=>
;; Compute output value
)
One additional issue that you will see with the protege code is that a concrete class inheriting from an abstract class will not match rules unless you declare the pattern-match attribute to be reactive: (pattern-match reactive)

Related

Using Excel VBA to send data to access database from an array

I am trying to change my code from storing data to excel spreadsheets to send to access database.
This is the code
If qty.Value <> "" Then
PatientDetails(1, 1) = LastRow - 1
zh.Cells(LastRow, 1).Resize(, 22) = PatientDetails
zh.Cells(LastRow, 23) = servees.Value
zh.Cells(LastRow, 25) = qty.Value
zh.Cells(LastRow, 27) = cost.Value
zh.Cells(LastRow, 29) = ThisWorkbook.Sheets("Support").Range("AM1").Value
zh.Cells(LastRow, 30) = [Text(Now(), "DD-MM-YY HH:MM:SS")]
LastRow = LastRow + 1
End If
'Next
im only posting the code that relates to the help i need,
zh is the sheet,LastRow is supposed to find the next empty row,
this section of code runs in a loop,
NOW "PatientDetails" is an array with data used to populate column1 to column22.
In changing this code to be able to send to access,
since i used
zh.Cells(LastRow, 1).Resize(, 22) = PatientDetails
to populate the first 22 columns of my spreadsheet.
If i want to send "PatientDetails" to access,
how do i populate access fields/columns with "PatientDetails"
This is the array
Private Function PatientDetails() As Variant
Dim ar(1 To 1, 1 To 22)
With PrivGNI
ar(1, 1) = 0
ar(1, 2) = "GNI HMO (PRIVATE)"
ar(1, 3) = .Txt_EnrolleeNoGNI.Value
ar(1, 4) = "Nil"
ar(1, 5) = Private_PreEntryForm1.cmb_ReferFromPef2.Value
ar(1, 6) = .Txt_EnrolleeNameGNI.Value
ar(1, 7) = .Txt_AuthorizationCode.Value
ar(1, 8) = Private_PreEntryForm1.Txt_AuthorisingOfficerPEF.Value
If Private_PreEntryForm1.Opt_OutpatientPef = True Then
ar(1, 9) = "OUTPATIENT"
Else
ar(1, 9) = "Nil"
End If
If Private_PreEntryForm1.Opt_InpatientPef2 = True Then
ar(1, 9) = "INPATIENT"
Else
ar(1, 9) = "Nil"
End If
ar(1, 10) = Private_PreEntryForm1.Cmb_PatientPlan.Value
ar(1, 11) = "PRIVATE HMO"
ar(1, 12) = .Txt_HmoCodeGNI.Value
ar(1, 13) = .txt_DateOfserv2.Value
ar(1, 14) = .Txt_DateOfAdmGNI.Value
ar(1, 15) = .Txt_DateOfDisGNI.Value
ar(1, 16) = Private_PreEntryForm1.cmd_Genderpef2.Value
ar(1, 17) = .Txt_AgeGNI.Value
ar(1, 18) = .Txt_SexGNI
ar(1, 19) = .txt_drsNameGNI
ar(1, 20) = "Nil"
ar(1, 21) = .Txt_DiagnosisGNI.Value
ar(1, 22) = .txt_PhoneGNI.Value
End With
PatientDetails = ar
End Function
if i may add,
does it make any sense to say
"Recordset.Fields(1,2,3,4,5,6 to 22).Value = PatientDetails"
Its only this line of code i need help on.
The ADO property or method that can refer to multiple columns/fields alongside the "fields" object to Send the array to access

Undefined class 'command_data' in object pattern - CLIPS

I'm using this Protege exported code on the first code block.
(defclass systemEntity
(is-a USER)
(role abstract)
(single-slot suspect
(type SYMBOL)
(allowed-values yes no)
(default no)
(create-accessor read-write))
(single-slot out
(type INTEGER)
(range 0 31)
(create-accessor read-write)))
(defclass command
(is-a systemEntity)
(role concrete))
(defclass component
(is-a systemEntity)
(role abstract))
(defclass sensor
(is-a component)
(role concrete)
(single-slot theoretical
(type INTEGER)
(range 0 31)
(create-accessor read-write))
(single-slot out
(type INTEGER)
(range 0 31)
(create-accessor read-write))
(single-slot reading
(type INTEGER)
(range 0 31)
(create-accessor read-write))
(single-slot input
(type INSTANCE)
(allowed-classes internal-component)
(create-accessor read-write)))
(defclass internal-component
(is-a component)
(role concrete)
(single-slot short-out
(type INTEGER)
(range 0 0)
(default 0)
(create-accessor read-write))
(multislot output
(type INSTANCE)
(allowed-classes component)
(create-accessor read-write))
(single-slot msb-out
(type INTEGER)
(range 0 15)
(create-accessor read-write))
(single-slot input2
(type INSTANCE)
(allowed-classes systemEntity)
(create-accessor read-write))
(single-slot input1
(type INSTANCE)
(allowed-classes systemEntity)
(create-accessor read-write)))
(defclass adder
(is-a internal-component)
(role concrete))
(defclass multiplier
(is-a internal-component)
(role concrete))
(defclass circuit
(is-a systemEntity)
(role concrete)
(multislot outputs
(type INSTANCE)
(allowed-classes sensor)
(create-accessor read-write))
(multislot has-components
(type INSTANCE)
(allowed-classes component)
(create-accessor read-write))
(multislot inputs
(type INSTANCE)
(allowed-classes command)
(create-accessor read-write)))
(defclass data
(is-a USER)
(role abstract)
(single-slot clock
(type INTEGER)
(range 1 ?VARIABLE)
(create-accessor read-write))
(single-slot object
(type INSTANCE)
(allowed-classes systemEntity)
(create-accessor read-write))
(single-slot value
(type INTEGER)
(create-accessor read-write)))
(defclass command_data
(is-a data)
(role concrete)
(single-slot object
(type INSTANCE)
(allowed-classes command)
(create-accessor read-write)))
(defclass reading_data
(is-a data)
(role concrete)
(single-slot object
(type INSTANCE)
(allowed-classes sensor)
(create-accessor read-write)))
(definstances facts
([a1] of adder
(input1 [input_1])
(input2 [input_1])
(output
[m1]
[p1])
(short-out 0)
(suspect no))
([a2] of adder
(input1 [p1])
(input2 [p2])
(output [out1])
(short-out 0)
(suspect no))
([circuit_1] of circuit
(has-components
[m1]
[m2]
[m3]
[out1]
[a1]
[a2]
[p1]
[p2])
(inputs
[input_1]
[input_2]
[input_3]
[input_4])
(outputs [out1])
(suspect no))
([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))
([input_1] of command
(suspect no))
([input_2] of command
(suspect no))
([input_3] of command
(suspect no))
([input_4] of command
(suspect no))
([m1] of sensor
(input [a1])
(suspect no))
([m2] of sensor
(input [p1])
(suspect no))
([m3] of sensor
(input [p2])
(suspect no))
([out1] of sensor
(input [a2])
(suspect no))
([p1] of multiplier
(input1 [input_2])
(input2 [a1])
(output
[m2]
[a2])
(short-out 0)
(suspect no))
([p2] of multiplier
(input1 [input_3])
(input2 [input_4])
(output
[m3]
[a2])
(short-out 0)
(suspect no))
([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 0))
([reading_9_out] of reading_data
(clock 9)
(object [out1])
(value 30))
)
These are a function and a rule i wrote.
I want to get from the slot value of a command_data object the value and im getting the Undefined class 'command_data' in object pattern error.
I also attach a print screen from CLIPS's console.
Any help?
(deffunction calculate-adder (?r ?z)
(bind ?g (+ ?z ?r))
(bind ?f (* 2 2 2 2 2))
(mod ?g ?f)
)
(defrule initial-rule
?x <- (initial-fact)
(bind ?temp =1)
(object (is-a command_data)
(clock ?temp)
(object [input_1])
(value ?l))
(object (is-a command_data)
(clock ?temp)
(object [input_2])
(value ?z))
=>
(retract ?x)
(bind ?w (calculate-adder (?l ?z)))
)
Edit: I changed a few things and now i have new error
The allowed-classes attribute is very aggressive enforcing its restrictions. For example, you can place an instance name in the object slot if an instance exists so that its class can be determined:
CLIPS (6.31 6/12/19)
CLIPS> (clear)
CLIPS>
(defclass command
(is-a USER))
CLIPS>
(defclass command_data
(is-a USER)
(slot object
(allowed-classes command)))
CLIPS> (make-instance [c1] of command)
[c1]
CLIPS>
(defrule no-error
(object
(is-a command_data)
(object [c1]))
=>)
CLIPS>
But if you use an instance name for an instance that has not yet been created and so its class cannot be determined, you'll get an error:
CLIPS>
(defrule triggers-static-error
(object
(is-a command_data)
(object [c2]))
=>)
[CSTRNCHK1] A literal restriction value found in CE #1
does not match the allowed classes for slot object.
ERROR:
(defrule MAIN::triggers-static-error
(object (is-a command_data)
(object [c2]))
=>)
CLIPS>
The simplest way to fix this is to disable static constraint checking:
CLIPS> (set-static-constraint-checking FALSE)
TRUE
CLIPS>
(defrule no-longer-triggers-static-error
(object
(is-a command_data)
(object [c2]))
=>)
CLIPS>
You can also remove the allowed-classes attribute from your classes or modify your rule so that the instance name constant is not referenced inside the slot pattern:
CLIPS> (set-static-constraint-checking TRUE)
FALSE
CLIPS>
(defrule no-longer-triggers-static-error
(object
(is-a command_data)
(object ?o))
(test (eq ?o [c2]))
=>)
CLIPS>

Accessing multiple (?) values in CLIPS

Assume I have the following set of definstances which show the inputs and outputs of various stages of an electric circuit. I don't include all the classes and instances as I don't think it's relevant to my problem. I will include a photo that will help you understand how this problem works.
Here input1 goes to adder A1 as both inputs. Input3 and input4 go to Π2 multiplier as inputs.
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))
)
)
By using the following assert rules I can get a list of all the facts along with which input or sensor they belong to :
(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)))
I want to somehow be able to handle all inputs in the facts and be able to see what happens after they pass an adder or a multiplier. I managed to do this for A1 because it takes as input only input1 two times like this :
(defrule check_a1
(fact ?clock ?object ?value)
(test (eq ?object [input_1]))
=>
(assert (fact ?clock [m1t] (mod(+ ?value ?value)(** 2 5)))))
However Π2 multiplier takes as input two different values input3 and input4. By using the following I can manage to print all the facts that are either of input3 or input4. The problem is I don't know how to use them in the same manner as I used them above when they were only one since for every new fact I want to create I have two different values. Is there an easy way to access these values? I tried to bind them to a different variable and access them like nth$ 1 and nth$ 2 but I couldn't make it work.
(defrule check_p2
(fact ?clock ?object ?value)
(test (or (eq ?object [input_3]) (eq ?object [input_4])))
=>
(printout t ?clock " " ?object " " ?value crlf))
If you want to grab two different facts with the same clock value, different values, and objects [input_3] and [input_4], use this rule:
(defrule check_p2
(fact ?clock [input_3] ?value3)
(fact ?clock [input_4] ?value4)
=>
; Your action here
)

Accessing values from definstances in CLIPS

I am working on a CLIPS program for an assignment that handles electric circuits. I have used Protege to create my ontology and from there I have created the clp file and loaded it into CLIPS. The result is the following:
(defclass systemEntity
(is-a USER)
(role abstract)
(single-slot suspect
(type SYMBOL)
(allowed-values yes no)
(default no)
(create-accessor read-write))
(single-slot out
(type INTEGER)
(range 0 31)
(create-accessor read-write)))
(defclass command
(is-a systemEntity)
(role concrete))
(defclass component
(is-a systemEntity)
(role abstract))
(defclass sensor
(is-a component)
(role concrete)
(single-slot theoretical
(type INTEGER)
(create-accessor read-write))
(single-slot out
(type INTEGER)
(range 0 31)
(create-accessor read-write))
(single-slot reading
(type INTEGER)
(range 0 31)
(create-accessor read-write))
(single-slot input
(type INSTANCE)
(allowed-classes internal-component)
(create-accessor read-write)))
(defclass internal-component
(is-a component)
(role concrete)
(single-slot short-out
(type INTEGER)
(range 0 0)
(default 0)
(create-accessor read-write))
(multislot output
(type INSTANCE)
(allowed-classes component)
(create-accessor read-write))
(single-slot msb-out
(type INTEGER)
(range 0 15)
(create-accessor read-write))
(single-slot input2
(type INSTANCE)
(allowed-classes systemEntity)
(create-accessor read-write))
(single-slot input1
(type INSTANCE)
(allowed-classes systemEntity)
(create-accessor read-write)))
(defclass adder
(is-a internal-component)
(role concrete))
(defclass multiplier
(is-a internal-component)
(role concrete))
(defclass circuit
(is-a systemEntity)
(role concrete)
(multislot outputs
(type INSTANCE)
(allowed-classes sensor)
(create-accessor read-write))
(multislot has-components
(type INSTANCE)
(allowed-classes component)
(create-accessor read-write))
(multislot inputs
(type INSTANCE)
(allowed-classes command)
(create-accessor read-write)))
(defclass data
(is-a USER)
(role abstract)
(single-slot clock
(type INTEGER)
(range 1 ?VARIABLE)
(create-accessor read-write))
(single-slot object
(type INSTANCE)
(allowed-classes systemEntity)
(create-accessor read-write))
(single-slot value
(type INTEGER)
(create-accessor read-write)))
(defclass command_data
(is-a data)
(role concrete)
(single-slot object
(type INSTANCE)
(allowed-classes command)
(create-accessor read-write)))
(defclass reading_data
(is-a data)
(role concrete)
(single-slot object
(type INSTANCE)
(allowed-classes sensor)
(create-accessor read-write)))
(definstances facts
([a1] of adder
(input1 [input_1])
(input2 [input_1])
(output
[m1]
[p1])
(short-out 0)
(suspect no))
([a2] of adder
(input1 [p1])
(input2 [p2])
(output [out1])
(short-out 0)
(suspect no))
([circuit_1] of circuit
(has-components
[m1]
[m2]
[m3]
[out1]
[a1]
[a2]
[p1]
[p2])
(inputs
[input_1]
[input_2]
[input_3]
[input_4])
(outputs [out1])
(suspect no))
([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))
([input_1] of command
(suspect no))
([input_2] of command
(suspect no))
([input_3] of command
(suspect no))
([input_4] of command
(suspect no))
([m1] of sensor
(input [a1])
(suspect no))
([m2] of sensor
(input [p1])
(suspect no))
([m3] of sensor
(input [p2])
(suspect no))
([out1] of sensor
(input [a2])
(suspect no))
([p1] of multiplier
(input1 [input_2])
(input2 [a1])
(output
[m2]
[a2])
(short-out 0)
(suspect no))
([p2] of multiplier
(input1 [input_3])
(input2 [input_4])
(output
[m3]
[a2])
(short-out 0)
(suspect no))
([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))
)
I am trying to figure out how to make defrules to print out all the inputs and outputs from a specific isntance of a class such as the adder a1. I will show what I mean below, by showing a few definstances:
([a1] of adder
(input1 [input_1])
(input2 [input_1])
(output
[m1]
[p1])
(short-out 0)
(suspect no))
a1 adder takes as input1 and input2 the input_1 instance which is this:
([command_1_inp1] of command_data
(clock 1)
(object [input_1])
(value 21))
and outputs to m1 and p1 from which the output can be obtained by the m1 instance which is this:
([reading_1_m1] of reading_data
(clock 1)
(object [m1])
(value 10))
However when I try to access the values of an instance (e.g. of the first input) I get an error No object of existing classes can satisfy is-a restriction in object pattern.
(defrule find-input-1
(object (is-a command_data)
(clock ?clock)
(value ?value))
=>
(printout t ?clock " " ?value crlf))
What am I doing wrong? How can I access the values that my instances have?
You need use the object keyword in your rule, otherwise CLIPS treats internal-component as if it was a deftemplate fact.
(defrule print-sensor
(object (is-a internal-component) (input1 ?input1) (input2 ?input2))
=>
(printout t ?input1 " " ?input2 crlf))
You also need to declare the internal-component class as reactive to use it in rules.
(defclass internal-component
(is-a component)
(role concrete)
(pattern-match reactive)
.
.
.
)

OxyPlot not refreshing in VB.net

I was using Visual Studio to chart data when I ran into a problem with the logarithmic X-Axis. I have now turned to OxyPlot, however, I am running into huge issues with getting my data to populate. I switched from the windows forms to WPF, so this could be a XAML issue with binding (unsure). Essentially I took their very limited example in VB.net and can easily reproduce it. What I am struggling with is reproducing dynamic plotting with OxyPlot. Here is my code so far:
Sample: (http://docs.oxyplot.org/en/latest/getting-started/hello-wpf-vb.html)
Public Sub New()
Model = New PlotModel()
Model.Title = "Simple example"
Model.Subtitle = "using OxyPlot in VB.NET"
Dim series1 = New LineSeries()
series1.Title = "Series 1"
series1.MarkerType = MarkerType.Circle
series1.Points.Add(New DataPoint(0, 0))
series1.Points.Add(New DataPoint(10, 18))
series1.Points.Add(New DataPoint(20, 12))
series1.Points.Add(New DataPoint(30, 8))
series1.Points.Add(New DataPoint(40, 15))
Dim series2 = New LineSeries()
series2.Title = "Series 2"
series2.MarkerType = MarkerType.Square
series2.Points.Add(New DataPoint(0, 4))
series2.Points.Add(New DataPoint(10, 12))
series2.Points.Add(New DataPoint(20, 16))
series2.Points.Add(New DataPoint(30, 25))
series2.Points.Add(New DataPoint(40, 5))
Model.Series.Add(series1)
Model.Series.Add(series2)
End Sub
Then I attempt to add more data to simulate dynamically loading data. I also am aware that I must use invalidate() and that Update() is deprecated. I added a button to the form and give it another series to add to the chart upon click.
Button Click:
Private Sub test_Click(sender As Object, e As RoutedEventArgs) Handles test.Click
Dim series3 = New LineSeries()
series3.Title = "Series 3"
series3.MarkerType = MarkerType.Square
series3.Points.Add(New DataPoint(20, 20))
series3.Points.Add(New DataPoint(21, 21))
series3.Points.Add(New DataPoint(22, 22))
series3.Points.Add(New DataPoint(23, 23))
series3.Points.Add(New DataPoint(24, 24))
Model.Series.Add(series3)
Model.InvalidatePlot(True)
End Sub
Here is also their lovely reference to updating their dataPlot: http://docs.oxyplot.org/en/latest/common-tasks/refresh-plot.html#examples
In your event handler, you need to add series3 to your Model before calling InvalidatePlot i.e.
Model.Series.Add(series3);
Model.InvalidatePlot(true);
Update
Also, you need to make sure your PlotModel notifies the view (XAML) of your changes. If I use the example from Oxyplot documentation as an example (the one you specified), I'd modify the code as such:
Public Class MainViewModel Implements INotifyPropertyChanged
Private mmodel As PlotModel
Public Event PropertyChanged As PropertyChangedEventHandler _
Implements INotifyPropertyChanged.PropertyChanged
Public Sub New()
Model = New PlotModel()
Model.Title = "Simple example"
Model.Subtitle = "using OxyPlot in VB.NET"
Dim series1 = New LineSeries()
series1.Title="Series 1"
series1.MarkerType = MarkerType.Circle
series1.Points.Add(New DataPoint(0, 0))
series1.Points.Add(New DataPoint(10, 18))
series1.Points.Add(New DataPoint(20, 12))
series1.Points.Add(New DataPoint(30, 8))
series1.Points.Add(New DataPoint(40, 15))
Dim series2 = New LineSeries()
series2.Title="Series 2"
series2.MarkerType = MarkerType.Square
series2.Points.Add(New DataPoint(0, 4))
series2.Points.Add(New DataPoint(10, 12))
series2.Points.Add(New DataPoint(20, 16))
series2.Points.Add(New DataPoint(30, 25))
series2.Points.Add(New DataPoint(40, 5))
Model.Series.Add(series1)
Model.Series.Add(series2)
End Sub
Property Model() As PlotModel
Get
Return mmodel
End Get
Set(value As PlotModel)
mmodel = value
NotifyPropertyChanged("Model")
End Set
End Property
Private Sub test_Click(sender As Object, e As RoutedEventArgs) Handles test.Click
Dim series3 = New LineSeries()
series3.Title = "Series 3"
series3.MarkerType = MarkerType.Square
series3.Points.Add(New DataPoint(20, 20))
series3.Points.Add(New DataPoint(21, 21))
series3.Points.Add(New DataPoint(22, 22))
series3.Points.Add(New DataPoint(23, 23))
series3.Points.Add(New DataPoint(24, 24))
Model.Series.Add(series3)
Model.InvalidatePlot(True)
End Sub
End Class

Resources