a step forward.

This commit is contained in:
Vítor Santos Costa 2012-08-13 09:23:36 -05:00
parent 4756948967
commit 7e8cac9fb1
2 changed files with 18 additions and 18 deletions

View File

@ -66,22 +66,23 @@ call_horus_ground_solver_for_probabilities(QueryKeys, _AllKeys, Factors, Evidenc
keys_to_ids(AllKeys, 0, Id1, Hash0, Hash1), keys_to_ids(AllKeys, 0, Id1, Hash0, Hash1),
get_factors_type(Factors, Type), get_factors_type(Factors, Type),
evidence_to_ids(Evidence, Hash1, Hash2, Id1, Id2, EvidenceIds), evidence_to_ids(Evidence, Hash1, Hash2, Id1, Id2, EvidenceIds),
%writeln(evidence:Evidence:EvidenceIds),
factors_to_ids(Factors, Hash2, Hash3, Id2, Id3, FactorIds), factors_to_ids(Factors, Hash2, Hash3, Id2, Id3, FactorIds),
%writeln(queryKeys:QueryKeys), writeln(''), %writeln(queryKeys:QueryKeys), writeln(''),
%% writeln(type:Type), writeln(''), %% writeln(type:Type), writeln(''),
%% writeln(allKeys:AllKeys), writeln(''), %% writeln(allKeys:AllKeys), writeln(''),
sort(AllKeys,SKeys), %% writeln(allSortedKeys:SKeys), writeln(''), sort(AllKeys,SKeys), %% writeln(allSortedKeys:SKeys), writeln(''),
keys_to_ids(SKeys, Id3, Id4, Hash3, Hash4), keys_to_ids(SKeys, Id3, Id4, Hash3, Hash4),
b_hash:b_hash_to_list(Hash1,_L4), writeln(h1:_L4), %b_hash:b_hash_to_list(Hash1,_L4), writeln(h1:_L4),
% writeln(factors:Factors), writeln(''), writeln(factors:Factors), writeln(''),
% writeln(factorIds:FactorIds), writeln(''), writeln(factorIds:FactorIds), writeln(''),
% writeln(evidence:Evidence), writeln(''), writeln(evidence:Evidence), writeln(''),
% writeln(evidenceIds:EvidenceIds), writeln(''), writeln(evidenceIds:EvidenceIds), writeln(''),
cpp_create_ground_network(Type, FactorIds, EvidenceIds, Network), cpp_create_ground_network(Type, FactorIds, EvidenceIds, Network),
get_vars_information(AllKeys, StatesNames), get_vars_information(AllKeys, StatesNames),
terms_to_atoms(AllKeys, KeysAtoms), terms_to_atoms(AllKeys, KeysAtoms),
cpp_set_vars_information(KeysAtoms, StatesNames), cpp_set_vars_information(KeysAtoms, StatesNames),
writeln(network:(Type, FactorIds, EvidenceIds, Network)), writeln(''), %writeln(network:(Type, FactorIds, EvidenceIds, Network)), writeln(''),
run_solver(ground(Network,Hash4,Id4), QueryKeys, Solutions), run_solver(ground(Network,Hash4,Id4), QueryKeys, Solutions),
cpp_free_ground_network(Network). cpp_free_ground_network(Network).
@ -98,8 +99,8 @@ run_solver(ground(Network,Hash,Id), QueryKeys, Solutions) :-
%get_dists_parameters(DistIds, DistsParams), %get_dists_parameters(DistIds, DistsParams),
%cpp_set_factors_params(Network, DistsParams), %cpp_set_factors_params(Network, DistsParams),
list_of_keys_to_ids(QueryKeys, Hash, _, Id, _, QueryIds), list_of_keys_to_ids(QueryKeys, Hash, _, Id, _, QueryIds),
writeln(queryKeys:QueryKeys), writeln(''), %writeln(queryKeys:QueryKeys), writeln(''),
writeln(queryIds:QueryIds), writeln(''), %writeln(queryIds:QueryIds), writeln(''),
cpp_run_ground_solver(Network, QueryIds, Solutions). cpp_run_ground_solver(Network, QueryIds, Solutions).
@ -152,9 +153,9 @@ get_ranges(K.Ks, Range.Rs) :- !,
evidence_to_ids([], H, H, I, I, []). evidence_to_ids([], H, H, I, I, []).
evidence_to_ids([Key=Ev|QueryKeys], Hash0, Hash, I0, I, [Id=Ev|QueryIds]) :- evidence_to_ids([Key=Ev|QueryKeys], Hash0, Hash, I0, I, [Id=Ev|QueryIds]) :-
b_hash_lookup(Key, Id, Hash0), b_hash_lookup(Key, Id, Hash0), !,
evidence_to_ids(QueryKeys, Hash0, Hash, I0, I, QueryIds). evidence_to_ids(QueryKeys, Hash0, Hash, I0, I, QueryIds).
evidence_to_ids([Key=Ev|QueryKeys], Hash0, Hash, I0, I, [I=Ev|QueryIds]) :- evidence_to_ids([Key=Ev|QueryKeys], Hash0, Hash, I0, I, [I0=Ev|QueryIds]) :-
b_hash_insert(Hash0, Key, I0, Hash1), b_hash_insert(Hash0, Key, I0, Hash1),
I1 is I0+1, I1 is I0+1,
evidence_to_ids(QueryKeys, Hash1, Hash, I1, I, QueryIds). evidence_to_ids(QueryKeys, Hash1, Hash, I1, I, QueryIds).
@ -180,17 +181,16 @@ finalize_horus_ground_solver(bp(Network, _)) :-
% %
% %
init_horus_ground_solver(QueryVars, _AllVars, _, horus(GKeys, Keys, Factors, Evidence)) :- init_horus_ground_solver(QueryVars, _AllVars, _, horus(GKeys, Keys, Factors, Evidence)) :-
generate_networks(QueryVars, GKeys, Keys, Factors, Evidence), trace,
writeln(qvs:QueryVars), generate_networks(QueryVars, GKeys, Keys, Factors, Evidence), !.
writeln(Keys), writeln(Factors), !. % writeln(qvs:QueryVars),
% writeln(Keys), writeln(Factors), !.
% %
% just call horus solver. % just call horus solver.
% %
run_horus_ground_solver(_QueryVars, Solutions, horus(GKeys, Keys, Factors, Evidence) ) :- !, run_horus_ground_solver(_QueryVars, Solutions, horus(GKeys, Keys, Factors, Evidence) ) :- !,
writeln(sols:Solutions), trace,
writeln(state:_State),
trace,
call_horus_ground_solver_for_probabilities(GKeys, Keys, Factors, Evidence, Solutions). call_horus_ground_solver_for_probabilities(GKeys, Keys, Factors, Evidence, Solutions).
%bp([[]],_,_) :- !. %bp([[]],_,_) :- !.

View File

@ -12,11 +12,11 @@ abi_table([0.3,0.3,0.4]).
pop_table([0.3,0.3,0.4,0.3,0.3,0.4,0.3,0.3,0.4]). pop_table([0.3,0.3,0.4,0.3,0.3,0.4,0.3,0.3,0.4]).
goal_list([/*abi(p0,h), goal_list([abi(p0,h),
abi(p1,m), abi(p1,m),
abi(p2,m), abi(p2,m),
abi(p3,m), abi(p3,m),
abi(p4,l),*/ abi(p4,l),
pop(p5,h), pop(p5,h),
abi(p5,_), abi(p5,_),
abi(p6,_), abi(p6,_),