From: Caspar Safarlou Date: Mon, 17 Nov 2014 14:07:32 +0000 (+0100) Subject: added hittingset code and edited report X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=733660f33b81a08fe83455ca421dd6c37109a5ba;p=ker1415-1.git added hittingset code and edited report --- diff --git a/report/ass2.tex b/report/ass2.tex index abdce8c..32f6adf 100644 --- a/report/ass2.tex +++ b/report/ass2.tex @@ -11,17 +11,14 @@ \caption{Hitting set datastructure} \prologcode{./src/hs.pl} \end{listing} -% Het doel van deze opdracht was om je datastructure te laten zien, je hebt -% alleen gezegd wat voor bomen geen hitting set kunnen zijn... - -%Our datastructure uses the predicate node to signify nodes and leaf for leaves. A node contains a list of edge labels and another list (with the same length as the amound of edge labels) that contains nodes or leaves. The edge label corresponds with its order in the list it is in. -%Good examples: -%isHittingSetTree(node([a,b],[leaf,leaf])). -%isHittingSetTree(node([a,b], [node([c,d], [leaf,leaf]), node([e,f], [leaf,leaf])])). -%isHittingSetTree(node([a,b], [node([c,d], [node([g,h,i], [leaf,leaf,leaf]),leaf]), node([a,f], [leaf,leaf])])). -% -%Wrong examples: -% -%isHittingSetTree(node([a,b], [node([c,d], [node([g,h], [leaf,leaf,leaf]),leaf]), node([a,f], [leaf,leaf])])). - +Our datastructure uses the predicate node to signify nodes and leaf for leaves. A node contains a list of edge labels and another list (with the same length as the amound of edge labels) that contains nodes or leaves. The edge label corresponds with its order in the list it is in. +Examples: +node([a,b],[leaf,leaf]) +node([a,b], [node([c,d], [leaf,leaf]), node([e,f], [leaf,leaf])]) +node([a,b], [node([c,d], [node([g,h,i], [leaf,leaf,leaf]),leaf]), node([a,f], [leaf,leaf])]) +%insert hittingsettrees.png \subsubsection{Task 14: Implementation} +\begin{listing}[H] + \caption{Code for generating a hitting set tree} + \prologcode{./src/task14.pl} +\end{listing} \ No newline at end of file diff --git a/report/report.out b/report/report.out index 37cc07e..7a7ad16 100644 --- a/report/report.out +++ b/report/report.out @@ -1,19 +1,19 @@ -\BOOKMARK [1][-]{section.1}{Assignment 1-1}{}% 1 -\BOOKMARK [2][-]{subsection.1.1}{Part 1: Modelling Sokoban}{section.1}% 2 -\BOOKMARK [3][-]{subsubsection.1.1.1}{Task 1: Knowledge base}{subsection.1.1}% 3 -\BOOKMARK [3][-]{subsubsection.1.1.2}{Task 2: Actions}{subsection.1.1}% 4 -\BOOKMARK [2][-]{subsection.1.2}{Part 2: Implementation}{section.1}% 5 -\BOOKMARK [3][-]{subsubsection.1.2.1}{Task 3: Translate Axioms}{subsection.1.2}% 6 -\BOOKMARK [3][-]{subsubsection.1.2.2}{Task 4: The Planning Problem in Figure 1}{subsection.1.2}% 7 -\BOOKMARK [3][-]{subsubsection.1.2.3}{Task 5: Crates go to Any Goal Location}{subsection.1.2}% 8 -\BOOKMARK [3][-]{subsubsection.1.2.4}{Task 6: Inverse Problem}{subsection.1.2}% 9 -\BOOKMARK [2][-]{subsection.1.3}{Part 3: Extending the domain}{section.1}% 10 -\BOOKMARK [3][-]{subsubsection.1.3.1}{Task 7: Unlocking the Crates}{subsection.1.3}% 11 -\BOOKMARK [2][-]{subsection.1.4}{Part 4: General questions}{section.1}% 12 -\BOOKMARK [3][-]{subsubsection.1.4.1}{Task 10: Sitcalc expressivity}{subsection.1.4}% 13 -\BOOKMARK [3][-]{subsubsection.1.4.2}{Task 11: Related work}{subsection.1.4}% 14 -\BOOKMARK [1][-]{section.2}{Assignment 1-2}{}% 15 -\BOOKMARK [2][-]{subsection.2.1}{Implementation of the hitting-set algorithm}{section.2}% 16 -\BOOKMARK [3][-]{subsubsection.2.1.1}{Task 12: Generate conflict}{subsection.2.1}% 17 -\BOOKMARK [3][-]{subsubsection.2.1.2}{Task 13: Define your data structure}{subsection.2.1}% 18 -\BOOKMARK [3][-]{subsubsection.2.1.3}{Task 14: Implementation}{subsection.2.1}% 19 +\BOOKMARK [1][-]{section.1}{Assignment 1-1}{} +\BOOKMARK [2][-]{subsection.1.1}{Part 1: Modelling Sokoban}{section.1} +\BOOKMARK [3][-]{subsubsection.1.1.1}{Task 1: Knowledge base}{subsection.1.1} +\BOOKMARK [3][-]{subsubsection.1.1.2}{Task 2: Actions}{subsection.1.1} +\BOOKMARK [2][-]{subsection.1.2}{Part 2: Implementation}{section.1} +\BOOKMARK [3][-]{subsubsection.1.2.1}{Task 3: Translate Axioms}{subsection.1.2} +\BOOKMARK [3][-]{subsubsection.1.2.2}{Task 4: The Planning Problem in Figure 1}{subsection.1.2} +\BOOKMARK [3][-]{subsubsection.1.2.3}{Task 5: Crates go to Any Goal Location}{subsection.1.2} +\BOOKMARK [3][-]{subsubsection.1.2.4}{Task 6: Inverse Problem}{subsection.1.2} +\BOOKMARK [2][-]{subsection.1.3}{Part 3: Extending the domain}{section.1} +\BOOKMARK [3][-]{subsubsection.1.3.1}{Task 7: Unlocking the Crates}{subsection.1.3} +\BOOKMARK [2][-]{subsection.1.4}{Part 4: General questions}{section.1} +\BOOKMARK [3][-]{subsubsection.1.4.1}{Task 10: Sitcalc expressivity}{subsection.1.4} +\BOOKMARK [3][-]{subsubsection.1.4.2}{Task 11: Related work}{subsection.1.4} +\BOOKMARK [1][-]{section.2}{Assignment 1-2}{} +\BOOKMARK [2][-]{subsection.2.1}{Implementation of the hitting-set algorithm}{section.2} +\BOOKMARK [3][-]{subsubsection.2.1.1}{Task 12: Generate conflict}{subsection.2.1} +\BOOKMARK [3][-]{subsubsection.2.1.2}{Task 13: Define your data structure}{subsection.2.1} +\BOOKMARK [3][-]{subsubsection.2.1.3}{Task 14: Implementation}{subsection.2.1} diff --git a/report/report.tex b/report/report.tex index eb2b224..42bf2c6 100644 --- a/report/report.tex +++ b/report/report.tex @@ -9,7 +9,7 @@ \usepackage{minted} \usepackage{hyperref} -\author{Mart Lubbers\and \small Caspar Safarlou} +\author{\small Mart Lubbers\and Caspar Safarlou} \title{Knowledge Representation and Reasoning.\\Assignment 1} \date{\today} diff --git a/report/src/hittingsettrees.png b/report/src/hittingsettrees.png new file mode 100644 index 0000000..12c76b6 Binary files /dev/null and b/report/src/hittingsettrees.png differ diff --git a/report/src/task14.pl b/report/src/task14.pl new file mode 100644 index 0000000..3cc3aa2 --- /dev/null +++ b/report/src/task14.pl @@ -0,0 +1,23 @@ +:- [diagnosis]. + + +generateHittingSetTree(SD, COMP, OBS, HS, T) :- %test with problem1(SD,COMP,OBS), generateHittingSetTree(SD,COMP,OBS,[],T). This needs to report node([a1], [node([a2], [leaf])]). + ( + tp(SD, COMP, OBS, HS, CS) -> %finds a conflict set + generateParts(SD, COMP, OBS, HS, [], T) ; generateParts(SD, COMP, OBS, HS, CS, T) %first part of the OR is needed to translate an empty conflict set into a leaf. + ). + +generateParts(SD, COMP, OBS, HS, [],leaf).%generates leaf if at the end of all possible conflict sets in a branch +generateParts(SD, COMP, OBS, HS, CS, node(CS, TS)) :- %generates node if the conflict set isn't empty and goes on. + repairBranch(SD, COMP, OBS, HS, CS, TS). %repairs the branch by branching out for each item in the conflict set + + +repairBranch(SD, COMP, OBS, HS, [CS], [X]) :- %single item left in conflict set + append(HS, [CS], HSNEW), %add the used conflict set item for this branch to the new hitting set + generateHittingSetTree(SD, COMP, OBS, HSNEW, X). %find the next new conflict set with the new hitted item + +repairBranch(SD, COMP, OBS, HS, [CSHEAD|CSTAIL], [X|Xs]) :- %multiple items left in conflict set + append(HS, [CSHEAD], HSNEW), %add the used conflict set item for this branch to the new hitting set + generateHittingSetTree(SD, COMP, OBS, HSNEW, X), %find the next new conflict set with the new hitted item + repairBranch(SD, COMP, OBS, HS, CSTAIL, Xs). %goes on in recursion for each item in the conflict set of the current node + \ No newline at end of file