corrected bugs in handling negation
improved performance git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@2044 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
b8f97132d2
commit
7f925bcd5b
@ -33,7 +33,7 @@ s(GoalsList,Prob):-
|
|||||||
|
|
||||||
solve(GoalsList,Prob):-
|
solve(GoalsList,Prob):-
|
||||||
setof(Deriv,find_deriv(GoalsList,Deriv),LDup),
|
setof(Deriv,find_deriv(GoalsList,Deriv),LDup),
|
||||||
rem_dup_lists(LDup,L),
|
rem_dup_lists(LDup,[],L),
|
||||||
build_formula(L,Formula,[],Var),
|
build_formula(L,Formula,[],Var),
|
||||||
var2numbers(Var,0,NewVar),
|
var2numbers(Var,0,NewVar),
|
||||||
(setting(save_dot,true)->
|
(setting(save_dot,true)->
|
||||||
@ -63,7 +63,7 @@ sc(Goals,Evidence,Prob):-
|
|||||||
|
|
||||||
solve_cond(Goals,Evidence,Prob):-
|
solve_cond(Goals,Evidence,Prob):-
|
||||||
setof(DerivE,find_deriv(Evidence,DerivE),LDupE),
|
setof(DerivE,find_deriv(Evidence,DerivE),LDupE),
|
||||||
rem_dup_lists(LDupE,LE),
|
rem_dup_lists(LDupE,[],LE),
|
||||||
build_formula(LE,FormulaE,[],VarE),
|
build_formula(LE,FormulaE,[],VarE),
|
||||||
var2numbers(VarE,0,NewVarE),
|
var2numbers(VarE,0,NewVarE),
|
||||||
compute_prob(NewVarE,FormulaE,ProbE,0),
|
compute_prob(NewVarE,FormulaE,ProbE,0),
|
||||||
@ -72,7 +72,7 @@ solve_cond(Goals,Evidence,Prob):-
|
|||||||
|
|
||||||
solve_cond_goals(Goals,LE,ProbGE):-
|
solve_cond_goals(Goals,LE,ProbGE):-
|
||||||
setof(DerivGE,find_deriv_GE(LE,Goals,DerivGE),LDupGE),
|
setof(DerivGE,find_deriv_GE(LE,Goals,DerivGE),LDupGE),
|
||||||
rem_dup_lists(LDupGE,LGE),
|
rem_dup_lists(LDupGE,[],LGE),
|
||||||
build_formula(LGE,FormulaGE,[],VarGE),
|
build_formula(LGE,FormulaGE,[],VarGE),
|
||||||
var2numbers(VarGE,0,NewVarGE),
|
var2numbers(VarGE,0,NewVarGE),
|
||||||
call_compute_prob(NewVarGE,FormulaGE,ProbGE).
|
call_compute_prob(NewVarGE,FormulaGE,ProbGE).
|
||||||
@ -151,7 +151,7 @@ solve([setof(V,G,L)|T],CIn,COut):-!,
|
|||||||
solve([\+ H |T],CIn,COut):-!,
|
solve([\+ H |T],CIn,COut):-!,
|
||||||
list2and(HL,H),
|
list2and(HL,H),
|
||||||
(setof(D,find_deriv(HL,D),LDup)->
|
(setof(D,find_deriv(HL,D),LDup)->
|
||||||
rem_dup_lists(LDup,L),
|
rem_dup_lists(LDup,[],L),
|
||||||
choose_clauses(CIn,L,C1),
|
choose_clauses(CIn,L,C1),
|
||||||
solve(T,C1,COut)
|
solve(T,C1,COut)
|
||||||
;
|
;
|
||||||
@ -280,19 +280,25 @@ choose_clauses(C,[],C).
|
|||||||
|
|
||||||
choose_clauses(CIn,[D|T],COut):-
|
choose_clauses(CIn,[D|T],COut):-
|
||||||
member((N,R,S),D),
|
member((N,R,S),D),
|
||||||
instantiation_present_with_the_same_head(N,R,S,CIn),
|
choose_a_head(N,R,S,CIn,C1),!,
|
||||||
choose_a_different_head(N,R,S,T,CIn,COut).
|
choose_clauses(C1,T,COut).
|
||||||
|
|
||||||
choose_a_different_head(N,R,S,D,CIn,COut):-
|
|
||||||
/* cases 1 and 2 of Select */
|
|
||||||
choose_a_head(N,R,S,CIn,C1),
|
|
||||||
choose_clauses(C1,D,COut).
|
|
||||||
|
|
||||||
choose_a_different_head(N,R,S,D,CIn,COut):-
|
choose_clauses(CIn,[D|T],COut):-
|
||||||
/* case 3 of Select */
|
member((N,R,S),D),
|
||||||
new_head(N,R,S,N1),
|
new_head(N,R,S,N1),
|
||||||
\+ already_present(N1,R,S,CIn),
|
\+ already_present(N1,R,S,CIn),
|
||||||
choose_clauses([(N1,R,S)|CIn],D,COut).
|
impose_dif_cons(R,S,CIn),
|
||||||
|
choose_clauses([(N1,R,S)|CIn],T,COut).
|
||||||
|
|
||||||
|
impose_dif_cons(_R,_S,[]):-!.
|
||||||
|
|
||||||
|
impose_dif_cons(R,S,[(_NH,R,SH)|T]):-!,
|
||||||
|
dif(S,SH),
|
||||||
|
impose_dif_cons(R,S,T).
|
||||||
|
|
||||||
|
impose_dif_cons(R,S,[_H|T]):-
|
||||||
|
impose_dif_cons(R,S,T).
|
||||||
|
|
||||||
/* instantiation_present_with_the_same_head(N,R,S,C)
|
/* instantiation_present_with_the_same_head(N,R,S,C)
|
||||||
takes rule R with substitution S and selected head N and a C set
|
takes rule R with substitution S and selected head N and a C set
|
||||||
@ -301,19 +307,20 @@ is an instantitation and have the same head selected */
|
|||||||
instantiation_present_with_the_same_head(_N,_R,_S,[]).
|
instantiation_present_with_the_same_head(_N,_R,_S,[]).
|
||||||
|
|
||||||
instantiation_present_with_the_same_head(N,R,S,[(NH,R,SH)|T]):-
|
instantiation_present_with_the_same_head(N,R,S,[(NH,R,SH)|T]):-
|
||||||
\+ \+ S=SH,
|
\+ \+ S=SH,!,
|
||||||
|
dif_head_or_subs(N,R,S,NH,SH,T).
|
||||||
|
|
||||||
|
instantiation_present_with_the_same_head(N,R,S,[_H|T]):-
|
||||||
|
instantiation_present_with_the_same_head(N,R,S,T).
|
||||||
|
|
||||||
|
dif_head_or_subs(N,R,S,NH,_SH,T):-
|
||||||
dif(N,NH),
|
dif(N,NH),
|
||||||
instantiation_present_with_the_same_head(N,R,S,T).
|
instantiation_present_with_the_same_head(N,R,S,T).
|
||||||
|
|
||||||
instantiation_present_with_the_same_head(N,R,S,[(NH,R,SH)|T]):-
|
dif_head_or_subs(N,R,S,N,SH,T):-
|
||||||
\+ \+ S=SH,
|
|
||||||
N=NH,!,
|
|
||||||
dif(S,SH),
|
dif(S,SH),
|
||||||
instantiation_present_with_the_same_head(N,R,S,T).
|
instantiation_present_with_the_same_head(N,R,S,T).
|
||||||
|
|
||||||
instantiation_present_with_the_same_head(N,R,S,[_H|T]):-
|
|
||||||
instantiation_present_with_the_same_head(N,R,S,T).
|
|
||||||
|
|
||||||
/* case 1 of Select: a more general rule is present in C with
|
/* case 1 of Select: a more general rule is present in C with
|
||||||
a different head, instantiate it */
|
a different head, instantiate it */
|
||||||
choose_a_head(N,R,S,[(NH,R,SH)|T],[(NH,R,SH)|T]):-
|
choose_a_head(N,R,S,[(NH,R,SH)|T],[(NH,R,SH)|T]):-
|
||||||
@ -355,14 +362,16 @@ already_present(N,R,S,[_H|T]):-
|
|||||||
|
|
||||||
/* rem_dup_lists removes the C sets that are a superset of
|
/* rem_dup_lists removes the C sets that are a superset of
|
||||||
another C sets further on in the list of C sets */
|
another C sets further on in the list of C sets */
|
||||||
rem_dup_lists([],[]).
|
/* rem_dup_lists removes the C sets that are a superset of
|
||||||
|
another C sets further on in the list of C sets */
|
||||||
|
rem_dup_lists([],L,L).
|
||||||
|
|
||||||
rem_dup_lists([H|T],T1):-
|
rem_dup_lists([H|T],L0,L):-
|
||||||
member_subset(H,T),!,
|
(member_subset(H,T);member_subset(H,L0)),!,
|
||||||
rem_dup_lists(T,T1).
|
rem_dup_lists(T,L0,L).
|
||||||
|
|
||||||
rem_dup_lists([H|T],[H|T1]):-
|
rem_dup_lists([H|T],L0,L):-
|
||||||
rem_dup_lists(T,T1).
|
rem_dup_lists(T,[H|L0],L).
|
||||||
|
|
||||||
member_subset(E,[H|_T]):-
|
member_subset(E,[H|_T]):-
|
||||||
subset_my(H,E),!.
|
subset_my(H,E),!.
|
||||||
@ -370,6 +379,8 @@ member_subset(E,[H|_T]):-
|
|||||||
member_subset(E,[_H|T]):-
|
member_subset(E,[_H|T]):-
|
||||||
member_subset(E,T).
|
member_subset(E,T).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* predicates for building the formula to be converted into a BDD */
|
/* predicates for building the formula to be converted into a BDD */
|
||||||
|
|
||||||
/* build_formula(LC,Formula,VarIn,VarOut) takes as input a set of C sets
|
/* build_formula(LC,Formula,VarIn,VarOut) takes as input a set of C sets
|
||||||
|
Reference in New Issue
Block a user