Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > by-pkgid > 2fc07611b08d4a735fd34d5eb60d8e16 > files > 2054

ciao-1.10p8-3mdv2010.0.i586.rpm

<HTML>
<HEAD>
<!-- Created by texi2html 1.56k + clip patches and <A href="http://www.clip.dia.fi.upm.es/Software">lpdoc</A> from ciao.texi on 28 January 2007 -->

<LINK rel="stylesheet" href="ciao.css" type="text/css">
<TITLE>The Ciao Prolog System               - Constraint programming over rationals</TITLE>
</HEAD>
<BODY> 
Go to the <A HREF="ciao_1.html">first</A>, <A HREF="ciao_110.html">previous</A>, <A HREF="ciao_112.html">next</A>, <A HREF="ciao_241.html">last</A> section, <A HREF="ciao_toc.html">table of contents</A>.
<P><HR><P>


<H1><A NAME="SEC457" HREF="ciao_toc.html#TOC457">Constraint programming over rationals</A></H1>
<P>
<A NAME="IDX5466"></A>


<P>
<STRONG>Author(s):</STRONG> Christian Holzbaur, Daniel Cabeza.


<P>
<STRONG>Version:</STRONG> 1.10#7 (2006/4/26, 19:22:13 CEST)


<P>
<STRONG>Version of last change:</STRONG> 1.9#184 (2003/12/5, 14:7:53 CET)


<P>
 


<P>
<STRONG>Note:</STRONG> This package is currently being adapted to the new characteristics of the Ciao module system. This new version now works right now to some extent, but it is under further development at the moment. Use with (lots of) caution. 



<UL>
<LI><A HREF="ciao_111.html#SEC458">Usage and interface (clpq)</A>
<LI><A HREF="ciao_111.html#SEC459">Other information (clpq)</A>
<LI><A HREF="ciao_111.html#SEC461">Known bugs and planned improvements (clpq)</A>
</UL>



<H2><A NAME="SEC458" HREF="ciao_toc.html#TOC458">Usage and interface (<CODE>clpq</CODE>)</A></H2>

<div class="cartouche">

<UL>

<LI><STRONG>Library usage:</STRONG>

<CODE>:- use_package(clpq).</CODE>

or

<CODE>:- module(...,...,[clpq]).</CODE>
</UL>

</div class="cartouche">



<H2><A NAME="SEC459" HREF="ciao_toc.html#TOC459">Other information (<CODE>clpq</CODE>)</A></H2>

<P>
 



<UL>
<LI><A HREF="ciao_111.html#SEC460">Some CLP(Q) examples</A>
</UL>



<H3><A NAME="SEC460" HREF="ciao_toc.html#TOC460">Some CLP(Q) examples</A></H3>

<P>
(Other examples can be found in the source and library directories.) 



<UL>
<LI>'Reversible' Fibonacci (clpq):

</UL>

<P>



<PRE>
:- module(_, [fib/2], []).
:- use_package(clpq).

fib(X,Y):- X .=. 0, Y .=. 0.
fib(X,Y):- X .=. 1, Y .=. 1.
fib(N,F) :-
        N .&#62;. 1,
        N1 .=. N - 1,
        N2 .=. N - 2,
        fib(N1, F1),
        fib(N2, F2),
        F .=. F1+F2.

</PRE>

<P>
 

<UL>
<LI>Matrix multiplication (clpq):

</UL>

<P>



<PRE>
:- use_package(clpq).
:- use_module(library(write)).

mmultiply([],_,[]).
mmultiply([V0|Rest], V1, [Result|Others]):-  
            mmultiply(Rest, V1, Others),
                multiply(V1,V0,Result).

multiply([],_,[]).
multiply([V0|Rest], V1, [Result|Others]):-  
            multiply(Rest, V1, Others),
                vmul(V0,V1,Result).

vmul([],[],0).
vmul([H1|T1], [H2|T2], Result):- 
        vmul(T1,T2, Newresult), 
        Result .=. H1*H2+Newresult.

matrix(1,[[1,2,3,4,5],[4,0,-1,5,6],[7,1,-2,8,9],[-1,0,1,3,2],[1,5,-3,2,4]]).
matrix(2,[[3,2,1,0,-1],[-2,1,3,0,2],[1,2,0,-1,5],[1,3,2,4,5],[-5,1,4,2,2]]).

%% Call with: ?- go(M).

go(M):-
        matrix(1,M1),
        matrix(2,M2), 
        mmultiply(M1, M, M2).

</PRE>

<P>
 

<UL>
<LI>Queens (clpq):

</UL>

<P>



<PRE>
:- use_package(clpq).

queens(N, Qs) :- constrain_values(N, N, Qs), place_queens(N, Qs).

constrain_values(0, _N, []).
constrain_values(N, Range, [X|Xs]) :-
        N .&#62;. 0, X .&#62;. 0, X .=&#60;. Range, 
        N1 .=. N - 1,
        constrain_values(N1, Range, Xs), no_attack(Xs, X, 1).

no_attack([], _Queen, _Nb).
no_attack([Y|Ys], Queen, Nb) :-
        Queen .&#60;&#62;. Y+Nb,
        Queen .&#60;&#62;. Y-Nb,
        Nb1 .=. Nb + 1,
        no_attack(Ys, Queen, Nb1).

place_queens(0, _).
place_queens(N, Q) :- 
        N &#62; 0, member(N, Q), N1 is N-1, place_queens(N1, Q).

</PRE>

<P>
 




<H2><A NAME="SEC461" HREF="ciao_toc.html#TOC461">Known bugs and planned improvements (<CODE>clpq</CODE>)</A></H2>


<UL>

<LI>

clp(Q) and clp(R) cannot be used simultaneously in the same program, or even within the same toplevel session.
</UL>

<P><HR><P>
Go to the <A HREF="ciao_1.html">first</A>, <A HREF="ciao_110.html">previous</A>, <A HREF="ciao_112.html">next</A>, <A HREF="ciao_241.html">last</A> section, <A HREF="ciao_toc.html">table of contents</A>.
</BODY>
</HTML>