How to compare two variables from a java class in jess and execute a rule?

Posted by user3417084 on Stack Overflow See other posts from Stack Overflow or by user3417084
Published on 2014-06-03T15:19:56Z Indexed on 2014/06/03 15:25 UTC
Read the original article Hit count: 292

Filed under:
|

I'm beginner in Jess. I'm trying to compare two variables from a Java class in Jess and trying to execute a rule.

I have imported cTNumber and measuredCurrent (both are integer)form a java class called CurrentSignal. Similarly imported vTNumberand measuredVoltage form a java class DERSignal. Now I want to make a rule such that if cTNumber is equal to vTNumber then multiply measuredCurrent and measuredVoltage (Both are double) for calculating power.

I'm trying in this way....

(import signals.*)
(deftemplate CurrentSignal (declare (from-class CurrentSignal)))
(deftemplate DERSignal (declare (from-class DERSignal)))

(defglobal ?*CTnumber* = 0)
(defglobal ?*VTnumber* = 0)
(defglobal ?*VTnumberDER* = 0)

(defglobal ?*measuredCurrent* = 0)
(defglobal ?*measuredVoltage* = 0)
(defglobal ?*measuredVoltageDER* = 0)


(defrule Get-CT-Number

   (CurrentSignal (cTNumber ?m)) 
   (CurrentSignal (measuredCurrent ?c))

=>
    (bind ?*measuredCurrent* ?c)
      (printout t "Measured Current : " ?*measuredCurrent*" Amps"crlf)
    (bind ?*CTnumber* ?m)
      (printout t ?*CTnumber* crlf)
)


(defrule Get-DER-Number

   (DERSignal (vTNumber ?o)) 
   (DERSignal (measuredVoltage ?V))

=>
     (bind ?*measuredVoltageDER* ?V)
       (printout t "Measured Voltage : " ?*measuredVoltageDER* " V" crlf)
    (bind ?*VTnumberDER* ?o)
       (printout t ?*VTnumberDER* crlf)
)


(defrule Power-Calculation-DER-signal

    "Power calculation of DER Bay"

    (test (= ?*CTnumber* ?*VTnumberDER* ))
    =>

  (printout t "Total Generation : " (* ?*measuredCurrent* ?*measuredVoltageDER*) crlf)
)

But the Total Generation is showing 0. But I tried calculating in Java and it's showing a number. Can anyone please help me to solve this problem. Thank you.

© Stack Overflow or respective owner

Related posts about java

Related posts about jess