1/* Part of CLP(Q,R) (Constraint Logic Programming over Rationals and Reals) 2 3 Author: Leslie De Koninck 4 E-mail: Leslie.DeKoninck@cs.kuleuven.be 5 WWW: http://www.swi-prolog.org 6 http://www.ai.univie.ac.at/cgi-bin/tr-online?number+95-09 7 Copyright (C): 2006, K.U. Leuven and 8 1992-1995, Austrian Research Institute for 9 Artificial Intelligence (OFAI), 10 Vienna, Austria 11 12 This software is based on CLP(Q,R) by Christian Holzbaur for SICStus 13 Prolog and distributed under the license details below with permission from 14 all mentioned authors. 15 16 This program is free software; you can redistribute it and/or 17 modify it under the terms of the GNU General Public License 18 as published by the Free Software Foundation; either version 2 19 of the License, or (at your option) any later version. 20 21 This program is distributed in the hope that it will be useful, 22 but WITHOUT ANY WARRANTY; without even the implied warranty of 23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 GNU General Public License for more details. 25 26 You should have received a copy of the GNU Lesser General Public 27 License along with this library; if not, write to the Free Software 28 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 29 30 As a special exception, if you link this library with other files, 31 compiled with a Free Software compiler, to produce an executable, this 32 library does not by itself cause the resulting executable to be covered 33 by the GNU General Public License. This exception does not however 34 invalidate any other reasons why the executable file might be covered by 35 the GNU General Public License. 36*/ 37 38 39% attribute = t(CLP,type(_),strictness(_),lin(_),order(_),class(_),forward(_), 40% nonzero,target,keep_indep,keep) 41 42:- module(clpqr_itf, 43 [ 44 dump_linear/3, 45 dump_nonzero/3, 46 clp_type/2 47 ]). 48:- use_module(library(apply), [maplist/2]). 49 50clp_type(Var,Type) :- 51 ( get_attr(Var,clpqr_itf,Att) 52 -> arg(1,Att,Type) 53 ; get_attr(Var,clpqr_geler,Att) 54 -> arg(1,Att,Type) 55 ). 56 57dump_linear(V) --> 58 { 59 get_attr(V,clpqr_itf,Att), 60 arg(1,Att,CLP), 61 arg(2,Att,type(Type)), 62 arg(4,Att,lin(Lin)), 63 !, 64 Lin = [I,_|H] 65 }, 66 ( { 67 Type=t_none 68 ; arg(9,Att,n) 69 } 70 -> [] 71 ; dump_v(CLP,t_none,V,I,H) 72 ), 73 ( { 74 Type=t_none, 75 arg(9,Att,n) % attribute should not have changed by dump_v... 76 } 77 -> % nonzero produces such 78 [] 79 ; dump_v(CLP,Type,V,I,H) 80 ). 81dump_linear(_) --> []. 82 83dump_v(clpq,Type,V,I,H) --> bv_q:dump_var(Type,V,I,H). 84dump_v(clpr,Type,V,I,H) --> bv_r:dump_var(Type,V,I,H). 85 86dump_nonzero(V) --> 87 { 88 get_attr(V,clpqr_itf,Att), 89 arg(1,Att,CLP), 90 arg(4,Att,lin(Lin)), 91 arg(8,Att,nonzero), 92 !, 93 Lin = [I,_|H] 94 }, 95 dump_nz(CLP,V,H,I). 96dump_nonzero(_) --> []. 97 98dump_nz(clpq,V,H,I) --> bv_q:dump_nz(V,H,I). 99dump_nz(clpr,V,H,I) --> bv_r:dump_nz(V,H,I). 100 101attr_unify_hook(t(CLP,n,n,n,n,n,n,n,_,_,_),Y) :- 102 !, 103 ( get_attr(Y,clpqr_itf,AttY), 104 \+ arg(1,AttY,CLP) 105 -> throw(error(permission_error('mix CLP(Q) variables with', 106 'CLP(R) variables:',Y),context(_))) 107 ; true 108 ). 109attr_unify_hook(t(CLP,Ty,St,Li,Or,Cl,_,No,_,_,_),Y) :- 110 ( get_attr(Y,clpqr_itf,AttY), 111 \+ arg(1,AttY,CLP) 112 -> throw(error(permission_error('mix CLP(Q) variables with', 113 'CLP(R) variables:',Y),context(_))) 114 ; true 115 ), 116 do_checks(CLP,Y,Ty,St,Li,Or,Cl,No,Later), 117 maplist(call,Later). 118 119do_checks(clpq,Y,Ty,St,Li,Or,Cl,No,Later) :- 120 itf_q:do_checks(Y,Ty,St,Li,Or,Cl,No,Later). 121do_checks(clpr,Y,Ty,St,Li,Or,Cl,No,Later) :- 122 itf_r:do_checks(Y,Ty,St,Li,Or,Cl,No,Later). 123 124 /******************************* 125 * SANDBOX * 126 *******************************/ 127:- multifile 128 sandbox:safe_primitive/1. 129 130sandbox:safe_primitive(clpqr_itf:clp_type(_,_))