Re: JESS: agenda change in Jess 7.0 and custom Strategies
A good technical question! The method listActivations() is not used internally by Jess; it's just provided for use by tools of various kinds. It's a fairly expensive method because it makes a copy of the whole agenda, and iterating over this copy does a full sort. The copy is necessary; the process of iterating over all the activations is destructive. They're not kept in sorted order -- they're pulled out "just in time." Anyway concern over using == vs equals() may be misplaced -- this is a small difference compared to the overall expense of copying the whole agenda. This much has always been true. What's changed in 7.0 is that an Activation object can't be part of more than one agenda at a time, because the Activation "knows" where in the agenda it lies. In older versions, the same Activation objects would live in the copied agenda as in the original; now copies are made of all the Activations, too. This new property of Activation objects is an optimization; it makes the process of removing activations from the agenda before firing them (due to a retraction, for example) much more efficient. I thought of this as an internal implementation detail and so didn't document it, but the change is permanent. On Dec 2, 2006, at 8:07 PM, Jonathan Sewall wrote: I've found that the method below behaves differently in Jess 7.0b7 and the formal v7.0 release. In the formal release, the Activations provided by the Iterator in 2 successive calls to Rete.listActivations() are different objects, even if nothing has happened between the calls. The change has ramifications for those with custom Strategy implementations. In our case, we scan the agenda for a particular Activation to favor before calling run(), and then our Strategy's compare() method tests its arguments for that object with the == operator. We can, with some impact on performance (presumably negligible on short agendas), use the Activation.equals() method instead of the == operator. But I wanted to ask about the intent of the change, and whether it's likely to be permanent. I hadn't seen (but could have simply missed) mention of it in the notes since beta 7. Thanks very much, Jonathan public void dumpAgenda(String label) { Map actMap = new HashMap(); Iterator it = listActivations(); // get the agenda and store Activations for (int i = 0; it.hasNext(); ++i) { Activation a = (Activation) it.next(); actMap.put(new Integer(a.hashCode()), a); } it = listActivations(); // get the agenda again; no intervening activity for (int i = 0; it.hasNext(); ++i) { Activation a = (Activation) it.next(); Activation aa = (Activation) actMap.get(new Integer (a.hashCode())); System.out.println("agenda a["+i+"]"+ (aa == null ? " not" : "")+" in map,"+ // aa ! = null in both v7.0b7 and 7.0 (a == aa ? "" : " not")+ " same obj"); // aa == a only in v7.0b7 } } 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 owner-jess- [EMAIL PROTECTED] - Ernest Friedman-Hill Advanced Software Research Phone: (925) 294-2154 Sandia National LabsFAX: (925) 294-2234 PO Box 969, MS 9012 [EMAIL PROTECTED] 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]
JESS: agenda change in Jess 7.0 and custom Strategies
I've found that the method below behaves differently in Jess 7.0b7 and the formal v7.0 release. In the formal release, the Activations provided by the Iterator in 2 successive calls to Rete.listActivations() are different objects, even if nothing has happened between the calls. The change has ramifications for those with custom Strategy implementations. In our case, we scan the agenda for a particular Activation to favor before calling run(), and then our Strategy's compare() method tests its arguments for that object with the == operator. We can, with some impact on performance (presumably negligible on short agendas), use the Activation.equals() method instead of the == operator. But I wanted to ask about the intent of the change, and whether it's likely to be permanent. I hadn't seen (but could have simply missed) mention of it in the notes since beta 7. Thanks very much, Jonathan public void dumpAgenda(String label) { Map actMap = new HashMap(); Iterator it = listActivations(); // get the agenda and store Activations for (int i = 0; it.hasNext(); ++i) { Activation a = (Activation) it.next(); actMap.put(new Integer(a.hashCode()), a); } it = listActivations(); // get the agenda again; no intervening activity for (int i = 0; it.hasNext(); ++i) { Activation a = (Activation) it.next(); Activation aa = (Activation) actMap.get(new Integer(a.hashCode())); System.out.println("agenda a["+i+"]"+ (aa == null ? " not" : "")+" in map,"+ // aa != null in both v7.0b7 and 7.0 (a == aa ? "" : " not")+ " same obj"); // aa == a only in v7.0b7 } } 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]
Re: JESS: A problem with accumulate
On Dec 2, 2006, at 2:28 AM, Skeptic 2000 wrote: Hi, I have a serious problem with accumulate, I wanted to use it on some shadow facts, but I noticed that I can't have more than one "contained CE". Yes, that's a limitation of the current implementation; it should be lifted for Jess 7.1. Something like (modifed from the manual): ?c <- (accumulate (bind ?list (new java.util.ArrayList)) (?list add ?o) ?list (employee (OBJECT ?o)) (test (?o xyzMethod "arg1")) ; <- that can't work if I understand correctly :( => (printout t (?c toString) crlf)) In this case, there would be no problem with just adding the call to xyzMethod to the employee CE directly -- i.e., (employee (OBJECT ?o&:(?o xyzMethod "arg1"))) --- Ernest Friedman-Hill Advanced Software Research Phone: (925) 294-2154 Sandia National LabsFAX: (925) 294-2234 PO Box 969, MS 9012 [EMAIL PROTECTED] 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]
JESS: A problem with accumulate
Hi,I have a serious problem with accumulate, I wanted to use it on some shadow facts, but I noticed that I can't have more than one "contained CE".I would need to use a "Time-varying method" (OBJECT) and a test-CE in the matching part of the Accumulate... Something like (modifed from the manual): ?c <- (accumulate (bind ?list (new java.util.ArrayList)) (?list add ?o) ?list (employee (OBJECT ?o))(test (?o xyzMethod "arg1")) ; <- that can't work if I understand correctly :( => (printout t (?c toString) crlf)) This causes me some serious trouble, so I'll hope there is a way to deal with it. Thanks again ! _ Soyez parmi les premiers à essayer Windows Live Mail. http://ideas.live.com/programpage.aspx?versionId=5d21c51a-b161-4314-9b0e-4911fb2b2e6d