This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/packages/ProbLog/problog_lbdd.yap

81 lines
2.4 KiB
Plaintext
Raw Normal View History

2012-04-26 13:52:09 +01:00
%
% ProbLog extension to use an YAP BDD interface module, instead of simplecudd.
%
:- use_module(library(trie_sp)).
:- use_module(library(bdd)).
:- use_module(library(bhash)).
2016-05-30 11:29:26 +01:00
problog_exact_lbdd(Goal,Prob,Status) :-
problog_control(on, exact),
problog_low_lbdd(Goal,0,Prob,Status),
problog_control(off, exact).
problog_low_lbdd(Goal, Threshold, _, _) :-
init_problog_low(Threshold),
problog_control(off, up),
timer_start(sld_time),
problog_call(Goal),
add_solution,
fail.
problog_low_lbdd(_, _, Prob, ok) :-
timer_stop(sld_time,SLD_Time),
problog_var_set(sld_time, SLD_Time),
nb_getval(problog_completed_proofs, Trie_Completed_Proofs),
tabled_trie_to_bdd(Trie_Completed_Proofs, BDD, MapList),
bind_maplist(MapList, BoundVars),
bdd_to_probability_sum_product(BDD, BoundVars, Prob),
(problog_flag(verbose, true)->
problog_statistics
;
true
),
delete_ptree(Trie_Completed_Proofs),
(problog_flag(retain_tables, true) -> retain_tabling; true),
clear_tabling.
2012-04-26 13:52:09 +01:00
problog_kbest_bdd(Goal, K, Prob, ok) :-
problog_kbest_to_bdd(Goal, K, BDD, MapList),
bind_maplist(MapList, BoundVars),
bdd_to_probability_sum_product(BDD, BoundVars, Prob).
2013-02-26 15:39:56 +00:00
problog_kbest_as_bdd(Goal, K, bdd(Dir, Tree, MapList)) :-
2012-04-26 13:52:09 +01:00
problog_kbest_to_bdd(Goal, K, BDD, MapList),
2013-02-26 15:39:56 +00:00
bdd_tree(BDD, bdd(Dir, Tree, _Vars)),
2012-04-26 13:52:09 +01:00
bdd_close(BDD).
problog_kbest_to_bdd(Goal, K, BDD, MapList) :-
problog_flag(first_threshold,InitT),
init_problog_kbest(InitT),
problog_control(off,up),
problog_kbest_id(Goal, K),
retract(current_kbest(_,ListFound,_NumFound)),
build_prefixtree(ListFound),
nb_getval(problog_completed_proofs, Trie_Completed_Proofs),
trie_to_bdd(Trie_Completed_Proofs, BDD, MapList),
delete_ptree(Trie_Completed_Proofs).
problog_fl_bdd(Goal, _) :-
init_problog_low(0.0),
problog_control(off, up),
timer_start(sld_time),
problog_call(Goal),
add_solution,
fail.
problog_fl_bdd(_,Prob) :-
timer_stop(sld_time,SLD_Time),
problog_var_set(sld_time, SLD_Time),
nb_getval(problog_completed_proofs, Trie_Completed_Proofs),
tabled_trie_to_bdd(Trie_Completed_Proofs, BDD, MapList),
bind_maplist(MapList, BoundVars),
bdd_to_probability_sum_product(BDD, BoundVars, Prob),
(problog_flag(retain_tables, true) -> retain_tabling; true),
clear_tabling.
bind_maplist([], []).
bind_maplist([Node-_|MapList], [ProbFact|BoundVars]) :-
get_fact_probability(Node,ProbFact),
bind_maplist(MapList, BoundVars).