<s>
Constraint	B-Application
programming	I-Application
(	O
CP	O
)	O
is	O
a	O
paradigm	O
for	O
solving	O
combinatorial	O
problems	O
that	O
draws	O
on	O
a	O
wide	O
range	O
of	O
techniques	O
from	O
artificial	B-Application
intelligence	I-Application
,	O
computer	B-General_Concept
science	I-General_Concept
,	O
and	O
operations	O
research	O
.	O
</s>
<s>
In	O
constraint	B-Application
programming	I-Application
,	O
users	O
declaratively	O
state	O
the	O
constraints	B-Application
on	O
the	O
feasible	O
solutions	O
for	O
a	O
set	O
of	O
decision	O
variables	O
.	O
</s>
<s>
Constraints	B-Application
differ	O
from	O
the	O
common	O
primitives	O
of	O
imperative	B-Application
programming	I-Application
languages	I-Application
in	O
that	O
they	O
do	O
not	O
specify	O
a	O
step	O
or	O
sequence	O
of	O
steps	O
to	O
execute	O
,	O
but	O
rather	O
the	O
properties	O
of	O
a	O
solution	O
to	O
be	O
found	O
.	O
</s>
<s>
In	O
addition	O
to	O
constraints	B-Application
,	O
users	O
also	O
need	O
to	O
specify	O
a	O
method	O
to	O
solve	O
these	O
constraints	B-Application
.	O
</s>
<s>
This	O
typically	O
draws	O
upon	O
standard	O
methods	O
like	O
chronological	O
backtracking	B-Algorithm
and	O
constraint	B-Application
propagation	I-Application
,	O
but	O
may	O
use	O
customized	O
code	O
like	O
a	O
problem-specific	O
branching	O
heuristic	B-Algorithm
.	O
</s>
<s>
Constraint	B-Application
programming	I-Application
takes	O
its	O
root	O
from	O
and	O
can	O
be	O
expressed	O
in	O
the	O
form	O
of	O
constraint	B-Application
logic	I-Application
programming	I-Application
,	O
which	O
embeds	O
constraints	B-Application
into	O
a	O
logic	B-Language
program	I-Language
.	O
</s>
<s>
This	O
variant	O
of	O
logic	B-Language
programming	I-Language
is	O
due	O
to	O
Jaffar	O
and	O
Lassez	O
,	O
who	O
extended	O
in	O
1987	O
a	O
specific	O
class	O
of	O
constraints	B-Application
that	O
were	O
introduced	O
in	O
Prolog	B-Language
II	I-Language
.	O
</s>
<s>
The	O
first	O
implementations	O
of	O
constraint	B-Application
logic	I-Application
programming	I-Application
were	O
Prolog	B-Language
III	O
,	O
CLP(R )	O
,	O
and	O
CHIP	B-Application
.	O
</s>
<s>
Instead	O
of	O
logic	B-Language
programming	I-Language
,	O
constraints	B-Application
can	O
be	O
mixed	O
with	O
functional	B-Language
programming	I-Language
,	O
term	O
rewriting	O
,	O
and	O
imperative	B-Application
languages	I-Application
.	O
</s>
<s>
Programming	O
languages	O
with	O
built-in	O
support	O
for	O
constraints	B-Application
include	O
Oz	B-Language
(	O
functional	B-Language
programming	I-Language
)	O
and	O
Kaleidoscope	B-Application
(	O
imperative	B-Application
programming	I-Application
)	O
.	O
</s>
<s>
Mostly	O
,	O
constraints	B-Application
are	O
implemented	O
in	O
imperative	B-Application
languages	I-Application
via	O
constraint	B-Application
solving	I-Application
toolkits	I-Application
,	O
which	O
are	O
separate	O
libraries	O
for	O
an	O
existing	O
imperative	B-Application
language	I-Application
.	O
</s>
<s>
Constraint	B-Application
programming	I-Application
is	O
an	O
embedding	O
of	O
constraints	B-Application
in	O
a	O
host	O
language	O
.	O
</s>
<s>
The	O
first	O
host	O
languages	O
used	O
were	O
logic	B-Language
programming	I-Language
languages	I-Language
,	O
so	O
the	O
field	O
was	O
initially	O
called	O
constraint	B-Application
logic	I-Application
programming	I-Application
.	O
</s>
<s>
The	O
two	O
paradigms	O
share	O
many	O
important	O
features	O
,	O
like	O
logical	O
variables	O
and	O
backtracking	B-Algorithm
.	O
</s>
<s>
Today	O
most	O
Prolog	B-Language
implementations	O
include	O
one	O
or	O
more	O
libraries	O
for	O
constraint	B-Application
logic	I-Application
programming	I-Application
.	O
</s>
<s>
Some	O
problems	O
are	O
more	O
natural	O
(	O
and	O
thus	O
,	O
simpler	O
)	O
to	O
write	O
as	O
logic	B-Language
programs	I-Language
,	O
while	O
some	O
are	O
more	O
natural	O
to	O
write	O
as	O
constraint	B-Application
programs	O
.	O
</s>
<s>
The	O
constraint	B-Application
programming	I-Application
approach	O
is	O
to	O
search	O
for	O
a	O
state	O
of	O
the	O
world	O
in	O
which	O
a	O
large	O
number	O
of	O
constraints	B-Application
are	O
satisfied	O
at	O
the	O
same	O
time	O
.	O
</s>
<s>
A	O
problem	B-Application
is	O
typically	O
stated	O
as	O
a	O
state	O
of	O
the	O
world	O
containing	O
a	O
number	O
of	O
unknown	O
variables	O
.	O
</s>
<s>
The	O
constraint	B-Application
program	O
searches	O
for	O
values	O
for	O
all	O
the	O
variables	O
.	O
</s>
<s>
Temporal	O
concurrent	O
constraint	B-Application
programming	I-Application
(	O
TCC	O
)	O
and	O
non-deterministic	O
temporal	O
concurrent	O
constraint	B-Application
programming	I-Application
(	O
MJV	O
)	O
are	O
variants	O
of	O
constraint	B-Application
programming	I-Application
that	O
can	O
deal	O
with	O
time	O
.	O
</s>
<s>
A	O
constraint	B-Application
is	O
a	O
relation	O
between	O
multiple	O
variables	O
which	O
limits	O
the	O
values	O
these	O
variables	O
can	O
take	O
simultaneously	O
.	O
</s>
<s>
Three	O
categories	O
of	O
constraints	B-Application
exist	O
:	O
</s>
<s>
extensional	O
constraints	B-Application
:	O
constraints	B-Application
are	O
defined	O
by	O
enumerating	O
the	O
set	O
of	O
values	O
that	O
would	O
satisfy	O
them	O
;	O
</s>
<s>
arithmetic	O
constraints	B-Application
:	O
constraints	B-Application
are	O
defined	O
by	O
an	O
arithmetic	O
expression	O
,	O
i.e.	O
,	O
using	O
;	O
</s>
<s>
logical	O
constraints	B-Application
:	O
constraints	B-Application
are	O
defined	O
with	O
an	O
explicit	O
semantic	O
,	O
i.e.	O
,	O
AllDifferent	O
,	O
AtMost	O
,...	O
</s>
<s>
A	O
partial	O
assignment	O
is	O
when	O
a	O
subset	O
of	O
the	O
variables	O
of	O
the	O
problem	B-Application
has	O
been	O
assigned	O
.	O
</s>
<s>
A	O
total	O
assignment	O
is	O
when	O
all	O
the	O
variables	O
of	O
the	O
problem	B-Application
have	O
been	O
assigned	O
.	O
</s>
<s>
finding	O
a	O
solution	O
(	O
satisfying	O
all	O
the	O
constraints	B-Application
)	O
;	O
</s>
<s>
finding	O
all	O
the	O
solutions	O
of	O
the	O
problem	B-Application
;	O
</s>
<s>
proving	B-Application
the	O
unsatisfiability	O
of	O
the	O
problem	B-Application
.	O
</s>
<s>
A	O
constraint	B-Application
optimization	O
problem	B-Application
(	O
COP	O
)	O
is	O
a	O
constraint	B-Application
satisfaction	I-Application
problem	I-Application
associated	O
to	O
an	O
objective	O
function	O
.	O
</s>
<s>
finding	O
a	O
solution	O
(	O
satisfying	O
all	O
the	O
constraints	B-Application
)	O
;	O
</s>
<s>
proving	B-Application
the	O
optimality	O
of	O
the	O
best	O
found	O
solution	O
;	O
</s>
<s>
proving	B-Application
the	O
unsatisfiability	O
of	O
the	O
problem	B-Application
.	O
</s>
<s>
Languages	O
for	O
constraint-based	O
programming	O
follow	O
one	O
of	O
two	O
approaches	O
:	O
</s>
<s>
Refinement	O
model	O
:	O
variables	O
in	O
the	O
problem	B-Application
are	O
initially	O
unassigned	O
,	O
and	O
each	O
variable	O
is	O
assumed	O
to	O
be	O
able	O
to	O
contain	O
any	O
value	O
included	O
in	O
its	O
range	O
or	O
domain	O
.	O
</s>
<s>
Perturbation	O
model	O
:	O
variables	O
in	O
the	O
problem	B-Application
are	O
assigned	O
a	O
single	O
initial	O
value	O
.	O
</s>
<s>
Constraint	B-Application
propagation	I-Application
in	O
constraint	B-Application
satisfaction	I-Application
problems	I-Application
is	O
a	O
typical	O
example	O
of	O
a	O
refinement	O
model	O
,	O
and	O
spreadsheets	B-Application
are	O
a	O
typical	O
example	O
of	O
a	O
perturbation	O
model	O
.	O
</s>
<s>
The	O
refinement	O
model	O
is	O
more	O
general	O
,	O
as	O
it	O
does	O
not	O
restrict	O
variables	O
to	O
have	O
a	O
single	O
value	O
,	O
it	O
can	O
lead	O
to	O
several	O
solutions	O
to	O
the	O
same	O
problem	B-Application
.	O
</s>
<s>
However	O
,	O
the	O
perturbation	O
model	O
is	O
more	O
intuitive	O
for	O
programmers	O
using	O
mixed	O
imperative	B-Application
constraint	B-Application
object-oriented	O
languages	O
.	O
</s>
<s>
The	O
constraints	B-Application
used	O
in	O
constraint	B-Application
programming	I-Application
are	O
typically	O
over	O
some	O
specific	O
domains	O
.	O
</s>
<s>
Some	O
popular	O
domains	O
for	O
constraint	B-Application
programming	I-Application
are	O
:	O
</s>
<s>
Finite	O
domains	O
is	O
one	O
of	O
the	O
most	O
successful	O
domains	O
of	O
constraint	B-Application
programming	I-Application
.	O
</s>
<s>
In	O
some	O
areas	O
(	O
like	O
operations	O
research	O
)	O
constraint	B-Application
programming	I-Application
is	O
often	O
identified	O
with	O
constraint	B-Application
programming	I-Application
over	O
finite	O
domains	O
.	O
</s>
<s>
Local	B-Application
consistency	I-Application
conditions	O
are	O
properties	O
of	O
constraint	B-Application
satisfaction	I-Application
problems	I-Application
related	O
to	O
the	O
consistency	B-General_Concept
of	O
subsets	O
of	O
variables	O
or	O
constraints	B-Application
.	O
</s>
<s>
They	O
can	O
be	O
used	O
to	O
reduce	O
the	O
search	O
space	O
and	O
make	O
the	O
problem	B-Application
easier	O
to	O
solve	O
.	O
</s>
<s>
Various	O
kinds	O
of	O
local	B-Application
consistency	I-Application
conditions	O
are	O
leveraged	O
,	O
including	O
node	O
consistency	B-General_Concept
,	O
arc	O
consistency	B-General_Concept
,	O
and	O
path	B-Application
consistency	I-Application
.	O
</s>
<s>
Every	O
local	B-Application
consistency	I-Application
condition	O
can	O
be	O
enforced	O
by	O
a	O
transformation	O
that	O
changes	O
the	O
problem	B-Application
without	O
changing	O
its	O
solutions	O
.	O
</s>
<s>
Such	O
a	O
transformation	O
is	O
called	O
constraint	B-Application
propagation	I-Application
.	O
</s>
<s>
Constraint	B-Application
propagation	I-Application
works	O
by	O
reducing	O
domains	O
of	O
variables	O
,	O
strengthening	O
constraints	B-Application
,	O
or	O
creating	O
new	O
ones	O
.	O
</s>
<s>
This	O
leads	O
to	O
a	O
reduction	O
of	O
the	O
search	O
space	O
,	O
making	O
the	O
problem	B-Application
easier	O
to	O
solve	O
by	O
some	O
algorithms	O
.	O
</s>
<s>
Constraint	B-Application
propagation	I-Application
can	O
also	O
be	O
used	O
as	O
an	O
unsatisfiability	O
checker	O
,	O
incomplete	O
in	O
general	O
but	O
complete	O
in	O
some	O
particular	O
cases	O
.	O
</s>
<s>
There	O
are	O
three	O
main	O
algorithmic	O
techniques	O
for	O
solving	O
constraint	B-Application
satisfaction	I-Application
problems	I-Application
:	O
backtracking	B-Algorithm
search	I-Algorithm
,	O
local	O
search	O
,	O
and	O
dynamic	O
programming	O
.	O
</s>
<s>
Backtracking	B-Algorithm
search	I-Algorithm
is	O
a	O
general	O
algorithm	O
for	O
finding	O
all	O
(	O
or	O
some	O
)	O
solutions	O
to	O
some	O
computational	O
problems	O
,	O
notably	O
constraint	B-Application
satisfaction	I-Application
problems	I-Application
,	O
that	O
incrementally	O
builds	O
candidates	O
to	O
the	O
solutions	O
,	O
and	O
abandons	O
a	O
candidate	O
(	O
"	O
backtracks	O
"	O
)	O
as	O
soon	O
as	O
it	O
determines	O
that	O
the	O
candidate	O
cannot	O
possibly	O
be	O
completed	O
to	O
a	O
valid	O
solution	O
.	O
</s>
<s>
Local	O
search	O
is	O
an	O
incomplete	O
method	O
for	O
finding	O
a	O
solution	O
to	O
a	O
problem	B-Application
.	O
</s>
<s>
It	O
is	O
based	O
on	O
iteratively	O
improving	O
an	O
assignment	O
of	O
the	O
variables	O
until	O
all	O
constraints	B-Application
are	O
satisfied	O
.	O
</s>
<s>
It	O
refers	O
to	O
simplifying	O
a	O
complicated	O
problem	B-Application
by	O
breaking	O
it	O
down	O
into	O
simpler	O
sub-problems	O
in	O
a	O
recursive	O
manner	O
.	O
</s>
<s>
Likewise	O
,	O
in	O
computer	B-General_Concept
science	I-General_Concept
,	O
if	O
a	O
problem	B-Application
can	O
be	O
solved	O
optimally	O
by	O
breaking	O
it	O
into	O
sub-problems	O
and	O
then	O
recursively	O
finding	O
the	O
optimal	O
solutions	O
to	O
the	O
sub-problems	O
,	O
then	O
it	O
is	O
said	O
to	O
have	O
optimal	B-Algorithm
substructure	I-Algorithm
.	O
</s>
<s>
The	O
syntax	O
for	O
expressing	O
constraints	B-Application
over	O
finite	O
domains	O
depends	O
on	O
the	O
host	O
language	O
.	O
</s>
<s>
The	O
following	O
is	O
a	O
Prolog	B-Language
program	O
that	O
solves	O
the	O
classical	O
alphametic	O
puzzle	O
SEND+MORE	O
=	O
MONEY	O
in	O
constraint	B-Application
logic	I-Application
programming	I-Application
:	O
</s>
<s>
The	O
constraints	B-Application
S#	O
\=0	O
and	O
M#	O
\=0	O
means	O
that	O
these	O
two	O
variables	O
cannot	O
take	O
the	O
value	O
zero	O
.	O
</s>
<s>
When	O
the	O
interpreter	O
evaluates	O
these	O
constraints	B-Application
,	O
it	O
reduces	O
the	O
domains	O
of	O
these	O
two	O
variables	O
by	O
removing	O
the	O
value	O
0	O
from	O
them	O
.	O
</s>
<s>
Then	O
,	O
the	O
constraint	B-Application
all_different(Digits )	O
is	O
considered	O
;	O
it	O
does	O
not	O
reduce	O
any	O
domain	O
,	O
so	O
it	O
is	O
simply	O
stored	O
.	O
</s>
<s>
The	O
last	O
constraint	B-Application
specifies	O
that	O
the	O
digits	O
assigned	O
to	O
the	O
letters	O
must	O
be	O
such	O
that	O
"	O
SEND+MORE	O
=	O
MONEY	O
"	O
holds	O
when	O
each	O
letter	O
is	O
replaced	O
by	O
its	O
corresponding	O
digit	O
.	O
</s>
<s>
From	O
this	O
constraint	B-Application
,	O
the	O
solver	O
infers	O
that	O
M	O
=	O
1	O
.	O
</s>
<s>
All	O
stored	O
constraints	B-Application
involving	O
variable	O
M	O
are	O
awakened	O
:	O
in	O
this	O
case	O
,	O
constraint	B-Application
propagation	I-Application
on	O
the	O
all_different	O
constraint	B-Application
removes	O
value	O
1	O
from	O
the	O
domain	O
of	O
all	O
the	O
remaining	O
variables	O
.	O
</s>
<s>
Constraint	B-Application
propagation	I-Application
may	O
solve	O
the	O
problem	B-Application
by	O
reducing	O
all	O
domains	O
to	O
a	O
single	O
value	O
,	O
it	O
may	O
prove	O
that	O
the	O
problem	B-Application
has	O
no	O
solution	O
by	O
reducing	O
a	O
domain	O
to	O
the	O
empty	O
set	O
,	O
but	O
may	O
also	O
terminate	O
without	O
proving	B-Application
satisfiability	O
or	O
unsatisfiability	O
.	O
</s>
