I suggest the following: 1) Prove to yourself that the demand objects are in working memory. Write a simple rule that matches only on a demand object and prints out the priority. If this simple rule does not fire, you probably have not definstanced the Demand objects .
2) You may also be suffering from typos. I suspect that (demandPool (demands $? ?demand $?))(OBJECT ?demandPool) (demand (cusPriority 1|2) )(OBJECT ?demand) should be (demandPool (demands $? ?demand $?)(OBJECT ?demandPool)) (demand (cusPriority 1|2)(OBJECT ?demand)) --Jack -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of [EMAIL PROTECTED] Sent: Sunday, July 18, 2004 11:59 AM To: [EMAIL PROTECTED] Subject: Re: JESS: writing priorities I think bhaskar yallala wrote: > These lines > > (demandPool (demands $? ?demand $?))(OBJECT ?demandPool) > > (demand (cusPriority 1|2) )(OBJECT ?demand) > are in rule. > But some how rules doesnt get fired although I have demands with cusPriority 1 and 2. > There are an uncountable number of reasons why this might be so; the demands may not actually be in working memory; the data type of "cusPriority" may not be "int"; the high-priority demands may not be in a "demands" slot; there may be other patterns on this rules LHS which don't match -- any many more possible reasons. > Secondly, I liked your suggestion. I am definitely going to > implement it. But now, I am just kind of prototyping the problem and > want to see whether I can do this simple way in JESS. > I guess you are suggesting to put the demands in loop for one > priority and process. But the thing is I can have more than three > properties which needs to be prioritized like customerPriority, > customerRating, costFactor so on. I want to match demand with best > of all these priorities. If I write loops for all three its going > to be complicated. And there is no fixed costFactor, it can be any > value >0. Basically I want to get demand with maximum of > costFactor. There are many different ways to solve your problem. Part of the issue is that you're trying to solve a complicated problem and simultaneously learn the tools you're using, and without (it appears) a detailed analysis of the problem domain. To solve this using rules, you'll need to better understand what a rule engine can do, better understand what you're trying to accomplish, and better understand the mechanics of using Jess itself. We can give you all sorts of hints and suggestions, but when it comes down to it, you're going to have to understand all this stuff yourself. My first suggestion was in the form of a loop because that's very easy for people new to rules to understand. Other possible algorithms could look like sorting. For example, in this rule, "priority" is a function that computes a numeric priority score for a demand: (defrule process-highest-priority-demand-1 (demand (OBJECT ?d1)) (not (demand (OBJECT ?d2&:(> (priority ?d2) (priority ?d1))))) => ;; ?d1 is the highest-priority demand Or, if instead it's easier to write a function that compares two demands: (defrule process-highest-priority-demand-2 (demand (OBJECT ?d1)) (not (demand (OBJECT ?d2&:(higher-priority ?d2 ?d1)))) => ;; ?d1 is the highest-priority demand Both of these are basically naive sorts; they potentially have n^2 performance in the number of demands. > This looks to me like more like procedural > programming. I can write loops in java better. > Does rule engine solve these kind of problems in simpe way? > If a problem has a simple procedural solution then solve it in a procedural way. Declarative (rule-based) programming is best suited to problems that don't have obvious efficient procedural solutions. You could use a "heap-based priority queue", a data structure that would let you very efficiently, repoeatedly select the highest-priority demand. Now, it may be that the "priority" and "higher-priority" functions I used above a complicated, and if so, then using a priority queue implemented in Java which used a rule-based comparison function might be a very interesting solution to your problem -- i.e., perhaps you could use a set of rules to decide which of two demands has a higher priority. --------------------------------------------------------- Ernest Friedman-Hill Science and Engineering PSEs Phone: (925) 294-2154 Sandia National Labs FAX: (925) 294-2234 PO Box 969, MS 9012 [EMAIL PROTECTED] Livermore, CA 94550 http://herzberg.ca.sandia.gov -------------------------------------------------------------------- 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] -------------------------------------------------------------------- -------------------------------------------------------------------- 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] --------------------------------------------------------------------