<div><div>I couldn'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'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"><<a href="mailto:acorvetto@gmail.com" target="_blank">acorvetto@gmail.com</a>></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 'efficient' (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"><<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>></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) >= Bid.size, price <= Bid.price<br>
(4) Offers must be used in increasing seqno<br>
<br>
Is this complete? I'm going to do implement this now.<br>
<br>
-W<br>
<br>
2010/4/28 Andrés Corvetto <<a href="mailto:acorvetto@gmail.com" target="_blank">acorvetto@gmail.com</a>>:<br>
<div><div></div><div>> The problem with this approach is that a Bid may not always match the head<br>
> of the list, because the price of the head Offer could be higher.<br>
> Given a Bid, I need to match it with the oldest Offer with equal o lower<br>
> price, and that Offer could be in any index of the list.<br>
> (Note that the previous approach did work, just not very efficiently)<br>
> - Andres<br>
> On Wed, Apr 28, 2010 at 6:13 AM, Wolfgang Laun <<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>><br>
> wrote:<br>
>><br>
>> Here is another way of matching Offers first-in first. It is based on<br>
>> a linked list connecting new Offers the way they arrive. You'll need<br>
>> another WME OfferList containing references to the head of the list<br>
>> and to the last element. An unlinked new Offer is added at the end.<br>
>> Matching is now done by looking at the "head" field of the OfferList<br>
>> WME, and a matched Offer is removed from the list. You'll probably<br>
>> need another field in an Offer to indicate the status (new, unmatched,<br>
>> matched) so that you don't get cycles in your loop firings.<br>
>><br>
>> -W<br>
>><br>
>> On Wed, Apr 28, 2010 at 3:43 AM, Andres Corvetto <<a href="mailto:acorvetto@gmail.com" target="_blank">acorvetto@gmail.com</a>><br>
>> wrote:<br>
>> ><br>
>> > Thank you for your answers.<br>
>> ><br>
>> > I tried this approach (which yields much more elegant rules), but i'm<br>
>> > afraid<br>
>> > it does not perform very well.<br>
>> > If I insert 10000 Offers and then 1 bid, it takes too much time to<br>
>> > execute.<br>
>> > If understand correctly it's because of the "not<br>
>> > Offer(creationTimestamp <<br>
>> > $ct)" clause in the LHS, which forces a comparison of every matching<br>
>> > Offer<br>
>> > against every other Offer.<br>
>> ><br>
>> > The motivation for my original post was to find a way of achieving the<br>
>> > results of an accumulator without having to sort all the matching Offers<br>
>> > by<br>
>> > creationTimestamp.<br>
>> > Going back to that first approach (using an accumulator), I found that<br>
>> > Drools feeds the accumulator with the matching Offers in reverse order<br>
>> > (ie,<br>
>> > newest first, LIFO).<br>
>> > Is this a natural consequence of the way facts are stored in the working<br>
>> > memory or is there a way of changing this behaviour (so that oldest are<br>
>> > feeded first, FIFO)?<br>
>> ><br>
>> > Thanks again<br>
>> ><br>
>> > - Andres<br>
>> ><br>
>> > --<br>
>> > View this message in context:<br>
>> > <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>
>> > Sent from the Drools - User mailing list archive at Nabble.com.<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>
>> ><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>
><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>
><br>
><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>