FD.distribute never returns and manual constraining fails?
Torsten Anders
torstenanders at gmx.de
Fri Apr 20 18:46:49 CEST 2007
Dear Joshua,
There are a number of problems with your example.
- You never call a solver
- You don't encapsulate your CSP in a script (your proc Dinner is not a
script!)
- You post constraints after calling FD.distribute
...
You may want to read the Finite Domain Constraint Programming tutorial
first (you are actually citing it, so I wonder..).
I also suggest first trying something out in the OPI before writing an
application.
Best,
Torsten
On 20.04.2007, at 17:50, Joshua ben Jore wrote:
> I am having difficulty writing a very simple little constraint
> program. When I use FD.distribute my program stops. When I manually
> set values that haven't been completely constrained yet, I get invalid
> results (unless I *reassert* a constraint).
>
> I'm certain I'm doing something wrong.
>
> {Dinner 20} returns the following where I expect a tuple of unique
> values. This is just ordering the numbers 1..20 by the rules in the
> solver.
>
> dinner(_{1#19} _{2#19} _{3#19} _{4#19} _{5#19} _{6#19} _{7#19} _{8#19}
> _{9#19} _{10#19} _{11#19} _{12#20} _{1#20} _{1#20} _{1#20}
> _{1#20} 1 _{1#19} _{2#20} _{1#20})
>
> If I use FD.distribute then my solver's execution stops. Wha? I don't
> much care *how* it picks solutions, I just want it to pick some
> solutions.
>
> If I try to set all variables to their minimum, I get this invalid
> result. I *hoped* that the range for each variable would adjust as I
> modified other variables they were constrained against. I don't see
> why I have a pile of values all '2'.
>
> dinner(2 3 4 5 6 7 8 9 10 11 12 13 2 2 2 2 1 2 3 2)
>
> If I use that previous loop but reassert FD.distinct then it actually
> finds a solution. Huh? Didn't I already assert FD.distinct? Why should
> I have to reassert it? Did it forget?
>
> Any help understanding my problem would be most appreciated. I have
> read http://www.mozart-oz.org/documentation/fdt/node52.html but don't
> see an immediate application. All my domains are finite and specified
> - they're just not getting solved.
>
> Thanks in advance,
> Josh.
>
> %% Example program follows:
> functor
> import
> Application
> System
> FD
> Property
> Browser
> define
> proc {LeftOf X Y}
> X <: Y
> end
> proc {ImmediatelyLeft X Y}
> X =: Y - 1
> end
> proc {Dinner NumGuests Guests}
> {FD.tuple dinner NumGuests 1#NumGuests Guests}
> {FD.distinct Guests}
>
> %% Guests 1 to 12 sit left of each other with people possibly
> %% between them.
> for L in 1..11 do
> R
> in
> R = L + 1
> {LeftOf Guests.L Guests.R}
> end
>
> %% 17th guest is in seat 1
> Guests.17 =: 1
>
> %% 18 is immediately to the left of 19.
> {ImmediatelyLeft Guests.18 Guests.19}
> end
> Sol
> in
> {Property.put 'print.width' 100}
> {Dinner 20 Sol}
> {Browser.browse Sol}
> {System.show Sol}
>
> %%% Appears to begin waiting for something. What?
> %%{FD.distribute ff Sol}
>
> %%% Also appears to wait for something.
> %% {FD.assign min Sol}
>
> %% Produces invalid results?! At least it finishes. I'm *Sure
> for I in 1..20 do
> Min Max
> in
> %% More than one possible solution for this variable?
> Min = {FD.reflect.min Sol.I}
> Max = {FD.reflect.max Sol.I}
> if Min \= Max then
> Sol.I = Min
> %% Works if I reassert this.
> {FD.distinct Sol}
> end
> end
>
> {System.show Sol}
> {Application.exit 0}
> end
> _______________________________________________________________________
> __________
> mozart-users mailing list
> mozart-users at mozart-oz.org
> http://www.mozart-oz.org/mailman/listinfo/mozart-users
>
>
--
Torsten Anders
Sonic Arts Research Centre • Queen's University Belfast
Frankstr. 49 • D-50996 Köln
Tel: +49-221-3980750
http://strasheela.sourceforge.net
http://www.torsten-anders.de
More information about the mozart-users
mailing list