hypothesisSelection_smallestShared(AllEIs):-
	gen_output_readIn_candiateH(AllEIs),
	forAll(candidateH0(EI,TI,H),scoreEachH(EI,TI,H)),
	indentifySharedHs(AllEIs,T_EITIs), %,EIGrouped_SharedHs),write(EIGrouped_SharedHs),
	write('finish indentify'),
nl.
/*
	%maplist(scoreEachCla,T_EITIs),
	forAll(candidateH0(EI,TI,H),scoreEachH(EI,TI,H)),
	write(EIGrouped_SharedHs),nl,
	maplist(smallestCandidate_eachEI,EIGrouped_SharedHs,EIGrouped_smallestDLSharedHs),
write('finish smallest for each'),nl,
findall(ClaID-EITIs,(smallestSharedH(EI1-TI1,ClaID),smallestSharedH(EI2-TI2,ClaID),EI1\==EI2,sharedControlReation(ClaID,EITIs)),SmallestSharedClaIDs),
write(SmallestSharedClaIDs),nl,
maplist(derive_smallest,SmallestSharedClaIDs,CandidateRecords),

%findall(CandidateRecord,(sharedControlReation(ClaID,EITIs),derive_smallest(ClaID,EITIs,CandidateRecord)),CandidateRecords),
sort(CandidateRecords,SortedCandidateRecords),
print_list(SortedCandidateRecords).
% put into a list --> iterative selection.
*/

% each ClaID the percentage
derive_smallest(ClaID-EITIs,Percentage-MinEIs-MinEITIs-EITIs):- % derive mupltiple
	selectlist(smallestSharedH,EITIs,SmallestEITIs),
	%ti_GroupedByEI(SmallestEITIs,Grouped),
	exExtraction(EITIs,EIs0),length(EIs0,CoveredNum),
	exExtraction(SmallestEITIs,MinEIs),length(MinEIs,MinEINum),
	Percentage is MinEINum/CoveredNum.
% ***combinable(SmallestEITIs).
% need to decide one that is combinable from this module. if there are same--then being greedy.
% claLength is in the file of score.pl within each application folder
/* no need as 
scoreEachCla(ClaID-EITIs):-
	claLength(ClaID,ClaLength),
	assertz(claScore(ClaID,ClaLength).*/

scoreEachH(EI,TI,H):-
	maplist(claLength,H,Scores),
	sumList(Scores,HScore),
	assertz(hScore(EI,TI,HScore)).

	
smallestCandidate_eachEI(EI-TIs,EI-SmallestSet):-
	maplist(getEachH_score(EI),TIs,ScoredTIs),
	minSet(ScoredTIs,1000,Min,SmallestSet),
	maplist(addSmallestSharedH(EI),SmallestSet).



getEachH_score(EI,TI,HScore-TI):-
	hScore(EI,TI,HScore).
addSmallestSharedH(EI,TI):-
	candidateH0(EI,TI,[ClaID|H]),
	assertz(smallestSharedH(EI-TI,ClaID)). 

