G51IAI
Introduction to Artificial
Intelligence
Dr Rong Qu
Constraint Satisfaction Problems
An Example
Constraint satisfaction problems are
everywhere in our everyday life
Map coloring
A region in a map has several sub-regions
Given a set of colors
Assign each sub-region a color so that no
adjacent sub-regions have the same color
G51IAI – Introduction to AI
2 of 31
An Example
Map coloring
Can we use 3 colors to color the map below
(Australia)?
NT
Q
WA
SA
NSW
V
T
G51IAI – Introduction to AI
3 of 31
An Example
Map coloring
The above map can be modelled as a graph
WA
NT
Q
Node: sub-region
WA
Edge: constraint (adjacency)
SA
Problem modelled NSW
as graph
coloring: adjacent V
nodes
have different colors
NT
Q
SA
NSW
V
T
G51IAI
– Introduction
to AI
Relationship
between
problem elements constraints
T
4 of 31
CSP – Definition
A constraint satisfaction problem (CSP)
consists of
a set of variables {x1, x2, … xi};
a finite set of domain D (possible values)
associated with each variable;
a set of constraints C restricting the values that
the variables can simultaneously take
CSP is to assign values to variables so that all
constraints are satisfied
G51IAI – Introduction to AI
5 of 31
CSP - Domain
The domain of a variable is a set of possible
values that can be assigned to the variable
{1 … 500} – finite, integer
{red, green, blue} – symbols
{yes, no} – Boolean
Temperatures – infinite; continuous
G51IAI – Introduction to AI
6 of 31
CSP - Constraints
Examples of constraints
The demand will be more than five thousands
units in August
John prefer to work at only weekends
Schedule these employees to cover all shifts
Optimise the benefit of products
G51IAI – Introduction to AI
7 of 31
CSP - Constraints
Constraint is a set of relations upon domains
of variables
Restriction on the values the variables can
simultaneously take
What values are (dis-)allowed among the variables
Functions
Matrices
Inequalities
x1 ≠ x2 or x1 < x2
3x + 6y = 0, y + x < 7
G51IAI – Introduction to AI
8 of 31
CSP - Constraints
Formal definition
A constraint Ci,j,k… is a subset of possible
relations between values of variables xi, xj, xk,
...; Ci,j,k…is a subset of Di × Dj × Dk × …
G51IAI – Introduction to AI
9 of 31
CSP - Constraints
Types of constraints
Unary: affect only one variable
x >= 1, WA = green
Binary: affect two variables
x >= y, WA ≠ NT
High-order: affect more than two variables
alldifferent(WA, NT, Q)
x = y = z
Binary CSP
With only unary and binary constraints
G51IAI – Introduction to AI
10 of 31
CSP - Constraints
Simplification of constraints
Replace a constraint by an equivalent constraint
which has a simpler form
Problem is easier to
understand
Information of
original form is more
apparent
G51IAI – Introduction to AI
11 of 31
CSP - Solutions
A solution to a CSP is an assignment of each
variable with a value (within its domain), such
that all constraints C are satisfied
if a CSP has a feasible solution
find one (any) solution
all solutions
G51IAI – Introduction to AI
12 of 31
CSP - Solutions
Often we not only want a CSP solution but
also the best one (optimal solution)
Optimisation problems
Objective function: to measure how good a
solution is
Constraint Optimisation Problems (COP)
G51IAI – Introduction to AI
13 of 31
CSP – Other Definitions
Label
a variable-value pair representing assigning the
value to the variable
Compound label
the finite set of labels representing simultaneous
assignments
G51IAI – Introduction to AI
14 of 31
CSP – Other Definitions
Satisfiable
a CSP (V,D,C) is satisfiable iff there is a compound
label assigning values to all variables V that satisfy
all constraints C
A solution can then be defined as
A compound label for all variables which satisfy all
the constraints
G51IAI – Introduction to AI
15 of 31
CSP – Example
Variables
Domains
{WA, NT, Q, SA, NSW, V, T}
WA
NT
SA
Q
NSW
V
{red, green, blue}
T
Constraints
{not_same(WA,NT), not_same(WA, SA),
not_same(NT,SA), …}
G51IAI – Introduction to AI
16 of 31
CSP – Example
WA
NT
SA
Q
NSW
V
T
The above formulate the map coloring problem into a
constraint satisfaction problem
Solution
{WA=red, NT=green, SA=blue, Q=red,
NSW=green, V=red, T=red}
G51IAI – Introduction to AI
17 of 31
CSP – Example
WA = red is a label
The problem is satisfiable.
G51IAI – Introduction to AI
18 of 31
CSP – Example
The above solution using 3 colors
Is actually an optimal solution (using the least
colors)
There are more than one solution
For example, given 7 colors, we’ll have 7!
solutions for the problem (at least)
G51IAI – Introduction to AI
19 of 31
CSP – Example
Graph coloring is NP-Hard (Karp, 1972)
Optimal solutions of least colors cannot be
obtained for 90-vertice graph (Johnson, 1991)
Constraint based techniques are the mostly
studied early approaches
G51IAI – Introduction to AI
20 of 31
CSP
So why is graph coloring important?
A typical constraint satisfaction problem
Can be used to model many real problems
CSP has many uses
Scheduling
Timetabling
Other optimisation problems in industrial
…
G51IAI – Introduction to AI
21 of 31
CSP – Search Tree
Depth first search
?
G51IAI – Introduction to AI
22 of 31
CSP – Search Tree
Backtracking
?
G51IAI – Introduction to AI
23 of 31
CSP Techniques
Constraint propagation
Consistency enforcing
Arc consistency, path consistency
Search strategies
Back and forward checking
Variable and Value ordering
Branch & bound (B&B)
Constraint optimisation techniques
G51IAI – Introduction to AI
24 of 31
CSP – Example II
Scene labeling problem
The first CSP studied
In vision, scene are captured as images, and
processed as lines to represent images
Lines need to be interpreted into types
G51IAI – Introduction to AI
25 of 31
CSP – Example II
Scene labeling problem
Types of lines
Convex edges +
Concave edges –
The edge is moving away from the viewer
The edge moves towards the viewer
Occluding edges
+
+
Face at right can be seen
by the viewer
+
-
G51IAI – Introduction to AI
26 of 31
CSP – Example II
Scene labeling problem defined as CSP
Variables
Domains
E
F
I
G
D
+-
A
H
C
B
G51IAI – Introduction to AI
27 of 31
CSP – Example II
Scene labeling problem defined as CSP
Constraints
G51IAI – Introduction to AI
28 of 31
CSP – Example III
Sudoku
Variables
Domain
Constraints
6
5
7
3
9
6
1
6
3
4
4
7
1
5
9
8
4
1
3
2
G51IAI – Introduction to AI
2
6
8
4
5
29 of 31
CSP – Example IV
N-Queen problem
Variables
Domain
Constraints
G51IAI – Introduction to AI
30 of 31
© Copyright 2026 Paperzz