0% found this document useful (0 votes)
3 views

AI_Chapter_06

Constraint Satisfaction Problems

Uploaded by

Joker
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

AI_Chapter_06

Constraint Satisfaction Problems

Uploaded by

Joker
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Artificial

Intelligence CSB2104
Prof. Abdel-Rahman Hedar
Constraint
Satisfaction
Problems
Chapter 6

2
Contents
» Constraint Satisfaction Problems (CSPs)
» Backtracking search for CSPs
» Problem structure and problem decomposition

3
Constraint
Satisfaction
Problems (CSPs)

4
Constraint Satisfaction Problems (CSPs)
» CSP:
• The state is defined by variables Xi with values from domain Di
• A goal test is a set of constraints specifying
• Allowable combinations of values for subsets of variables
» Allows useful general-purpose algorithms with more power than
standard search algorithms

5
Example: Map-Coloring

6
Example: Map-Coloring

7
Constraint Graph
» Binary CSP: each constraint relates at most
two variables
» Constraint graph: nodes are variables, arcs
show constraints
» General-purpose CSP algorithms use the
graph structure to speed up search.
• E.g., Tasmania is an independent sub-problem!

8
Example: Job-shop scheduling
» Consider the problem of scheduling the assembly of a car.
» The whole job is composed of tasks, and we can model each task
as a variable, where the value of each variable is the time that the
task starts, expressed as an integer number of minutes.
» Constraints can assert that one task must occur before another.
• For example, a wheel must be installed before the hubcap is put on.
» Constraints can also specify that a task takes a certain amount of
time to complete.

9
Example: Job-shop scheduling
» We consider a small part of the car assembly, consisting of 15
tasks:
• install axles (front and back),
• affix all four wheels (right and left, front and back),
• tighten nuts for each wheel,
• affix hubcaps, and
• inspect the final assembly.

10
Example: Job-shop scheduling
» The value of each variable is the time that the task starts.
» Next, we represent precedence constraints between individual
tasks.
» Whenever a task T1 must occur before task T2, and task T1 takes
duration d1 to complete, we add an arithmetic constraint of the
form T1 + d1 ≤ T2.
» In our example, the axles have to be in place before the wheels are
put on, and it takes 10 minutes to install an axle, so we write

11
Varieties of constraints
» Unary constraints involve a single variable,
• e.g., SA ≠ green
» Binary constraints involve pairs of variables,
• e.g., SA ≠ WA
» Higher-order constraints involve 3 or more variables
» Preferences (soft constraints),
• e.g., red is better than green

12
Real-world CSPs
» Assignment Problems
• e.g., who teaches what class
» Timetabling Problems
• e.g., which class is offered when and where?
» Hardware Configuration
» Transportation Scheduling
» Factory Scheduling
» Floor Planning

13
Backtracking
search for CSPs

14
Standard Search Formulation (Incremental)
» Let's start with the straightforward, dumb approach, then fix it.
» States are defined by the values assigned so far.

▪ Initial state: the empty assignment.


▪ Successor function: assign a value to an unassigned variable that
does not conflict with current assignment.
⇒ fail if no legal assignments (not fixable!).
▪ Goal test: the current assignment is complete.

15
Backtracking Search
» Variable assignments are commutative, i.e.,
• [WA = red, then NT = green] same as [NT = green, then WA = red].
» Only need to consider assignments to a single variable at each
node.
» Depth-first search for CSPs with single-variable assignments is
called backtracking search.
» Backtracking search is the basic uninformed algorithm for CSPs
» Can solve n-queens for n ≈ 25.

16
Backtracking Example

17
Problem structure
and problem
decomposition

18
Improving backtracking efficiency
General-purpose methods can give huge gains in speed:
1. Which variable should be assigned next?
2. In what order should its values be tried?
3. Can we detect inevitable failure early?
4. Can we take advantage of problem structure?

19
Minimum Remaining Values
» The Minimum Remaining Values (MRV) heuristic is a
strategy used in solving CSPs.
» It helps in deciding which variable to assign a value to next by
choosing the variable with the fewest legal values
remaining.
» This approach aims to reduce the search space and prune
impossible assignments early.

20
Minimum Remaining Values
» WA is colored Red, and NT is colored Green.
» SA is the next region to be colored, with only Blue remaining as a
legal color.

21
Degree Heuristic
» Degree heuristic: choose the variable with
the most constraints on remaining variables.
• WA: Adjacent to NT and SA (2 constraints).
• NT: Adjacent to WA, SA, and Q (3 constraints).
• SA: Adjacent to WA, NT, Q, NSW, and V (5 constraints).
• Q: Adjacent to NT, SA, and NSW (3 constraints).
• NSW: Adjacent to Q, SA, and V (3 constraints).
• V: Adjacent to SA and NSW (2 constraints).
• T: No adjacent regions colored yet (0 constraints).

22
Least Constraining Value
» Given a variable, choose the least constraining value: the one that
rules out the fewest values in the remaining variables.

i.e., what value will leave the most other values for other variables.

23
Forward Checking
Idea:
» Keep track of remaining legal values for unassigned variables
» Terminate search when any variable has no legal values

24
Constraint Propagation
» Forward checking propagates information from assigned to unassigned
variables, but doesn't provide early detection for all failures:

» NT and SA cannot both be blue!


» Constraint propagation repeatedly enforces constraints locally.
» The idea is to iteratively apply constraints to eliminate values from the
domains of variables that cannot participate in any valid solution.
25
Arc Consistency
» Simplest form of propagation makes each arc consistent
X → Y is consistent iff: for every value x of X there is some allowed y

26
Arc Consistency
» Simplest form of propagation makes each arc consistent
X → Y is consistent iff: for every value x of X there is some allowed y

27
Arc Consistency
» Simplest form of propagation makes each arc consistent
X → Y is consistent iff: for every value x of X there is some allowed y

» If X loses a value, neighbors of X need to be rechecked.


» Arc consistency detects failure earlier than forward checking.
» Can be run as a preprocessor or after each assignment. 28
Arc Consistency Algorithm

29
Conclusion
» CSPs are a special kind of problem:
• States defined by values of a fixed set of variables.
• Goal test defined by constraints on variable values.
» Backtracking = depth-first search with one
variable assigned per node.
» Variable ordering and value selection heuristics
help significantly.
» Forward checking prevents assignments that
guarantee later failure.
» Constraint propagation (e.g., arc consistency)
does additional work to constrain values and
detect inconsistencies.
» The CSP representation allows analysis of
problem structure.
30
Questions & Comments
Abdel-Rahman Hedar
a.hedar@bua.edu.eg
https://shorturl.at/ntI2x

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy