Rule-based sorting is tricky, and while scoring as you describe does
work, it's also a bit messy. The most common way to do this kind of
thing is to pick off the highest ranking item one at a time, marking
or deleting each one that's selected to make it ineligible. If you
have multiple ranking rules, then just write them all as separate
rules and use salience to make them fire in order of priority. You can
have a function in Jess or code in Java to run the engine just long
enough to select a single item, and invoke it as many times as needed.
On Jun 18, 2008, at 12:02 PM, David Coyle wrote:
Hi all:
just a general question regarding sorting arrays of objects. I'm
sure this is a common problem for Jess users, so I thought I'd ask:
Is there a general design pattern for sorting a list when there are
multiple rules, some potentially quite complex, used to perform the
evaluation?
Let's use a real example:
In a warehouse situation, I have a number of orders that need to be
filled, and I have to make sure that the most critical ones are
filled first, considering that we have inventory constraints and not
all orders can be filled.
So I'm wanting to group orders with the same shipping method (not
ship ground today if I only have < 5 ground orders, for example, but
ship ground regardless if I haven't shipped anything ground in the
last 3 days), evaluate priority orders first ("rush" orders),
possibly look ahead to incoming inventory in the next few days, and
not ship accessories before I ship the main product (don't send the
guy his wireless mouse when he won't get the computer for another
week, for example, but do ship it if I know Computers are due in the
warehouse tomorrow). &c &c...
The best approach I have come up with is to create a "score"
attribute on Order, and each rule can add to or subtract from the
base score value.
Then after evaluating them all so that there are no Orders with
equal scores, sort the array on score outside of Jess, in Java.
Any other thoughts?
-dave-
David Coyle, PhD
[EMAIL PROTECTED]
"Entia non sunt multiplicanda praeter necessitatem"
---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences, Sandia National Laboratories
PO Box 969, MS 9012, Livermore, CA 94550
http://www.jessrules.com
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------