exercises/solutions/sol04.tex
author Eugen Sawin <sawine@me73.com>
Mon, 04 Jun 2012 05:00:02 +0200
changeset 18 c4cbf19866b3
parent 17 60edc408c19e
permissions -rw-r--r--
Added final sol04.
     1 \documentclass[a4paper, 10pt, pagesize, smallheadings]{article}
     2 \usepackage{graphicx}
     3 %\usepackage[latin1]{inputenc}
     4 \usepackage{amsmath, amsthm, amssymb}
     5 \usepackage{typearea}
     6 \usepackage{algorithm}
     7 \usepackage{algorithmic}
     8 \usepackage{fullpage}
     9 \usepackage{mathtools}
    10 \usepackage[all]{xy}
    11 \usepackage{tikz}
    12 \usepackage{tikz-qtree}
    13 \usetikzlibrary{decorations.pathmorphing} % noisy shapes
    14 \usetikzlibrary{fit}					% fitting shapes to coordinates
    15 \usetikzlibrary{backgrounds}	% drawin
    16 \usetikzlibrary{shapes,snakes}
    17 \addtolength{\voffset}{-20pt}
    18 \title{CSP Exercise 04 Solution}
    19 \author{Eugen Sawin}
    20 \renewcommand{\familydefault}{\sfdefault}
    21 \newcommand{\R}{\mathcal{R}}
    22 \newcommand{\N}{\mathbb{N}}
    23 \newcommand{\C}{\mathcal{C}}
    24 \newcommand{\bo}{\mathcal{O}}
    25 
    26 %\include{pythonlisting}
    27 
    28 \pagestyle{empty}
    29 \begin{document}
    30 \maketitle
    31 %
    32 \section*{Exercise 4.1}
    33 (a) The zebra problem is the constraint network $N=\langle V,D,C\rangle$ with
    34 \begin{align*}
    35   V=&(english,spanish,ukrainian,norwegian,japanese,\\
    36     &red,green,ivory,yellow,blue\\
    37     &dog,snail,fox,horse,zebra\\
    38     &coffee,tea,milk,juice,water\\
    39     &oldgold,kools,chesterfield,lucky,parliament)\\
    40   D=&(D_v)_{v\in V}\text{ where } D_v=\left\{\begin{array}{l l}
    41                                                \{1\}, & \text{if }v = norwegian\\
    42                                                \{3\}, & \text{if }v = milk\\
    43                                    \{1, 2, 3, 4, 5\}, & \text{otherwise}\\
    44                                              \end{array} \right.\\
    45   R_{eq}=&\{(a,a)\mid a\in \N\}\\
    46   R_{next}=&\{(a,b)\mid a,b\in\N, |a-b| = 1\}\\
    47   R_{rightof}=&\{(a+1,a)\mid a\in \N\}\\
    48   C=&\{R_{v_1, v_2\in\{english,spanish,ukrainian,norwegian,japanese\}}=(D_{v_1}\times D_{v_j})\setminus R_{eq},\\
    49     &R_{v_1, v_2\in\{red,green,ivory,yellow,blue\}}=(D_{v_1}\times D_{v_j})\setminus R_{eq},\\
    50     &R_{v_1, v_2\in\{dog,snail,fox,horse,zebra\}}=(D_{v_1}\times D_{v_j})\setminus R_{eq},\\
    51     &R_{v_1, v_2\in\{coffee,tea,milk,juice,water\}}=(D_{v_1}\times D_{v_j})\setminus R_{eq},\\
    52     &R_{v_1, v_2\in\{oldgold,kools,chesterfield,lucky,parliament\}}=(D_{v_1}\times D_{v_j})\setminus R_{eq},\\
    53     &R_{english, red}=(D_{english}\times D_{red}) \cap R_{eq},\\
    54     &R_{spanish, dog}=(D_{spanish}\times D_{dog}) \cap R_{eq},\\
    55     &R_{coffee, green}=(D_{coffee}\times D_{green}) \cap R_{eq},\\
    56     &R_{ukrainian, tea}=(D_{ukrainian}\times D_{tea}) \cap R_{eq},\\
    57     &R_{oldgold, snail}=(D_{oldgold}\times D_{snail}) \cap R_{eq},\\
    58     &R_{kool, yellow}=(D_{kool}\times D_{yellow}) \cap R_{eq},\\
    59     &R_{lucky, juice}=(D_{lucky}\times D_{juice}) \cap R_{eq},\\
    60     &R_{japanese, parliament}=(D_{japanese}\times D_{parliament}) \cap R_{eq},\\
    61     &R_{chesterfield, fox}=(D_{chesterfield}\times D_{fox}) \cap R_{next},\\
    62     &R_{yellow, horse}=(D_{yellow}\times D_{horse}) \cap R_{next},\\
    63     &R_{norwegian, blue}=(D_{norwegian}\times D_{blue}) \cap R_{next},\\
    64     &R_{green, ivory}=(D_{green}\times D_{ivory}) \cap R_{rightof}\}
    65 \end{align*}
    66 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)}.\\\\
    67 (b) See figure 1 (names are abbreviated).
    68 \begin{figure}[h]
    69 \centering
    70 \tikzstyle{var}=[circle,
    71   draw=black!100,
    72   fill=black!0]
    73 \begin{tikzpicture}[>=latex,text height=1.5ex,text depth=0.25ex]
    74   \matrix[row sep=1.1cm,column sep=0.7cm] {    
    75     \node(eng)[var]{$eng$}; &\node(spa)[var]{$spa$}; &\node(ukr)[var]{$ukr$}; &\node(nor)[var]{$nor$}; &\node(jap)[var]{$jap$};\\
    76   \node(red)[var]{$red$}; &\node(gre)[var]{$gre$}; &\node(ivo)[var]{$ivo$}; &\node(yel)[var]{$yel$}; &\node(blu)[var]{$blu$};\\
    77   \node(dog)[var]{$dog$}; &\node(sna)[var]{$sna$}; &\node(fox)[var]{$fox$}; &\node(hor)[var]{$hor$}; &\node(zeb)[var]{$zeb$};\\
    78   \node(cof)[var]{$cof$}; &\node(tea)[var]{$tea$}; &\node(mil)[var]{$mil$}; &\node(jui)[var]{$jui$}; &\node(wat)[var]{$wat$};\\
    79   \node(old)[var]{$old$}; &\node(koo)[var]{$koo$}; &\node(che)[var]{$che$}; &\node(luc)[var]{$luc$}; &\node(par)[var]{$par$};\\
    80   };
    81   \path[-]
    82   (eng) edge (red)
    83   (spa) edge[bend right=60] (dog)
    84   (cof) edge (gre)
    85   (ukr) edge (tea)
    86   (old) edge (sna)
    87   (koo) edge (yel)
    88   (luc) edge (jui)
    89   (jap) edge[bend left] (par)
    90   (che) edge[bend left] (fox)
    91   (yel) edge (hor)
    92   (nor) edge (blu)
    93   (gre) edge (ivo)
    94 
    95   (eng) edge (spa)
    96   (eng) edge[bend left] (ukr)
    97   (eng) edge[bend left] (nor)
    98   (eng) edge[bend left] (jap)
    99   (spa) edge (ukr)
   100   (spa) edge[bend right] (nor)
   101   (spa) edge[bend right] (jap)
   102   (ukr) edge (nor)
   103   (ukr) edge[bend left] (jap)
   104   (nor) edge (jap)
   105 
   106   (red) edge (gre)
   107   (red) edge[bend left] (ivo)
   108   (red) edge[bend left] (yel)
   109   (red) edge[bend left] (blu)
   110   (gre) edge (ivo)
   111   (gre) edge[bend right] (yel)
   112   (gre) edge[bend right] (blu)
   113   (ivo) edge (yel)
   114   (ivo) edge[bend left] (blu)
   115   (yel) edge (blu)
   116   
   117   (dog) edge (sna)
   118   (dog) edge[bend left] (fox)
   119   (dog) edge[bend left] (hor)
   120   (dog) edge[bend left] (zeb)
   121   (sna) edge (fox)
   122   (sna) edge[bend right] (hor)
   123   (sna) edge[bend right] (zeb)
   124   (fox) edge (hor)
   125   (fox) edge[bend left] (zeb)
   126   (hor) edge (zeb)
   127 
   128   (cof) edge (tea)
   129   (cof) edge[bend left] (mil)
   130   (cof) edge[bend left] (jui)
   131   (cof) edge[bend left] (wat)
   132   (tea) edge (mil)
   133   (tea) edge[bend right] (jui)
   134   (tea) edge[bend right] (wat)
   135   (mil) edge (jui)
   136   (mil) edge[bend left] (wat)
   137   (jui) edge (wat)
   138 
   139   (old) edge (koo)
   140   (old) edge[bend left] (che)
   141   (old) edge[bend left] (luc)
   142   (old) edge[bend left] (par)
   143   (koo) edge (che)
   144   (koo) edge[bend right] (luc)
   145   (koo) edge[bend right] (par)
   146   (che) edge (luc)
   147   (che) edge[bend left] (par)
   148   (luc) edge (par)
   149   ;      
   150 \end{tikzpicture}
   151 \caption{(3.1b) primal constraint graph of $N$}
   152 \end{figure}\\
   153 (c) No, $N$ is not arc-consistent. We provide the arc-consistent constraint network $N'=\langle V, D', C\rangle$ with
   154 \begin{align*}
   155   D'_{v}=\left\{
   156     \begin{array}{l l}
   157       \{1\}, & \text{if }v = norwegian\\
   158       \{3\}, & \text{if }v = milk\\
   159       \{2\}, & \text{if }v = blue\\
   160     \{3,4\}, & \text{if }v = ivory\\
   161     \{4,5\}, & \text{if }v \in \{coffee,green\}\\
   162   \{2,3,4\}, & \text{if }v = horse\\
   163   \{3,4,5\}, & \text{if }v \in \{english,red\}\\
   164   \{2,4,5\}, & \text{if }v \in \{ukrainian,tea\}\\
   165 \{2,3,4,5\}, & \text{if }v \in \{spanish,japanese,dog,parliament\}\\
   166 \{1,2,4,5\}, & \text{if }v \in \{juice,water,lucky\}\\
   167 \{1,3,4,5\}, & \text{if }v \in \{yellow,kool\}\\
   168 \{1, 2, 3, 4, 5\}, & \text{otherwise}\\
   169     \end{array} \right.\\
   170 \end{align*}
   171 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.
   172 
   173 \section*{Exercise 4.2}
   174 (a) We show that $Sol(\C) = Sol(\C')$ by contradiction.
   175 
   176 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)$.
   177 
   178 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)$.
   179 
   180 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\\\\
   181 %
   182 (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.
   183 
   184 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$.
   185 
   186 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)$. 
   187 
   188 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\\\\
   189 %
   190 (c) All trivial assignments with complexity of $\bo(1)$ are left out of this analysis. Further it is assumed that set containment can be tested in $\bo(1)$, while is is only true for fully expanded sets with exponential space requirements. We can, however, archieve $\bo(1)^*$ using hash tables and amortized analysis in linear space. The natural tree-based approach yields $\bo(\log n)$. For the queue, we assume a stack is used with $\bo(1)$ insertion and removal (last inserted value). Let $n$ be the number of variables, all domains have size $\leq k$ and $e$ is the number of constraints.
   191 
   192 The initialisation of the counters consists of an iteration over all constraints $R_{ij}$ and values $a_i\in D_i$, $a_j\in D_j$, this takes $\Theta(e\cdot k^2)$ time.
   193 
   194 Next we initialise the set $S[v_j,a_j]$ with the supported tuples, adjust the counters and move unsupported tuples into $Q$ for each constraint $R_{ij}$ and values $a_i\in D_i$, $a_j\in D_j$, again this takes $\Theta(e\cdot k^2)$ time. We notice that each set $S[v_j,a_j]$ and $Q$ have at most $e\cdot k$ elements, also the counter value for any variable-value pair is $\leq e\cdot k$.
   195 
   196 The while loop needs some special treatment based on the observation that $|S[v_j,a_j]|+|Q|=e\cdot k$ and others. But, due to limited time, I have to skip this part this time.
   197 \end{document}