Lecture 5 constraint satisfaction
This presentation is the property of its rightful owner.
Sponsored Links
1 / 35

Lecture 5: Constraint Satisfaction PowerPoint PPT Presentation

  • Uploaded on
  • Presentation posted in: General

Lecture 5: Constraint Satisfaction. Definition and examples Properties of CSP problems Heuristics arc-consistency checking heuristic repair most-constrained first. Heshaam Faili [email protected] University of Tehran. Constraint Satisfaction Problems.

Download Presentation

Lecture 5: Constraint Satisfaction

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript

Lecture 5: Constraint Satisfaction

  • Definition and examples

  • Properties of CSP problems

  • Heuristics

    • arc-consistency checking

    • heuristic repair

    • most-constrained first

Heshaam Faili

[email protected]

University of Tehran

Constraint Satisfaction Problems

  • Many problems can be formulated as finding a solution, possibly optimal, that satisfies a set of constraints.

    • built a time table for the next semester with the minimum number of conflicts

    • schedule air crew assignments so that pilots don’t fly too many hours, have evenly-spaced breaks, …

    • find a 0/1 assignment to a propositional formula

    • 8-queen problem, crypto arithmetic

CSP as a search problem (1)

  • State:

    • a set of variables x1, x2, …,xn

    • variable domains D1, D2 …Dn

    • state vector (x1, x2, x3, … xn) with instantiated and uninstantiated variables

  • Rule: constraints relating the variables

    • xi xj,  xi = 1, min f(x1, x2, …,xn)

  • Start state: vector of uninstantiated variables

  • Goal state: instantiated vector that satisfies all the constraints

Examples of CSP formulation

  • Cryptoarithmetic problem


+ T E N

+ T E N


2 9 7 8 6

+ 8 5 0

+ 8 5 0

3 1 4 8 6


F=2, O=9

R=7, T=8

Y=6, E=5

N=0, I=1, X=4

  • 8-queensproblem

  • Time-table schedule










CSP and Constraint Graph

CSP as a search problem (2)

  • Simplest form: discrete and finite domain

  • For n variables and domain size d the possible assignments are O(dn)

  • Boolean CSP: domains are boolean, like 3SAT , special case of NP-complete

  • Infinite domain: no exact solution can be found

    • Linear constraints

    • Non-linear constraints

  • Continuous domains:

    • The best-known category is linear programming

    • Constraints are linear inequalities forming a convex region

  • Constraints:

    • Unary: involve only one variable: can be eliminated by remove any value violate the constraint from the domain of that variable

    • Binary: involves two variables (like 8-queen)

    • Higher-order : like crypt arithmetic

Higher-order Constraints

  • Can be represented by a constraints hyper-graph

  • prove, every higher-order, finite-domain constraint can be reduced to a set of binary constraints if enough auxiliary variables are introduced.

Backtracking in CSP

  • For n variables with d value in each domain

    • Branching factor for level 1 is nd, level 2 is (n-1)d, level 3 is (n-2)d, …

    • Tree has n!dn leaves while there are only dn possible assignments

  • Commutativity: if the order of application of any given set of actions has no effect on the outcome.

  • CSPs are commutative

    • all CSP search algorithms generate successors by considering possible assignments for only a single variable at each node in the search tree

    • In root node of Australia region coloring: we choice between SA = red, SA = green, and SA = blue, and we never choose between SA = red and WA = blue.

    • The number of leaves are dn

CSP as a search problem

  • Search strategy

    1. pick an uninstantiated variable, pick a value from its domain, check if all constraints are satisfied

    2. if constraints are satisfied, continue search recursively

    3. else, backtrack: go back to previous decision and make another choice

  • Size of search tree:bd

    • d = n, number of variables

    • b = max Di when only one variable at a time is

Backtracking Search

CSP search example





CSP search example

C1 C2 C3

M = 1

O = 0

O = 2

O = 3

N = 2

S 3 2 D

1 0 R 3

1 0 2 3 Y

E = 3


CSP problem characteristics (1)

  • Special case of a search problem

  • Domains can be discrete or continuous

  • The order in which the constraints are satisfied does not matter.

  • The order in which variables and their values are picked makes a big difference!

CSP problem characteristics (2)

  • The goal test is decomposed into a set of constraints on variables, rather than a single black box

  • When sets of variables are independent (no constraints between them) the problem is decomposable and sub-problems can be solved independently.

  • A each step we must check for consistency. We need constraint propagation methods!

CSP problem characteristics (3)

  • Answering the following questions are important key:

    • Which variable should be assigned next, and in what order should its values be tried?

    • What are the implications of the current variable assignments for the other unassigned variables?

    • When a path fails—that is, a state is reached in which a variable has no legal values— can the search avoid repeating this failure in subsequent paths?

Comparison of various CSP algorithms

Variable and value ordering

  • Pick values for the minimum remaining values (MRV) or most constrained variables or first fail principle

    • choosing the variable with the fewest "legal" value

    • those with smaller domains and which appear in more constraints.

    • The rationale: those leave fewer choices and focus the search

  • Improve the search from 3 til 3000 times better than simple

Variable and value ordering

  • MRV doesn’t help in choosing the first variable

    • Degree heuristic: attempts to reduce the BF in feature by selecting the variables that is involved in the largest number of constraints on other unassigned variables

      • SA on region coloring example

Value ordering

  • least-constraining-value: prefers the value that rules out the fewest choices for the neighboring variables in the constraint

  • In the previous coloring problem:

    • WA = red and NT = green, Q is better to assign red that blue

  • if we are trying to find all the solutions to a problem, not just the first one, then the ordering does not matter because we have to consider every value anyway.

Propagating information through constraints (1)

  • Forward checking: delete values from domains as the assignments are made. When a domain becomes empty, abort. Often more efficient than backtracking

Forward checking example

Propagating information through constraints (2)

  • Forward Checking:doesn't detect all of inconsistencies.

    • WA = red, Q=green => NT = SA = blue (this inconsistency doesn’t detected)

  • Arc-consistency: a state is arc-consistent if every variable has a value in its domain that is consistent with each of the constraints of that variable. This is a form of constraint propagation.

  • Arc-consistency provides a fast method of constraint propagation that is substantially stronger than forward checking.

  • arc-consistency is directed arc in constraint graph

  • (SA, NSW) is consistent while (NSW,SA) is not consistent

  • Complexity: O(n2d3) for binary CSP

    • Binary CSP has at most O(n2) arcs

    • Each arc (Xi,Xk) can be inserted on the agenda only d times: Xi has at most d values to delete

    • Checking consistency of an arc can be done in O(d2)


AC-3 can not find harder the inconsistency (WA=red, NSW=red)

Need more concepts

CSP terminology

  • Label <xi, a>

  • Compound Label { <xi, a> }

  • K-Constraint

  • Modeling 8-Queen problem:

    • Q1,Q2, …,Q8 in [a,b,…,h]

    • Qx  Qy , |Qx-Qy|  |x-y|

A {red, green}


But not 2-Consistent



Important Concepts

  • K-Satisfiable

  • K-Consistency

    • K=1: node consistency

    • K>1: for each K-1 satisfiable variable set can add the Kth variable with consistent value and no change in the previous K-1 variable values

  • K-strongly consistent

Handling special constraints

  • some problem-specific constraints are used much in different problems

    • AllDiff constraints says that all variables should be different

    • If n variables with m values and n>m, the constraints should not be satisfied

  • Use the following idea to develop a method:

    • First, remove any variable in the constraint that has a singleton domain, and delete that variable's value from the domains of the remaining variables.

    • Repeat as long as there are singleton variables.

    • If at any point an empty domain is produced or there are more variables than domain values left, then an inconsistency has been detected.

  • By using the above method, the inconsistency (WA=red, NSW=red) can be detected.

Handling special constraints

  • Resource constraints: the most important higher-order constraints

  • Atmost constraints:(A0, PA1, PA2, PA3, PA4).

    • Checking the sum of minimum values of current domains (in each step of procedure)

  • For example, let's suppose there are two flights, 271 and 272, for which the planes have capacities 165 and 385, respectively. The initial domains for the numbers of passengers on each flight are then

    • Flight271  [0,165] and Flight272  [0, 385]

  • Now suppose we have the additional constraint that the two flights together must carry 420 people: Flight271 + Flight272  [420,420]. Propagating bounds constraints, we reduce the domains to

    • Flight271  [35,165] and Flight272  [255, 385]





CSP heuristics: example

C1 C2 C3 C4

C1 = 1

C2 + S + 1 = O

M = 1

C2 + S + 1 = 1

C3 + E + 0 = N

C4 + N + R = E

O = 0

O = 2

O = 3

N = 2

Conflict is detected as

soon as the assignement

is made

E = 3



Graph of variables dependencies



X + Y = Z

X - Z < 7

Y = Z

X - W = 3

U - V = 0


DX = {0, 1, 2}

DY = {0, … 10}





Intelligent backtracking: looking backward

  • chronological backtracking: Simple BT

  • More intelligent: use conflict set

  • Backjumping method: backtrack to the most recent variable in conflict set

Min-conflict strategy on 8-queens

Important concept (constraint graph)

  • Graph Order

  • Node width

  • Graph Order width

  • Graph Width

  • Value ordering for CSP search in the minimum Graph order width

  • If the level of strong consistency is greater than the width of constraint graph, the search for solution tuple is backtrack free

Search Strategies (Haralick & Elliot 1980)

  • Standard Backtracking

  • Fully Looking Forward

  • Partial Looking Ahead

  • Forward Checking

  • Backchecking

  • BackMarking

CSP problems at large

  • An area of great economic importance

    • scheduling, production, etc.

  • Closely related to optimization problems

    • integer programming

    • multiobjective optimization

  • Large body of literature in different areas: AI, CS, Operations Research, Mathematics, …


  • Login