Thanks, but that only matches
on the single set of facts with the lowest priority. I want to get all of the
facts, I just want them to be given to the rule in order of priority. For
example, given the following set of facts: (assert (SomethingIWant (Name "TiVo") (Price 200) (Priority 1) ) ) (assert (SomethingIWant (Name "Tires") (Price 800) (Priority 1) ) ) (assert (SomethingIWant (Name "Carb") (Price 400) (Priority 1) ) ) (assert (SomethingIWant (Name "DVD Burner") (Price 400) (Priority 5) ) ) (assert (SomethingIWant (Name "Wheels") (Price 1000) (Priority 2) ) ) (assert (SomethingIWant (Name "shocks") (Price 900) (Priority 2) ) ) I get the following output: TRUE Jess> (run) Found: Carb, 400, 1 Found: Tires, 800, 1 Found: TiVo, 200, 1 3 Jess> The output I want to see would be
something like: Found: Carb, 400, 1 Found: Tires, 800, 1 Found: TiVo, 200, 1 Found: Wheels, 1000, 2 Found: shocks, 900, 2 Found: DVD Burner, 400, 5 If I can get that to work, I’d have
some additional logic to stop processing at some point. In this example, maybe
I’d keep a running total of items and stop when I’ve reached my
budget, but I want to make sure I get the higher priority items first. Should I maybe be setting another fact to
the “current priority”, initialize it to 1 and just match facts
that have that priority, then increment the current priority fact and match
against facts that have that new priority and continue through the valid range
of priorities? That just feels like I’m trying to impose my procedural
thinking on the rules engine. So, I’m looking for a more rules friendly
approach. Or maybe have separate rules that match on each individual priority
and have the “then” part of each rule call the same function, and
use salience to fire the rules in the desired order? Thanks, Eric From: owner- Eric, OK, I’m very, very new to JESS and rules engines, so
please forgive me for a very basic question. I have read “JESS in
Action” but I’m still stumped on this one. I get that the rules
engine will match all possible facts against my rule(s). I think of it as kind
of an implied iteration, versus a loop in a procedural language. But, I’d
like to have some control over the order in which those facts are applied to my
rule. For example, imagine I have a database of stuff on my wish list. I keep
the name of each item and the price. And I have a rule that will match on all
of the entries in the database, and do something like make a shopping list and
keep a running total. So far, so good. But, I have a limited budget, and an
infinite wish list. So, I want to make sure my rule matches the things I want
the most, first. And this is where I’m stuck. I can add a
“Priority” slot. But, how do I write the rule to match on the
higher priority facts, first? I played with a (not …) statement I saw in
“JESS in Action”, but it doesn’t quite do what I’m
looking for. I may have 3 priority 1 items and I’ll want the rule to
match on all of them, and I might have 2 priority 2 items and I’ll want
to rule to match on both of those. But, I want the rule to match on all of the
priority 1 items before any of the priority 2 items. I pasted my test code
below. I’m sure I just haven’t gotten my mind wrapped around how
you do things in this environment, yet. But, I could use a nudge in the right
direction on this one. Thanks in advance for any suggestions!
|
- JESS: Getting Facts in Sorted Order Eric W. Bonnett
- Re: JESS: Getting Facts in Sorted Order Dusan Sormaz
- RE: JESS: Getting Facts in Sorted Order Eric W. Bonnett
- Re: JESS: Getting Facts in Sorted Order ejfried
- RE: JESS: Getting Facts in Sorted Order Eric W. Bonnett
- Re: JESS: Getting Facts in Sorted Or... ejfried
- RE: JESS: Getting Facts in Sorte... Eric W. Bonnett