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: Thomas Bourdeaud'huy
Subject: Re: Constraining two vectors to be different
Date: 01 Jul 2003 09:57:16 +0200

Yes, but the problem is that the size of vectors may change with the
applications ...

Is it possible to define a predicate like : 

vectDif([],[]).
vectDif([E1|R1],[E2|R2]):-
        (E1 #\= E2) #\/ vectDif(R1,R2). 

        I have tried but Gprolog doesn't like the second member ...


Or anything defined with a negation : not(Vect1 #= Vect2) for example ? 

Thanks

Thomas
 

Le mar 01/07/2003 à 08:50, LECONTE Jean Michel a écrit :
> 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]