Merge branch 'master' of ../yap-6.2

This commit is contained in:
Vítor Santos Costa 2010-12-02 19:42:52 +00:00
commit 4e0390da5c
22 changed files with 751 additions and 161 deletions

View File

@ -148,11 +148,11 @@ p_close_shared_object(void) {
void *handle; void *handle;
if (IsVarTerm(t)) { if (IsVarTerm(t)) {
Yap_Error(INSTANTIATION_ERROR,t,"open_shared_object/3"); Yap_Error(INSTANTIATION_ERROR,t,"close_shared_object/1");
return FALSE; return FALSE;
} }
if (!IsIntegerTerm(t)) { if (!IsIntegerTerm(t)) {
Yap_Error(TYPE_ERROR_INTEGER,t,"open_shared_object/3"); Yap_Error(TYPE_ERROR_INTEGER,t,"close_shared_object/1");
return FALSE; return FALSE;
} }
handle = (char *)IntegerOfTerm(t); handle = (char *)IntegerOfTerm(t);
@ -164,27 +164,48 @@ static Int
p_call_shared_object_function(void) { p_call_shared_object_function(void) {
Term t = Deref(ARG1); Term t = Deref(ARG1);
Term tfunc = Deref(ARG2); Term tfunc = Deref(ARG2);
Term tmod;
void *handle; void *handle;
Term OldCurrentModule = CurrentModule;
Int res;
tmod = CurrentModule;
restart:
if (IsVarTerm(t)) { if (IsVarTerm(t)) {
Yap_Error(INSTANTIATION_ERROR,t,"open_shared_object/3"); Yap_Error(INSTANTIATION_ERROR,t,"call_shared_object_function/2");
return FALSE;
} else if (IsApplTerm(t)) {
Functor fun = FunctorOfTerm(t);
if (fun == FunctorModule) {
tmod = ArgOfTerm(1, t);
if (IsVarTerm(tmod) ) {
Yap_Error(INSTANTIATION_ERROR,t,"call_shared_object_function/2");
return FALSE; return FALSE;
} }
if (!IsIntegerTerm(t)) { if (!IsAtomTerm(tmod) ) {
Yap_Error(TYPE_ERROR_INTEGER,t,"open_shared_object/3"); Yap_Error(TYPE_ERROR_ATOM,ARG1,"call_shared_object_function/2");
return FALSE;
}
t = ArgOfTerm(2, t);
goto restart;
}
} else if (!IsIntegerTerm(t)) {
Yap_Error(TYPE_ERROR_INTEGER,t,"call_shared_object_function/2");
return FALSE; return FALSE;
} }
handle = (void *)IntegerOfTerm(t); handle = (void *)IntegerOfTerm(t);
if (IsVarTerm(tfunc)) { if (IsVarTerm(tfunc)) {
Yap_Error(INSTANTIATION_ERROR,t,"open_shared_object/3"); Yap_Error(INSTANTIATION_ERROR,t,"call_shared_object_function/2");
return FALSE; return FALSE;
} }
if (!IsAtomTerm(tfunc)) { if (!IsAtomTerm(tfunc)) {
Yap_Error(TYPE_ERROR_ATOM,t,"open_shared_object/3"); Yap_Error(TYPE_ERROR_ATOM,t,"call_shared_object_function/2/3");
return FALSE; return FALSE;
} }
CurrentModule = tmod;
return Yap_CallForeignFile(handle, RepAtom(AtomOfTerm(tfunc))->StrOfAE); res = Yap_CallForeignFile(handle, RepAtom(AtomOfTerm(tfunc))->StrOfAE);
CurrentModule = OldCurrentModule;
return res;
} }
static Int static Int

View File

@ -27,6 +27,11 @@
#include <wchar.h> #include <wchar.h>
typedef struct atom_blob {
size_t length;
char data[MIN_ARRAY];
} atom_blob_t;
/********* operations for atoms ****************************************/ /********* operations for atoms ****************************************/
/* Atoms are assumed to be uniquely represented by an OFFSET and to have /* Atoms are assumed to be uniquely represented by an OFFSET and to have
@ -55,10 +60,7 @@ typedef struct AtomEntryStruct
union { union {
char uStrOfAE[MIN_ARRAY]; /* representation of atom as a string */ char uStrOfAE[MIN_ARRAY]; /* representation of atom as a string */
wchar_t uWStrOfAE[MIN_ARRAY]; /* representation of atom as a string */ wchar_t uWStrOfAE[MIN_ARRAY]; /* representation of atom as a string */
struct { struct atom_blob blob[MIN_ARRAY];
size_t length; /* size of blob */
char data[MIN_ARRAY]; /* data */
} blob;
} rep; } rep;
} }
AtomEntry; AtomEntry;

View File

@ -1604,3 +1604,4 @@ PredPropByAtom (Atom at, Term cur_mod)
#endif #endif
#endif #endif

View File

@ -85,11 +85,11 @@ PL_blob_data(atom_t a, size_t *len, struct PL_blob_t **type)
return x->StrOfAE; return x->StrOfAE;
} }
if ( len ) if ( len )
*len = x->rep.blob.length; *len = x->rep.blob[0].length;
if ( type ) if ( type )
*type = RepBlobProp(x->PropsOfAE)->blob_t; *type = RepBlobProp(x->PropsOfAE)->blob_t;
return x->rep.blob.data; return x->rep.blob[0].data;
} }
PL_EXPORT(void) PL_EXPORT(void)

View File

@ -49,13 +49,14 @@
extern X_API Int YAP_PLArityOfSWIFunctor(functor_t at); extern X_API Int YAP_PLArityOfSWIFunctor(functor_t at);
/* This is silly, but let's keep it like that for now */
X_API Int X_API Int
YAP_PLArityOfSWIFunctor(functor_t at) { YAP_PLArityOfSWIFunctor(functor_t f) {
if (IsAtomTerm(at)) if ((CELL)(f) & 2 && ((CELL)f) < N_SWI_FUNCTORS*4+2)
return ArityOfFunctor(SWI_Functors[(CELL)f/4]);
if (IsAtomTerm(f))
return 0; return 0;
if ((CELL)(at) & 2) return ArityOfFunctor((Functor)f);
return ArityOfFunctor(SWI_Functors[((CELL)at)/4]);
return ArityOfFunctor((Functor)at);
} }
void void
@ -64,10 +65,10 @@ Yap_InitSWIHash(void)
int i, j; int i, j;
memset(SWI_ReverseHash, 0, N_SWI_HASH*sizeof(swi_rev_hash)); memset(SWI_ReverseHash, 0, N_SWI_HASH*sizeof(swi_rev_hash));
for (i=0; i < N_SWI_ATOMS; i++) { for (i=0; i < N_SWI_ATOMS; i++) {
add_to_hash(i*2+1, (ADDR)SWI_Atoms[i]); add_to_hash(i, (ADDR)SWI_Atoms[i]);
} }
for (j=0; j < N_SWI_FUNCTORS; j++) { for (j=0; j < N_SWI_FUNCTORS; j++) {
add_to_hash((((CELL)(j))*4+2), (ADDR)SWI_Functors[j]); add_to_hash(j, (ADDR)SWI_Functors[j]);
} }
} }

View File

@ -83,15 +83,15 @@ AtomToSWIAtom(Atom at)
{ {
atom_t ats; atom_t ats;
if ((ats = in_hash((ADDR)at))) if ((ats = in_hash((ADDR)at)))
return ats; return (atom_t)((CELL)ats*2+1);
return (atom_t)at; return (atom_t)at;
} }
static inline Atom static inline Atom
SWIAtomToAtom(atom_t at) SWIAtomToAtom(atom_t at)
{ {
if ((CELL)at & 1) if ((CELL)at < N_SWI_ATOMS*(LowTagBits+1))
return SWI_Atoms[at>>1]; return SWI_Atoms[((CELL)at)/2];
return (Atom)at; return (Atom)at;
} }
@ -110,17 +110,16 @@ FunctorToSWIFunctor(Functor at)
{ {
atom_t ats; atom_t ats;
if ((ats = in_hash((ADDR)at))) if ((ats = in_hash((ADDR)at)))
return (functor_t)ats; return (functor_t)((CELL)ats*4+2);
return (functor_t)at; return (functor_t)at;
} }
/* This is silly, but let's keep it like that for now */
static inline Functor static inline Functor
SWIFunctorToFunctor(functor_t at) SWIFunctorToFunctor(functor_t f)
{ {
if (IsAtomTerm(at)) if ((CELL)(f) & 2 && ((CELL)f) < N_SWI_FUNCTORS*4+2)
return (Functor)at; return SWI_Functors[((CELL)f)/4];
if ((CELL)(at) & 2) return (Functor)f;
return SWI_Functors[((CELL)at)/4];
return (Functor)at;
} }

View File

@ -46,13 +46,14 @@ PROBLOG_PROGRAMS= \
$(srcdir)/problog/sampling.yap \ $(srcdir)/problog/sampling.yap \
$(srcdir)/problog/tabling.yap \ $(srcdir)/problog/tabling.yap \
$(srcdir)/problog/timer.yap \ $(srcdir)/problog/timer.yap \
$(srcdir)/problog/tptree.yap \ $(srcdir)/problog/ptree.yap \
$(srcdir)/problog/variable_elimination.yap \ $(srcdir)/problog/variable_elimination.yap \
$(srcdir)/problog/print_learning.yap \ $(srcdir)/problog/print_learning.yap \
$(srcdir)/problog/utils_learning.yap \ $(srcdir)/problog/utils_learning.yap \
$(srcdir)/problog/version_control.yap \ $(srcdir)/problog/version_control.yap \
$(srcdir)/problog/nestedtries.yap \ $(srcdir)/problog/nestedtries.yap \
$(srcdir)/problog/utils.yap \ $(srcdir)/problog/utils.yap \
$(srcdir)/problog/ad_converter.yap \
$(srcdir)/problog/variables.yap $(srcdir)/problog/variables.yap
PROBLOG_EXAMPLES = \ PROBLOG_EXAMPLES = \

View File

@ -304,7 +304,7 @@
:- use_module('problog/os', [convert_filename_to_working_path/2, :- use_module('problog/os', [convert_filename_to_working_path/2,
convert_filename_to_problog_path/2]). convert_filename_to_problog_path/2]).
:- use_module('problog/tptree', [delete_ptree/1]). :- use_module('problog/ptree', [delete_ptree/1]).
:- use_module('problog/tabling', [clear_tabling/0]). :- use_module('problog/tabling', [clear_tabling/0]).

View File

@ -2,8 +2,8 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% $Date: 2010-11-09 02:47:35 +0100 (Tue, 09 Nov 2010) $ % $Date: 2010-11-23 11:47:48 +0100 (Tue, 23 Nov 2010) $
% $Revision: 4991 $ % $Revision: 5027 $
% %
% This file is part of ProbLog % This file is part of ProbLog
% http://dtai.cs.kuleuven.be/problog % http://dtai.cs.kuleuven.be/problog
@ -314,7 +314,36 @@
:- use_module('problog/flags'). :- use_module('problog/flags').
:- use_module('problog/print'). :- use_module('problog/print').
:- use_module('problog/os'). :- use_module('problog/os').
:- use_module('problog/tptree'). :- use_module('problog/ptree', [init_ptree/1,
delete_ptree/1,
member_ptree/2,
enum_member_ptree/2,
insert_ptree/2,
delete_ptree/2,
edges_ptree/2,
count_ptree/2,
prune_check_ptree/2,
empty_ptree/1,
merge_ptree/2,
merge_ptree/3,
bdd_ptree/3,
bdd_struct_ptree/3,
bdd_ptree_map/4,
bdd_struct_ptree_map/4,
traverse_ptree/2, %theo
print_ptree/1, %theo
statistics_ptree/0, %theo
print_nested_ptree/1, %theo
trie_to_bdd_trie/5, %theo
trie_to_bdd_struct_trie/5,
nested_trie_to_bdd_trie/5, %theo
nested_trie_to_bdd_struct_trie/5,
ptree_decomposition/3,
ptree_decomposition_struct/3,
nested_ptree_to_BDD_script/3, %theo
nested_ptree_to_BDD_struct_script/3,
ptree_db_trie_opt_performed/3,
bdd_vars_script/1]).
:- use_module('problog/tabling'). :- use_module('problog/tabling').
:- use_module('problog/sampling'). :- use_module('problog/sampling').
:- use_module('problog/intervals'). :- use_module('problog/intervals').
@ -393,7 +422,7 @@
:- initialization(( :- initialization((
problog_define_flag(first_threshold, problog_flag_validate_indomain_0_1_open, 'starting threshold iterative deepening', 0.1, inference), problog_define_flag(first_threshold, problog_flag_validate_indomain_0_1_open, 'starting threshold iterative deepening', 0.1, inference),
problog_define_flag(last_threshold, problog_flag_validate_indomain_0_1_open, 'stopping threshold iterative deepening', 1e-30, inference, flags:last_threshold_handler), problog_define_flag(last_threshold, problog_flag_validate_indomain_0_1_open, 'stopping threshold iterative deepening', 1.0E-30, inference, flags:last_threshold_handler),
problog_define_flag(id_stepsize, problog_flag_validate_indomain_0_1_close, 'threshold shrinking factor iterative deepening', 0.5, inference, flags:id_stepsize_handler) problog_define_flag(id_stepsize, problog_flag_validate_indomain_0_1_close, 'threshold shrinking factor iterative deepening', 0.5, inference, flags:id_stepsize_handler)
)). )).

View File

@ -0,0 +1,394 @@
%%% -*- Mode: Prolog; -*-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Date: 2010-10-13 17:09:47 +0200 (Wed, 13 Oct 2010) $
% $Revision: 4915 $
%
% This file is part of ProbLog
% http://dtai.cs.kuleuven.be/problog
%
% ProbLog was developed at Katholieke Universiteit Leuven
%
% Copyright 2009
% Angelika Kimmig, Vitor Santos Costa, Bernd Gutmann
%
% Main authors of this file:
% Bernd Gutmann
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Artistic License 2.0
%
% Copyright (c) 2000-2006, The Perl Foundation.
%
% Everyone is permitted to copy and distribute verbatim copies of this
% license document, but changing it is not allowed. Preamble
%
% This license establishes the terms under which a given free software
% Package may be copied, modified, distributed, and/or
% redistributed. The intent is that the Copyright Holder maintains some
% artistic control over the development of that Package while still
% keeping the Package available as open source and free software.
%
% You are always permitted to make arrangements wholly outside of this
% license directly with the Copyright Holder of a given Package. If the
% terms of this license do not permit the full use that you propose to
% make of the Package, you should contact the Copyright Holder and seek
% a different licensing arrangement. Definitions
%
% "Copyright Holder" means the individual(s) or organization(s) named in
% the copyright notice for the entire Package.
%
% "Contributor" means any party that has contributed code or other
% material to the Package, in accordance with the Copyright Holder's
% procedures.
%
% "You" and "your" means any person who would like to copy, distribute,
% or modify the Package.
%
% "Package" means the collection of files distributed by the Copyright
% Holder, and derivatives of that collection and/or of those files. A
% given Package may consist of either the Standard Version, or a
% Modified Version.
%
% "Distribute" means providing a copy of the Package or making it
% accessible to anyone else, or in the case of a company or
% organization, to others outside of your company or organization.
%
% "Distributor Fee" means any fee that you charge for Distributing this
% Package or providing support for this Package to another party. It
% does not mean licensing fees.
%
% "Standard Version" refers to the Package if it has not been modified,
% or has been modified only in ways explicitly requested by the
% Copyright Holder.
%
% "Modified Version" means the Package, if it has been changed, and such
% changes were not explicitly requested by the Copyright Holder.
%
% "Original License" means this Artistic License as Distributed with the
% Standard Version of the Package, in its current version or as it may
% be modified by The Perl Foundation in the future.
%
% "Source" form means the source code, documentation source, and
% configuration files for the Package.
%
% "Compiled" form means the compiled bytecode, object code, binary, or
% any other form resulting from mechanical transformation or translation
% of the Source form.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Permission for Use and Modification Without Distribution
%
% (1) You are permitted to use the Standard Version and create and use
% Modified Versions for any purpose without restriction, provided that
% you do not Distribute the Modified Version.
%
% Permissions for Redistribution of the Standard Version
%
% (2) You may Distribute verbatim copies of the Source form of the
% Standard Version of this Package in any medium without restriction,
% either gratis or for a Distributor Fee, provided that you duplicate
% all of the original copyright notices and associated disclaimers. At
% your discretion, such verbatim copies may or may not include a
% Compiled form of the Package.
%
% (3) You may apply any bug fixes, portability changes, and other
% modifications made available from the Copyright Holder. The resulting
% Package will still be considered the Standard Version, and as such
% will be subject to the Original License.
%
% Distribution of Modified Versions of the Package as Source
%
% (4) You may Distribute your Modified Version as Source (either gratis
% or for a Distributor Fee, and with or without a Compiled form of the
% Modified Version) provided that you clearly document how it differs
% from the Standard Version, including, but not limited to, documenting
% any non-standard features, executables, or modules, and provided that
% you do at least ONE of the following:
%
% (a) make the Modified Version available to the Copyright Holder of the
% Standard Version, under the Original License, so that the Copyright
% Holder may include your modifications in the Standard Version. (b)
% ensure that installation of your Modified Version does not prevent the
% user installing or running the Standard Version. In addition, the
% modified Version must bear a name that is different from the name of
% the Standard Version. (c) allow anyone who receives a copy of the
% Modified Version to make the Source form of the Modified Version
% available to others under (i) the Original License or (ii) a license
% that permits the licensee to freely copy, modify and redistribute the
% Modified Version using the same licensing terms that apply to the copy
% that the licensee received, and requires that the Source form of the
% Modified Version, and of any works derived from it, be made freely
% available in that license fees are prohibited but Distributor Fees are
% allowed.
%
% Distribution of Compiled Forms of the Standard Version or
% Modified Versions without the Source
%
% (5) You may Distribute Compiled forms of the Standard Version without
% the Source, provided that you include complete instructions on how to
% get the Source of the Standard Version. Such instructions must be
% valid at the time of your distribution. If these instructions, at any
% time while you are carrying out such distribution, become invalid, you
% must provide new instructions on demand or cease further
% distribution. If you provide valid instructions or cease distribution
% within thirty days after you become aware that the instructions are
% invalid, then you do not forfeit any of your rights under this
% license.
%
% (6) You may Distribute a Modified Version in Compiled form without the
% Source, provided that you comply with Section 4 with respect to the
% Source of the Modified Version.
%
% Aggregating or Linking the Package
%
% (7) You may aggregate the Package (either the Standard Version or
% Modified Version) with other packages and Distribute the resulting
% aggregation provided that you do not charge a licensing fee for the
% Package. Distributor Fees are permitted, and licensing fees for other
% components in the aggregation are permitted. The terms of this license
% apply to the use and Distribution of the Standard or Modified Versions
% as included in the aggregation.
%
% (8) You are permitted to link Modified and Standard Versions with
% other works, to embed the Package in a larger work of your own, or to
% build stand-alone binary or bytecode versions of applications that
% include the Package, and Distribute the result without restriction,
% provided the result does not expose a direct interface to the Package.
%
% Items That are Not Considered Part of a Modified Version
%
% (9) Works (including, but not limited to, modules and scripts) that
% merely extend or make use of the Package, do not, by themselves, cause
% the Package to be a Modified Version. In addition, such works are not
% considered parts of the Package itself, and are not subject to the
% terms of this license.
%
% General Provisions
%
% (10) Any use, modification, and distribution of the Standard or
% Modified Versions is governed by this Artistic License. By using,
% modifying or distributing the Package, you accept this license. Do not
% use, modify, or distribute the Package, if you do not accept this
% license.
%
% (11) If your Modified Version has been derived from a Modified Version
% made by someone other than you, you are nevertheless required to
% ensure that your Modified Version complies with the requirements of
% this license.
%
% (12) This license does not grant you the right to use any trademark,
% service mark, tradename, or logo of the Copyright Holder.
%
% (13) This license includes the non-exclusive, worldwide,
% free-of-charge patent license to make, have made, use, offer to sell,
% sell, import and otherwise transfer the Package with respect to any
% patent claims licensable by the Copyright Holder that are necessarily
% infringed by the Package. If you institute patent litigation
% (including a cross-claim or counterclaim) against any party alleging
% that the Package constitutes direct or contributory patent
% infringement, then this Artistic License to you shall terminate on the
% date that such litigation is filed.
%
% (14) Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT
% HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED
% WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
% PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT
% PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT
% HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT,
% INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
% OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
:- module(ad_converter,[compile_annotated_disjunction/5,
compile_tunable_annotated_disjunction/5,
proper_annotated_disjunction/1,
proper_tunable_annotated_disjunction/1,
term_expansion_intern_ad/3,
op(1149, yfx, <-- ),
op( 550, yfx, :: )
]).
% general yap modules
:- use_module(library(lists),[reverse/2]).
:- style_check(all).
:- yap_flag(unknown,error).
:- op( 550, yfx, :: ).
% for annotated disjunctions
:- op(1149, yfx, <-- ).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
term_expansion_intern_ad( (Head<--Body),Module,ad_intern((Head<--Body),ID)) :-
proper_tunable_annotated_disjunction(Head),
!,
compile_tunable_annotated_disjunction(Head,Body,Facts,Bodies,ID),
assert_all_ad_facts(Facts,Module),
assert_all_ad_bodies(Bodies,Module).
term_expansion_intern_ad( (Head<--Body),Module,ad_intern((Head<--Body),ID)) :-
proper_annotated_disjunction(Head),
!,
compile_annotated_disjunction(Head,Body,Facts,Bodies,ID),
assert_all_ad_facts(Facts,Module),
assert_all_ad_bodies(Bodies,Module).
term_expansion_intern_ad( (Head<--Body),_,_) :-
format_to_chars('Error at compiling the annotated disjunction ~q<--Body.',[Head,Body],Error),
print_message(error,Error),
fail.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
assert_all_ad_facts([],_).
assert_all_ad_facts([F|T],Module) :-
once(problog:term_expansion_intern(F,Module,Atom)),
assertz(problog:Atom),
assert_all_ad_facts(T,Module).
assert_all_ad_bodies([],_).
assert_all_ad_bodies([B|T],Module) :-
assertz(Module:B),
assert_all_ad_bodies(T,Module).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
get_next_unique_id(ID) :-
(
bb_get(mvs_unique_id,ID)
->
true;
ID=1
),
ID2 is ID+1,
bb_put(mvs_unique_id,ID2).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
proper_annotated_disjunction(AD) :-
proper_annotated_disjunction(AD,0.0,Sum),
Sum=<1.
proper_annotated_disjunction( P :: _, OldSum,NewSum) :-
% evaluate P
P2 is P,
P2>=0,
P2=<1,
NewSum is OldSum+P.
proper_annotated_disjunction((X;Y),OldSum,Sum) :-
proper_annotated_disjunction(X,OldSum,NewSum),
proper_annotated_disjunction(Y,NewSum,Sum).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
proper_tunable_annotated_disjunction( t(_) :: _).
proper_tunable_annotated_disjunction((X;Y)) :-
proper_tunable_annotated_disjunction(X),
proper_tunable_annotated_disjunction(Y).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
compile_tunable_annotated_disjunction(Head,Body,Facts2,Bodies2,Extra_ID) :-
get_next_unique_id(Extra_ID),
convert_a_tunable(Head,Extra_ID,[],Facts),
convert_b(Head,Body,_NewBody,Extra_ID,[],Bodies),
reverse(Facts,Facts2),
reverse(Bodies,Bodies2).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
compile_annotated_disjunction(Head,Body,Facts2,Bodies2,Extra_ID) :-
get_next_unique_id(Extra_ID),
convert_a(Head,0.0,_Acc,Extra_ID,[],Facts),
convert_b(Head,Body,_NewBody,Extra_ID,[],Bodies),
reverse(Facts,Facts2),
reverse(Bodies,Bodies2).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
convert_a((X;Y),OldAcc,Acc,Extra_ID,OldFacts,Facts) :-
convert_a(X,OldAcc,NewAcc,Extra_ID,OldFacts,NewFacts),
convert_a(Y,NewAcc,Acc,Extra_ID,NewFacts,Facts).
convert_a(P::Atom,OldAcc,NewAcc,Extra_ID,OldFacts,[P1::ProbFact|OldFacts]) :-
Atom =.. [Functor|AllArguments],
length(AllArguments,Arity),
atomic_concat([mvs_fact_,Functor,'_',Arity,'_',Extra_ID],NewAtom),
ProbFact =.. [NewAtom|AllArguments],
(
P=:=0
->
P1 is 0.0 ;
(
OldAcc=:=0
->
P1 is P;
P1 is P/(1-OldAcc)
)
),
NewAcc is OldAcc+P.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
convert_a_tunable((X;Y),Extra_ID,OldFacts,Facts) :-
convert_a_tunable(X,Extra_ID,OldFacts,NewFacts),
convert_a_tunable(Y,Extra_ID,NewFacts,Facts).
convert_a_tunable(P::Atom,Extra_ID,OldFacts,[P::ProbFact|OldFacts]) :-
Atom =.. [Functor|AllArguments],
length(AllArguments,Arity),
atomic_concat([mvs_fact_,Functor,'_',Arity,'_',Extra_ID],NewAtom),
ProbFact =.. [NewAtom|AllArguments].
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
convert_b((X;Y),OldBody,Body,ExtraID,OldBodies,Bodies) :-
convert_b(X,OldBody,NewBody,ExtraID,OldBodies,NewBodies),
convert_b(Y,NewBody,Body,ExtraID,NewBodies,Bodies).
convert_b(_::Atom,OldBody,NewBody,Extra_ID,OldBodies,[(Atom:-ThisBody)|OldBodies]) :-
Atom =.. [Functor|AllArguments],
length(AllArguments,Arity),
atomic_concat([mvs_fact_,Functor,'_',Arity,'_',Extra_ID],NewFunctor),
ProbFact =.. [NewFunctor|AllArguments],
tuple_append(OldBody,ProbFact,ThisBody),
tuple_append(OldBody,problog_not(ProbFact),NewBody).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
tuple_append(true,X,X) :-
!.
tuple_append(X,true,X) :-
!.
tuple_append((A,B),X,(A,B2)) :-
X \= true,
!,
tuple_append(B,X,B2).
tuple_append(X,Y,(X,Y)) :-
X \= true,
Y \= true,
X \= (_,_).

View File

@ -2,8 +2,8 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% $Date: 2010-10-06 12:56:13 +0200 (Wed, 06 Oct 2010) $ % $Date: 2010-11-29 10:58:04 +0100 (Mon, 29 Nov 2010) $
% $Revision: 4877 $ % $Revision: 5029 $
% %
% This file is part of ProbLog % This file is part of ProbLog
% http://dtai.cs.kuleuven.be/problog % http://dtai.cs.kuleuven.be/problog
@ -219,7 +219,7 @@
% load library modules % load library modules
:- use_module(library(system), [exec/3, file_exists/1]). :- use_module(library(system), [exec/3, file_exists/1,wait/2]).
:- use_module(library(lists), [memberchk/2]). :- use_module(library(lists), [memberchk/2]).
% load our own modules % load our own modules
@ -228,10 +228,23 @@
:- dynamic(problog_path/1). :- dynamic(problog_path/1).
:- dynamic(problog_working_path/1). :- dynamic(problog_working_path/1).
%========================================================================
%=
%=
%=
%========================================================================
set_problog_path(Path):- set_problog_path(Path):-
retractall(problog_path(_)), retractall(problog_path(_)),
assertz(problog_path(Path)). assertz(problog_path(Path)).
%========================================================================
%=
%=
%=
%========================================================================
convert_filename_to_working_path(File_Name, Path):- convert_filename_to_working_path(File_Name, Path):-
flag_get(dir, Dir), flag_get(dir, Dir),
concat_path_with_filename(Dir, File_Name, Path). concat_path_with_filename(Dir, File_Name, Path).
@ -240,6 +253,13 @@ convert_filename_to_problog_path(File_Name, Path):-
problog_path(Dir), problog_path(Dir),
concat_path_with_filename(Dir, File_Name, Path). concat_path_with_filename(Dir, File_Name, Path).
%========================================================================
%=
%=
%=
%========================================================================
concat_path_with_filename(Path, File_Name, Result):- concat_path_with_filename(Path, File_Name, Result):-
nonvar(File_Name), nonvar(File_Name),
nonvar(Path), nonvar(Path),
@ -257,6 +277,7 @@ concat_path_with_filename2(Path, File_Name, Result):-
(atomic_concat(Path_Absolute, Path_Seperator, Path) ; Path_Absolute = Path), (atomic_concat(Path_Absolute, Path_Seperator, Path) ; Path_Absolute = Path),
atomic_concat([Path_Absolute, Path_Seperator, File_Name], Result). atomic_concat([Path_Absolute, Path_Seperator, File_Name], Result).
%======================================================================== %========================================================================
%= Calculate the MD5 checksum of +Filename by calling md5sum %= Calculate the MD5 checksum of +Filename by calling md5sum
%= in case m5sum is not installed, try md5, otherwise fail %= in case m5sum is not installed, try md5, otherwise fail
@ -278,7 +299,7 @@ calc_md5_intern(Filename,Command,MD5) :-
atomic_concat([Command,' "',Filename,'"'],Call), atomic_concat([Command,' "',Filename,'"'],Call),
% execute the md5 command % execute the md5 command
exec(Call,[null,pipe(S),null],_PID), exec(Call,[null,pipe(S),null],PID),
bb_put(calc_md5_temp,End-End), % use difference list bb_put(calc_md5_temp,End-End), % use difference list
bb_put(calc_md5_temp2,0), bb_put(calc_md5_temp2,0),
@ -308,23 +329,44 @@ calc_md5_intern(Filename,Command,MD5) :-
!, !,
close(S), close(S),
wait(PID,_Status),
bb_delete(calc_md5_temp, FinalList-[]), bb_delete(calc_md5_temp, FinalList-[]),
bb_delete(calc_md5_temp2,_), bb_delete(calc_md5_temp2,_),
atom_codes(MD5,FinalList). atom_codes(MD5,FinalList).
%========================================================================
%=
%=
%=
%========================================================================
path_seperator('\\'):- path_seperator('\\'):-
yap_flag(windows, true), !. yap_flag(windows, true), !.
path_seperator('/'). path_seperator('/').
%========================================================================
%=
%=
%=
%========================================================================
split_path_file(PathFile, Path, File):- split_path_file(PathFile, Path, File):-
path_seperator(PathSeperator), path_seperator(PathSeperator),
atomic_concat(Path, File, PathFile),
name(PathSeperator, [PathSeperatorName]), name(PathSeperator, [PathSeperatorName]),
atomic_concat(Path, File, PathFile),
name(File, FileName), name(File, FileName),
\+ memberchk(PathSeperatorName, FileName), \+ memberchk(PathSeperatorName, FileName),
!. !.
% (Path = '' ; atomic_concat(_, PathSeperator, Path)).
%========================================================================
%=
%=
%=
%========================================================================
check_existance(FileName):- check_existance(FileName):-
convert_filename_to_problog_path(FileName, Path), convert_filename_to_problog_path(FileName, Path),

View File

@ -2,8 +2,8 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% $Date: 2010-11-03 19:08:13 +0100 (Wed, 03 Nov 2010) $ % $Date: 2010-12-02 14:35:05 +0100 (Thu, 02 Dec 2010) $
% $Revision: 4984 $ % $Revision: 5041 $
% %
% This file is part of ProbLog % This file is part of ProbLog
% http://dtai.cs.kuleuven.be/problog % http://dtai.cs.kuleuven.be/problog
@ -483,12 +483,11 @@ nested_ptree_to_BDD_struct_script(Trie, BDDFileName, Variables):-
true; true;
VarCNT = 0 VarCNT = 0
), ),
create_bdd_file_with_header(BDDFileName,VarCNT,InterCNT,TmpFile1), prefix_bdd_file_with_header(BDDFileName,VarCNT,InterCNT,TmpFile1),
delete_file_silent(TmpFile1),
cleanup_BDD_generation cleanup_BDD_generation
);( );(
close(BDDS), close(BDDS),
delete_file_silent(TmpFile1), delete_file_silently(TmpFile1),
cleanup_BDD_generation, cleanup_BDD_generation,
fail fail
) )
@ -610,8 +609,7 @@ ptree_decomposition_struct(Trie, BDDFileName, Variables) :-
write('L1'), nl write('L1'), nl
), ),
told, told,
create_bdd_file_with_header(BDDFileName,VarCnt,LCnt,TmpFile1), prefix_bdd_file_with_header(BDDFileName,VarCnt,LCnt,TmpFile1).
delete_file_silent(TmpFile1).
%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%
% write BDD info for given ptree to file % write BDD info for given ptree to file
@ -1113,15 +1111,14 @@ nested_ptree_to_BDD_script(Trie, BDDFileName, VarFileName):-
true; true;
VarCNT = 0 VarCNT = 0
), ),
create_bdd_file_with_header(BDDFileName,VarCNT,InterCNT,TmpFile1), prefix_bdd_file_with_header(BDDFileName,VarCNT,InterCNT,TmpFile1),
delete_file_silent(TmpFile1),
open(VarFileName, 'write', VarStream), open(VarFileName, 'write', VarStream),
bddvars_to_script(Vars, VarStream), bddvars_to_script(Vars, VarStream),
close(VarStream), close(VarStream),
cleanup_BDD_generation cleanup_BDD_generation
; ;
close(BDDS), close(BDDS),
delete_file_silent(TmpFile1), delete_file_silently(TmpFile1),
cleanup_BDD_generation, cleanup_BDD_generation,
fail fail
). ).
@ -1853,8 +1850,7 @@ ptree_decomposition(Trie, BDDFileName, VarFileName) :-
write('L1'), nl write('L1'), nl
), ),
told, told,
create_bdd_file_with_header(BDDFileName,VarCnt,LCnt,TmpFile1), prefix_bdd_file_with_header(BDDFileName,VarCnt,LCnt,TmpFile1).
delete_file_silent(TmpFile1).
get_next_inter_step(I):- get_next_inter_step(I):-
nb_getval(next_inter_step, I), nb_getval(next_inter_step, I),
@ -2040,24 +2036,3 @@ mark_deref(DB_Trie):-
), ),
fail. fail.
mark_deref(_). mark_deref(_).
% end of Theo
create_bdd_file_with_header(BDD_File_Name,VarCount,IntermediateSteps,TmpFile) :-
open(BDD_File_Name,write,H),
% this is the header of the BDD script for problogbdd
format(H, '@BDD1~n~q~n0~n~q~n',[VarCount,IntermediateSteps]),
% append the content of the file TmpFile
open(TmpFile,read,H2),
(
repeat,
get_byte(H2,C),
put_byte(H,C),
at_end_of_stream(H2),
!
),
close(H2),
close(H).

View File

@ -2,8 +2,8 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% $Date: 2010-10-20 18:06:47 +0200 (Wed, 20 Oct 2010) $ % $Date: 2010-12-02 14:35:05 +0100 (Thu, 02 Dec 2010) $
% $Revision: 4969 $ % $Revision: -1 $
% %
% This file is part of ProbLog % This file is part of ProbLog
% http://dtai.cs.kuleuven.be/problog % http://dtai.cs.kuleuven.be/problog
@ -204,22 +204,54 @@
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
:- module(utils, [delete_file_silent/1, :- module(utils, [delete_file_silently/1,
delete_files_silently/1,
delete_file_pattern_silently/2,
variable_in_term_exactly_once/2, variable_in_term_exactly_once/2,
slice_n/4]). slice_n/4,
sorted_overlap_test/2,
prefix_bdd_file_with_header/4,
split_list/3]).
:- use_module(library(system), [delete_file/1]).
% load swi library, at some point vitor will make swi_expand_file_name/2 a built-in
:- load_foreign_files([libplstream], [], initIO).
% load our own modules
:- use_module(os).
:- use_module(library(system), [delete_file/1, file_exists/1]).
%======================================================================== %========================================================================
%= %=
%= %=
%======================================================================== %========================================================================
delete_file_silent(File) :- delete_file_silently(File) :-
file_exists(File),
delete_file(File), delete_file(File),
!. !.
delete_file_silent(_). delete_file_silently(_).
%========================================================================
%=
%=
%========================================================================
delete_files_silently([]).
delete_files_silently([H|T]) :-
delete_file_silently(H),
delete_files_silently(T).
%========================================================================
%=
%=
%========================================================================
delete_file_pattern_silently(Path,Pattern) :-
concat_path_with_filename(Path,Pattern,AbsolutePattern),
swi_expand_file_name(AbsolutePattern,Files),
delete_files_silently(Files).
%======================================================================== %========================================================================
%= Split a list into the first n elements and the tail %= Split a list into the first n elements and the tail
@ -234,7 +266,7 @@ slice_n([H|T],N,[H|T2],T3) :-
!, !,
N2 is N-1, N2 is N-1,
slice_n(T,N2,T2,T3). slice_n(T,N2,T2,T3).
slice_n(L,_,[],L). slice_n(L,0,[],L).
%======================================================================== %========================================================================
%= succeeds if the variable V appears exactly once in the term T %= succeeds if the variable V appears exactly once in the term T
@ -255,3 +287,66 @@ var_memberchk_none([H|T],V) :-
var_memberchk_none(T,V). var_memberchk_none(T,V).
var_memberchk_none([],_). var_memberchk_none([],_).
%========================================================================
%= sorted_overlap_test(+L1,+L2)
%= L1 and L2 are ground sorted lists
%= the predicate is true if there is an element X both appearing in L1 and L2
%========================================================================
sorted_overlap_test([H|_],[H|_]) :-
!.
sorted_overlap_test([H1|T1],[H2|T2]) :-
H1 @> H2,
!,
sorted_overlap_test([H1|T1],T2).
sorted_overlap_test([_|T1],[H2|T2]) :-
sorted_overlap_test(T1,[H2|T2]).
%========================================================================
%= TmpFile is the file name that contains the "body" of a SimpleCUDD
%= script file. This predicate creates a new file BDD_File_Name that
%= starts with the right header and contains the body. The body file
%= is deleted afterwards.
%=
%= prefix_bdd_file_with_header(+BDD_File_Name,+VarCount,+IntermediateSteps,+TmpFile)
%========================================================================
prefix_bdd_file_with_header(BDD_File_Name,VarCount,IntermediateSteps,TmpFile) :-
open(BDD_File_Name,write,H),
% this is the header of the BDD script for problogbdd
format(H, '@BDD1~n~q~n0~n~q~n',[VarCount,IntermediateSteps]),
% append the content of the file TmpFile
open(TmpFile,read,H2),
(
repeat,
get_byte(H2,C),
put_byte(H,C),
at_end_of_stream(H2),
!
),
close(H2),
close(H),
delete_file_silently(TmpFile).
%========================================================================
%=
%=
%=
%========================================================================
split_list([],[],[]).
split_list([H|T],L1,L2) :-
length([H|T],Len),
Len1 is integer(Len/2+0.5),
split_list_intern(Len1,[H|T],L1,L2).
split_list_intern(0,L,[],L).
split_list_intern(N,[H|T],[H|T1],L) :-
N>0,
N2 is N-1,
split_list_intern(N2,T,T1,L).

View File

@ -2,8 +2,8 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% $Date: 2010-10-20 18:06:47 +0200 (Wed, 20 Oct 2010) $ % $Date: 2010-12-02 14:35:05 +0100 (Thu, 02 Dec 2010) $
% $Revision: 4969 $ % $Revision: 5041 $
% %
% This file is part of ProbLog % This file is part of ProbLog
% http://dtai.cs.kuleuven.be/problog % http://dtai.cs.kuleuven.be/problog
@ -205,12 +205,13 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
:- module(utils_learning, [empty_bdd_directory/0, :- module(utils_learning, [empty_bdd_directory/0,
empty_output_directory/0]). empty_output_directory/0,
create_known_values_file_name/2,
create_bdd_file_name/3,
create_bdd_input_file_name/2,
create_bdd_output_file_name/4]).
% load library modules
:- use_module(library(lists), [append/3, member/2]).
:- use_module(library(system), [delete_file/1, directory_files/2, file_exists/1]).
% load our own modules % load our own modules
:- use_module(os). :- use_module(os).
@ -225,14 +226,11 @@
empty_bdd_directory :- empty_bdd_directory :-
problog_flag(bdd_directory,Path), problog_flag(bdd_directory,Path),
!, !,
delete_file_pattern_silently(Path,'query*').
atom_codes('query_', PF1), % 'query_*'
directory_files(Path,List),
delete_files_with_matching_prefix(List,Path,[PF1]).
empty_bdd_directory :- empty_bdd_directory :-
throw(error(problog_flag_does_not_exist(bdd_directory))). throw(error(problog_flag_does_not_exist(bdd_directory))).
%======================================================================== %========================================================================
%= %=
%= %=
@ -245,41 +243,72 @@ empty_output_directory :-
concat_path_with_filename(Path,'log.dat',F1), concat_path_with_filename(Path,'log.dat',F1),
concat_path_with_filename(Path,'out.dat',F2), concat_path_with_filename(Path,'out.dat',F2),
delete_file_silent(F1), delete_file_silently(F1),
delete_file_silent(F2), delete_file_silently(F2),
atom_codes('values_', PF1), % 'values_*_q_*.dat' delete_file_pattern_silently(Path,'values_*'),
atom_codes('factprobs_', PF2), % 'factprobs_*.pl' delete_file_pattern_silently(Path,'factprobs_*'),
atom_codes('input_', PF3), % 'input_*.pl' delete_file_pattern_silently(Path,'input_*'),
atom_codes('trainpredictions_',PF4), % 'trainpredictions_*.pl' delete_file_pattern_silently(Path,'trainpredictions_*'),
atom_codes('testpredictions_',PF5), % 'testpredictions_*.pl' delete_file_pattern_silently(Path,'testpredictions_*'),
atom_codes('predictions_',PF6), % 'predictions_*.pl' delete_file_pattern_silently(Path,'predictions_*').
directory_files(Path,List),
delete_files_with_matching_prefix(List,Path,[PF1,PF2,PF3,PF4,PF5,PF6]).
empty_output_directory :- empty_output_directory :-
throw(error(problog_flag_does_not_exist(output_directory))). throw(error(problog_flag_does_not_exist(output_directory))).
%========================================================================
%=
%=
%========================================================================
create_known_values_file_name(QueryID,Absolute_File_Name) :-
problog_flag(bdd_directory,Path),
!,
atomic_concat(['query_',QueryID,'_known_values'],File_Name),
concat_path_with_filename(Path,File_Name,Absolute_File_Name).
create_known_values_file_name(_,_) :-
throw(error(problog_flag_does_not_exist(bdd_directory))).
%======================================================================== %========================================================================
%= %=
%= %=
%======================================================================== %========================================================================
delete_files_with_matching_prefix([],_,_). create_bdd_file_name(QueryID,ClusterID,Absolute_File_Name) :-
delete_files_with_matching_prefix([Name|T],Path,Prefixes) :- problog_flag(bdd_directory,Path),
atom_codes(Name,NameCode), !,
( atomic_concat(['query_',QueryID,'_cluster_',ClusterID],File_Name),
(member(Prefix,Prefixes), append(Prefix,_Suffix,NameCode)) concat_path_with_filename(Path,File_Name,Absolute_File_Name).
-> create_bdd_file_name(_,_,_) :-
( throw(error(problog_flag_does_not_exist(bdd_directory))).
concat_path_with_filename(Path,Name,F),
delete_file_silent(F)
);
true
),
delete_files_with_matching_prefix(T,Path,Prefixes). %========================================================================
%=
%=
%========================================================================
create_bdd_output_file_name(QueryID,ClusterID,Iteration,Absolute_File_Name) :-
problog_flag(output_directory,Path),
!,
atomic_concat(['values_',Iteration,'_query_',QueryID,'_cluster_',ClusterID],File_Name),
concat_path_with_filename(Path,File_Name,Absolute_File_Name).
create_bdd_output_file_name(_,_,_,_) :-
throw(error(problog_flag_does_not_exist(output_directory))).
%========================================================================
%=
%=
%========================================================================
create_bdd_input_file_name(Iteration,Absolute_File_Name) :-
problog_flag(output_directory,Path),
!,
atomic_concat(['input_',Iteration,'.txt'],File_Name),
concat_path_with_filename(Path,File_Name,Absolute_File_Name).
create_bdd_input_file_name(_,_) :-
throw(error(problog_flag_does_not_exist(output_directory))).

View File

@ -6,7 +6,7 @@
% $Id: graph.pl 4875 2010-10-05 15:28:35Z theo $ % $Id: graph.pl 4875 2010-10-05 15:28:35Z theo $
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
:- use_module('../problog'). :- use_module(library(problog)).
%%%% %%%%
% background knowledge % background knowledge

View File

@ -6,7 +6,7 @@
% $Id: graph_tabled.pl 4875 2010-10-05 15:28:35Z theo $ % $Id: graph_tabled.pl 4875 2010-10-05 15:28:35Z theo $
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
:- use_module('../problog'). :- use_module(library(problog)).
% New trie method ensures Probibilistic Cycle Handling needed for tabling that handles loops % New trie method ensures Probibilistic Cycle Handling needed for tabling that handles loops
:- set_problog_flag(use_db_trie, true). :- set_problog_flag(use_db_trie, true).

View File

@ -14,8 +14,8 @@
% will run 20 iterations of learning with default settings % will run 20 iterations of learning with default settings
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
:- use_module('../problog'). :- use_module(library(problog)).
:- use_module('../problog_learning'). :- use_module(library(problog_learning)).
%%%% %%%%
% background knowledge % background knowledge

View File

@ -3,13 +3,13 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ProbLog program describing an office window % ProbLog program describing an office window
% example for using hybrid ProbLog % example for using hybrid ProbLog
% $Id: office.pl 4876 2010-10-05 16:15:57Z theo $ % $Id: office.pl 4970 2010-10-21 08:47:36Z bernd $
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
:- use_module('../problog'). :- use_module(library(problog)).
width(gaussian(2,1)). (W,gaussian(2,1)) :: width(W).
length(gaussian(9,3)). (L,gaussian(9,3)) :: length(L).
0.8 :: office_has_window. 0.8 :: office_has_window.
0.001 :: corridor_has_window. 0.001 :: corridor_has_window.

View File

@ -8,7 +8,7 @@
% The viral marketing example consists of a social network of friend relations. You have to decide which persons to market. Sending marketing has a cost of 2, but might cause people to buy your product, giving you a profit of 5. When someone buys the product, it becomes more likely that his friends also buy the product. % The viral marketing example consists of a social network of friend relations. You have to decide which persons to market. Sending marketing has a cost of 2, but might cause people to buy your product, giving you a profit of 5. When someone buys the product, it becomes more likely that his friends also buy the product.
:- use_module('../dtproblog'). :- use_module(library(dtproblog)).
% Decisions % Decisions
? :: marketed(P) :- person(P). ? :: marketed(P) :- person(P).

View File

@ -8,7 +8,7 @@
% The viral marketing example consists of a social network of friend relations. You have to decido which persons to market. Sending marketing has a cost of 2, but might cause people to buy your product, giving you a profit of 5. When someone buys the product, it becomes more likely that his friends also buy the product. % The viral marketing example consists of a social network of friend relations. You have to decido which persons to market. Sending marketing has a cost of 2, but might cause people to buy your product, giving you a profit of 5. When someone buys the product, it becomes more likely that his friends also buy the product.
:- use_module('../dtproblog'). :- use_module(library(dtproblog)).
% Decisions % Decisions
? :: marketed(P) :- person(P). ? :: marketed(P) :- person(P).

View File

@ -2,8 +2,8 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% $Date: 2010-10-20 18:06:47 +0200 (Wed, 20 Oct 2010) $ % $Date: 2010-12-02 14:35:05 +0100 (Thu, 02 Dec 2010) $
% $Revision: 4969 $ % $Revision: 5041 $
% %
% This file is part of ProbLog % This file is part of ProbLog
% http://dtai.cs.kuleuven.be/problog % http://dtai.cs.kuleuven.be/problog
@ -770,7 +770,7 @@ update_values :-
% start write current probabilities to file % start write current probabilities to file
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
bdd_input_file(Probabilities_File), bdd_input_file(Probabilities_File),
delete_file_silent(Probabilities_File), delete_file_silently(Probabilities_File),
open(Probabilities_File,'write',Handle), open(Probabilities_File,'write',Handle),

View File

@ -565,6 +565,7 @@ source_module(Mod) :-
call_cleanup(0,?,0), call_cleanup(0,?,0),
call_residue(0,?), call_residue(0,?),
call_residue_vars(0,?), call_residue_vars(0,?),
call_shared_object_function(:,+),
catch(0,?,0), catch(0,?,0),
clause(:,?), clause(:,?),
clause(:,?,?), clause(:,?,?),