<!--
  - Authors:
  -   Christian Schulte <schulte@ps.uni-sb.de>
  -   Gert Smolka <smolka@dfki.de>
  -
  - Contributors:
  -   Daniel Simon <dansim@ps.uni-sb.de>
  -   Andy Walter <anwalt@ps.uni-sb.de>
  -   
  - Copyright:
  -   Christian Schulte, 1998
  -   Gert Smolka, 1998
  -
  - Last change:
  -   $Date$ by $Author$
  -   $Revision$
  -
  - This file is part of Mozart, an implementation
  - of Oz 3
  -    http://www.mozart-oz.org
  -
  - See the file "LICENSE" or
  -    http://www.mozart-oz.org/LICENSE.html
  - for information on usage and redistribution
  - of this file, and for a DISCLAIMER OF ALL
  - WARRANTIES.
  -
  -->

<chapter id=chapter.intro>
  <title/Introduction/
 
<p>
This document is a first introduction to
constraint-based problem solving and its
implementation in Oz.  We restrict our
attention to combinatorial problems that can be stated
with variables ranging over finite sets of nonnegative
integers.  Problems in this class range from puzzles
to real world applications as diverse as scheduling,
ware house allocation, configuration and placement.

<p>
The two basic techniques of constraint programming
are constraint propagation and constraint
distribution.  Constraint propagation is an efficient
inference mechanism obtained with concurrent
propagators accumulating information in a constraint
store.  Constraint distribution splits a problem
into complementary cases once constraint propagation
cannot advance further.  By iterating propagation and
distribution, propagation will eventually determine
the solutions of a problem.

<p>
Constraint distribution can easily lead to an
exponential growth of the number of subproblems to
be considered.  Fortunately, this potential
combinatorial explosion can often be contained by
combining strong propagation mechanisms with
problem specific heuristics for selecting
distribution steps.

<p>
The following puzzles give a first idea of the
combinatorial problems we will solve in this
document:

<section class=unnumbered>
  <title/Money/

<p>
The Send More Money Problem
consists in finding distinct digits for the letters
<math/D/, <math/E/, <math/M/, <math/N/, <math/O/, <math/R/, <math/S/,
<math/Y/ such that <math/S/ and <math/M/ are different from zero (no
leading zeros) and the equation
<math display>
SEND\;+\;MORE\;=\;MONEY
</math>
is satisfied.  The unique solution of the problem
is <math/9567+1085=10652/.

<section class=unnumbered>
  <title/Safe/

<p>
The code of Professor Smart's safe is
a sequence of 9 distinct nonzero digits 
<math/C_1,\ldots,C_9/
such that the following equations and inequations are
satisfied:
<math display>
\begin{array}{c}
C_4 - C_6 = C_7\\
C_1 * C_2 * C_3 = C_8 + C_9\\
C_2 + C_3 + C_6 < C_8\\
C_9 < C_8\\
C_1\neq 1,\ldots, C_9\neq 9
\end{array}
</math>
Can you determine the code?


<section class=unnumbered>
  <title/Coloring/

<p>
Given a map showing the West
European countries Netherlands, Belgium, France,
Spain, Portugal, Germany, Luxemburg, Switzerland,
Austria, and Italy, find a coloring such that
neighboring countries have different color and a
minimal number of colors is used.

<section class=unnumbered>
  <title/Grocery/

<p>
A kid goes into a grocery
store and buys four items.  The cashier charges
$7.11, the kid pays and is about to leave when
the cashier calls the kid back, and says <q/Hold on,
I multiplied the four items instead of adding them;
I'll try again; Hah, with adding them the price
still comes to $7.11/. What were the prices of
the four items?

<section class=unnumbered>
  <title/Queens/

<p>
Place 8 queens on a chess board such that no two
queens attack each other.

<p>
The problems have in common that they can be stated
with variables that are a priori constrained to
finite sets of nonnegative integers.  Consequently,
the problems could be solved by simply checking all
possible combinations of the values of the
variables.  This naive generate and test method is
however infeasible for most realistic problems
since there are just too many possible
combinations.


<section class=unnumbered>
  <title/More Information/

<p>
While this tutorial tries to be as self-contained as possible for
constraint programming in Oz, it is expected that the reader has
already a working knowledge of functional Oz programming. As an
introduction for functional and object-oriented programming in Oz we
suggest <Ptr.extern to="ozdoc:tutorial">.  The full functionality of
Oz provided for constraint programming is included in the document
<ptr.extern to="ozdoc:system" key="part.constraints">.

<section class=unnumbered>
  <title/The Examples/

<p>
The tutorial features a large number of examples. To ease the
understanding the examples should be tried in the <Ref.extern
to="ozdoc:opi"/Oz Programming Environment (OPI)/. The Oz programs are
contained in the following <Ref.extern
to="FiniteDomainTutorial.oz"/file/. Oz programs for some solutions to
the exercises are contained in the following <Ref.extern
to="FiniteDomainTutorialSolutions.oz"/file/.

<section class=unnumbered>
  <title/Acknowledgements/

<p>
The tutorial is based on the document ``Finite Domain Constraint
Programming in Oz. A Tutorial'' by Gert Smolka, Christian Schulte, and
Jörg Würtz for a previous version of Oz. 

</chapter>

