4 extractDiagnoses
(HSTree
,Diagnoses
):-
5 extractDiagnoses2
(HSTree
, Diagnoses
, []). %adding a variable
for the current path
7 extractDiagnoses2
(leaf
, [PATHEND
], PATHEND
). %set path
in set
and end recursion
when leaf had been reached
8 extractDiagnoses2
(node
([], []), [], PATH
). %finished clearing empty node
9 extractDiagnoses2
(node
([CSHEAD
|CSTAIL
], [CSHEADBRANCH
|CSTAILBRANCHES
]), DIAGNOSESSET
, CURRENTPATH
) :-
10 append
(CURRENTPATH
, [CSHEAD
], NEWPATH
), %add new visited conflict item to the visited path
11 append
(DEPTHPATHS
, WIDTHPATHS
, DIAGNOSESSET
), %recursively collects all paths from the recursive calls into the depth
and the width
and puts them into the DIAGNOSESSET
12 extractDiagnoses2
(CSHEADBRANCH
,DEPTHPATHS
,NEWPATH
), %continues into the depth of the branch
13 extractDiagnoses2
(node
(CSTAIL
, CSTAILBRANCHES
), WIDTHPATHS
, CURRENTPATH
). %calls on all conflict items
in the width of the branch
15 getLengthSmallestSet
([DIAGNOSIS
], DIAGNOSISLENGTH
):- %computes length of smallest diagnosis
16 length(DIAGNOSIS
,DIAGNOSISLENGTH
). %calls length single diagnosis
17 getLengthSmallestSet
([HEADDIAGNOSIS
|RESTOFDIAGNOSES
], Minimal
):-
18 getLengthSmallestSet
(RESTOFDIAGNOSES
, RESTLENGTH
), %recursively gets the
length of tail
19 length(HEADDIAGNOSIS
,HEADLENGTH
), %initialises length of the head diagnosis
20 Minimal is min
(HEADLENGTH
, RESTLENGTH
). %gets minimal
length of diagnoses
24 X \
== LENGTHY
. %checks if the set isn
't bigger than the checked set
26 getSubsetMinimalDiagnoses(DIAGNOSESSETS, MINIMALDIAGNOSESSETS):- %deze functie moet opnieuw geschreven worden, hij moet de subsetminimal opleveren en niet de kleinste diagnoses
27 getLengthSmallestSet(DIAGNOSESSETS,LENGTH),!,
28 exclude(filterLength(LENGTH), DIAGNOSESSETS, MINIMALDIAGNOSESSETS). %excludes sets that are bigger than the smallest set
30 subsetMinimalDiagnoses(SD, COMP, OBS, MINIMALDIAGNOSESSETS) :- %function that returns minimal hitting sets from a problem
31 generateHittingSetTree(SD, COMP, OBS, [], HSTREE), %generate hitting tree
32 extractDiagnoses(HSTREE, DIAGNOSESSETS), %get diagnoses out of the hitting tree
33 getSubsetMinimalDiagnoses(DIAGNOSESSETS, MINIMALDIAGNOSESSETS). %determine subset minimal diagnoses