How to create non-numeric constraints in Mozart/Oz?
I want to implement a CSP with the variables' domain being non-numeric (something like [lisa ann m开发者_C百科ary joanna] ). Is there a way to achieve this in Mozart/Oz?
It might be possible to implement such a thing as a language extension in C++, but within the language itself, it is not possible.
The only built-in types of constraints are finite domain constraints (non-negative integers), finite set constraints (constraints on the domain of sets of non-negative ints) and record constraints.
Maybe you can use integer constants to model your problem, e.g.
declare
%% 4 constants
Lisa = 1
Ann = 2
Mary = 3
Joanna = 4
%% N will be the constrained variable
N
in
N::[Lisa Ann Mary Joanna]
{Show N} %% displays N{1#4}, i.e. N is between 1 and 4
N \=: Mary %% tell: N is not Mary
{Show N} %% displays N{1 2 4}, i.e. N is one of 1,2,4
If you don't want to work with finite domains, there is the more general idea of logic programming. You can create choice points for different possible values of a variable, e.g.:
declare
proc {Script A}
A =
choice
lisa
[] ann
[] mary
[] joanna
end
end
{Show {SearchOne Script}} %% displays "[lisa]"
{Show {SearchAll Script}} %% displays "[lisa ann mary joanna]"
It is also possible to do that with a not statically known number of values, using Combinators.
精彩评论