apply rule to multiple facts?

18 views
Skip to first unread message

Xuan Wu

unread,
Apr 17, 2025, 3:48:16 PMApr 17
to CLIPSESG
Hi all,
I'm still learning and trying to simulate an ecosystem, with multiple lives aging as time flies. Seems one rule only applies to the newest fact, and I can't get all lives aging together. As a test case:

```
(deftemplate human
  (slot id)
  (slot age))

(defrule time_flies
  ?h <- (human (id ?id) (age ?age))
  =>
  (modify ?h (age (+ ?age 1))))
```

and two facts:

(assert (human (id 0) (age 0)))
(assert (human (id 1) (age 0)))

When running I got fact 1 and 2, with only 2 aging by itself. My goal is to see 1 and 2 aging hopefully at the same speed.

Any suggestion is appreciated.

Ryan Johnston

unread,
Apr 17, 2025, 5:17:05 PMApr 17
to clip...@googlegroups.com

In CLIPS, the order in which things execute is not guaranteed. Thus, you must build your rules in a way that explicitly describes that, once one human ages, it should not age again until all other humans have aged.

One way you could achieve this is by adding a test such that the rule only triggers for humans with no other human facts are younger than it. Something like (not (human (age ?a&:(< ?a ?age)))). This would give other human facts a chance to "catch up" to the human facts that have already aged.

This works for your current scenario in which all humans start at the same age. If you will have humans of different ages, you'll need to track something like "number of times a human fact has aged" along with a humans overall age.


--
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 visit https://groups.google.com/d/msgid/clipsesg/d5e35c37-8f13-4691-a93b-790dcec9c9e8n%40googlegroups.com.

Xuan Wu

unread,
Apr 19, 2025, 6:28:23 PMApr 19
to CLIPSESG
Thanks a lot! The solution works. For now I chose to keep the time of birth instead of refreshing age, just to avoid the complexity of adding tracking. Nevertheless thanks for the suggestion.
Reply all
Reply to author
Forward
0 new messages