users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Constraining two vectors to be different


From: LECONTE Jean Michel
Subject: Re: Constraining two vectors to be different
Date: Tue, 1 Jul 2003 08:50:01 +0200
User-agent: Internet Messaging Program (IMP) 3.0

try 

vectDif([A,B],[C,D]):- 
        (A#\= C) #\/ (B #\=D ). % means A not equal to C OR B not equal to D

notIn(_,[]):-!. 
notIn(E,[E1|List]):- 
        vectDif(E,E1), 
        notIn(E,List). 

tousDif([_]):-!. 
tousDif([E|List]):- 
        notIn(E,List), 
        tousDif(List). 



but here you have to represent a vector as a list of two elements
Jean Michel LECONTE
ENI de Brest


Quoting Thomas Bourdeaud'huy <address@hidden>:

> Hi, I'm using the FD solver,
> and  try to define the predicate allDiferent(List_Of_Vectors)
> I use this predicate not to verify that all the vectors are different,
> but to constrain the variables of these vectors not to allow them to be
> equals...
> 
> I know that \= and #\=# exist, but i defined :
> 
> vectDif(E1,E2):-
>       \=(E1,E2).
> 
> notIn(_,[]):-!.
> notIn(E,[E1|List]):-
>       vectDif(E,E1),
>       notIn(E,List).
> 
> tousDif([_]):-!.
> tousDif([E|List]):-
>       notIn(E,List),
>       tousDif(List).
> 
> And tested : 
> 
> tousDif([[1,2],[3,4]]).
> yes
> 
> tousDif([[1,2],[X,4]]).
> yes
> 
> tousDif([[1,2],[X,2]]).
> no
> 
> The last result is not the one i needed : i just wanted to make X <>
> 1...
> 
> If I use  #\= or #\=# in the definition of vectDif, the results are : 
> 
> tousDif([[1,2],[3,4]]).      
> uncaught exception: error(type_error(fd_evaluable,[1,2]),(#\=)/2)
> 
> tousDif([[1,2],[X,4]]).      
> uncaught exception: error(type_error(fd_evaluable,[1,2]),(#\=)/2)
> 
> What's wrong with my implementation ? Is there a 'dif' function in GNU
> Prolog ? 
> 
> Thanks, 
> 
> Thomas Bourdeaud'huy
> Ecole Centrale de Lille







reply via email to

[Prev in Thread] Current Thread [Next in Thread]