new version of ve

This commit is contained in:
Vítor Santos Costa 2012-09-23 13:23:53 +01:00
parent 2603f18a10
commit 34dc03d43b

View File

@ -112,7 +112,7 @@ init_ve_solver_for_question(G, RG, Vs, NVs) :-
% %
% construct a bipartite graph with vars and factors % construct a bipartite graph with vars and factors
% the nodes of the var graph just contain pointer to the factors % the nodes of the var graph just contain pointer to the factors
% the nodes of the factors contain alist of variables and a matrix % the nodes of the factors contain a list of variables and a matrix
% also provide a matrix with evidence % also provide a matrix with evidence
% %
vars_to_bigraph(VMap, bigraph(VInfo, IF, Fs), Evs) :- vars_to_bigraph(VMap, bigraph(VInfo, IF, Fs), Evs) :-
@ -301,7 +301,7 @@ replace_factor(_F,_NF,OF, OF).
eliminate(QVs, digraph(Vs0, I, Fs0), Dist) :- eliminate(QVs, digraph(Vs0, I, Fs0), Dist) :-
find_best(Vs0, QVs, BestV, VFs), !, find_best(Vs0, QVs, BestV, VFs), !,
%writeln(best:BestV:QVs), %writeln(best:BestV:VFs),
% delete all factors that touched the variable % delete all factors that touched the variable
foldl2(del_fac, VFs, Fs0, Fs1, Vs0, Vs1), foldl2(del_fac, VFs, Fs0, Fs1, Vs0, Vs1),
% delete current variable % delete current variable
@ -325,11 +325,16 @@ best_var(QVs, I, _Node, Info, Info) :-
!. !.
% pick the variable with less factors % pick the variable with less factors
best_var(_Qs, I, Node, i(ValSoFar,_,_), i(NewVal,I,Node)) :- best_var(_Qs, I, Node, i(ValSoFar,_,_), i(NewVal,I,Node)) :-
length(Node, NewVal), foldl(szfac,Node,1,NewVal),
%length(Node, NewVal),
NewVal < ValSoFar, NewVal < ValSoFar,
!. !.
best_var(_, _I, _Node, Info, Info). best_var(_, _I, _Node, Info, Info).
szfac(f(_,Vs,_), I0, I) :-
length(Vs,L),
I is I0*L.
% delete one factor, need to also touch all variables % delete one factor, need to also touch all variables
del_fac(f(I,FVs,_), Fs0, Fs, Vs0, Vs) :- del_fac(f(I,FVs,_), Fs0, Fs, Vs0, Vs) :-
rb_delete(Fs0, I, Fs), rb_delete(Fs0, I, Fs),