As long as I'm exploring the similarities between chapter 9 and 12, I
thought I'd try my hand at translating the Suit example from the
relational example into a constraint example. The code below seems to
do the trick, though any suggestions about a more elegant translation
would be appreciated:
%% Encoding: beige=0 coral=1 mauve=2 ochre=3
proc {CPSuit ?Sol}
suit(Shirt Pants Socks) = Sol
Soft Hard
in
Soft::0#1 Hard::2#3
Shirt::0#3 Pants::0#3 Socks::0#3
{FD.distinct Sol}
{FD.disj
{FD.conj Shirt>=:Hard {FD.conj Pants=<:Soft Socks>=:Hard}}
{FD.conj Shirt=<:Soft {FD.conj Pants>=:Hard Socks=<:Soft}}} =: 1
{FD.distribute ff [Shirt Pants Socks]}
end
{ExploreAll CPSuit}
%% Solutions
%% suit(0 2 1) suit(beige mauve coral)
%% suit(0 3 1) suit(beige ochre coral)
%% suit(1 2 0) suit(coral mauve beige)
%% suit(1 3 0) suit(coral ochre beige)
%% suit(2 0 3) suit(mauve beige ochre)
%% suit(2 1 3) suit(mauve coral ochre)
%% suit(3 0 2) suit(ochre beige mauve)
%% suit(3 1 2) suit(ochre coral mauve)
I'm left with a couple of questions though:
First, what's the best way to seamlessly go from an enumeration type
(colors) into integers? Although I've manually encoded the digits, the
code loses sight of what those numbers represent in the original problem
description. I would assume that constraint programming constantly
bumps into problems where one maps sets of widgets into finite numbers
(and then back again).
Second, I tried to encode the disjunction above as:
{FD.disj
{FD.conj Shirt=:Hard {FD.conj Pants=:Soft Socks=:Hard}}
{FD.conj Shirt=:Soft {FD.conj Pants=:Hard Socks=:Soft}}} =: 1
To more closely resemble the nature of the combinations. Unfortunately,
this seems to reject all the combinations. I'm assuming that using the
=: as opposed to comparison operators results in a sort of unification -
whereby the variable gets assigned in the first expression and the
comparison is rejected on the next expression in line. And there
doesn't seem to be a equal-compare type operator (==:). So I'm
wondering how one does a constraint whereby you say that (X == i )
orelse (X== j)? (A non-contiuous domain).
Thanks,
Chris Rathman
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users