Amazing.  ...really.

I get similar (excellent) results by reordering the patterns (half-dollar
first).

At this point (i.e. newbie) I would never have thought to reorder the
patterns within a rule.  I would have thought that the same Rete network
would result regardless of the ordering of the patterns.

Unfortunately, the "bush" analogy didn't quite clear this up for me.  I'm
heading into chapter 8 of JIA now.  Maybe that will help.

Thanks again.
-Mitch

FWIW, I chose not to use the pennies_mod_5 optimization so I could specify
any target amount (i.e. $1.07).

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Behalf Of [EMAIL PROTECTED]
Sent: Monday, August 11, 2003 8:00 PM
To: [EMAIL PROTECTED]
Subject: Re: JESS: Newbie question (Coin puzzle-SOLVED)


I think Win Carus wrote:

> (defrule find-solution
> (coin (denomination penny) (count ?cp) (amount ?ap))
> (test (= 0 (mod ?cp 5)))
> (coin (denomination nickel) (count ?cn) (amount ?an))
> (test (< (+ ?ap ?an) ?*totalAmt*))
> (coin (denomination dime) (count ?cd) (amount ?ad))
> (test (< (+ ?ap ?an ?ad) ?*totalAmt*))
> (coin (denomination quarter) (count ?cq) (amount ?aq))
> (test (< (+ ?ap ?an ?ad ?aq) ?*totalAmt*))
> (coin (denomination half-dollar) (count ?ch) (amount ?ah))
> (test (= (+ ?ch ?cq ?cd ?cn ?cp) ?*coinCount*))
> (test (= (+ ?ah ?aq ?ad ?an ?ap) ?*totalAmt*))
> =>
> (printout t "Solution : " ?cp " pennies, " ?cn " nickels, " ?cd " dimes,
> " ?cq " quarters, " ?ch " half-dollars" crlf))
>

Actually I was already doing that -- here's what mine looks like
(assumes mod 5 for pennies was done during the setup phase:)

(defrule find-solution
  (coin (denomination half-dollar) (count ?ch) (amount ?ah))
  (coin (denomination quarter)
        (count ?cq&:(<= (+ ?cq ?ch) ?*coinCount*))
        (amount ?aq&:(<= (+ ?aq ?ah) ?*totalAmt*)))
  (coin (denomination dime)
        (count ?cd&:(<= (+ ?cd ?cq ?ch) ?*coinCount*))
        (amount ?ad&:(<= (+ ?ad ?aq ?ah) ?*totalAmt*)))
  (coin (denomination nickel)
        (count ?cn&:(<= (+ ?cn ?cd ?cq ?ch) ?*coinCount*))
        (amount ?an&:(<= (+ ?an ?ad ?aq ?ah) ?*totalAmt*)))
  (coin (denomination penny)
        (count ?cp&:(= (+ ?cp ?cn ?cd ?cq ?ch) ?*coinCount*))
        (amount ?ap&:(= (+ ?ap ?an ?ad ?aq ?ah) ?*totalAmt*)))

  =>
  (printout t "Solution : " ?cp " pennies, " ?cn " nickels, " ?cd " dimes, "
            ?cq " quarters, " ?ch " half-dollars" crlf))

50 coins, $1.00: 0.627
50,       $2.00: 0.805
50/$3.00:        1.165
50/$4.00:        1.881
50/$10.00       15.326

---------------------------------------------------------
Ernest Friedman-Hill
Distributed Systems Research        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]
--------------------------------------------------------------------

Reply via email to