added a new version of iterative deepening

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@2272 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
rzf 2008-06-09 17:57:30 +00:00
parent e835cfddc5
commit c1f9fc9bcf
5 changed files with 846 additions and 31 deletions

View File

@ -155,7 +155,7 @@ static int compute_prob(void)
/* the BDD build by retFunction is converted to an ADD (algebraic decision diagram)
because it is easier to interpret and to print */
add=Cudd_BddToAdd(mgr,function);
Cudd_PrintInfo(mgr,stderr);
//Cudd_PrintInfo(mgr,stderr);
if (create_dot)
/* if specified by the user, a dot file for the BDD is written to cpl.dot */

View File

@ -23,6 +23,7 @@ only the head is grounded. In the case in which the body contains variables
not appearing in the head, the body represents an existential event */
setting(min_error,0.01).
setting(depth_bound,4).
setting(prob_threshold,0.00001).
/* end of list of parameters */
/* s(GoalsLIst,Prob) compute the probability of a list of goals
@ -102,14 +103,47 @@ solve(GoalsList,Prob,CPUTime1,CPUTime2,WallTime1,WallTime2):-
si(GoalsList,ProbL,ProbU,CPUTime):-
statistics(cputime,[_,_]),
setting(depth_bound,D),
solvei(GoalsList,D,ProbL,ProbU),
solve_i([(GoalsList,[])],[],D,ProbL,ProbU),
statistics(cputime,[_,CT]),
CPUTime is CT/1000.
solvei(GoalsList,D,ProbL0,ProbU0):-
(setof(Deriv,find_deriv(GoalsList,D,Deriv),LDup)->
solve_i(L0,Succ,D,ProbL0,ProbU0):-
(findall((G1,Deriv),(member((G0,C0),L0),solvei(G0,D,C0,Deriv,G1)),L)->
% print_mem,
separate_ulbi(L,[],LL0,[],LU,[],Incomplete),
append(Succ,LL0,LL),
compute_prob_deriv(LL,ProbL),
append(Succ,LU,LU1),
compute_prob_deriv(LU1,ProbU),
Err is ProbU-ProbL,
setting(min_error,ME),
(Err<ME->
ProbU0=ProbU,
ProbL0=ProbL
;
setting(depth_bound,DB),
D1 is D+DB,
solve_i(Incomplete,LL,D1,ProbL0,ProbU0)
)
;
% print_mem,
ProbL0=0.0,
ProbU0=0.0
).
sir(GoalsList,ProbL,ProbU,CPUTime):-
statistics(cputime,[_,_]),
setting(depth_bound,D),
solveir(GoalsList,D,ProbL,ProbU),
statistics(cputime,[_,CT]),
CPUTime is CT/1000.
solveir(GoalsList,D,ProbL0,ProbU0):-
(setof(Deriv,find_derivr(GoalsList,D,Deriv),LDup)->
rem_dup_lists(LDup,[],L),
% print_mem,
separate_ulb(L,[],LL,[],LU),
@ -123,7 +157,7 @@ solvei(GoalsList,D,ProbL0,ProbU0):-
;
setting(depth_bound,DB),
D1 is D+DB,
solvei(GoalsList,D1,ProbL0,ProbU0)
solveir(GoalsList,D1,ProbL0,ProbU0)
)
;
% print_mem,
@ -131,6 +165,33 @@ solvei(GoalsList,D,ProbL0,ProbU0):-
ProbU0=0.0
).
sic(GoalsList,ProbL,ProbU,CPUTime):-
statistics(cputime,[_,_]),
setting(depth_bound,D),
solveic(GoalsList,D,ProbL,ProbU),
statistics(cputime,[_,CT]),
CPUTime is CT/1000.
solveic(GoalsList,D,ProbL0,ProbU0):-
(setof((Deriv,P,Pruned),solvec(GoalsList,D,[],Deriv,1.0,P,Pruned),L)->
% print_mem,
separate_ulbc(L,[],LL,0,Err),
compute_prob_deriv(LL,ProbL0),
ProbU0 is ProbL0+Err
/*(ProbU>1.0->
ProbU0=1.0
;
ProbU0=ProbU
)*/
;
% print_mem,
ProbL0=0.0,
ProbU0=0.0
).
compute_prob_deriv(LL,ProbL):-
build_formula(LL,FormulaL,[],VarL,0,ConjL),
length(LL,NDL),
@ -158,10 +219,11 @@ find_deriv(GoalsList,Deriv):-
solve(GoalsList,[],DerivDup),
remove_duplicates(DerivDup,Deriv).
find_deriv(GoalsList,DB,Deriv):-
solve(GoalsList,DB,[],DerivDup),
find_derivr(GoalsList,DB,Deriv):-
solver(GoalsList,DB,[],DerivDup),
remove_duplicates(DerivDup,Deriv).
/* duplicate can appear in the C set because two different unistantiated clauses may become the
same clause when instantiated */
@ -200,15 +262,68 @@ solve_cond(Goals,Evidence,Prob):-
sci(Goals,Evidence,ProbL,ProbU,CPUTime):-
statistics(cputime,[_,_]),
setting(depth_bound,D),
solve_condi(Goals,Evidence,D,ProbL,ProbU),
append(Goals,Evidence,GE),
solve_condi([(GE,[])],[(Evidence,[])],[],[],D,ProbL,ProbU),
statistics(cputime,[_,CT]),
CPUTime is CT/1000.
solve_condi(Goals,Evidence,D,ProbL0,ProbU0):-
(call_residue(setof(DerivE,find_deriv(Evidence,D,DerivE),LDupE),_R0)->
solve_condi(LGoals,LEvidence,SuccGE,SuccE,D,ProbL0,ProbU0):-
findall((GE1,DerivE),
(member((GE,CE),LEvidence),solvei(GE,D,CE,DerivE,GE1)),
LE),
findall((GE1,DerivE),
(member((GE,CE),LGoals),solvei(GE,D,CE,DerivE,GE1)),
LGE),
separate_ulbi(LE,[],LLE0,[],LUE0,[],IncE),
append(SuccE,LUE0,LUE),
compute_prob_deriv(LUE,ProbUE),
(ProbUE\==0.0->
separate_ulbi(LGE,[],LLGE0,[],LUGE0,[],IncGE),
append(SuccGE,LLGE0,LLGE),
compute_prob_deriv(LLGE,ProbLGE),
ProbL is ProbLGE/ProbUE,
append(SuccE,LLE0,LLE),
compute_prob_deriv(LLE,ProbLE),
(ProbLE\==0.0->
append(SuccGE,LUGE0,LUGE),
compute_prob_deriv(LUGE,ProbUGE),
ProbU1 is ProbUGE/ProbLE
;
ProbU1=1.0
),
(ProbU1>1.0->
ProbU=1.0
;
ProbU=ProbU1
),
Err is ProbU-ProbL,
setting(min_error,ME),
(Err<ME->
ProbU0=ProbU,
ProbL0=ProbL
;
setting(depth_bound,DB),
D1 is D+DB,
solve_condi(IncGE,IncE,LLGE,LLE,D1,ProbL0,ProbU0)
)
;
ProbL0=undefined,
ProbU0=undefined
).
scir(Goals,Evidence,ProbL,ProbU,CPUTime):-
statistics(cputime,[_,_]),
setting(depth_bound,D),
solve_condir(Goals,Evidence,D,ProbL,ProbU),
statistics(cputime,[_,CT]),
CPUTime is CT/1000.
solve_condir(Goals,Evidence,D,ProbL0,ProbU0):-
(call_residue(setof(DerivE,find_derivr(Evidence,D,DerivE),LDupE),_R0)->
rem_dup_lists(LDupE,[],LE),
append(Evidence,Goals,EG),
(call_residue(setof(DerivGE,find_deriv(EG,D,DerivGE),LDupGE),_R1)->
(call_residue(setof(DerivGE,find_derivr(EG,D,DerivGE),LDupGE),_R1)->
rem_dup_lists(LDupGE,[],LGE),
separate_ulb(LGE,[],LLGE,[],LUGE),
compute_prob_deriv(LLGE,ProbLGE),
@ -235,7 +350,54 @@ solve_condi(Goals,Evidence,D,ProbL0,ProbU0):-
;
setting(depth_bound,DB),
D1 is D+DB,
solve_condi(Goals,Evidence,D1,ProbL0,ProbU0)
solve_condir(Goals,Evidence,D1,ProbL0,ProbU0)
)
;
ProbL0=0.0,
ProbU0=0.0
)
;
ProbL0=undefined,
ProbU0=undefined
).
scic(Goals,Evidence,ProbL,ProbU,CPUTime):-
statistics(cputime,[_,_]),
setting(depth_bound,D),
solve_condic(Goals,Evidence,D,ProbL,ProbU),
statistics(cputime,[_,CT]),
CPUTime is CT/1000.
solve_condic(Goals,Evidence,D,ProbL0,ProbU0):-
(call_residue(setof((DerivE,P,Pruned),solvec(Evidence,D,[],DerivE,1.0,P,Pruned),LE),_R0)->
append(Evidence,Goals,EG),
(call_residue(setof((DerivGE,P,Pruned),solvec(EG,D,[],DerivGE,1.0,P,Pruned),LGE),_R1)->
separate_ulbc(LGE,[],LLGE,0.0,ErrGE),
compute_prob_deriv(LLGE,ProbLGE),
separate_ulbc(LE,[],LLE,0.0,ErrE),
compute_prob_deriv(LLE,ProbLE),
ProbUGE0 is ProbLGE+ErrGE,
(ProbUGE0>1.0->
ProbUGE=1.0
;
ProbUGE=ProbUGE0
),
ProbUE0 is ProbLE+ErrE,
(ProbUE0>1.0->
ProbUE=1.0
;
ProbUE=ProbUE0
),
ProbL0 is ProbLGE/ProbUE,
(ProbLE=0.0->
ProbU1=1.0
;
ProbU1 is ProbUGE/ProbLE
),
(ProbU1>1.0->
ProbU0=1.0
;
ProbU0=ProbU1
)
;
ProbL0=0.0,
@ -401,13 +563,48 @@ solve([H|T],CIn,COut):-
solve_pres(R,S,N,B,T,CIn,COut).
solve([],_DB,C,C):-!.
solvei([],_DB,C,C,[]):-!.
solve(_G,0,C,[(_,pruned,_)|C]):-!.
solvei(G,0,C,C,G):-!.
solve([\+ H |T],DB,CIn,COut):-!,
solvei([\+ H |T],DB,CIn,COut,G):-!,
list2and(HL,H),
(setof(D,find_deriv(HL,DB,D),LDup)->
(findall((GH,D),solvei(HL,DB,CIn,D,GH),L)->
separate_ulbi(L,[],LB,[],UB,[],I),
(I\=[]->
C1=CIn,
G=[\+ H|G1]
;
choose_clauses(CIn,LB,C1),
G=G1
),
solvei(T,DB,C1,COut,G1)
;
solvei(T,DB,CIn,COut,G1)
).
solvei([H|T],DB,CIn,COut,G):-
builtin(H),!,
call(H),
solvei(T,DB,CIn,COut,G).
solvei([H|T],DB,CIn,COut,G):-
def_rule(H,B),
append(B,T,NG),
DB1 is DB-1,
solvei(NG,DB1,CIn,COut,G).
solvei([H|T],DB,CIn,COut,G):-
find_rule(H,(R,S,N),B,CIn),
DB1 is DB-1,
solve_presi(R,S,N,B,T,DB1,CIn,COut,G).
solver([],_DB,C,C):-!.
solver(_G,0,C,[(_,pruned,_)|C]):-!.
solver([\+ H |T],DB,CIn,COut):-!,
list2and(HL,H),
(setof(D,find_derivr(HL,DB,D),LDup)->
rem_dup_lists(LDup,[],L),
separate_ulb(L,[],LB,[],UB),
(\+ LB=UB->
@ -417,25 +614,68 @@ solve([\+ H |T],DB,CIn,COut):-!,
;
choose_clauses(CIn,L,C1)
),
solve(T,DB,C1,COut)
solver(T,DB,C1,COut)
;
solve(T,DB,CIn,COut)
solver(T,DB,CIn,COut)
).
solve([H|T],DB,CIn,COut):-
solver([H|T],DB,CIn,COut):-
builtin(H),!,
call(H),
solve(T,DB,CIn,COut).
solver(T,DB,CIn,COut).
solve([H|T],DB,CIn,COut):-
solver([H|T],DB,CIn,COut):-
def_rule(H,B),
append(B,T,NG),
DB1 is DB-1,
solve(NG,DB1,CIn,COut).
solver(NG,DB1,CIn,COut).
solve([H|T],DB,CIn,COut):-
solver([H|T],DB,CIn,COut):-
find_rule(H,(R,S,N),B,CIn),
DB1 is DB-1,
solve_pres(R,S,N,B,T,DB1,CIn,COut).
solve_presr(R,S,N,B,T,DB1,CIn,COut).
solvec([],_DB,C,C,P,P,false):-!.
solvec(_G,0,C,C,P,P,true):-!.
solvec(_G,_DB,C,C,P,P,true):-
setting(prob_threshold,T),
P=<T,!.
solvec([\+ H |T],DB,CIn,COut,P0,P1,Pruned):-!,
list2and(HL,H),
(setof((D,P,Pr),solvec(HL,DB,[],D,1,P,Pr),L)->
separate_ulbc(L,[],LB,0.0,PP),
(PP=\=0.0->
choose_clausesc(CIn,LB,C1,P0,P2),
Pruned=true,
solvec(T,DB,C1,COut,P2,P1,_)
;
choose_clausesc(CIn,LB,C1,P0,P2),
solvec(T,DB,C1,COut,P2,P1,Pruned)
)
;
solve(T,DB,CIn,COut,P0,P1,Pruned)
).
solvec([H|T],DB,CIn,COut,P0,P1,Pruned):-
builtin(H),!,
call(H),
solvec(T,DB,CIn,COut,P0,P1,Pruned).
solvec([H|T],DB,CIn,COut,P0,P1,Pruned):-
def_rule(H,B),
append(B,T,NG),
DB1 is DB-1,
solvec(NG,DB1,CIn,COut,P0,P1,Pruned).
solvec([H|T],DB,CIn,COut,P0,P1,Pruned):-
find_rulec(H,(R,S,N),B,CIn,P),
DB1 is DB-1,
solve_presc(R,S,N,B,T,DB1,CIn,COut,P,P0,P1,Pruned).
@ -449,15 +689,39 @@ solve_pres(R,S,N,B,T,CIn,COut):-
append(B,T,NG),
solve(NG,C1,COut).
solve_pres(R,S,N,B,T,DB,CIn,COut):-
solve_presi(R,S,N,B,T,DB,CIn,COut,G):-
member_eq((N,R,S),CIn),!,
append(B,T,NG),
solve(NG,DB,CIn,COut).
solvei(NG,DB,CIn,COut,G).
solve_pres(R,S,N,B,T,DB,CIn,COut):-
solve_presi(R,S,N,B,T,DB,CIn,COut,G):-
append(CIn,[(N,R,S)],C1),
append(B,T,NG),
solve(NG,DB,C1,COut).
solvei(NG,DB,C1,COut,G).
solve_presr(R,S,N,B,T,DB,CIn,COut):-
member_eq((N,R,S),CIn),!,
append(B,T,NG),
solver(NG,DB,CIn,COut).
solve_presr(R,S,N,B,T,DB,CIn,COut):-
append(CIn,[(N,R,S)],C1),
append(B,T,NG),
solver(NG,DB,C1,COut).
solve_presc(R,S,N,B,T,DB,CIn,COut,_,P0,P1,Pruned):-
member_eq((N,R,S),CIn),!,
append(B,T,NG),
solvec(NG,DB,CIn,COut,P0,P1,Pruned).
solve_presc(R,S,N,B,T,DB,CIn,COut,P,P0,P1,Pruned):-
append(CIn,[(N,R,S)],C1),
append(B,T,NG),
P2 is P0*P,
solvec(NG,DB,C1,COut,P2,P1,Pruned).
build_initial_graph(N,G):-
listN(0,N,Vert),
@ -524,6 +788,12 @@ find_rule(H,(R,S,Number),Body,C):-
rule(R,S,_,uniform(H:1/_Num,_P,Number),Body),
not_already_present_with_a_different_head(Number,R,S,C).
find_rulec(H,(R,S,N),Body,C,P):-
rule(R,S,_,Head,Body),
member_headc(H,Head,0,N,P),
not_already_present_with_a_different_head(N,R,S,C).
not_already_present_with_a_different_head(_N,_R,_S,[]).
@ -552,6 +822,13 @@ member_head(H,[(_H:_P)|T],NIn,NOut):-
N1 is NIn+1,
member_head(H,T,N1,NOut).
member_headc(H,[(H:P)|_T],N,N,P).
member_headc(H,[(_H:_P)|T],NIn,NOut,P):-
N1 is NIn+1,
member_headc(H,T,N1,NOut,P).
/* choose_clauses(CIn,LC,COut) takes as input the current C set and
the set of C sets for a negative goal and returns a new C set that
excludes all the derivations for the negative goals */
@ -571,6 +848,26 @@ choose_clauses(CIn,[D|T],COut):-
impose_dif_cons(R,S,CIn),
choose_clauses([(N1,R,S)|CIn],T,COut).
choose_clausesc(C,[],C,P,P).
choose_clausesc(CIn,[D|T],COut,P0,P1):-
member((N,R,S),D),
already_present_with_a_different_head(N,R,S,CIn),!,
choose_a_headc(N,R,S,CIn,C1,P0,P2),
choose_clausesc(C1,T,COut,P2,P1).
choose_clausesc(CIn,[D|T],COut,P0,P1):-
member((N,R,S),D),
new_head(N,R,S,N1),
\+ already_present(N1,R,S,CIn),
impose_dif_cons(R,S,CIn),
rule(R,S,_Numbers,Head,_Body),
nth0(N1, Head, (_H:P), _Rest),
P2 is P0*P,
choose_clausesc([(N1,R,S)|CIn],T,COut,P2,P1).
choose_clauses_DB(C,[],C).
choose_clauses_DB(CIn,[D|T],COut):-
@ -619,6 +916,26 @@ dif_head_or_subs(N,R,S,N,SH,T):-
dif(S,SH),
instantiation_present_with_the_same_head(N,R,S,T).
/* case 1 of Select: a more general rule is present in C with
a different head, instantiate it */
choose_a_headc(N,R,S,[(NH,R,SH)|T],[(NH,R,SH)|T],P,P):-
S=SH,
dif(N,NH).
/* case 2 of Select: a more general rule is present in C with
a different head, ensure that they do not generate the same
ground clause */
choose_a_headc(N,R,S,[(NH,R,SH)|T],[(NH,R,S),(NH,R,SH)|T],P0,P1):-
\+ \+ S=SH, S\==SH,
dif(N,NH),
dif(S,SH),
rule(R,S,_Numbers,Head,_Body),
nth0(NH, Head, (_H:P), _Rest),
P1 is P0*P.
choose_a_headc(N,R,S,[H|T],[H|T1],P0,P1):-
choose_a_headc(N,R,S,T,T1,P0,P1).
/* case 1 of Select: a more general rule is present in C with
a different head, instantiate it */
choose_a_head(N,R,S,[(NH,R,SH)|T],[(NH,R,SH)|T]):-
@ -636,6 +953,7 @@ choose_a_head(N,R,S,[(NH,R,SH)|T],[(NH,R,S),(NH,R,SH)|T]):-
choose_a_head(N,R,S,[H|T],[H|T1]):-
choose_a_head(N,R,S,T,T1).
/* select a head different from N for rule R with
substitution S, return it in N1 */
new_head(N,R,S,N1):-
@ -684,6 +1002,20 @@ member_subset(E,[H|_T]):-
member_subset(E,[_H|T]):-
member_subset(E,T).
separate_ulbi([],L,L,U,U,I,I):-!.
/*
separate_ulb([H|T],L0,L1,U0,[H|U1]):-
member(pruned,H),!,
separate_ulb(T,L0,L1,U0,U1).
*/
separate_ulbi([([],H)|T],L0,[H|L1],U0,[H|U1],I0,I1):-
!,
separate_ulbi(T,L0,L1,U0,U1,I0,I1).
separate_ulbi([(G,H)|T],L0,L1,U0,[H1|U1],I0,[(G,H)|I1]):-
get_ground(H,H1),
separate_ulbi(T,L0,L1,U0,U1,I0,I1).
separate_ulb([],L,L,U,U):-!.
/*
@ -699,6 +1031,17 @@ separate_ulb([H|T],L0,L1,U0,[H1|U1]):-
get_ground(H,H1),
separate_ulb(T,L0,L1,U0,U1).
separate_ulbc([],L,L,P,P):-!.
separate_ulbc([(H,P,true)|T],L0,L1,P0,P1):-!,
P2 is P0+P,
separate_ulbc(T,L0,L1,P2,P1).
separate_ulbc([(H,_P,false)|T],L0,[H|L1],P0,P1):-
separate_ulbc(T,L0,L1,P0,P1).
get_ground([],[]):-!.
get_ground([H|T],[H|T1]):-

View File

@ -70,10 +70,12 @@ test_alli(F,[H|T]):-
files([
exapprox,exrange,
exapprox,
exrange,
threesideddice,
mendel,
coin2,ex,trigger,throws,light]).
%mendel,
coin2,ex,trigger,throws,light
]).
test((s([death],P),close_to(P,0.305555555555556)),trigger,_).

236
cplint/testlpadslditc.pl Normal file
View File

@ -0,0 +1,236 @@
/*
LPAD and CP-Logic reasoning suite
Copyright (c) 2007, Fabrizio Riguzzi
Test file for lpadsld.pl, case where the body is grounded
Use
:-t.
to execute the test
*/
:-source.
:-use_module(library(lpadsld)).
epsilon(0.000001).
close_to(V,T):-
epsilon(E),
TLow is T-E,
THigh is T+E,
TLow<V,
V<THigh.
t:-
format("~nTesting iterative deepening lpadsld.yap~n~n",[]),
files(F),
statistics(runtime,[_,_]),
set(ground_body,true),
set(depth_bound,7),
set(min_error,0.05),
format("~nGround body~n~n",[]),
test_filesi(F,ground_body(true)),
statistics(runtime,[_,T]),
T1 is T /1000,
format("Test successful, time ~f secs.~n",[T1]).
t:-
format("Test unsuccessful.~n",[]).
test_filesi([],_GB).
test_filesi([H|T],GB):-
library_directory(LD),
atom_concat(LD,'/cplint/examples/',ExDir),
atom_concat(ExDir,H,NH),
p(NH),!,
findall(A,test(A,H,GB),L),
test_alli(H,L),
test_filesi(T,GB).
test_alli(_F,[]).
test_alli(F,[H|T]):-
copy_term(H,NH),
NH=(s(Q,_P),close_to('P',P)),!,
format("~a ~p.~n",[F,NH]),
sic(Q,PL,PU,_Time),!,
format("Lower bound ~f, Upper bound ~f~n",[PL,PU]),
P>=PL-1e-7,P=<PU+1e-7,
test_alli(F,T).
test_alli(F,[H|T]):-
copy_term(H,NH),
NH=(sc(Q,E,_P),close_to('P',P)),
format("~a ~p.~n",[F,NH]),
scic(Q,E,PL,PU,_Time),!,
format("Lower bound ~f, Upper bound ~f~n",[PL,PU]),
P>=PL-1e-10,P=<PU+1e-10,
test_alli(F,T).
files([
exapprox,
exrange,
threesideddice,
mendel,
coin2,ex,trigger,throws,light
]).
test((s([death],P),close_to(P,0.305555555555556)),trigger,_).
test((s([throws(mary),throws(john),break],P),close_to(P,0.46)),throws,_).
test((s([throws(mary),throws(john),\+break],P),close_to(P,0.04)),throws,_).
test((s([\+ throws(mary),throws(john),break],P),close_to(P,0.3)),throws,_).
test((s([\+ throws(mary),throws(john),\+ break],P),close_to(P,0.2)),throws,_).
test((s([push,replace],P),close_to(P,0.5)),light,_).
test((s([push,light],P),close_to(P,0.5)),light,_).
test((s([push,light,replace],P),close_to(P,0)),light,_).
test((s([light,replace],P),close_to(P,0)),light,_).
test((s([light],P),close_to(P,0.5)),light,_).
test((s([replace],P),close_to(P,0.5)),light,_).
test((s([\+ cites_cited(c1,p1)],P),close_to(P,0.7)),paper_ref_not,_).
test((s([cites_citing(c1,p1)],P),close_to(P,0.14)),paper_ref_not,_).
test((s([cites_cited(c1,p1)],P),close_to(P,0.181333333)),paper_ref,_).
test((s([cites_cited(c1,p2)],P),close_to(P,0.181333333)),paper_ref,_).
test((s([cites_cited(c1,p4)],P),close_to(P,0.181333333)),paper_ref,_).
test((s([cites_cited(c1,p3)],P),close_to(P,0.228)),paper_ref,_).
test((s([cites_cited(c1,p5)],P),close_to(P,0.228)),paper_ref,_).
test((s([female(f)],P),close_to(P,0.6)),female,_).
test((s([male(f)],P),close_to(P,0.4)),female,_).
test((s([a],P),close_to(P,0.1719)),exapprox,ground_body(true)).
test((s([a],P),close_to(P,0.099)),exapprox,ground_body(false)).
test((s([a(1)],P),close_to(P,0.2775)),exrange,_).
test((s([a(2)],P),close_to(P,0.36)),exrange,_).
test((s([on(0,1)],P),close_to(P,0.333333333333333)),threesideddice,_).
test((s([on(1,1)],P),close_to(P,0.222222222222222)),threesideddice,_).
test((s([on(2,1)],P),close_to(P,0.148148147703704)),threesideddice,_).
test((s([on(3,1)],P),close_to(P,0.0987654320987654)),threesideddice,_).
test((s([on(4,1)],P),close_to(P,0.0658436213991769)),threesideddice,_).
test((sc([on(2,1)],[on(0,1)],P),close_to(P,0.222222222222222)),threesideddice,_).
test((sc([on(2,1)],[on(1,1)],P),close_to(P,0.333333333333333)),threesideddice,_).
test((sc([on(4,1)],[on(1,1)],P),close_to(P, 0.148148148148148)),threesideddice,_).
test((sc([on(5,1)],[on(2,1)],P),close_to(P, 0.148148148148148)),threesideddice,_).
test((s([cg(s,1,p)],P),close_to(P,0.75)),mendel,_).
test((s([cg(s,1,w)],P),close_to(P,0.25)),mendel,_).
test((s([cg(s,2,p)],P),close_to(P,0.25)),mendel,_).
test((s([cg(s,2,w)],P),close_to(P,0.75)),mendel,_).
test((s([cg(f,2,w)],P),close_to(P,0.5)),mendel,_).
test((s([cg(s,2,w)],P),close_to(P,0.75)),mendel,_).
test((s([a],P),close_to(P,0.226)),ex,_).
test((s([heads(coin1)],P),close_to(P,0.51)),coin2,_).
test((s([heads(coin2)],P),close_to(P,0.51)),coin2,_).
test((s([tails(coin1)],P),close_to(P,0.49)),coin2,_).
test((s([tails(coin2)],P),close_to(P,0.49)),coin2,_).
test((s([student_rank(jane_doe,h)],P),close_to(P,0.465)),student,_).
test((s([student_rank(jane_doe,l)],P),close_to(P,0.535)),student,_).
test((s([course_rat(phil101,h)],P),close_to(P,0.330656)),student,_).
test((s([course_rat(phil101,l)],P),close_to(P,0.669344)),student,_).
test((s([professor_ability(p0,h)],P),close_to(P,0.5)),school,_).
test((s([professor_ability(p0,m)],P),close_to(P,0.4)),school,_).
test((s([professor_ability(p0,l)],P),close_to(P,0.1)),school,_).
test((s([professor_popularity(p0,h)],P),close_to(P,0.531)),school,_).
test((s([professor_popularity(p0,l)],P),close_to(P,0.175)),school,_).
test((s([professor_popularity(p0,m)],P),close_to(P,0.294)),school,_).
test((sc([professor_ability(p0,h)],[professor_popularity(p0,h)],P),close_to(P,0.847457627118644)),school,_).
test((sc([professor_ability(p0,l)],[professor_popularity(p0,h)],P),close_to(P,0.00188323917137476)),school,_).
test((sc([professor_ability(p0,m)],[professor_popularity(p0,h)],P),close_to(P,0.150659133709981)),school,_).
test((sc([professor_popularity(p0,h)],[professor_ability(p0,h)],P),close_to(P,0.9)),school,_).
test((sc([professor_popularity(p0,l)],[professor_ability(p0,h)],P),close_to(P,0.01)),school,_).
test((sc([professor_popularity(p0,m)],[professor_ability(p0,h)],P),close_to(P,0.09)),school,_).
test(( s([registration_grade(r0,1)],P),close_to(P,0.06675)),school,_).
test(( s([registration_grade(r0,2)],P),close_to(P,0.16575)),school,_).
test(( s([registration_grade(r0,3)],P),close_to(P, 0.356)),school,_).
test(( s([registration_grade(r0,4)],P),close_to(P,0.4115)),school,_).
test((sc([registration_grade(r0,1)],[registration_course(r0,C), course_difficulty(C,h)],P),close_to(P,0.15)),school,_).
test((sc([registration_grade(r0,2)],[registration_course(r0,C), course_difficulty(C,h)],P),close_to(P,0.285)),school,_).
test((sc([registration_grade(r0,3)],[registration_course(r0,C), course_difficulty(C,h)],P),close_to(P,0.424)),school,_).
test((sc([registration_grade(r0,4)],[registration_course(r0,C), course_difficulty(C,h)],P),close_to(P,0.141)),school,_).
test((sc([registration_grade(r0,1)], [registration_course(r0,C), course_difficulty(C,h),
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.05)),school,_).
test((sc([registration_grade(r0,2)], [registration_course(r0,C), course_difficulty(C,h),
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.15)),school,_).
test((sc([registration_grade(r0,3)], [registration_course(r0,C), course_difficulty(C,h),
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.6)),school,_).
test((sc([registration_grade(r0,4)], [registration_course(r0,C), course_difficulty(C,h),
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.2)),school,_).
test((sc([registration_grade(r0,1)],[registration_course(r0,C), course_difficulty(C,l),
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.01)),school,_).
test((sc([registration_grade(r0,2)],[registration_course(r0,C), course_difficulty(C,l),
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.02)),school,_).
test((sc([registration_grade(r0,3)],[registration_course(r0,C), course_difficulty(C,l),
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.12)),school,_).
test((sc([registration_grade(r0,4)],[registration_course(r0,C), course_difficulty(C,l),
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.85)),school,_).
test((s([registration_satisfaction(r0,1)],P),close_to(P,0.15197525)),school,_).
test((s([registration_satisfaction(r0,2)],P),close_to(P,0.1533102)),school,_).
test((s([registration_satisfaction(r0,3)],P),close_to(P,0.6947145)),school,_).
test((sc([registration_satisfaction(r0,1)],[ registration_student(r0,S),
student_intelligence(S,h)],P),close_to(P,0.0959225)),school,_).
test((sc([registration_satisfaction(r0,2)],[ registration_student(r0,S),
student_intelligence(S,h)],P),close_to(P,0.124515)),school,_).
test((sc([registration_satisfaction(r0,3)],[ registration_student(r0,S),
student_intelligence(S,h)],P),close_to(P,0.7795625)),school,_).
test((sc([registration_satisfaction(r0,1)],[registration_grade(r0,4)],P),close_to(P,0.04)),school,_).
test((sc([registration_satisfaction(r0,2)],[registration_grade(r0,4)],P),close_to(P,0.06)),school,_).
test((sc([registration_satisfaction(r0,3)],[registration_grade(r0,4)],P),close_to(P,0.9)),school,_).
test((sc([registration_satisfaction(r0,1)],[registration_grade(r0,1)],P),close_to(P,0.528)),school,_).
test((sc([registration_satisfaction(r0,2)],[registration_grade(r0,1)],P),close_to(P,0.167)),school,_).
test((sc([registration_satisfaction(r0,3)],[registration_grade(r0,1)],P),close_to(P,0.305)),school,_).
test((sc([ registration_grade(r0,1)],[registration_satisfaction(r0,3)],P),close_to(P,0.0293052037923492)),school,_).
test((sc([ registration_grade(r0,2)],[registration_satisfaction(r0,3)],P),close_to(P, 0.114760451955444)),school,_).
test((sc([ registration_grade(r0,3)],[registration_satisfaction(r0,3)],P),close_to(P,0.322837654892765)),school,_).
test((sc([ registration_grade(r0,4)],[registration_satisfaction(r0,3)],P),close_to(P,0.533096689359442)),school,_).
test((s([course_rating(c0,h)],P),close_to(P,0.5392099)),school,_).
test((s([course_rating(c0,l)],P),close_to(P, 0.2)),school,_).
test((s([course_rating(c0,m)],P),close_to(P,0.2607901)),school,_).
test((sc([course_difficulty(c0,h)],[course_rating(c0,h)],P),close_to(P,0.235185778302661)),school,_).
test((sc([course_difficulty(c0,l)],[course_rating(c0,h)],P),close_to(P,0.259096503977393)),school,_).
test((sc([course_difficulty(c0,m)],[course_rating(c0,h)],P),close_to(P,0.505717717719945)),school,_).
test((s([course_difficulty(c0,h)],P),close_to(P,0.25)),school,_).
test((s([course_difficulty(c0,l)],P),close_to(P,0.25)),school,_).
test((s([course_difficulty(c0,m)],P),close_to(P,0.5)),school,_).
test((s([student_ranking(s0,h)],P),close_to(P,0.6646250000000005)),school_simple,_).
test((s([student_ranking(s0,l)],P),close_to(P,0.33537499999999987)),school_simple,_).

234
cplint/testlpadslditr.pl Normal file
View File

@ -0,0 +1,234 @@
/*
LPAD and CP-Logic reasoning suite
Copyright (c) 2007, Fabrizio Riguzzi
Test file for lpadsld.pl, case where the body is grounded
Use
:-t.
to execute the test
*/
:-source.
:-use_module(library(lpadsld)).
epsilon(0.000001).
close_to(V,T):-
epsilon(E),
TLow is T-E,
THigh is T+E,
TLow<V,
V<THigh.
t:-
format("~nTesting iterative deepening lpadsld.yap~n~n",[]),
files(F),
statistics(runtime,[_,_]),
set(ground_body,true),
set(depth_bound,1),
set(min_error,0.05),
format("~nGround body~n~n",[]),
test_filesi(F,ground_body(true)),
statistics(runtime,[_,T]),
T1 is T /1000,
format("Test successful, time ~f secs.~n",[T1]).
t:-
format("Test unsuccessful.~n",[]).
test_filesi([],_GB).
test_filesi([H|T],GB):-
library_directory(LD),
atom_concat(LD,'/cplint/examples/',ExDir),
atom_concat(ExDir,H,NH),
p(NH),!,
findall(A,test(A,H,GB),L),
test_alli(H,L),
test_filesi(T,GB).
test_alli(_F,[]).
test_alli(F,[H|T]):-
copy_term(H,NH),
NH=(s(Q,_P),close_to('P',P)),!,
format("~a ~p.~n",[F,NH]),
sir(Q,PL,PU,_Time),!,
format("Lower bound ~f, Upper bound ~f~n",[PL,PU]),
P>=PL-1e-7,P=<PU+1e-7,
test_alli(F,T).
test_alli(F,[H|T]):-
copy_term(H,NH),
NH=(sc(Q,E,_P),close_to('P',P)),
format("~a ~p.~n",[F,NH]),
scir(Q,E,PL,PU,_Time),!,
format("Lower bound ~f, Upper bound ~f~n",[PL,PU]),
P>=PL-1e-10,P=<PU+1e-10,
test_alli(F,T).
files([
%exapprox,exrange,
threesideddice,
mendel,
coin2,ex,trigger,throws,light]).
test((s([death],P),close_to(P,0.305555555555556)),trigger,_).
test((s([throws(mary),throws(john),break],P),close_to(P,0.46)),throws,_).
test((s([throws(mary),throws(john),\+break],P),close_to(P,0.04)),throws,_).
test((s([\+ throws(mary),throws(john),break],P),close_to(P,0.3)),throws,_).
test((s([\+ throws(mary),throws(john),\+ break],P),close_to(P,0.2)),throws,_).
test((s([push,replace],P),close_to(P,0.5)),light,_).
test((s([push,light],P),close_to(P,0.5)),light,_).
test((s([push,light,replace],P),close_to(P,0)),light,_).
test((s([light,replace],P),close_to(P,0)),light,_).
test((s([light],P),close_to(P,0.5)),light,_).
test((s([replace],P),close_to(P,0.5)),light,_).
test((s([\+ cites_cited(c1,p1)],P),close_to(P,0.7)),paper_ref_not,_).
test((s([cites_citing(c1,p1)],P),close_to(P,0.14)),paper_ref_not,_).
test((s([cites_cited(c1,p1)],P),close_to(P,0.181333333)),paper_ref,_).
test((s([cites_cited(c1,p2)],P),close_to(P,0.181333333)),paper_ref,_).
test((s([cites_cited(c1,p4)],P),close_to(P,0.181333333)),paper_ref,_).
test((s([cites_cited(c1,p3)],P),close_to(P,0.228)),paper_ref,_).
test((s([cites_cited(c1,p5)],P),close_to(P,0.228)),paper_ref,_).
test((s([female(f)],P),close_to(P,0.6)),female,_).
test((s([male(f)],P),close_to(P,0.4)),female,_).
test((s([a],P),close_to(P,0.1719)),exapprox,ground_body(true)).
test((s([a],P),close_to(P,0.099)),exapprox,ground_body(false)).
test((s([a(1)],P),close_to(P,0.2775)),exrange,_).
test((s([a(2)],P),close_to(P,0.36)),exrange,_).
test((s([on(0,1)],P),close_to(P,0.333333333333333)),threesideddice,_).
test((s([on(1,1)],P),close_to(P,0.222222222222222)),threesideddice,_).
test((s([on(2,1)],P),close_to(P,0.148148147703704)),threesideddice,_).
test((s([on(3,1)],P),close_to(P,0.0987654320987654)),threesideddice,_).
test((s([on(4,1)],P),close_to(P,0.0658436213991769)),threesideddice,_).
test((sc([on(2,1)],[on(0,1)],P),close_to(P,0.222222222222222)),threesideddice,_).
test((sc([on(2,1)],[on(1,1)],P),close_to(P,0.333333333333333)),threesideddice,_).
test((sc([on(4,1)],[on(1,1)],P),close_to(P, 0.148148148148148)),threesideddice,_).
test((sc([on(5,1)],[on(2,1)],P),close_to(P, 0.148148148148148)),threesideddice,_).
test((s([cg(s,1,p)],P),close_to(P,0.75)),mendel,_).
test((s([cg(s,1,w)],P),close_to(P,0.25)),mendel,_).
test((s([cg(s,2,p)],P),close_to(P,0.25)),mendel,_).
test((s([cg(s,2,w)],P),close_to(P,0.75)),mendel,_).
test((s([cg(f,2,w)],P),close_to(P,0.5)),mendel,_).
test((s([cg(s,2,w)],P),close_to(P,0.75)),mendel,_).
test((s([a],P),close_to(P,0.226)),ex,_).
test((s([heads(coin1)],P),close_to(P,0.51)),coin2,_).
test((s([heads(coin2)],P),close_to(P,0.51)),coin2,_).
test((s([tails(coin1)],P),close_to(P,0.49)),coin2,_).
test((s([tails(coin2)],P),close_to(P,0.49)),coin2,_).
test((s([student_rank(jane_doe,h)],P),close_to(P,0.465)),student,_).
test((s([student_rank(jane_doe,l)],P),close_to(P,0.535)),student,_).
test((s([course_rat(phil101,h)],P),close_to(P,0.330656)),student,_).
test((s([course_rat(phil101,l)],P),close_to(P,0.669344)),student,_).
test((s([professor_ability(p0,h)],P),close_to(P,0.5)),school,_).
test((s([professor_ability(p0,m)],P),close_to(P,0.4)),school,_).
test((s([professor_ability(p0,l)],P),close_to(P,0.1)),school,_).
test((s([professor_popularity(p0,h)],P),close_to(P,0.531)),school,_).
test((s([professor_popularity(p0,l)],P),close_to(P,0.175)),school,_).
test((s([professor_popularity(p0,m)],P),close_to(P,0.294)),school,_).
test((sc([professor_ability(p0,h)],[professor_popularity(p0,h)],P),close_to(P,0.847457627118644)),school,_).
test((sc([professor_ability(p0,l)],[professor_popularity(p0,h)],P),close_to(P,0.00188323917137476)),school,_).
test((sc([professor_ability(p0,m)],[professor_popularity(p0,h)],P),close_to(P,0.150659133709981)),school,_).
test((sc([professor_popularity(p0,h)],[professor_ability(p0,h)],P),close_to(P,0.9)),school,_).
test((sc([professor_popularity(p0,l)],[professor_ability(p0,h)],P),close_to(P,0.01)),school,_).
test((sc([professor_popularity(p0,m)],[professor_ability(p0,h)],P),close_to(P,0.09)),school,_).
test(( s([registration_grade(r0,1)],P),close_to(P,0.06675)),school,_).
test(( s([registration_grade(r0,2)],P),close_to(P,0.16575)),school,_).
test(( s([registration_grade(r0,3)],P),close_to(P, 0.356)),school,_).
test(( s([registration_grade(r0,4)],P),close_to(P,0.4115)),school,_).
test((sc([registration_grade(r0,1)],[registration_course(r0,C), course_difficulty(C,h)],P),close_to(P,0.15)),school,_).
test((sc([registration_grade(r0,2)],[registration_course(r0,C), course_difficulty(C,h)],P),close_to(P,0.285)),school,_).
test((sc([registration_grade(r0,3)],[registration_course(r0,C), course_difficulty(C,h)],P),close_to(P,0.424)),school,_).
test((sc([registration_grade(r0,4)],[registration_course(r0,C), course_difficulty(C,h)],P),close_to(P,0.141)),school,_).
test((sc([registration_grade(r0,1)], [registration_course(r0,C), course_difficulty(C,h),
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.05)),school,_).
test((sc([registration_grade(r0,2)], [registration_course(r0,C), course_difficulty(C,h),
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.15)),school,_).
test((sc([registration_grade(r0,3)], [registration_course(r0,C), course_difficulty(C,h),
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.6)),school,_).
test((sc([registration_grade(r0,4)], [registration_course(r0,C), course_difficulty(C,h),
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.2)),school,_).
test((sc([registration_grade(r0,1)],[registration_course(r0,C), course_difficulty(C,l),
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.01)),school,_).
test((sc([registration_grade(r0,2)],[registration_course(r0,C), course_difficulty(C,l),
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.02)),school,_).
test((sc([registration_grade(r0,3)],[registration_course(r0,C), course_difficulty(C,l),
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.12)),school,_).
test((sc([registration_grade(r0,4)],[registration_course(r0,C), course_difficulty(C,l),
registration_student(r0,S), student_intelligence(S,h)],P),close_to(P,0.85)),school,_).
test((s([registration_satisfaction(r0,1)],P),close_to(P,0.15197525)),school,_).
test((s([registration_satisfaction(r0,2)],P),close_to(P,0.1533102)),school,_).
test((s([registration_satisfaction(r0,3)],P),close_to(P,0.6947145)),school,_).
test((sc([registration_satisfaction(r0,1)],[ registration_student(r0,S),
student_intelligence(S,h)],P),close_to(P,0.0959225)),school,_).
test((sc([registration_satisfaction(r0,2)],[ registration_student(r0,S),
student_intelligence(S,h)],P),close_to(P,0.124515)),school,_).
test((sc([registration_satisfaction(r0,3)],[ registration_student(r0,S),
student_intelligence(S,h)],P),close_to(P,0.7795625)),school,_).
test((sc([registration_satisfaction(r0,1)],[registration_grade(r0,4)],P),close_to(P,0.04)),school,_).
test((sc([registration_satisfaction(r0,2)],[registration_grade(r0,4)],P),close_to(P,0.06)),school,_).
test((sc([registration_satisfaction(r0,3)],[registration_grade(r0,4)],P),close_to(P,0.9)),school,_).
test((sc([registration_satisfaction(r0,1)],[registration_grade(r0,1)],P),close_to(P,0.528)),school,_).
test((sc([registration_satisfaction(r0,2)],[registration_grade(r0,1)],P),close_to(P,0.167)),school,_).
test((sc([registration_satisfaction(r0,3)],[registration_grade(r0,1)],P),close_to(P,0.305)),school,_).
test((sc([ registration_grade(r0,1)],[registration_satisfaction(r0,3)],P),close_to(P,0.0293052037923492)),school,_).
test((sc([ registration_grade(r0,2)],[registration_satisfaction(r0,3)],P),close_to(P, 0.114760451955444)),school,_).
test((sc([ registration_grade(r0,3)],[registration_satisfaction(r0,3)],P),close_to(P,0.322837654892765)),school,_).
test((sc([ registration_grade(r0,4)],[registration_satisfaction(r0,3)],P),close_to(P,0.533096689359442)),school,_).
test((s([course_rating(c0,h)],P),close_to(P,0.5392099)),school,_).
test((s([course_rating(c0,l)],P),close_to(P, 0.2)),school,_).
test((s([course_rating(c0,m)],P),close_to(P,0.2607901)),school,_).
test((sc([course_difficulty(c0,h)],[course_rating(c0,h)],P),close_to(P,0.235185778302661)),school,_).
test((sc([course_difficulty(c0,l)],[course_rating(c0,h)],P),close_to(P,0.259096503977393)),school,_).
test((sc([course_difficulty(c0,m)],[course_rating(c0,h)],P),close_to(P,0.505717717719945)),school,_).
test((s([course_difficulty(c0,h)],P),close_to(P,0.25)),school,_).
test((s([course_difficulty(c0,l)],P),close_to(P,0.25)),school,_).
test((s([course_difficulty(c0,m)],P),close_to(P,0.5)),school,_).
test((s([student_ranking(s0,h)],P),close_to(P,0.6646250000000005)),school_simple,_).
test((s([student_ranking(s0,l)],P),close_to(P,0.33537499999999987)),school_simple,_).