Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A difficult Jess rule

 
Hope Zhu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am working on writing a rule to figure out which shadow fact in a group has the latest timestamp. Then use the found out in another rule. All shadow facts are the same java object and the size of the group is changable. If there are only two in the group I know how to achieve the goal, but more than two in a group I could not figure out how to do it. Can someone please help!!!

Thanks in advance
 
Hope Zhu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Forgot one more thing. I know if I always retract the shadow fact which has the older timestamp then I will only have the latest left. But I may need the old facts to stay in for other rules. So the question should be without retracting any facts how to find out which one is the latest.

Thanks again.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The general way to write this is (pseudocode)



A rule like this will fire just once, for the very latest fact. So, imagine there's a template like

(deftemplate object (slot timestamp (type LONG)))

then the rule might look like

 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic