<div><div>I couldn&#39;t help myself and started looking at the source code to find the reason for the order in which facts are fed to the accumulator.</div><div>I found that in version 5.1.0 M1, JBRULES-2242 was fixed, which (as a side effect, I guess) changes that order to insertion time, ascending (FIFO). The class that keeps the facts is org.drools.util.RightTupleList.</div>


<div>I don&#39;t know if it is correct to rely on that order, but this could helpful with the accumulator approach again. </div><div><br></div><div>- Andrés</div></div><br><br><div class="gmail_quote">On Wed, Apr 28, 2010 at 2:02 PM, Andrés Corvetto <span dir="ltr">&lt;<a href="mailto:acorvetto@gmail.com" target="_blank">acorvetto@gmail.com</a>&gt;</span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Once again, my lack of knowledge stands in the way... How would you write the rule to perform the skipping?<div><br></div><div>Those requirements look fine, i would add:</div><div>(5) The matching of a Bid should be &#39;efficient&#39; (for example: it should not require to sort all Offers with the right price to match a Bid)</div>




<div><br></div><div>Let me know how it goes. And thank you very much for your time and dedication!</div><div>- Andres</div><div><div></div><div><div><br><div class="gmail_quote">On Wed, Apr 28, 2010 at 12:12 PM, Wolfgang Laun <span dir="ltr">&lt;<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>&gt;</span> wrote:<br>




<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Processing one Bid at a time, the solution is simple: skip offers<br>
exceeding the Bid price.<br>
<br>
If you have multiple Bids, select one (due to whatever) and mark it<br>
with a Token WME.<br>
<br>
This is developing into a very nice demo/exercise. The summary of requirements:<br>
<br>
(1) Bid: price, size<br>
(2) Offer: price, size, seqno<br>
(3) Collect Offer facts so that sum(size) &gt;= Bid.size, price &lt;= Bid.price<br>
(4) Offers must be used in increasing seqno<br>
<br>
Is this complete? I&#39;m going to do implement this now.<br>
<br>
-W<br>
<br>
2010/4/28 Andrés Corvetto &lt;<a href="mailto:acorvetto@gmail.com" target="_blank">acorvetto@gmail.com</a>&gt;:<br>
<div><div></div><div>&gt; The problem with this approach is that a Bid may not always match the head<br>
&gt; of the list, because the price of the head Offer could be higher.<br>
&gt; Given a Bid, I need to match it with the oldest Offer with equal o lower<br>
&gt; price, and that Offer could be in any index of the list.<br>
&gt; (Note that the previous approach did work, just not very efficiently)<br>
&gt; - Andres<br>
&gt; On Wed, Apr 28, 2010 at 6:13 AM, Wolfgang Laun &lt;<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>&gt;<br>
&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; Here is another way of matching Offers first-in first. It is based on<br>
&gt;&gt; a linked list connecting new Offers the way they arrive. You&#39;ll need<br>
&gt;&gt; another WME OfferList containing references to the head of the list<br>
&gt;&gt; and to the last element. An unlinked new Offer is added at the end.<br>
&gt;&gt; Matching is now done by looking at the &quot;head&quot; field of the OfferList<br>
&gt;&gt; WME, and a matched Offer is removed from the list. You&#39;ll probably<br>
&gt;&gt; need another field in an Offer to indicate the status (new, unmatched,<br>
&gt;&gt; matched) so that you don&#39;t get cycles in your loop firings.<br>
&gt;&gt;<br>
&gt;&gt; -W<br>
&gt;&gt;<br>
&gt;&gt; On Wed, Apr 28, 2010 at 3:43 AM, Andres Corvetto &lt;<a href="mailto:acorvetto@gmail.com" target="_blank">acorvetto@gmail.com</a>&gt;<br>
&gt;&gt; wrote:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Thank you for your answers.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; I tried this approach (which yields much more elegant rules), but i&#39;m<br>
&gt;&gt; &gt; afraid<br>
&gt;&gt; &gt; it does not perform very well.<br>
&gt;&gt; &gt; If I insert 10000 Offers and then 1 bid, it takes too much time to<br>
&gt;&gt; &gt; execute.<br>
&gt;&gt; &gt; If understand correctly it&#39;s because of the  &quot;not<br>
&gt;&gt; &gt; Offer(creationTimestamp &lt;<br>
&gt;&gt; &gt; $ct)&quot;  clause in the LHS, which forces a comparison of every matching<br>
&gt;&gt; &gt; Offer<br>
&gt;&gt; &gt; against every other Offer.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; The motivation for my original post was to find a way of achieving the<br>
&gt;&gt; &gt; results of an accumulator without having to sort all the matching Offers<br>
&gt;&gt; &gt; by<br>
&gt;&gt; &gt; creationTimestamp.<br>
&gt;&gt; &gt; Going back to that first approach (using an accumulator), I found that<br>
&gt;&gt; &gt; Drools feeds the accumulator with the matching Offers in reverse order<br>
&gt;&gt; &gt; (ie,<br>
&gt;&gt; &gt; newest first, LIFO).<br>
&gt;&gt; &gt; Is this a natural consequence of the way facts are stored in the working<br>
&gt;&gt; &gt; memory or is there a way of changing this behaviour (so that oldest are<br>
&gt;&gt; &gt; feeded first, FIFO)?<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Thanks again<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; - Andres<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; --<br>
&gt;&gt; &gt; View this message in context:<br>
&gt;&gt; &gt; <a href="http://drools-java-rules-engine.46999.n3.nabble.com/Rule-using-accumulate-tp757311p761181.html" target="_blank">http://drools-java-rules-engine.46999.n3.nabble.com/Rule-using-accumulate-tp757311p761181.html</a><br>





&gt;&gt; &gt; Sent from the Drools - User mailing list archive at Nabble.com.<br>
&gt;&gt; &gt; _______________________________________________<br>
&gt;&gt; &gt; rules-users mailing list<br>
&gt;&gt; &gt; <a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
&gt;&gt; &gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;&gt; &gt;<br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; rules-users mailing list<br>
&gt;&gt; <a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; rules-users mailing list<br>
&gt; <a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;<br>
&gt;<br>
<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br>