# HG changeset patch # User Eugen Sawin # Date 1338419865 -7200 # Node ID 5fef2580e4458d9245515fe630ef5e4a6245e5dd # Parent 7db450445696042f150527bfb6d295cb0f5e0be8 First exercise completed. diff -r 7db450445696 -r 5fef2580e445 exercises/solutions/sol04.tex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/exercises/solutions/sol04.tex Thu May 31 01:17:45 2012 +0200 @@ -0,0 +1,170 @@ +\documentclass[a4paper, 10pt, pagesize, smallheadings]{article} +\usepackage{graphicx} +%\usepackage[latin1]{inputenc} +\usepackage{amsmath, amsthm, amssymb} +\usepackage{typearea} +\usepackage{algorithm} +\usepackage{algorithmic} +\usepackage{fullpage} +\usepackage{mathtools} +\usepackage[all]{xy} +\usepackage{tikz} +\usepackage{tikz-qtree} +\usetikzlibrary{decorations.pathmorphing} % noisy shapes +\usetikzlibrary{fit} % fitting shapes to coordinates +\usetikzlibrary{backgrounds} % drawin +\usetikzlibrary{shapes,snakes} +\addtolength{\voffset}{-20pt} +\title{CSP Exercise 04 Solution} +\author{Eugen Sawin} +\renewcommand{\familydefault}{\sfdefault} +\newcommand{\R}{\mathcal{R}} +\newcommand{\N}{\mathbb{N}} + +%\include{pythonlisting} + +\pagestyle{empty} +\begin{document} +\maketitle + +\section*{Exercise 4.1} +(a) The zebra problem is the constraint network $N=\langle V,D,C\rangle$ with +\begin{align*} + V=&(english,spanish,ukrainian,norwegian,japanese,\\ + &red,green,ivory,yellow,blue\\ + &dog,snail,fox,horse,zebra\\ + &coffee,tea,milk,juice,water\\ + &oldgold,kools,chesterfield,lucky,parliament)\\ + D=&(D_v)_{v\in V}\text{ where } D_v=\left\{\begin{array}{l l} + \{1\} & v = norwegian\\ + \{3\} & v = milk\\ + \{1, 2, 3, 4, 5\} & otherwise\\ + \end{array} \right.\\ + R_{eq}=&\{(a,a)\mid a\in \N\}\\ + R_{next}=&\{(a,b)\mid a,b\in\N, |a-b| = 1\}\\ + R_{rightof}=&\{(a+1,a)\mid a\in \N\}\\ + C=&\{R_{v_1, v_2\in\{english,spanish,ukrainian,norwegian,japanese\}}=(D_{v_1}\times D_{v_j})\setminus R_{eq},\\ + &R_{v_1, v_2\in\{red,green,ivory,yellow,blue\}}=(D_{v_1}\times D_{v_j})\setminus R_{eq},\\ + &R_{v_1, v_2\in\{dog,snail,fox,horse,zebra\}}=(D_{v_1}\times D_{v_j})\setminus R_{eq},\\ + &R_{v_1, v_2\in\{coffee,tea,milk,juice,water\}}=(D_{v_1}\times D_{v_j})\setminus R_{eq},\\ + &R_{v_1, v_2\in\{oldgold,kools,chesterfield,lucky,parliament\}}=(D_{v_1}\times D_{v_j})\setminus R_{eq},\\ + &R_{english, red}=(D_{english}\times D_{red}) \cap R_{eq},\\ + &R_{spanish, dog}=(D_{spanish}\times D_{dog}) \cap R_{eq},\\ + &R_{coffee, green}=(D_{coffee}\times D_{green}) \cap R_{eq},\\ + &R_{ukrainian, tea}=(D_{ukrainian}\times D_{tea}) \cap R_{eq},\\ + &R_{oldgold, snail}=(D_{oldgold}\times D_{snail}) \cap R_{eq},\\ + &R_{kool, yellow}=(D_{kool}\times D_{yellow}) \cap R_{eq},\\ + &R_{lucky, juice}=(D_{lucky}\times D_{juice}) \cap R_{eq},\\ + &R_{japanese, parliament}=(D_{japanese}\times D_{parliament}) \cap R_{eq},\\ + &R_{chesterfield, fox}=(D_{chesterfield}\times D_{fox}) \cap R_{next},\\ + &R_{yellow, horse}=(D_{yellow}\times D_{horse}) \cap R_{next},\\ + &R_{norwegian, blue}=(D_{norwegian}\times D_{blue}) \cap R_{next},\\ + &R_{green, ivory}=(D_{green}\times D_{ivory}) \cap R_{rightof}\} +\end{align*} +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)}.\\\\ +(b) See figure 1 (names are abbreviated). +\begin{figure}[h] +\centering +\tikzstyle{var}=[circle, + draw=black!100, + fill=black!0] +\begin{tikzpicture}[>=latex,text height=1.5ex,text depth=0.25ex] + \matrix[row sep=1.1cm,column sep=0.7cm] { + \node(eng)[var]{$eng$}; &\node(spa)[var]{$spa$}; &\node(ukr)[var]{$ukr$}; &\node(nor)[var]{$nor$}; &\node(jap)[var]{$jap$};\\ + \node(red)[var]{$red$}; &\node(gre)[var]{$gre$}; &\node(ivo)[var]{$ivo$}; &\node(yel)[var]{$yel$}; &\node(blu)[var]{$blu$};\\ + \node(dog)[var]{$dog$}; &\node(sna)[var]{$sna$}; &\node(fox)[var]{$fox$}; &\node(hor)[var]{$hor$}; &\node(zeb)[var]{$zeb$};\\ + \node(cof)[var]{$cof$}; &\node(tea)[var]{$tea$}; &\node(mil)[var]{$mil$}; &\node(jui)[var]{$jui$}; &\node(wat)[var]{$wat$};\\ + \node(old)[var]{$old$}; &\node(koo)[var]{$koo$}; &\node(che)[var]{$che$}; &\node(luc)[var]{$luc$}; &\node(par)[var]{$par$};\\ + }; + \path[-] + (eng) edge (red) + (spa) edge[bend right=60] (dog) + (cof) edge (gre) + (ukr) edge (tea) + (old) edge (sna) + (koo) edge (yel) + (luc) edge (jui) + (jap) edge[bend left] (par) + (che) edge[bend left] (fox) + (yel) edge (hor) + (nor) edge (blu) + (gre) edge (ivo) + + (eng) edge (spa) + (eng) edge[bend left] (ukr) + (eng) edge[bend left] (nor) + (eng) edge[bend left] (jap) + (spa) edge (ukr) + (spa) edge[bend right] (nor) + (spa) edge[bend right] (jap) + (ukr) edge (nor) + (ukr) edge[bend left] (jap) + (nor) edge (jap) + + (red) edge (gre) + (red) edge[bend left] (ivo) + (red) edge[bend left] (yel) + (red) edge[bend left] (blu) + (gre) edge (ivo) + (gre) edge[bend right] (yel) + (gre) edge[bend right] (blu) + (ivo) edge (yel) + (ivo) edge[bend left] (blu) + (yel) edge (blu) + + (dog) edge (sna) + (dog) edge[bend left] (fox) + (dog) edge[bend left] (hor) + (dog) edge[bend left] (zeb) + (sna) edge (fox) + (sna) edge[bend right] (hor) + (sna) edge[bend right] (zeb) + (fox) edge (hor) + (fox) edge[bend left] (zeb) + (hor) edge (zeb) + + (cof) edge (tea) + (cof) edge[bend left] (mil) + (cof) edge[bend left] (jui) + (cof) edge[bend left] (wat) + (tea) edge (mil) + (tea) edge[bend right] (jui) + (tea) edge[bend right] (wat) + (mil) edge (jui) + (mil) edge[bend left] (wat) + (jui) edge (wat) + + (old) edge (koo) + (old) edge[bend left] (che) + (old) edge[bend left] (luc) + (old) edge[bend left] (par) + (koo) edge (che) + (koo) edge[bend right] (luc) + (koo) edge[bend right] (par) + (che) edge (luc) + (che) edge[bend left] (par) + (luc) edge (par) + ; +\end{tikzpicture} +\caption{(3.1b) primal constraint graph of $N$} +\end{figure}\\ +(c) No, $N$ is not arc-consistent. We provide the arc-consistent constraint network $N^c=\langle V, D^c, C\rangle$ with +\begin{align*} + D^c_{v}=\left\{ + \begin{array}{l l} + \{1\} & v = norwegian\\ + \{3\} & v = milk\\ + \{2\} & v = blue\\ + \{3,4\} & v = ivory\\ + \{4,5\} & v \in \{coffee,green\}\\ + \{2,3,4\} & v = horse\\ + \{3,4,5\} & v \in \{english,red\}\\ + \{2,4,5\} & v \in \{ukrainian,tea\}\\ + \{2,3,4,5\} & v \in \{spanish,japanese,dog,parliament\}\\ + \{1,2,4,5\} & v \in \{juice,water,lucky\}\\ + \{1,3,4,5\} & v \in \{yellow,kool\}\\ + \{1, 2, 3, 4, 5\} & otherwise\\ + \end{array} \right.\\ +\end{align*} +That makes 32 domain values less and one hour less of my life. My solver spent full 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. +\end{document}