exercises/solutions/sol04.tex
author Eugen Sawin <sawine@me73.com>
Thu, 31 May 2012 17:36:51 +0200
changeset 15 f94c11c455e8
parent 14 5c6d1fbfd37a
child 16 359c996c91a2
permissions -rw-r--r--
Added ex4.2b.
sawine@9
     1
\documentclass[a4paper, 10pt, pagesize, smallheadings]{article}
sawine@9
     2
\usepackage{graphicx}
sawine@9
     3
%\usepackage[latin1]{inputenc}
sawine@9
     4
\usepackage{amsmath, amsthm, amssymb}
sawine@9
     5
\usepackage{typearea}
sawine@9
     6
\usepackage{algorithm}
sawine@9
     7
\usepackage{algorithmic}
sawine@9
     8
\usepackage{fullpage}
sawine@9
     9
\usepackage{mathtools}
sawine@9
    10
\usepackage[all]{xy}
sawine@9
    11
\usepackage{tikz}
sawine@9
    12
\usepackage{tikz-qtree}
sawine@9
    13
\usetikzlibrary{decorations.pathmorphing} % noisy shapes
sawine@9
    14
\usetikzlibrary{fit}					% fitting shapes to coordinates
sawine@9
    15
\usetikzlibrary{backgrounds}	% drawin
sawine@9
    16
\usetikzlibrary{shapes,snakes}
sawine@9
    17
\addtolength{\voffset}{-20pt}
sawine@13
    18
\title{CSP Exercise 04 Solution}
sawine@9
    19
\author{Eugen Sawin}
sawine@9
    20
\renewcommand{\familydefault}{\sfdefault}
sawine@9
    21
\newcommand{\R}{\mathcal{R}}
sawine@13
    22
\newcommand{\N}{\mathbb{N}}
sawine@14
    23
\newcommand{\C}{\mathcal{C}}
sawine@9
    24
sawine@9
    25
%\include{pythonlisting}
sawine@9
    26
sawine@9
    27
\pagestyle{empty}
sawine@9
    28
\begin{document}
sawine@9
    29
\maketitle
sawine@9
    30
sawine@13
    31
\section*{Exercise 4.1}
sawine@13
    32
(a) The zebra problem is the constraint network $N=\langle V,D,C\rangle$ with
sawine@9
    33
\begin{align*}
sawine@13
    34
  V=&(english,spanish,ukrainian,norwegian,japanese,\\
sawine@13
    35
    &red,green,ivory,yellow,blue\\
sawine@13
    36
    &dog,snail,fox,horse,zebra\\
sawine@13
    37
    &coffee,tea,milk,juice,water\\
sawine@13
    38
    &oldgold,kools,chesterfield,lucky,parliament)\\
sawine@13
    39
  D=&(D_v)_{v\in V}\text{ where } D_v=\left\{\begin{array}{l l}
sawine@13
    40
                                               \{1\} & v = norwegian\\
sawine@13
    41
                                               \{3\} & v = milk\\
sawine@13
    42
                                   \{1, 2, 3, 4, 5\} & otherwise\\
sawine@13
    43
                                             \end{array} \right.\\
sawine@13
    44
  R_{eq}=&\{(a,a)\mid a\in \N\}\\
sawine@13
    45
  R_{next}=&\{(a,b)\mid a,b\in\N, |a-b| = 1\}\\
sawine@13
    46
  R_{rightof}=&\{(a+1,a)\mid a\in \N\}\\
sawine@13
    47
  C=&\{R_{v_1, v_2\in\{english,spanish,ukrainian,norwegian,japanese\}}=(D_{v_1}\times D_{v_j})\setminus R_{eq},\\
sawine@13
    48
    &R_{v_1, v_2\in\{red,green,ivory,yellow,blue\}}=(D_{v_1}\times D_{v_j})\setminus R_{eq},\\
sawine@13
    49
    &R_{v_1, v_2\in\{dog,snail,fox,horse,zebra\}}=(D_{v_1}\times D_{v_j})\setminus R_{eq},\\
sawine@13
    50
    &R_{v_1, v_2\in\{coffee,tea,milk,juice,water\}}=(D_{v_1}\times D_{v_j})\setminus R_{eq},\\
sawine@13
    51
    &R_{v_1, v_2\in\{oldgold,kools,chesterfield,lucky,parliament\}}=(D_{v_1}\times D_{v_j})\setminus R_{eq},\\
sawine@13
    52
    &R_{english, red}=(D_{english}\times D_{red}) \cap R_{eq},\\
sawine@13
    53
    &R_{spanish, dog}=(D_{spanish}\times D_{dog}) \cap R_{eq},\\
sawine@13
    54
    &R_{coffee, green}=(D_{coffee}\times D_{green}) \cap R_{eq},\\
sawine@13
    55
    &R_{ukrainian, tea}=(D_{ukrainian}\times D_{tea}) \cap R_{eq},\\
sawine@13
    56
    &R_{oldgold, snail}=(D_{oldgold}\times D_{snail}) \cap R_{eq},\\
sawine@13
    57
    &R_{kool, yellow}=(D_{kool}\times D_{yellow}) \cap R_{eq},\\
sawine@13
    58
    &R_{lucky, juice}=(D_{lucky}\times D_{juice}) \cap R_{eq},\\
sawine@13
    59
    &R_{japanese, parliament}=(D_{japanese}\times D_{parliament}) \cap R_{eq},\\
sawine@13
    60
    &R_{chesterfield, fox}=(D_{chesterfield}\times D_{fox}) \cap R_{next},\\
sawine@13
    61
    &R_{yellow, horse}=(D_{yellow}\times D_{horse}) \cap R_{next},\\
sawine@13
    62
    &R_{norwegian, blue}=(D_{norwegian}\times D_{blue}) \cap R_{next},\\
sawine@13
    63
    &R_{green, ivory}=(D_{green}\times D_{ivory}) \cap R_{rightof}\}
sawine@9
    64
\end{align*}
sawine@13
    65
To answer the questions, the Norwegian drinks water and the Japanese owns the zebra. I have added the corresponding problem file in XCSP2.1 format to my project repository \emph{(xcsp2\_examples/zebra.xml)}.\\\\
sawine@13
    66
(b) See figure 1 (names are abbreviated).
sawine@9
    67
\begin{figure}[h]
sawine@9
    68
\centering
sawine@9
    69
\tikzstyle{var}=[circle,
sawine@9
    70
  draw=black!100,
sawine@9
    71
  fill=black!0]
sawine@9
    72
\begin{tikzpicture}[>=latex,text height=1.5ex,text depth=0.25ex]
sawine@13
    73
  \matrix[row sep=1.1cm,column sep=0.7cm] {    
sawine@13
    74
    \node(eng)[var]{$eng$}; &\node(spa)[var]{$spa$}; &\node(ukr)[var]{$ukr$}; &\node(nor)[var]{$nor$}; &\node(jap)[var]{$jap$};\\
sawine@13
    75
  \node(red)[var]{$red$}; &\node(gre)[var]{$gre$}; &\node(ivo)[var]{$ivo$}; &\node(yel)[var]{$yel$}; &\node(blu)[var]{$blu$};\\
sawine@13
    76
  \node(dog)[var]{$dog$}; &\node(sna)[var]{$sna$}; &\node(fox)[var]{$fox$}; &\node(hor)[var]{$hor$}; &\node(zeb)[var]{$zeb$};\\
sawine@13
    77
  \node(cof)[var]{$cof$}; &\node(tea)[var]{$tea$}; &\node(mil)[var]{$mil$}; &\node(jui)[var]{$jui$}; &\node(wat)[var]{$wat$};\\
sawine@13
    78
  \node(old)[var]{$old$}; &\node(koo)[var]{$koo$}; &\node(che)[var]{$che$}; &\node(luc)[var]{$luc$}; &\node(par)[var]{$par$};\\
sawine@9
    79
  };
sawine@9
    80
  \path[-]
sawine@13
    81
  (eng) edge (red)
sawine@13
    82
  (spa) edge[bend right=60] (dog)
sawine@13
    83
  (cof) edge (gre)
sawine@13
    84
  (ukr) edge (tea)
sawine@13
    85
  (old) edge (sna)
sawine@13
    86
  (koo) edge (yel)
sawine@13
    87
  (luc) edge (jui)
sawine@13
    88
  (jap) edge[bend left] (par)
sawine@13
    89
  (che) edge[bend left] (fox)
sawine@13
    90
  (yel) edge (hor)
sawine@13
    91
  (nor) edge (blu)
sawine@13
    92
  (gre) edge (ivo)
sawine@13
    93
sawine@13
    94
  (eng) edge (spa)
sawine@13
    95
  (eng) edge[bend left] (ukr)
sawine@13
    96
  (eng) edge[bend left] (nor)
sawine@13
    97
  (eng) edge[bend left] (jap)
sawine@13
    98
  (spa) edge (ukr)
sawine@13
    99
  (spa) edge[bend right] (nor)
sawine@13
   100
  (spa) edge[bend right] (jap)
sawine@13
   101
  (ukr) edge (nor)
sawine@13
   102
  (ukr) edge[bend left] (jap)
sawine@13
   103
  (nor) edge (jap)
sawine@13
   104
sawine@13
   105
  (red) edge (gre)
sawine@13
   106
  (red) edge[bend left] (ivo)
sawine@13
   107
  (red) edge[bend left] (yel)
sawine@13
   108
  (red) edge[bend left] (blu)
sawine@13
   109
  (gre) edge (ivo)
sawine@13
   110
  (gre) edge[bend right] (yel)
sawine@13
   111
  (gre) edge[bend right] (blu)
sawine@13
   112
  (ivo) edge (yel)
sawine@13
   113
  (ivo) edge[bend left] (blu)
sawine@13
   114
  (yel) edge (blu)
sawine@13
   115
  
sawine@13
   116
  (dog) edge (sna)
sawine@13
   117
  (dog) edge[bend left] (fox)
sawine@13
   118
  (dog) edge[bend left] (hor)
sawine@13
   119
  (dog) edge[bend left] (zeb)
sawine@13
   120
  (sna) edge (fox)
sawine@13
   121
  (sna) edge[bend right] (hor)
sawine@13
   122
  (sna) edge[bend right] (zeb)
sawine@13
   123
  (fox) edge (hor)
sawine@13
   124
  (fox) edge[bend left] (zeb)
sawine@13
   125
  (hor) edge (zeb)
sawine@13
   126
sawine@13
   127
  (cof) edge (tea)
sawine@13
   128
  (cof) edge[bend left] (mil)
sawine@13
   129
  (cof) edge[bend left] (jui)
sawine@13
   130
  (cof) edge[bend left] (wat)
sawine@13
   131
  (tea) edge (mil)
sawine@13
   132
  (tea) edge[bend right] (jui)
sawine@13
   133
  (tea) edge[bend right] (wat)
sawine@13
   134
  (mil) edge (jui)
sawine@13
   135
  (mil) edge[bend left] (wat)
sawine@13
   136
  (jui) edge (wat)
sawine@13
   137
sawine@13
   138
  (old) edge (koo)
sawine@13
   139
  (old) edge[bend left] (che)
sawine@13
   140
  (old) edge[bend left] (luc)
sawine@13
   141
  (old) edge[bend left] (par)
sawine@13
   142
  (koo) edge (che)
sawine@13
   143
  (koo) edge[bend right] (luc)
sawine@13
   144
  (koo) edge[bend right] (par)
sawine@13
   145
  (che) edge (luc)
sawine@13
   146
  (che) edge[bend left] (par)
sawine@13
   147
  (luc) edge (par)
sawine@9
   148
  ;      
sawine@9
   149
\end{tikzpicture}
sawine@13
   150
\caption{(3.1b) primal constraint graph of $N$}
sawine@9
   151
\end{figure}\\
sawine@15
   152
(c) No, $N$ is not arc-consistent. We provide the arc-consistent constraint network $N'=\langle V, D', C\rangle$ with
sawine@13
   153
\begin{align*}
sawine@15
   154
  D'_{v}=\left\{
sawine@13
   155
    \begin{array}{l l}
sawine@13
   156
      \{1\} & v = norwegian\\
sawine@13
   157
      \{3\} & v = milk\\
sawine@13
   158
      \{2\} & v = blue\\
sawine@13
   159
      \{3,4\} & v = ivory\\
sawine@13
   160
      \{4,5\} & v \in \{coffee,green\}\\
sawine@13
   161
      \{2,3,4\} & v = horse\\
sawine@13
   162
      \{3,4,5\} & v \in \{english,red\}\\
sawine@13
   163
      \{2,4,5\} & v \in \{ukrainian,tea\}\\
sawine@13
   164
      \{2,3,4,5\} & v \in \{spanish,japanese,dog,parliament\}\\
sawine@13
   165
      \{1,2,4,5\} & v \in \{juice,water,lucky\}\\
sawine@13
   166
      \{1,3,4,5\} & v \in \{yellow,kool\}\\
sawine@13
   167
      \{1, 2, 3, 4, 5\} & otherwise\\
sawine@13
   168
    \end{array} \right.\\
sawine@13
   169
\end{align*}
sawine@14
   170
That makes 32 domain values less. I've spent an hour and this, where my solver spent 1.5ms on this task. I'm glad we have the power to build machines for doing such tedious work instead of doing it by hand.
sawine@14
   171
sawine@14
   172
\section*{Exercise 4.2}
sawine@14
   173
(a) We show that $Sol(\C) = Sol(\C')$ by contradiction.
sawine@14
   174
sawine@14
   175
Let $\C=\langle V,D,C\rangle$ and $\C'=\langle V,D',C\rangle$. By definition each variable assignment $a(v_i)$ must be in its variable domain $D_i$, i.e., $a(v_i)\in D_i$. Therefore, a reduction of domains can only yield a network with less solutions. Since AC3 reduces domains, there can not be more solutions for $\C'$, i.e., $Sol(\C') \subseteq Sol(\C)$.
sawine@14
   176
sawine@15
   177
Assume that solution $a\in Sol(\C)$ is lost after the domain reduction by AC3, i.e., $a\notin Sol(\C')$. WLOG it follows that at some iteration of AC3 the value $a(v_i)$ was removed from the domain $D_i'$, so it holds $a(v_i)\notin D_i'$. By the definition of the revise function of AC3, it holds that $D_i'\leftarrow D_i\cap\pi_i(R_{ij} \bowtie D_j)$. Since $a(v_i)$ is in $D_i$ but not in $D_i'$, it follows that $a(v_i)\notin\pi_i(R_{ij}\bowtie D_j) \implies (a(v_i),a(v_j))\notin(R_{ij}\bowtie D_j)$.
sawine@15
   178
sawine@15
   179
The join $R_{ij}\bowtie D_j$ represents the set of all consistent assignments of variable $v_j$ over the relation $R_{ij}$. With $(a(v_i),a(v_j))\notin (R_{ij}\bowtie D_j)$ it follows that variable assignments $(a(v_i),a(v_j))$ are not consistent with the constraint over $R_{ij}$. It contradicts with our assumption that $a\in Sol(\C)$, because a solution must satisfy all constraints of the network. We have shown that there is no solution $a\in Sol(\C)$, such that $a\notin Sol(\C')$. \qed\\\\
sawine@15
   180
%
sawine@15
   181
(b) To show that AC3 produces an arc-consistent network $\C'$ we consider three cases. The first case is trivial, given an arc-consistent network the revise function does not remove any domain values and therefore does not modify the network.
sawine@15
   182
sawine@15
   183
Let $\C$ be a network with some not arc-consistent $R_{ij}$, i.e., there is some assignment a with $a(v_i)\in D_i$, $a(v_j)\in D_j$ and $(a(v_i),a(v_j))\notin (R_{ij}\bowtie D_j)$. Initially, AC3 does revise all variable pairs $(v_i,v_j)$ and $(v_j,v_i)$ with $(v_i,v_j)$ in some constraint's scope ($R_{ij}$). It follows that AC3 does revise $(v_i,v_j)$ in respect of $R_{ij}$ in some iteration and reduces $D_i'\leftarrow D_i\cap\pi_i(R_{ij}\bowtie D_j)$. Because $(a(v_i),a(v_j))\notin (R_{ij}\bowtie D_j)$ implies $a(v_i)\notin\pi_i(R_{ij}\bowtie D_j)$, it holds that $a(v_i)\notin D_i'$. This reduces the initial arc-inconsitency of $v_i$ relative to $v_j$.
sawine@15
   184
sawine@15
   185
By the domain value reduction, AC3 can introduce new not arc-consistent constraints. Let $a(v_i)\in D_i$ be a value, that was removed by the revise function for constraint $R_{ij}$. Since the revise function changed $D_i$, AC3 will again revise all variable pairs $(v_k,v_i)$ with $k\neq i,k\neq j$ for all constraints $R_{ki}$. This removes all inconsistent values for all domains $D_k$,i.e., all $a(v_k)\in D_k$ with $a(v_k)\notin\pi_k(R_{ki}\bowtie D_i)$ are removed from $D_k$. All other constraints $R_{lm}$ with $m\neq i$ are not directly affected by the reduced domain $D_i$ and can therefore not become not arc-consistent by the revisal of $(v_i,v_j)$. 
sawine@15
   186
sawine@15
   187
We have shown, that all initial not arc-consistent constraints are made arc-consistent and the same holds for all newly introduced inconsistencies by the domain reduction. It follows that all remaining domains of $\C'$ form an arc-consistent network. \qed\\\\
sawine@15
   188
%
sawine@15
   189
(c)
sawine@9
   190
\end{document}