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