Chris, Take some time to read the Finite Domain Constraint Programming Tutorial ( http://www.mozart-oz.org/documentation/fdt/index.html). It is well written, and you will find many answers there.
Here are quick answers to your questions: On Tue, Apr 14, 2009 at 4:45 AM, Chris Rathman <[email protected]>wrote: > 1). If I have a list of constraint variables, is there a shorter way to > define that the variables involve a decreasing value? In project euler > problem #240, there are five 6-sided dice (sides numbered 1 to 6) that can > be rolled so that the top three sum to 15. (I've already solved problem > #240, it just gets to be long when we have twenty 12-sided dice). > > proc {TopDiceFiveSix ?Sol} > D01|D02|D03|D04|D05|nil = Sol > in > D01::1#6 D02::1#6 D03::1#6 D04::1#6 D05::1#6 > > This is just as good: Sol ::: 1#6 > > D01 + D02 + D03 =: 15 > > % This is the relations what I want to describe in shorthand??? > D01>=:D02 > D01>=:D03 D02>=:D03 > D01>=:D04 D02>=:D04 D03>=:D04 > D01>=:D05 D02>=:D05 D03>=:D05 D04>=:D05 > > Use a for loop on the list Sol: {List.forAllTail Sol proc {$ X|T} for Y in T do X >=: Y end end} In the specific case above, I don't think that the redundant constraints bring much performance. I suspect the following is good enough: for X in Sol Y in Sol.2 do X >=: Y end Note that propagation will really improve if you use '>:' instead of '>=:', but I don't know whether strict decrease is what the problem asks. > > {FD.distribute split Sol} > end > > 2). If I have a list of constraint variables, is it possible to define > that not of the values can be equal? In project euler problem #68, we have > the following "magic" 3-gon ring, filled with the numbers 1 to 6, and each > line adding to nine. (I've also already solved problem #68, but it too gets > to be long when dealing with a five-gon). > > proc {ThreeGonRing ?Sol} > XA#RA#RB # XB#RB#RC # XC#RC#RA = Sol > in > RA::1#6 RB::1#6 RC::1#6 > XA::1#6 XB::1#6 XC::1#6 > > % none of the nodes is equal (should be a shorthand for this???) > RA\=:RB RB\=:RC RC\=:XA XA\=:XB XB\=:XC > RA\=:RC RB\=:XA RC\=:XB XA\=:XC > RA\=:XA RB\=:XB RC\=:XC > RA\=:XB RB\=:XC > RA\=:XC > > There is a propagator made just for that: {FD.distinct [RA RB RC XA XB XC]} > % each line adds to n > XA + RA + RB =: XB + RB + RC > XB + RB + RC =: XC + RC + RA > > % Working clockwise, starting from the group of three with the > numerically lowest external node > XA <: XB > XA <: XC > > {FD.distribute split Sol} > end > > Cheers, raph
_________________________________________________________________________________ mozart-users mailing list [email protected] http://www.mozart-oz.org/mailman/listinfo/mozart-users
