All, I'm learning Jess and I've a little problem that I don't know exactly how to solve, and Jess may not even be the ideal tool... I guess that some of you out there have worked on a problem similar to this one before. (deftemplate A (slot initialQty) ;; [any number, inside the range or not, ] (slot cummulativeQtyChange) ;; [initially 0, totalQty=initialQty+cummulativeQtyChange)] (slot priority) ;;[varies from -10 to 10] (slot lowerLimit) (slot upperLimit) (slot targetQty)) In Jess terms, I need to know: 1 - what is the difference between the priority for a fact f and the highest priority among all facts of type A which have totalQty less than targetQty. - note that in the above template, only the values in cummulativeQtyChange slots change over time. All others slot values are fixed during the run. 2 - how to process the facts in descending order of the absolute value of priority (eg. A(priority 10), A(p -7), A(p 6), ...); 3 - how to ensure that all facts that fire a rule are executed in a circular order, instead of repeatedly. In other words, how to avoid (fact-1, fact-1, fact-1, fact-2, ...). I'd prefer a cyclic execution sequence (fact-1, fact-2, fact-3, fact-1, ...), or even facts processed in a random order. Here is some additional info. The idea is to balance all facts, with quantities between their respectives ranges, as close as possible to their targetQty, and as fairly as possible according to the priority of each fact. In the actual problem, there are a number of rules/constraints that need to be satisfied, but to keep it simple: - excess quantities are removed from a fact and added to a common bucket; - deficits are covered using the quantity available in the common bucket; - the adjustments take in account the absolute size of the excess/deficit and the priority, i,e, the adjustment corresponds to a certain percentage of the excess/deficit, to avoid a single fact dominating all transfers (loosing it all at once, or winning it all at once), so that all facts have a "fair go" (hence question 3 above); - the speed of convergence towards the target is the (priority)% of the deficit/excess, for each time the rule is fired; - low priority facts may go below their target to contribute towards reducing deficits in high priority facts, depending on the differences of priorities between the 2 facts (hence question 1). - quantities of facts with negative priorities can only go down. - deficits in low positive priorities can be covered by excesses in higher priority facts. - the rules are grouped with appropriate saliences. - there is no need for a perfect solution that satisfies all range/target constraints, so the music stops when the size of each transfer is below a certain threshold. Your suggestions and pointers to relevant examples are very much welcome. Many thanks Ismael --------------------------------------------------------------------- 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] ---------------------------------------------------------------------
