Re: lost access to domain variables?

From: Warwick Harvey <>
Date: Fri 31 May 2002 08:22:43 PM GMT
Message-ID: <>
Hi Sebastian,

On Wed, May 29, 2002 at 09:20:06PM -0400, Sebastian Sardina wrote:
> One easy way would be to make X, Y and Z arguments of b/0 so I would use
> b/3 instead, and then I can do the query: 
> -? b(X,Y,Z), labeling([X,Y,Z]). Is there any other way so that I can
> keep my b/0? Since the pending constraints are stored in a kind of
> database constraints,  maybe there is some tool to retrive all "pending"
> variables....

As Marco points out, you can use delayed_goals/1, etc.  However, I'd
recommend against doing that on software engineering grounds.  Not all
variables appearing in delayed goals will be finite domain variables,
you have no way of knowing which of the delayed goals are "yours", and your
program is too easy to break accidentally.  For example, suppose you wanted
to extend your program by introducing a new top-level goal which set up some
constraints, solved the original problem, and then went on to do something
else: you'd be trying to label the variables from the new top-level goal as
well as those from the original problem, which is not what you want.

The right way is to do as you suggest: keep track of the variables yourself
(e.g. by passing a list of variables out of the predicate), and then
labelling those variables.  A typical top-level of a constraint program
might look something like this:

solve(Vars) :-

where model/1 sets up the variables, etc., constrain/1 sets up the
constraints between the variables, and search/1 searches for a solution.  Of
course it can be more complicated than that, and you can have multiple sets
of variables, other data being passed around, etc. (and the variables don't
have to be in a list, they could be in a matrix or some other structure),
but I think you get the general idea.

Received on Fri May 31 21:22:56 2002

This archive was generated by hypermail 2.1.8 : Wed 16 Nov 2005 06:07:14 PM GMT GMT