% ***** Notice, the multiE in this file is a fake multiE, it is essentially a single E, It is like this, just because the convenience to use the grammar top theory.
%  

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%	
% generate hypothesis space for examples
%	1. get one example by index;
%	2. output a bunch of Ts
%	--only T(ID is useless after reconstruction)
%	--duplicate removed

WORK OR NOT:
Top Theory
DepthLimit (Peano number)

This file is just findall -- all predicate is just for wrapping 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

% this g can be adapted to different 
g(EI,Ts):-
	%tell('hypothesesGenTest.txt'),
	set(depthLimit,DepthLimit),
	%singleE(DepthLimit,EI,Ts),
	multiE(DepthLimit,EI,Ts),
	%numbersList(From,To,EIs),
	%allEs(DepthLimit,EIs,Ts),

	length(Ts,K), write(K),	
	Ts=Ts1, %remove_duplicates(Ts,Ts1),
 length(Ts1,K1), write(' Duplicate removed, then remain:  '), write(K1),% in case of no duplicates--then no remove_duplicate to save time
	%write(' HYPOSESE have been obtained and they are '),nl,
	nl , print_list(Ts)
	.
	%, told.






/*************** Single-Example Seed ***************/
% single E -> Ts
singleE(DepthLimit,EI,RecordAll):-
	findall(OneTr,
		(
			gEx(DepthLimit,EI,OneTr)
		%portray_clause(candidateH(EI,OneTr))
		%,write('*** One candidate Hypothesis'),write(OneTr),nl
		/*, %remove_duplicates(OneTr0,OneTr),
		tInterpreter(OneTr,T),
		%,write('*** One theory'),nl,
		write(OneTr),nl,	% track the ID of clauses in B
		print_list(T),nl,
		nl*/
	 
		),
		RecordAll).


/*************** Multi-Example Seed ***************/
% please notice here has been changed to accommodate.
multiE(DepthLimit,EI,RecordAll):-
	EIs=[EI],
	findall(OneTr,
		(
		multi_gEx(DepthLimit,EIs,OneTr0),
		OneTr0=OneTr %remove_duplicates(OneTr0,OneTr)
		%portray_clause(candidateH(EI,OneTr))
		%, tInterpreter(OneTr,T),
		%nl,nl,write(OneTr),nl,	% track the ID of clauses in B
		%print_list(T),nl,nl
		),
		RecordAll).


/*************** All Examples (Single-Example Seed) ***************/
all_singleEIs(_,[],[]).
all_singleEIs(DepthLimit,[EI|EIs],[EI-Ts|AllT]):-
	all_singleEIs(DepthLimit,EIs,AllT),
	singleE(DepthLimit,EI,Ts).

% index the candidates
genAll([],[],1).
genAll([EI|EIs],[Ts|RestTs],Total):-
	genAll(EIs,RestTs,Pre),
	set(depthLimit,DepthLimit),
	multiE(DepthLimit,EI,Ts),
	%remove_duplicates(Ts0,Ts), % there are same hypotheses derived by the same example
	indexEI_CadidateHs(EI,Ts,TsNum),
	length(Ts,K),
	write('%***TRACE each time'),write({EI,K}),nl,nl,
	Total is Pre*K.

indexEI_CadidateHs(EI,[],0).
indexEI_CadidateHs(EI,[T|Ts],Index):-
	indexEI_CadidateHs(EI,Ts,PreIndex),
	Index is PreIndex + 1,
	portray_clause(candidateH0(EI,Index,T)).


candidateH(EI,Index,T):-
	candidateH0(EI,Index,T0),
	maplist(usedRuleRemoved,T0,T).

usedRuleRemoved([rs-{ReactionID,LimitingType,State,UsedRule,Time}],[rs-{ReactionID,LimitingType,State,Time}]).


%---------- signed here means each T is signed with EI
genAll_EIsigned([],[],1).
genAll_EIsigned([EI|EIs],[EI-Ts|RestTs],Total):-
	genAll_EIsigned(EIs,RestTs,Pre),
	set(depthLimit,DepthLimit),
	singleE(DepthLimit,EI,Ts0),	
	Ts=Ts0, %remove_duplicates(Ts0,Ts),
	length(Ts,K),
	write('***TRACE each time'),write({EI,K}),nl,
	Total is Pre*K.


/*************** All Examples (Multi-Example Seed) ***************/
% The input
all_multiEIs(_,[],[]).
all_multiEIs(DepthLimit,[PairedEIs|AllEIs],[PairedEIs-Ts|AllT]):-
	all_multiEIs(DepthLimit,AllEIs,AllT),
	multiE(DepthLimit,PairedEIs,Ts).











