hp.pl vervangen door isHittingSet.pl en report en comments bij code bijgewerkt
[ker1415-1.git] / report / src / task14part1.pl
1 :- [diagnosis].
2
3 %Test with problem1(SD,COMP,OBS),
4 %generateHittingSetTree(SD,COMP,OBS,[],HSTREE). This needs to report node([a1],
5 %[node([a2], [leaf])]).
6 %Second part of the OR is needed to translate an empty conflict set into a leaf.
7 generateHittingSetTree(SD, COMP, OBS, HS, HSTREE) :-
8 %Prolog version of: if -> then ; else, here used to generate conflict sets.
9 tp(SD, COMP, OBS, HS, CS) -> generateParts(SD, COMP, OBS, HS, CS, HSTREE);
10 generateParts(_,_,_,_, [], HSTREE).
11
12 %Generates leaf if at the end of all possible conflict sets in a branch
13 generateParts(_,_,_,_, [],leaf).
14 %Generates node if the conflict set isn't empty and goes on.
15 generateParts(SD, COMP, OBS, HS, CS, node(CS, RESTOFTREE)) :-
16 %Repairs the branch by branching out for each item in the conflict set and
17 %generating new conflict sets for the next node
18 repairBranch(SD, COMP, OBS, HS, CS, RESTOFTREE).
19
20 %Single item left in conflict set:
21 repairBranch(SD, COMP, OBS, HS, [CONFLICTITEM], [BRANCH]) :-
22 %Add the used conflict set item for this branch to the new hitting set
23 append(HS, [CONFLICTITEM], HSNEW),
24 %Find the next new conflict set with the new hitted item added builds next tree-part.
25 generateHittingSetTree(SD, COMP, OBS, HSNEW, BRANCH).
26 %Multiple items left in conflict set:
27 repairBranch(SD, COMP, OBS, HS, [CSHEAD|CSTAIL], [BRANCHHEAD|BRANCHTAIL]) :-
28 %Add the used conflict set item for this branch to the new hitting set.
29 append(HS, [CSHEAD], HSNEW),
30 %Find the next new conflict set with the new hitted item added and builds next tree-part.
31 generateHittingSetTree(SD, COMP, OBS, HSNEW, BRANCHHEAD),
32 %Goes on in recursion for each item in the conflict set of the current node (the width of the branch).
33 repairBranch(SD, COMP, OBS, HS, CSTAIL, BRANCHTAIL).