This is what in Portuguese we call a "tempest in a glass of water"...
:)

    In fact, the problem is simple once you think about how write a
constraint to give you the largest Price. Using the "not" CE will help you
on this matter:

rule "Price Product rule using price length"
  when
      $s : Product ( $productLength : length > 0)
      $price : Price( $priceLength : length <= $productLength )
      not Price( length > $priceLength, length <= $productLength )
  then
      $s.setAmount($s.getAmount() + $price.getAmount());
      $s.setLength($s.getLength() - $priceLength.intValue());
      modify($s);
end

  So the above rule is saying: match a Product with a Price, in a way that
does NOT exist another Price whose length is greater than the matched Price,
but still less or equal to the Product length. In other words, match a
Product with the Price with the greatest length but still less or equal to
the Product length.

  Hope it helps.

  Regards,
      Edson

2007/5/11, Mark Proctor <[EMAIL PROTECTED]>:

Interesting problem, you want dyanmic prioritisation based upon the
value of a field. We have no declarative sugar for this, but it might
make a nice use case. We could allow someone to specify an expression
that determine a value of priority.
    salience = ($price.length);

That would allow for some interesting situations. Its unlikely this will
make 4.0 - but the solution interests me enough that if I get bored, I
might just do it ;)

Until that time I think you'll have to use some combination of a
command/semaphore object and additional rules.

Mark

Maxime wrote:
> Hello,
>
> I'm trying to find how to manage priority within a rule.  Let me
> explain the problem. I'll try to be as clear as possible but bear with
> me since I am new to rules.
> We have two objects, the Product is the object I'm trying to price and
> the object Price is the one that knows all the prices. Both products
> and prices have fields amount and length.  Product amount is
> initialized to 0 and prices are going to determine the product amount
> depending on its length.
>
> Let's see an example :
>
> Product : P -> length = 5, amount = 0
> Price : P1  -> length = 1, amount = 50
> Price : P2  -> length = 3, amount = 100
>
> With this configuration, after asserting the 3 objects to the WM, the
> amount field of Product P should have a value of 200 ( 1*100 + 2*50)
> because the price with the greatest length should be favored over the
> other ones.
>
> Here is the rule I made :
>
> rule "Price Product rule using price length"
>    when
>        $s : Product (length > 0)
>        $price : Price($length: length)
>    then
>        $s.setAmount($s.getAmount() + $price.getAmount());
>        $s.setLength($s.getLength() - $length.intValue());
>        modify($s);
> end
>
> This is obviously wrong because it always takes the first asserted
> price object.  I don't know how to make a rule which would take the
> amount of the price object with the greatest length in priority.
>
> Any help would be very much appreciated.
>
> Cheers,
>
> Max
>
> _______________________________________________
> rules-users mailing list
> [email protected]
> https://lists.jboss.org/mailman/listinfo/rules-users
>

_______________________________________________
rules-users mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/rules-users




--
 Edson Tirelli
 Software Engineer - JBoss Rules Core Developer
 Office: +55 11 3529-6000
 Mobile: +55 11 9287-5646
 JBoss, a division of Red Hat @ www.jboss.com
_______________________________________________
rules-users mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/rules-users

Reply via email to