Re: copy variables including their constraints

From: Joachim Schimpf <>
Date: Thu 24 Apr 2003 03:40:51 PM GMT
Message-ID: <>
Sorry for the late reply...

Ulrich Scholz wrote:
>  Dear all,
> I'm using ECLiPSe (5.5) constraints and would like to be able to copy
> constrained variables including their constraints, eg
> :- X ~= Y, magic_copy([X, Y], [A, B]), A = B.
> should fail.  Hereby, ~= is imported from notinstance.
> Unfortunately, copy_term does not copy constraints,

Let's say "fortunately" it doesn't copy constraints :-)
Don't forget that constraint networks are usually totally connected,
so you would end up copying your whole constraint store every time.

Ideally, of course, you would like to create some kind of projection
of the constraints onto the variables that you copy. However,
projection algorithms are only known for certain special forms
of constraint sets, so this is not something the system can do

It is a conscious decision that copy_term/2 does not copy everything
attached to the variables. What gets copied are conceptually the
"unary constraints" on the variables, e.g. the domain in the case of fd.

> therefore
> :- X ~= Y, copy_term([X, Y], [A, B]), A = B.
> succeeds.  I guess, there is no such "magic_copy" in the ECLiPSe constraint
> solver.  Or is it?  It could well be that I missed it.  Then I would
> appreciate a hint.

I do not recommend using this seriously (for the reasons given above),
but for a quick experiment you can try:

magic_copy(Orig, Copy) :-
	shelf_get(S, 1, Copy),

> My first try to implement magic_copy is to keep all constraints in an explicit
> way.  Then they are copied along with the variables and called afterwards.
> For example
> :-  X ~= Y, C =.. [~=,X,Y], copy_term([X,Y,C], [A,B,C2]), call(C2), A = B.
> fails as desired.  Is there a better way?

If you can collect the constraints in that way, this is probably the
best solution. You might not need to list all individual constraints,
you just need one goal that sets them all up:

?-  setup_cstr(Vars),
    copy_term(Vars-setup_cstr(Vars), VarsCopy-GoalCopy),

Side remark: In your code above, you don't need the =..
just write  C = (X ~= Y)

> If not, I wonder if is it beneficial to filter out those constraints that use
> none of the copied variables or not.  Is there a large overhead of calling
> constraints that are already called?  For example, would it help a lot to
> filter out Z1~=Z2 before copying the variables in the following example?
> :- X~=Y, C1=..[~=,X,Y],Z1~=Z2,C2=..[~=,Z1,Z2],Cs=(C1,C2),
>    copy_term([X,Y,Cs],[A,B,Cs2]),call(Cs2),A=B.

I would expect it helps.

 Joachim Schimpf              /             phone: +44 20 7594 8187
 IC-Parc                     /
 Imperial College London    /
Received on Thu Apr 24 16:41:02 2003

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