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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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	[
42	    {}/1,
43	    maximize/1,
44	    minimize/1,
45	    inf/2, inf/4, sup/2, sup/4,
46	    bb_inf/3,
47	    bb_inf/4,
48	    ordering/1,
49	    entailed/1,
50	    clp_type/2,
51	    dump/3%, projecting_assert/1
52	]).
53
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:- load_files(
68	[
69	    'clpq/bb_q',
70	    'clpq/bv_q',
71	    'clpq/fourmotz_q',
72	    'clpq/ineq_q',
73	    'clpq/itf_q',
74	    'clpq/nf_q',
75	    'clpq/store_q',
76	    'clpqr/class',
77	    'clpqr/dump',
78	    'clpqr/geler',
79	    'clpqr/itf',
80	    'clpqr/ordering',
81	    'clpqr/project',
82	    'clpqr/redund',
83	    library(ugraphs)
84	],
85	[
86	    if(not_loaded),
87	    silent(true)
88	]).
89
90		 /*******************************
91		 *	 TOPLEVEL PRINTING	*
92		 *******************************/
93
94:- multifile
95	prolog:message/3.
96
97% prolog:message(query(YesNo)) --> !,
98% 	['~@'-[chr:print_all_stores]],
99%         '$messages':prolog_message(query(YesNo)).
100
101prolog:message(query(YesNo,Bindings)) --> !,
102	{dump_toplevel_bindings(Bindings,Constraints)},
103	{dump_format(Constraints,Format)},
104	Format,
105        '$messages':prolog_message(query(YesNo,Bindings)).
106
107dump_toplevel_bindings(Bindings,Constraints) :-
108	dump_vars_names(Bindings,[],Vars,Names),
109	dump(Vars,Names,Constraints).
110
111dump_vars_names([],_,[],[]).
112dump_vars_names([Name=Term|Rest],Seen,Vars,Names) :-
113	(   var(Term),
114	    (   get_attr(Term,itf,_)
115	    ;   get_attr(Term,geler,_)
116	    ),
117	    \+ memberchk_eq(Term,Seen)
118	->  Vars = [Term|RVars],
119	    Names = [Name|RNames],
120	    NSeen = [Term|Seen]
121	;   Vars = RVars,
122	    Names = RNames,
123	    Seen = NSeen
124	),
125	dump_vars_names(Rest,NSeen,RVars,RNames).
126
127dump_format([],[]).
128dump_format([X|Xs],['{~w}'-[X],nl|Rest]) :-
129	dump_format(Xs,Rest).
130
131memberchk_eq(X,[Y|Ys]) :-
132	(   X == Y
133	->  true
134	;   memberchk_eq(X,Ys)
135	).
136