I think Mitch Christensen wrote: > FYI, Making $10.00 in 100 coins took over an hour, and consumed >125meg RAM, > but suceeded just fine. >
Just as in any language, you can optimize programs written in the Jess language. Two simple, obvious, but powerful optimizations for this program: 1) All possible solutions must have the number of pennies divisible by 5; therefore, the (coin) facts that denote other quantities aren't needed. If you modify the setup code to not emit them, the program goes from a hour's runtime down to (on my machine) about 3:40, and it fits into the default 64M heap. But we're not through... 2) This one's a little harder to explain. We originally wrote the rule with the "pennies" pattern at the top; if you think of a sort of decision tree of possiblities, this makes the tree very bushy at the root. If instead, we make it bushier at the leaves, there's more commonality in the matches along those thick lower branches; this represents sharing of Java objects, hence lower memory consumption, hence better performance. By flipping the rule upside down so the half-dollar pattern is first, followed by quarter, etc, the time drops in half again, down to 1:46, for a total improvement of well over 30:1. (Talking about this problem has been fun!) --------------------------------------------------------- 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] --------------------------------------------------------------------