This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/CHR/chr/examples/leq.pl
vsc e5f4633c39 This commit was generated by cvs2svn to compensate for changes in r4,
which included commits to RCS files with non-trunk default branches.


git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@5 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
2001-04-09 19:54:03 +00:00

49 lines
1.1 KiB
Prolog

% simple constraint solver for inequalities between variables
% thom fruehwirth ECRC 950519, LMU 980207, 980311
:- use_module( library(chr)).
handler leq.
constraints leq/2.
% X leq Y means variable X is less-or-equal to variable Y
:- op(500, xfx, leq).
reflexivity @ X leq X <=> true.
antisymmetry @ X leq Y , Y leq X <=> X=Y.
idempotence @ X leq Y \ X leq Y <=> true.
transitivity @ X leq Y , Y leq Z ==> X leq Z.
/*
% more efficient, less propagating version using pragma passive
reflexivity @ X leq X <=> true.
antisymmetry @ X leq Y , Y leq X # Id <=> X=Y pragma passive(Id).
idempotence @ X leq Y # Id \ X leq Y <=> true pragma passive(Id).
transitivity @ X leq Y # Id , Y leq Z ==> X leq Z pragma passive(Id).
*/
% this generates a circular leq-relation chain with N variables
time(N):-
cputime(X),
length(L,N),
genleq(L,Last),
L=[First|_],
Last leq First,
cputime( Now),
Time is Now-X,
write(N-Time), nl.
genleq([Last],Last).
genleq([X,Y|Xs],Last):-
X leq Y,
genleq([Y|Xs],Last).
cputime( Ts) :-
statistics( runtime, [Tm,_]),
Ts is Tm/1000.
% eof handler leq -----------------------------------------------