Re: [eclipse-users] Domain intersection in lib(ic)

From: Joachim Schimpf (Independent Contractor) <jschimpf_at_cisco.com>
Date: Thu, 10 Jan 2008 23:47:04 +0000
Tallys Yunes wrote:
> Hi,
> 
> I'm trying to figure out what would be the best way to
> do the equivalent of lib(fd)'s dom_intersection/4 in lib(ic).
> Say I want the domain of X to become itself intersected
> with the domain of Y (I'm implementing a constraint propagator).
> 
> I thought of using is_in_domain/2 and exclude/2 from lib(ic_kernel) like this:
> 
> 1) get_domain_as_list(X,Lx)
> 2) for each element E in Lx, if not is_in_domain(Y,E), exclude(X,E).
> 
> Does this look like a good approach?

That would work.

You could also use the following trick, which i would expect to be
faster for larger domains:

?- X :: [1, 2, 5, 6], Y :: [0, 2, 4, 5, 8], copy_term(Y, X).
X = X{[2, 5]}
Y = Y{[0, 2, 4, 5, 8]}
Yes (0.00s cpu)

It creates a copy of Y (without delayed goals) and unifies it with X.


-- Joachim
Received on Thu Jan 10 2008 - 23:47:17 CET

This archive was generated by hypermail 2.2.0 : Thu Feb 02 2012 - 02:31:58 CET