View source with raw comments or as raw
    1/*
    2
    3    Part of CLP(Q) (Constraint Logic Programming over Rationals)
    4
    5    Author:        Leslie De Koninck
    6    E-mail:        Leslie.DeKoninck@cs.kuleuven.be
    7    WWW:           http://www.swi-prolog.org
    8		   http://www.ai.univie.ac.at/cgi-bin/tr-online?number+95-09
    9    Copyright (C): 2006, K.U. Leuven and
   10		   1992-1995, Austrian Research Institute for
   11		              Artificial Intelligence (OFAI),
   12			      Vienna, Austria
   13
   14    This software is based on CLP(Q,R) by Christian Holzbaur for SICStus
   15    Prolog and distributed under the license details below with permission from
   16    all mentioned authors.
   17
   18    This program is free software; you can redistribute it and/or
   19    modify it under the terms of the GNU General Public License
   20    as published by the Free Software Foundation; either version 2
   21    of the License, or (at your option) any later version.
   22
   23    This program is distributed in the hope that it will be useful,
   24    but WITHOUT ANY WARRANTY; without even the implied warranty of
   25    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   26    GNU General Public License for more details.
   27
   28    You should have received a copy of the GNU Lesser General Public
   29    License along with this library; if not, write to the Free Software
   30    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
   31
   32    As a special exception, if you link this library with other files,
   33    compiled with a Free Software compiler, to produce an executable, this
   34    library does not by itself cause the resulting executable to be covered
   35    by the GNU General Public License. This exception does not however
   36    invalidate any other reasons why the executable file might be covered by
   37    the GNU General Public License.
   38*/
   39
   40:- module(clpq,
   41	  [ {}/1,
   42	    maximize/1,
   43	    minimize/1,
   44	    inf/2, inf/4, sup/2, sup/4,
   45	    bb_inf/3,
   46	    bb_inf/4,
   47	    ordering/1,
   48	    entailed/1,
   49	    clp_type/2,
   50	    dump/3
   51	  ]).   52:- license(gpl_swipl, 'CLP(Q)').   53:- use_module(library(dialect)).   54:- expects_dialect(swi).   55
   56%
   57% Don't report export of private predicates from clpq
   58%
   59:- multifile
   60	user:portray_message/2.   61
   62:- dynamic
   63	user:portray_message/2.   64%
   65user:portray_message(warning,import(_,_,clpq,private)).
   66
   67:- use_module([ clpq/bb_q,
   68		clpq/bv_q,
   69		clpq/fourmotz_q,
   70		clpq/ineq_q,
   71		clpq/itf_q,
   72		clpq/nf_q,
   73		clpq/store_q,
   74		clpqr/class,
   75		clpqr/dump,
   76		clpqr/geler,
   77		clpqr/itf,
   78		clpqr/project,
   79		clpqr/redund,
   80		library(ugraphs)
   81	      ]).   82
   83:- use_module(clpqr/ordering, [ordering/2]).
 ordering(+Spec) is det
Specify the preferred variable ordering of answer constraints. A variable that comes first in Spec is the one the answer constraint defines, i.e. the one on its left hand side. Spec is either a list of variables or a term A<B or A>B. As ordering/1 interns variables the solver does not know yet, it may be stated before or after the constraints it talks about.
   94ordering(Spec) :-
   95	ordering(clpq, Spec).
   96
   97		 /*******************************
   98		 *	       SANDBOX		*
   99		 *******************************/
  100
  101:- multifile
  102	sandbox:safe_primitive/1.  103
  104sandbox:safe_primitive(clpq:ordering(_)).
  105
  106		 /*******************************
  107		 *	 TOPLEVEL PRINTING	*
  108		 *******************************/
  109
  110:- multifile
  111	prolog:message/3.  112
  113prolog:message(query(YesNo,Bindings)) --> !,
  114	{dump_toplevel_bindings(Bindings,Constraints)},
  115	dump_format(Constraints),
  116        '$messages':prolog_message(query(YesNo,Bindings)).
  117
  118dump_toplevel_bindings(Bindings,Constraints) :-
  119	dump_vars_names(Bindings,[],Vars,Names),
  120	dump(Vars,Names,Constraints).
  121
  122dump_vars_names([],_,[],[]).
  123dump_vars_names([Name=Term|Rest],Seen,Vars,Names) :-
  124	(   var(Term),
  125	    (   get_attr(Term,clpqr_itf,_)
  126	    ;   get_attr(Term,clpqr_geler,_)
  127	    ),
  128	    \+ memberchk_eq(Term,Seen)
  129	->  Vars = [Term|RVars],
  130	    Names = [Name|RNames],
  131	    NSeen = [Term|Seen]
  132	;   Vars = RVars,
  133	    Names = RNames,
  134	    Seen = NSeen
  135	),
  136	dump_vars_names(Rest,NSeen,RVars,RNames).
  137
  138dump_format([]) --> [].
  139dump_format([X|Xs]) -->
  140	['{~w}'-[X], nl],
  141	dump_format(Xs).
  142
  143memberchk_eq(X,[Y|Ys]) :-
  144	(   X == Y
  145	->  true
  146	;   memberchk_eq(X,Ys)
  147	)