Recurring Variable values

41 views
Skip to first unread message

shoaib ayyaz

unread,
Apr 12, 2023, 6:49:09 PM4/12/23
to CLIPSESG
Hi @Gary

Hope you are well. My question is I wrote a program that checks values of pressure with the facts and find out peaks at certain times. What I want is I want a gap in time so Instead of checking a very next variable I wanted to keep a gap and check another set of peak at the following times. Let me know if you get the idea. 

Thanks

CLIPS Support

unread,
Apr 13, 2023, 11:04:29 AM4/13/23
to CLIPSESG
You could assert a fact indicating how long you want the gap to be and then modify your rules so that you don't check during that gap and then possibly discarding any values during that gap. Another rule could then remove the fact indicating the gap period once that period has been passed.

shoaiba...@gmail.com

unread,
Apr 15, 2023, 8:41:17 AM4/15/23
to clip...@googlegroups.com
Thats perfect. Is it possible to get it in example. I tried it but can able to add facts like you said. 

I just have another question. I created some numerical data in python I want to import it in clips, its like my FACTS that i am working on. How would i import them in clips

Sent from my iPhone

On 13-Apr-2023, at 4:04 PM, CLIPS Support <garyd...@gmail.com> wrote:

You could assert a fact indicating how long you want the gap to be and then modify your rules so that you don't check during that gap and then possibly discarding any values during that gap. Another rule could then remove the fact indicating the gap period once that period has been passed.
--
You received this message because you are subscribed to the Google Groups "CLIPSESG" group.
To post to this group, send email to CLIP...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/CLIPSESG?hl=en
 
--> IF YOU NO LONGER WANT TO RECEIVE EMAIL <--
Visit this group at http://groups.google.com/group/CLIPSESG?hl=en
Click on "Edit my membership" link.
Select the "No Email" radio button.
Click the "Save these settings" button.

--> IF YOU WANT TO UNSUBSCRIBE <--
Visit this group at http://groups.google.com/group/CLIPSESG?hl=en
Sign in
Click on "Edit my membership" link.
Click the "Unsubscribe" button.
Note: This appears to be the most reliable way to unsubscribe
 
Alternately, send email to CLIPSESG-u...@googlegroups.com. You will receive an email which you must respond to as well to unsubscribe. Clicking the link mentioned in the unsubscribe reply does not appear to work reliably.
---
You received this message because you are subscribed to the Google Groups "CLIPSESG" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clipsesg+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/clipsesg/e3aea132-4e1e-408a-93e9-c6a87eda7aaen%40googlegroups.com.

CLIPS Support

unread,
Apr 16, 2023, 1:17:53 PM4/16/23
to CLIPSESG
If you want to ignore data during a gap you'd add something like this to your patterns:

(data (cycle ?cycle))
(not (gap (ignore-until ?iu-cycle&:(< ?cycle ?iu-cycle))))

This code as part of a rule would remove data in the gap:

?d <- (data (cycle ?cycle))
(gap (ignore-until ?iu-cycle&:(< ?cycle ?iu-cycle)))
=>
(retract ?d)

And this rule fragment would remove the gap fact once the gap had been passed:

(data (cycle ?cycle))
?g <- (gap (ignore-until ?iu-cycle&:(>= ?cycle ?iu-cycle)))
=>
(retract ?g)

If you want to export data from a python program, just write it to a file in a series of facts and use the load-facts function to load it into CLIPS. 

shoaib ayyaz

unread,
Apr 17, 2023, 1:37:27 AM4/17/23
to clip...@googlegroups.com
Perfect I got it. Can you please check below I should suppose to be getting two facts added to the list but its only adding one fact however condition of another fact is also met.

CLIPS> (deftemplate slope
   (slot variable)
   (slot value)
   (slot time)
   (slot peak))
CLIPS> (deftemplate output
   (slot variable)
   (slot time)
   (slot peak))
CLIPS> (defrule score
   (slope (variable ?v)
          (time ?t1)
          (value 0)
          (peak 0))
   (slope (variable ?v)
          (time ?t2&=(+ ?t1 1))
          (value ?v1&:(> ?v1 0))
          (peak ?p1&:(> ?p1 0)))
   (slope (variable ?v)
          (time ?t3&=(+ ?t1 2))
          (value 0)
          (peak ?p2&:(> ?p2 ?p1)))
   (slope (variable ?v)
          (time ?t4&=(+ ?t1 3))
          (value ?v3&:(< ?v3 0))
          (peak ?p3&:(< ?p3 ?p2)))
   (slope (variable ?v)
 (time ?t5&=(+ ?t1 4))
 (value ?v4&:(= ?v4 0))
 (peak ?p4&:(= ?p4 0)))
   (slope (variable ?v)
 (time ?t6&=(+ ?t1 5))
 (value ?v5&:(> ?v5 0))
 (peak ?p5&:(> ?p5 ?p4)))

   (slope (variable ?v)
 (time ?t7&=(+ ?t1 6))
 (value ?v6&:(< ?v6 0))
 (peak ?p6&:(< ?p6 ?p5)))

=>
(assert (output (variable ?v)(time ?t3)(peak ?p2) )))
CLIPS> (defrule scores
   (slope (variable ?v)
          (time ?t1)
          (value 0)
          (peak 0))

   (slope (variable ?v)
          (time ?t2&=(+ ?t1 1))
          (value INF)
          (peak ?p1&:(> ?p1 0)))

   (slope (variable ?v)
          (time ?t3&=(+ ?t1 2))
          (value INF)
          (peak ?p2&:(> ?p2 ?p1)))

(slope (variable ?v)
          (time ?t4&=(+ ?t1 3))
          (value INF)
          (peak ?p3&:(> ?p3 ?p2)))

(slope (variable ?v)
          (time ?t5&=(+ ?t1 4))
          (value 0)
          (peak ?p4&:(= ?p4 ?p3)))

(slope (variable ?v)
          (time ?t6&=(+ ?t1 5))
          (value INF)
          (peak ?p5&:(< ?p5 ?p4)))

(slope (variable ?v)
          (time ?t7&=(+ ?t1 6))
          (value 0)
          (peak 0))

=> (assert (output (variable ?v)(time ?t5)(peak ?p4))))

CLIPS> (assert (slope (variable drill) (time 1) (value 0) (peak 0))
        (slope (variable drill) (time 2) (value 3) (peak 200))
        (slope (variable drill) (time 3) (value 0) (peak 300))
        (slope (variable drill) (time 4) (value -2) (peak 100))
(slope (variable drill) (time 5) (value 0) (peak 0))
        (slope (variable drill) (time 6) (value 4) (peak 600))
        (slope (variable drill) (time 7) (value -1) (peak 550))
(slope (variable drillpipe)(time 1)(value 0)(peak 0))
(slope (variable drill)(time 2)(value INF)(peak 20))
(slope (variable drill)(time 3)(value INF)(peak 35))
(slope (variable drill)(time 4)(value INF)(peak 50))
(slope (variable drill)(time 5)(value 0)(peak 50))
(slope (variable drill)(time 6)(value INF)(peak 45))
(slope (variable drill)(time 7)(value 0)(peak 0)))
 

CLIPS Support

unread,
Apr 17, 2023, 3:26:37 PM4/17/23
to CLIPSESG
The assertion of facts stops before they're all asserted because the value slot for some of your facts contain the value INF. Your score rule is passing this value to the <, >, and = functions which are expecting numeric values:

CLIPS> (watch facts)

CLIPS>
(assert (slope (variable drill) (time 1) (value 0) (peak 0))
        (slope (variable drill) (time 2) (value 3) (peak 200))
        (slope (variable drill) (time 3) (value 0) (peak 300))
        (slope (variable drill) (time 4) (value -2) (peak 100))
        (slope (variable drill) (time 5) (value 0) (peak 0))
        (slope (variable drill) (time 6) (value 4) (peak 600))
        (slope (variable drill) (time 7) (value -1) (peak 550))
        (slope (variable drillpipe)(time 1)(value 0)(peak 0))
        (slope (variable drill)(time 2)(value INF)(peak 20))
        (slope (variable drill)(time 3)(value INF)(peak 35))
        (slope (variable drill)(time 4)(value INF)(peak 50))
        (slope (variable drill)(time 5)(value 0)(peak 50))
        (slope (variable drill)(time 6)(value INF)(peak 45))
        (slope (variable drill)(time 7)(value 0)(peak 0)))
==> f-1     (slope (variable drill) (value 0) (time 1) (peak 0))
==> f-2     (slope (variable drill) (value 3) (time 2) (peak 200))
==> f-3     (slope (variable drill) (value 0) (time 3) (peak 300))
==> f-4     (slope (variable drill) (value -2) (time 4) (peak 100))
==> f-5     (slope (variable drill) (value 0) (time 5) (peak 0))
==> f-6     (slope (variable drill) (value 4) (time 6) (peak 600))
==> f-7     (slope (variable drill) (value -1) (time 7) (peak 550))
==> f-8     (slope (variable drillpipe) (value 0) (time 1) (peak 0))
==> f-9     (slope (variable drill) (value INF) (time 2) (peak 20))
[ARGACCES2] Function '>' expected argument #1 to be of type integer or float.

[FACTMCH1] This error occurred in the fact pattern network.
   Currently active fact: (slope (variable drill) (value INF) (time 2) (peak 20))
   Problem resides in slot value
      Of pattern #6 in rule score

[ARGACCES2] Function '=' expected argument #1 to be of type integer or float.

[FACTMCH1] This error occurred in the fact pattern network.
   Currently active fact: (slope (variable drill) (value INF) (time 2) (peak 20))
   Problem resides in slot value
      Of pattern #5 in rule score

[ARGACCES2] Function '<' expected argument #1 to be of type integer or float.

[FACTMCH1] This error occurred in the fact pattern network.
   Currently active fact: (slope (variable drill) (value INF) (time 2) (peak 20))
   Problem resides in slot value
      Of pattern #7 in rule score
      Of pattern #4 in rule score

[ARGACCES2] Function '>' expected argument #1 to be of type integer or float.

[FACTMCH1] This error occurred in the fact pattern network.
   Currently active fact: (slope (variable drill) (value INF) (time 2) (peak 20))
   Problem resides in slot value
      Of pattern #2 in rule score

FALSE
CLIPS> (agenda)
0      score: f-1,f-2,f-3,f-4,f-5,f-6,f-7
For a total of 1 activation.
CLIPS>

Modify your rule to prevent the value INF being passed to these functions:

 (defrule score
   (slope (variable ?v) (time ?t1) (value 0) (peak 0))
   (slope (variable ?v) (time ?t2&=(+ ?t1 1)) (value ?v1&~INF&:(> ?v1 0)) (peak ?p1&:(> ?p1 0)))

   (slope (variable ?v) (time ?t3&=(+ ?t1 2)) (value 0) (peak ?p2&:(> ?p2 ?p1)))
   (slope (variable ?v) (time ?t4&=(+ ?t1 3)) (value ?v3&~INF&:(< ?v3 0)) (peak ?p3&:(< ?p3 ?p2)))
   (slope (variable ?v) (time ?t5&=(+ ?t1 4)) (value ?v4&~INF&:(= ?v4 0)) (peak ?p4&:(= ?p4 0)))
   (slope (variable ?v) (time ?t6&=(+ ?t1 5)) (value ?v5&~INF&:(> ?v5 0)) (peak ?p5&:(> ?p5 ?p4)))
   (slope (variable ?v) (time ?t7&=(+ ?t1 6)) (value ?v6&~INF&:(< ?v6 0)) (peak ?p6&:(< ?p6 ?p5)))

   =>
   (assert (output (variable ?v) (time ?t3) (peak ?p2))))
Reply all
Reply to author
Forward
0 new messages