\usepackage{fullpage}
\usepackage{floatrow}
-\usepackage{lipsum}
\usepackage{enumerate}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{minted}
-\usepackage[hidelinks]{hyperref}
+\usepackage{hyperref}
\usepackage{tikz}
\author{Mart Lubbers\and Caspar Safarlou}
\everymath{\displaystyle}
\floatsetup[listing]{style=Plaintop}
+\hypersetup{
+ pdfborder={0 0 0},
+ pdftitle={Knowledge Representation and Reasoning: Assignment 1},
+ pdfauthor={Mart \& Caspar},
+ pdfsubject={Knowledge Representation and Reasoning},
+ pdfproducer={Mart Lubbers},
+ pdfkeywords={Sokoban,Planning,Prolog,Hittingsets,Conflicsets},
+ colorlinks=false
+}
+
\definecolor{mintedbackground}{rgb}{0.95,0.95,0.95}
\newmintedfile[prologcode]{prolog}{
bgcolor=mintedbackground,
+++ /dev/null
-:- [diagnosis].\r
-\r
-generateHittingSetTree(SD, COMP, OBS, HS, HSTREE) :- %test with problem1(SD,COMP,OBS), generateHittingSetTree(SD,COMP,OBS,[],HSTREE). This needs to report node([a1], [node([a2], [leaf])]).\r
- tp(SD, COMP, OBS, HS, CS) -> generateParts(SD, COMP, OBS, HS, CS, HSTREE) ; generateParts(_,_,_,_, [], HSTREE). %second part of the OR is needed to translate an empty conflict set into a leaf. \r
- \r
-generateParts(_,_,_,_, [],leaf).%generates leaf if at the end of all possible conflict sets in a branch\r
-generateParts(SD, COMP, OBS, HS, CS, node(CS, RESTOFTREE)) :- %generates node if the conflict set isn't empty and goes on.\r
- repairBranch(SD, COMP, OBS, HS, CS, RESTOFTREE). %repairs the branch by branching out for each item in the conflict set and generating new conflict sets for the next node\r
- \r
- \r
-repairBranch(SD, COMP, OBS, HS, [CONFLICTITEM], [BRANCH]) :- %single item left in conflict set\r
- append(HS, [CONFLICTITEM], HSNEW), %add the used conflict set item for this branch to the new hitting set\r
- generateHittingSetTree(SD, COMP, OBS, HSNEW, BRANCH). %find the next new conflict set with the new hitted item\r
-repairBranch(SD, COMP, OBS, HS, [CSHEAD|CSTAIL], [BRANCHHEAD|BRANCHTAIL]) :- %multiple items left in conflict set\r
- append(HS, [CSHEAD], HSNEW), %add the used conflict set item for this branch to the new hitting set\r
- generateHittingSetTree(SD, COMP, OBS, HSNEW, BRANCHHEAD), %find the next new conflict set with the new hitted item\r
- repairBranch(SD, COMP, OBS, HS, CSTAIL, BRANCHTAIL). %goes on in recursion for each item in the conflict set of the current node\r
-
\ No newline at end of file
:- [diagnosis].\r
\r
-generateHittingSetTree(SD, COMP, OBS, HS, HSTREE) :- %test with problem1(SD,COMP,OBS), generateHittingSetTree(SD,COMP,OBS,[],HSTREE). This needs to report node([a1], [node([a2], [leaf])]).\r
- tp(SD, COMP, OBS, HS, CS) -> generateParts(SD, COMP, OBS, HS, CS, HSTREE) ; generateParts(_,_,_,_, [], HSTREE). %second part of the OR is needed to translate an empty conflict set into a leaf. \r
+%test with problem1(SD,COMP,OBS),\r
+%generateHittingSetTree(SD,COMP,OBS,[],HSTREE). This needs to report node([a1],\r
+%[node([a2], [leaf])]).\r
+%second part of the OR is needed to translate an empty conflict set into a leaf. \r
+generateHittingSetTree(SD, COMP, OBS, HS, HSTREE) :-\r
+ tp(SD, COMP, OBS, HS, CS) -> generateParts(SD, COMP, OBS, HS, CS, HSTREE);\r
+ generateParts(_,_,_,_, [], HSTREE). \r
+ \r
+%generates leaf if at the end of all possible conflict sets in a branch\r
+generateParts(_,_,_,_, [],leaf).\r
+%generates node if the conflict set isn't empty and goes on.\r
+generateParts(SD, COMP, OBS, HS, CS, node(CS, RESTOFTREE)) :- \r
+ %repairs the branch by branching out for each item in the conflict set and\r
+ %generating new conflict sets for the next node\r
+ repairBranch(SD, COMP, OBS, HS, CS, RESTOFTREE). \r
\r
-generateParts(_,_,_,_, [],leaf).%generates leaf if at the end of all possible conflict sets in a branch\r
-generateParts(SD, COMP, OBS, HS, CS, node(CS, RESTOFTREE)) :- %generates node if the conflict set isn't empty and goes on.\r
- repairBranch(SD, COMP, OBS, HS, CS, RESTOFTREE). %repairs the branch by branching out for each item in the conflict set and generating new conflict sets for the next node\r
- \r
- \r
-repairBranch(SD, COMP, OBS, HS, [CONFLICTITEM], [BRANCH]) :- %single item left in conflict set\r
- append(HS, [CONFLICTITEM], HSNEW), %add the used conflict set item for this branch to the new hitting set\r
- generateHittingSetTree(SD, COMP, OBS, HSNEW, BRANCH). %find the next new conflict set with the new hitted item\r
-repairBranch(SD, COMP, OBS, HS, [CSHEAD|CSTAIL], [BRANCHHEAD|BRANCHTAIL]) :- %multiple items left in conflict set\r
- append(HS, [CSHEAD], HSNEW), %add the used conflict set item for this branch to the new hitting set\r
- generateHittingSetTree(SD, COMP, OBS, HSNEW, BRANCHHEAD), %find the next new conflict set with the new hitted item\r
- repairBranch(SD, COMP, OBS, HS, CSTAIL, BRANCHTAIL). %goes on in recursion for each item in the conflict set of the current node\r
-
\ No newline at end of file
+%single item left in conflict set\r
+repairBranch(SD, COMP, OBS, HS, [CONFLICTITEM], [BRANCH]) :- \r
+ %add the used conflict set item for this branch to the new hitting set\r
+ append(HS, [CONFLICTITEM], HSNEW),\r
+ %find the next new conflict set with the new hitted item\r
+ generateHittingSetTree(SD, COMP, OBS, HSNEW, BRANCH).\r
+%multiple items left in conflict set\r
+repairBranch(SD, COMP, OBS, HS, [CSHEAD|CSTAIL], [BRANCHHEAD|BRANCHTAIL]) :-\r
+ %add the used conflict set item for this branch to the new hitting set\r
+ append(HS, [CSHEAD], HSNEW),\r
+ %find the next new conflict set with the new hitted item\r
+ generateHittingSetTree(SD, COMP, OBS, HSNEW, BRANCHHEAD),\r
+ %goes on in recursion for each item in the conflict set of the current node\r
+ repairBranch(SD, COMP, OBS, HS, CSTAIL, BRANCHTAIL).\r
-:- [task14part1]\r
-\r
+:- [task14part1].\r
\r
+% Adding a variable for the current path\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
+ extractDiagnoses2(HSTree, Diagnoses, []). \r
+\r
+% Set path in set and end recursion when leaf had been reached\r
+extractDiagnoses2(leaf, [PathEnd], PathEnd).\r
+% Finished clearing empty node\r
+extractDiagnoses2(node([], []), [], _). \r
+extractDiagnoses2(node([CsHead|CsTail], [CsHeadBranch|CsTailBranches]),\r
+ DiagnosesSet, CurrentPath) :-\r
+ % Add new visited conflict item to the visited path \r
+ append(CurrentPath, [CsHead], NewPath),\r
+ % Recursively collects all paths from the recursive calls into the depth\r
+ % and the width and puts them into the DiagnosesSet\r
+ append(DepthPaths, WidthPaths, DiagnosesSet), \r
+ % Continues into the depth of the branch\r
+ extractDiagnoses2(CsHeadBranch,DepthPaths,NewPath),\r
+ % Calls on all conflict items in the width of the branch\r
+ extractDiagnoses2(node(CsTail, CsTailBranches), WidthPaths, CurrentPath). \r
+\r
+% Computes length of smallest diagnosis\r
+getLengthSmallestSet([Diagnosis], DiagnosisLength):-\r
+ % Calls length single diagnosis\r
+ length(Diagnosis,DiagnosisLength). \r
+getLengthSmallestSet([HeadDiagnosis|RestOfDiagnoses], Minimal):-\r
+ % Recursively gets the length of tail\r
+ getLengthSmallestSet(RestOfDiagnoses, RestLength),\r
+ % Initialises length of the head diagnosis\r
+ length(HeadDiagnosis,HeadLength),\r
+ % Gets minimal length of diagnoses\r
+ Minimal is min(HeadLength, RestLength).\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
+ length(Y, LengthY),\r
+ %checks if the set isn't bigger than the checked set\r
+ X \== LengthY. \r
+\r
+% Deze functie moet opnieuw geschreven worden, hij moet de subsetminimal\r
+% opleveren en niet de kleinste diagnoses\r
+getSubsetMinimalDiagnoses(DiagnosesSets, MinimalDiagnosesSets):- \r
+ getLengthSmallestSet(DiagnosesSets,Length),!,\r
+ % Excludes sets that are bigger than the smallest set\r
+ exclude(filterLength(Length), DiagnosesSets, MinimalDiagnosesSets).\r
+\r
+% Function that returns minimal hitting sets from a problem\r
+subsetMinimalDiagnoses(SD, COMP, OBS, MinimalDiagnosesSets) :-\r
+ % Generate hitting tree\r
+ generateHittingSetTree(SD, COMP, OBS, [], HsTree),\r
+ write(HsTree),\r
+ % Get diagnoses out of the hitting tree\r
+ extractDiagnoses(HsTree, DiagnosesSets),\r
+ write(DiagnosesSets),\r
+ % Determine subset minimal diagnoses\r
+ getSubsetMinimalDiagnoses(DiagnosesSets, MinimalDiagnosesSets).\r