Add chessboard visualisations

This commit is contained in:
Jip J. Dekker 2021-05-25 12:10:09 +10:00
parent 7cdd112321
commit bc7d05cc2d
No known key found for this signature in database
GPG Key ID: 517DF4A00618C9C3
2 changed files with 82 additions and 14 deletions

View File

@ -74,6 +74,11 @@
\usepackage{graphicx}
\usepackage{subcaption}
% Drawing chessboards (background)
\usepackage{chessboard}
\setchessboard{showmover=false}
% Algorithms
% \usepackage[ruled,vlined]{algorithm2e}

View File

@ -86,8 +86,8 @@ problem format these techniques expect. \Cref{sec:back-other-languages}
introduces alternative \cmls\ and compares their functionality to \minizinc{}.
Then,\cref{sec:back-term} survey the closely related technologies in the field
of \glspl{trs}. Finally, \cref{sec:back-mzn-interpreter} explores the process
that the current \minizinc\ interpreter uses to translate a \minizinc{} instance
into a solver-level constraint model.
that the current \minizinc\ interpreter uses to translate a \minizinc{}
instance into a solver-level constraint model.
\section{\glsentrytext{minizinc}}%
\label{sec:back-minizinc}
@ -99,8 +99,8 @@ library of constraints allow users to easily model complex problems.
\begin{listing}
\mznfile{assets/mzn/back_knapsack.mzn}
\caption{\label{lst:back-mzn-knapsack} A \minizinc\ model describing a 0-1 knapsack
problem}
\caption{\label{lst:back-mzn-knapsack} A \minizinc\ model describing a 0-1
knapsack problem}
\end{listing}
\begin{example}%
@ -684,7 +684,7 @@ track of \gls{domain} changes using a \gls{trail}. For every \gls{domain} change
that is made during propagation (after the first search decision), the reverse
change is stored on in a list. Whenever a new search decision is made, the
current position of the list is tagged. If the \solver{} now needs to undo a
search decision (\ie\ \gls{backtrack}), it can apply all change until it reaches
search decision (\ie\ \gls{backtrack}), it can apply all changes until it reaches
the change that is tagged with the search decision. Because all changes before
the tagged point on the \gls{trail} were made before the search decision was
made, it is guaranteed that these \gls{domain} changes do not depend on the
@ -730,19 +730,82 @@ constraints otherwise.
When solving the problem, initially no values can be eliminated from the
\glspl{domain} of the \variables{}. The first propagation will happen when the
first queen is placed on the board. The search space will then look like this:
first queen is placed on the board, the first search decision.
\jip{Insert image of n-queens board with one queen assigned.}
Now that one queen is placed on the board the propagators for the
\mzninline{all_different} constraints can start propagating. They can eliminate
all values that are on the same row or diagonal as the queen placed on the
board.
\jip{Insert previous image with all impossible moves marked red.}
\Cref{fig:back-nqueens} visualises the domain propagation of placing a queen
on the d3 square of an eight by eight chess board. When the queen it placed
on the board in \cref{sfig:back-nqueens-1}, it fixes the value of row 4 to
the value 3. This implicitly eliminates any possibility of placing another
queen in the row. Now that one queen is placed on the board the propagators
for the \mzninline{all_different} constraints can start propagating. As show
in \cref{sfig:back-nqueens-2}, the first \mzninline{all_different} constraint
can now stop other queens to be placed in the same column. It eliminates the
value 3 from the domains of the queens in the remaining rows. Similarly, the
other \mzninline{all_different} constraints remove all values that correspond
to positions on the same diagonal as the placed queen, shown in
\cref{sfig:back-nqueens-3,sfig:back-nqueens-4}.
The propagation of the first placed queen severely limits the positions where
a second queen can be placed.
\end{example}
\begin{figure}
\centering
\begin{subfigure}[b]{.48\columnwidth}
\centering
\chessboard[
setwhite={Qd3},
pgfstyle=cross,
color=red,
markarea={d1-d2,d4-d8},
]
\caption{\label{sfig:back-nqueens-1} Assign a queen to d3}
\end{subfigure}%
\hspace{0.04\columnwidth}%
\begin{subfigure}[b]{.48\columnwidth}
\centering
\chessboard[
setwhite={Qd3},
pgfstyle=cross,
color=red!35!white,
markareas={d1-d2,d4-d8},
pgfstyle=cross,
color=red,
markareas={a3-c3,e3-h3},
]
\caption{\label{sfig:back-nqueens-2} Propagate rows}
\end{subfigure}
\begin{subfigure}[b]{.48\columnwidth}
\centering
\chessboard[
setwhite={Qd3},
pgfstyle=cross,
color=red!35!white,
markareas={d1-d2,d4-d8,a3-c3,e3-h3},
pgfstyle=cross,
color=red,
markareas={b1-b1,c2-c2,e4-e4,f5-f5,g6-g6,h7-h7},
]
\caption{\label{sfig:back-nqueens-3} Propagate upwards diagonal}
\end{subfigure}%
\hspace{0.04\columnwidth}%
\begin{subfigure}[b]{.48\columnwidth}
\centering
\chessboard[
setwhite={Qd3},
pgfstyle=cross,
color=red!35!white,
markareas={d1-d2,d4-d8,a3-c3,e3-h3,b1-b1,c2-c2,e4-e4,f5-f5,g6-g6,h7-h7},
pgfstyle=cross,
color=red,
markareas={a6-a6,b5-b5,c4-c4,e2-e2,f1-f1},
]
\caption{\label{sfig:back-nqueens-4} Propagate downward diagonal}
\end{subfigure}
\caption{\label{fig:back-nqueens} An example of domain propagation when a
queen gets assigned in the N-Queens problem.}
\end{figure}
In \gls{cp} solving there is a trade-off between the amount of time spend
propagating a constraint and the amount of search that is otherwise required.
The golden standard for a \gls{propagator} is to be \gls{domain-con}, meaning