SlideShare une entreprise Scribd logo
1  sur  57
Constraint Satisfaction Problem
CSI 341 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP – Constraint Satisfaction Problem
Standard Search Problem >>
▸Searches a space of states for the solution.
▸Heuristics are domain specific.
▸Each state is atomic/indivisible i.e. a black box with no internal structure.
CSP >>
▸CSP uses a factored representation for each state: a set of variables, each of which has a value.
▸A problem is solved when each variable has a value that satisfies all the constraints in the variable.
▸A problem described this way is called a constraint satisfaction problem.
Advantages
▸Uses general-purpose rather than problem-specific heuristics to enable the solution of complex problems.
▸Represents each state as a set of variables and takes advantage of the structure of states.
▸Eliminates large portions of the search space all at once by identifying variable/value combinations that violate the
constraints.
2
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Formal Definition
A constraint satisfaction problem consists of three components, X, D, and C:
▸X is the set of variables, { X1, . . . , Xn }
▸D is a set of domains, { D1, . . . , Dn }, one for each variable.
▸C is a set of constraints that specify allowable combinations of values.
Here,
▸Each domain Di consists of a set of allowable values, { v1, . . . , vk } for each variable Xi
▸Each constraint Ci consists of a pair 𝑠𝑐𝑜𝑝𝑒, 𝑟𝑒𝑙 ,
where scope is a tuple of variables that participate in the constraint
and rel is a relation that defines the values that those variables can take on.
▸A relation can be represented as an explicit list of all tuples of values that satisfy the constraint,
or as an abstract relation. For example,
𝑋1, 𝑋2 , [ 𝐴, 𝐵 , (𝐵, 𝐴)] or 𝑋1, 𝑋2 , 𝑋1 ! = 𝑋2
3
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Solution
▸Each state in a CSP is defined by an assignment of values to some or all of the variables.
{ Xi = vi , Xj = vj , . . . }
▸An assignment that does not violate any constraints is called a consistent or legal assignment.
▸A complete assignment is one in which every variable is assigned.
▸A partial assignment is one that assigns values to only some of the variables.
▸A solution to a CSP is consistent and complete assignment.
Advantages of formulating a problem as a CSP
▸CSPs yield natural representation for a wide variety of problems.
▸CSP solvers can be faster than state-space searchers because the CSP solver can quickly eliminate large swatches of the
search space.
▸With CSP, once we find out that a partial assignment is not a solution, we can immediately discard further refinements of
the partial assignment.
▸We can see why a assignment is not a solution – which variables violate a constraint – we can focus attention on the
variables that matter.
4
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Problem Formulation
Map Coloring Problem >>
your task is to color each region either red, green, or blue in such a way that no neighboring regions have the
same color.
CSP Formulation
Each region is a variable, X = { WA, NT, Q, NSW, V, SA, T }
Domain of each variable, Di = { red, green, blue }
Set of constraints,
C = { SA ≠ WA, SA ≠ NT, SA ≠ Q, SA ≠ NSW, SA ≠ V,
WA ≠ NT, NT ≠ Q, Q ≠ NSW, NSW ≠ V }
Here, SA ≠ WA is a shortcut for 𝑠𝑐𝑜𝑝𝑒, 𝑟𝑒𝑙 = 𝑆𝐴, 𝑊𝐴 , 𝑆𝐴 ≠ 𝑊𝐴
5
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Possible Solution
There are many possible solutions to this problem,
Such as
{ WA = red, NT = green, Q = red, NSW = green, V = red, SA = blue, T = green }
6
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Constraint Graph
Binary CSP >> each constraint relates at most two variables.
Constraint Graph >>
▸Nodes correspond to the variables of the problem.
▸An edge connects any two variables that participate in a constraint.
7
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Job-shop Scheduling
Let’s consider a small part(wheel installation) of the car assembly, consisting of 15 tasks.
▸Install axles (front and back) – requires 10 mins to install
▸Affix all four wheels (right and left, front and back) – takes 1 mins
▸Tighten nuts for each wheel – takes 2 mins
▸Affix hubcaps and – requires 1 mins
▸Inspect the final assembly – takes 3 mins
And get the whole assembly done in 30 mins
8
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
I
n
s
p
e
c
t
CSP >> Job-shop Scheduling
We can represent the tasks with 15 variables:
X = { AxleF, AxleB, WheelRF, WheelLF, WheelRB, WheelLB, NutsRF, NutsLF, NutsRB, NutsLB, CapRF, CapLF, CapRB, CapLB, Inspect }
Precedence constraints >> whenever a task T1 must occur before task T2 and task T1 takes duration d1 to complete, then we
can represent the constraint as
T1 + d1 <= T2
So the constraints are,
C = {
AxleF + 10 <= WheelRF , AxleF + 10 <= WheelLF , AxleB + 10 <= WheelRB , AxleB + 10 <= WheelLB ,
WheelRF + 1 <= NutsRF , WheelLF + 1 <= NutsLF , WheelRB + 1 <= NutsRB , WheelLB + 1 <= NutsLB ,
NutsRF + 2 <= CapRF , NutsLF + 2 <= CapLF , NutsRB + 2 <= CapRB , NutsLB + 2 <= CapLB ,
CapRF + 1 <= Inspect, CapLF + 1 <= Inspect, CapRB + 1 <= Inspect, CapLB + 1 <= Inspect,
AxleF + 10 <= Inspect, AxleB + 10 <= Inspect,
WheelRF + 1 <= Inspect , WheelLF + 1 <= Inspect , WheelRB + 1 <= Inspect , WheelLB + 1 <= Inspect ,
NutsRF + 2 <= Inspect , NutsLF + 2 <= Inspect , NutsRB + 2 <= Inspect , NutsLB + 2 <= Inspect
}
As inspection takes 3 mins to complete and the total task need to complete within 30 minutes,
So domain of each variable, Di = { 1, 2, 3, . . . . . . , 27 }
9
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> N-Queens
Set of variables, X = { Q1, Q2, … …, QN }
Each variable Qi represents the position of each queen in columns 1, 2, … …, N
Domains for each variable, Di = { 1, 2, … …, N }
Constraints:
implicit form: ∀𝑖, 𝑗 no-threatening (Qi, Qj)
explicit form: (Q1, Q2) ∈ { (1,3), (1,4), … … }
… …
10
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Cryptarithmetic puzzle
Variables, X = { F, T, U, W, R, O, X1, X2, X3 }
Domains for variables X1, X2, X3 is, { 0, 1 }
Domains for all other variables, Di = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
Constraints:
alldiff (F, T, U, W, R, O)
O + O = R + 10 . X1
X1 + W + W = U + 10 . X2
X2 + T + T = O + 10 . X3
X3 = F, T ≠ 0, F ≠ 0
11
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
Constraint hypergraph
CSP >> Sudoku
Variables, X = each open square
Domains for each variable, Di = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }
Constraints:
9-way alldiff for each column
9-way alldiff for each row
9-way alldiff for each region
12
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Example 1
You are in charge of scheduling for computer science classes that meet Mondays, Wednesdays and Fridays. There are 5
classes that meet on these days and 3 professors who will be teaching these classes. You are constrained by the fact that
each professor can only teach one class at a time.
The classes are:
▸Class 1 - Intro to Programming: meets from 8:00-9:00am
▸Class 2 - Intro to Artificial Intelligence: meets from 8:30-9:30am
▸Class 3 - Natural Language Processing: meets from 9:00-10:00am
▸Class 4 - Computer Vision: meets from 9:00-10:00am
▸Class 5 - Machine Learning: meets from 9:30-10:30am
The professors are:
▸Professor A, who is available to teach Classes 3 and 4.
▸Professor B, who is available to teach Classes 2, 3, 4, and 5.
▸Professor C, who is available to teach Classes 1, 2, 3, 4, 5
13
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Example 1 Solution
14
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
Variables Domains
C1 C
C2 B, C
C3 A, B, C
C4 A, B, C
C5 B, C
Constraints:
C1≠C2
C2≠C3
C3≠C4
C4≠C5
C2≠C4
C3≠C5
CSP >> Constraint Graph Practice 1
Suppose that a delivery robot must carry out a number of delivery activities, a, b, c, d, and e. Suppose that each activity
happens at any of times 1, 2, 3, or 4. Let A be the variable representing the time that activity a will occur, and similarly for the
other activities.
Suppose the following constraints must be satisfied:
▸Activity b cannot be done at time 3.
▸Activity c cannot be done at time 2.
▸Activity a and d must be done at the same time.
▸Activity a and b cannot be done at the same time.
▸Activity b and c cannot be done at the same time.
▸Activity b and d cannot be done at the same time.
▸Activity c must be done before activity d.
▸Activity e must be done before all other activities.
15
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Constraint Graph Practice 2
Imagine the following scenario:
You are trying to divide eight students in three groups for a project show. The three groups are for Machine learning,
Software engineering and Networking. The assignment of groups to students is subject to the following constraints:
▸Student 1, 2 and 3 must be in different groups as they will be group leaders.
▸Student 4 and 7 want the same group as they are close friends.
▸Student 5 will not be in Software engineering group.
▸Student 3 and 6 don’t like each other and won’t be in the same group.
16
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Constraint Graph Practice 3
Suppose you are designing a CSP for a job shop scheduling problem with five jobs namely J1, J2, J3, J4 and J5. The required
time to complete each job is given below. In the job shop scheduling problem, the task is to order or schedule the jobs.
▸J1 has to be completed before starting all other jobs.
▸J2 has to be completed before starting J3 and J4.
▸J4 and J5 cannot be done parallelly (one has to be completed before the other can be started).
▸All jobs must be completed within one hour.
17
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
Job 1 2 3 4 5
Required Time(mins) 10 5 15 10 20
CSP >> Types of Variables
Discrete variables >>
▸Finite domains:
▹n variables, each domain size d; so O(dn) complete assignments.
▹e.g. Map coloring problem, 8-queens problem.
▸Infinite domains:
▹Set of integers, strings, etc.
▹e.g. job scheduling problem with no deadline, variables are start/end days for each job.
▹Need a constraint language to describe constraints, ex. StartJob1 + 5 ≤ StartJob3
Continuous variables >>
▸e.g., start/end times for Hubble Telescope observations
▸linear constraints solvable in poly time by LP methods
18
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Types of Constraints
▸Unary constraints involve a single variable,
e.g., SA ≠ green
▸Binary constraints involve pairs of variables,
e.g., SA ≠ WA
only binary constraints can be represented as a constraint graph.
▸Higher-order constraints involve 3 or more variables,
e.g., SA ≠ WA ≠ NT
▸Global constraints involve arbitrary number of variables,
e.g. alldiff that represents all of the variables involved in the constraint must have different values.
19
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Solving CSPs
We can formulate CSP problems as standard search problems.
▸States: defined by the values assigned so far
▸Initial state: the empty assignment { }
▸Successor function: assign value to variable without conflict
-fail, if no legal assignments possible
▸Goal test: the current assignment is complete
▸Path cost: constant step cost
Standard search algorithms can be applied directly to solve CSPs.
Let, n variables and the domain size for each variable is d
For BFS:
Branching factor, b = nd
Nodes at level 1 = nd
Nodes at level 2 = nd * (n-1) d
Nodes/leaves at level n = nd * (n-1)d * … … * d = n! * dn
20
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Backtracking Search
A crucial property to all CSPs: commutativity
▸The order of application of any given set of actions has no effect on the outcome.
▸Variable assignments are commutative, i.e. [WA=red then NT=green] same as [NT=green then WA=red]
So new need to consider only assignments to a single variable at each node. So branching factor becomes b=d and total no
of leaves reduces to bd
Depth-first search for CSPs with single-variable assignment and backtracks when a variable has no legal values left to
assign is called Backtracking search.
▸Backtracking search is used for a depth-first search that chooses values for one variable at a time and backtracks when a
variable has no legal values left to assign.
▸Backtracking search is the basic uninformed algorithm for CSPs.
21
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> How Backtrack Works!
22
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Backtracking Search Algorithm
23
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Backtracking Search Example 1
24
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Backtracking Search Example 1
25
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Backtracking Search Example 1
26
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Backtracking Search Example 1
27
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Backtracking Search Example 2
28
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Backtracking Search Practice
Let,
X = { A, B, C}
D = { DA, DB, DC }
where DA = DB = DC = { 1, 2, 3 }
C = {
A > B,
B ≠ C,
A ≠ C
}
Draw the Constraint Graph and perform Backtrack Search.
29
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Improving Backtracking Efficiency
General-purpose methods can give huge gains in speed:
Issue 1 >> Which variable should be assigned next?
sol >> Minimum remaining values heuristic
sol >> Degree heuristic
Issue 2 >> In what order should its values be tried?
sol >> Least constraining value heuristic
Issue 3 >> Can we detect inevitable failure early?
sol >> Forward checking constraint propagation
sol >> Maintaining Arc-Consistency inference
30
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Variable Selection [MRV Heuristic]
Minimum remaining values / Most constrained variable / Fail-first heuristic >>
▸Choose the variable with the fewest legal values.
Can’t answer the following questions:
▸Which variable to choose first?
▸Which variable to choose if they have the same minimum remaining number of legal values?
31
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
MRV MRVMRV
CSP >> Variable Selection [Degree Heuristic]
Degree / Most constraining variable heuristic >>
▸Selecting the variable that has the largest number of constraints on other unassigned variables.
▸Tie-breaker among MRV
32
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
MRV+DH MRV+DH MRV
CSP >> Value Ordering [Least-constraining-value]
Least-constraining-value heuristic >>
▸Choose the value that rules out fewest choices for the neighboring variables in the constraint graph.
▸Leaves maximum flexibility for the neighbors.
33
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
LCV suggests RED
CSP >> Early Failure Detection [Forward-checking]
Forward-checking Inference >>
▸Keep track of remaining legal values for unassigned variables.
▸Terminate search when any variable has no legal values.
34
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Early Failure Detection [Forward-checking]
Forward-checking Inference >>
▸Keep track of remaining legal values for unassigned variables.
▸Terminate search when any variable has no legal values.
35
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Early Failure Detection [Forward-checking]
Forward-checking Inference >>
▸Keep track of remaining legal values for unassigned variables.
▸Terminate search when any variable has no legal values.
36
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Early Failure Detection [Forward-checking]
Forward-checking Inference >>
▸Keep track of remaining legal values for unassigned variables.
▸Terminate search when any variable has no legal values.
Problems >>
▸FC only propagates information from assigned to unassigned variables, but doesn’t provide early detection for all failures.
▸For example, NT and SA can’t both be blue!
37
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Problem 1 [Backtrack + MRV + DH + FC]
Consider the constraint graph on the right.
The domain for every variable is [1,2,3,4].
There are 2 unary constraints:
▸variable “a” cannot take values 3 and 4.
▸variable “b” cannot take value 4.
There are 8 binary constraints stating that variables connected by an edge cannot have
the same value.
Find a solution for this CSP by using backtracking search with the following heuristics:
minimum value heuristic, degree heuristic, forward checking. Explain each step of your
answer.
38
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Problem 2 [Backtrack + Forward Checking]
39
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Problem 2 (Backtrack + Forward Checking)
40
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Problem 2 (Backtrack + Forward Checking)
41
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Problem 2 (Backtrack + Forward Checking)
42
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Problem 2 (Backtrack + Forward Checking)
43
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Problem 2 (Backtrack + Forward Checking)
44
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Problem 2 (Backtrack + Forward Checking)
45
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Problem 2 (Backtrack + Forward Checking)
46
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Problem 2 (Backtrack + Forward Checking)
47
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Problem 2 (Backtrack + Forward Checking)
48
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Problem 2 (Backtrack + Forward Checking)
49
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Problem 2 (Backtrack + Forward Checking)
50
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Practice 1
Suppose that a delivery robot must carry out a number of delivery activities, a, b, c, d, and e. Suppose that each activity
happens at any of times 1, 2, 3, or 4. Let A be the variable representing the time that activity a will occur, and similarly for
the other activities.
Suppose the following constraints must be satisfied:
▸Activity b cannot be done at time 3.
▸Activity c cannot be done at time 2.
▸Activity a and d must be done at the same time.
▸Activity a and b cannot be done at the same time.
▸Activity b and c cannot be done at the same time.
▸Activity b and d cannot be done at the same time.
▸Activity c must be done before activity d.
▸Activity e must be done before all other activities.
Show the steps followed by the backtracking algorithm with the minimum remaining values heuristic, the degree heuristic
and forward checking inference.
51
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Practice 2
You want to color the vertices of the graph shown below with the colors red, green and blue in a way that adjacent vertices
have different colors.
Construct this problem as a CSP, show the steps followed by the backtracking algorithm with minimum value, degree
heuristic and forward checking inference.
52
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Practice 3
You want to color the vertices of the graph shown given below with the colors red, green and blue in a way that adjacent
vertices have different colors.
Construct this problem as a CSP, show the steps followed by the backtracking algorithm with the minimum remaining
values heuristic, degree heuristic and forward checking inference.
53
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Arc Consistency
54
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
Out of Syllabus
CSP >> Local Search
▸Local search use complete-state formulation
- The initial state assigns a value to every variable
▸Variable selection: randomly select any conflicted variable
▸Value selection: min-conflicts heuristic
- Select the value that results in the minimum number of conflicts with other variables
55
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
CSP >> Local Search
56
Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
57
THANKS!
Any questions?
You can find me at imam@cse.uiu.ac.bd

Contenu connexe

Tendances

Adversarial search
Adversarial searchAdversarial search
Adversarial search
Nilu Desai
 
Issues in knowledge representation
Issues in knowledge representationIssues in knowledge representation
Issues in knowledge representation
Sravanthi Emani
 

Tendances (20)

Problem reduction AND OR GRAPH & AO* algorithm.ppt
Problem reduction AND OR GRAPH & AO* algorithm.pptProblem reduction AND OR GRAPH & AO* algorithm.ppt
Problem reduction AND OR GRAPH & AO* algorithm.ppt
 
Informed search
Informed searchInformed search
Informed search
 
Adversarial search
Adversarial searchAdversarial search
Adversarial search
 
Dempster shafer theory
Dempster shafer theoryDempster shafer theory
Dempster shafer theory
 
Hill climbing
Hill climbingHill climbing
Hill climbing
 
ProLog (Artificial Intelligence) Introduction
ProLog (Artificial Intelligence) IntroductionProLog (Artificial Intelligence) Introduction
ProLog (Artificial Intelligence) Introduction
 
Daa notes 1
Daa notes 1Daa notes 1
Daa notes 1
 
Game Playing in Artificial Intelligence
Game Playing in Artificial IntelligenceGame Playing in Artificial Intelligence
Game Playing in Artificial Intelligence
 
I. Mini-Max Algorithm in AI
I. Mini-Max Algorithm in AII. Mini-Max Algorithm in AI
I. Mini-Max Algorithm in AI
 
Issues in knowledge representation
Issues in knowledge representationIssues in knowledge representation
Issues in knowledge representation
 
Unification and Lifting
Unification and LiftingUnification and Lifting
Unification and Lifting
 
And or graph
And or graphAnd or graph
And or graph
 
Introduction Artificial Intelligence a modern approach by Russel and Norvig 1
Introduction Artificial Intelligence a modern approach by Russel and Norvig 1Introduction Artificial Intelligence a modern approach by Russel and Norvig 1
Introduction Artificial Intelligence a modern approach by Russel and Norvig 1
 
First order logic
First order logicFirst order logic
First order logic
 
Artificial Intelligence- TicTacToe game
Artificial Intelligence- TicTacToe gameArtificial Intelligence- TicTacToe game
Artificial Intelligence- TicTacToe game
 
sum of subset problem using Backtracking
sum of subset problem using Backtrackingsum of subset problem using Backtracking
sum of subset problem using Backtracking
 
Water jug problem ai part 6
Water jug problem ai part 6Water jug problem ai part 6
Water jug problem ai part 6
 
Artificial Intelligence -- Search Algorithms
Artificial Intelligence-- Search Algorithms Artificial Intelligence-- Search Algorithms
Artificial Intelligence -- Search Algorithms
 
AI: Logic in AI
AI: Logic in AIAI: Logic in AI
AI: Logic in AI
 
Machine Learning with Decision trees
Machine Learning with Decision treesMachine Learning with Decision trees
Machine Learning with Decision trees
 

Similaire à AI 7 | Constraint Satisfaction Problem

Highly Constrained University Class Scheduling using Ant Colony Optimization
Highly Constrained University Class Scheduling using Ant Colony OptimizationHighly Constrained University Class Scheduling using Ant Colony Optimization
Highly Constrained University Class Scheduling using Ant Colony Optimization
AIRCC Publishing Corporation
 
HIGHLY CONSTRAINED UNIVERSITY CLASS SCHEDULING USING ANT COLONY OPTIMIZATION
HIGHLY CONSTRAINED UNIVERSITY CLASS SCHEDULING USING ANT COLONY OPTIMIZATIONHIGHLY CONSTRAINED UNIVERSITY CLASS SCHEDULING USING ANT COLONY OPTIMIZATION
HIGHLY CONSTRAINED UNIVERSITY CLASS SCHEDULING USING ANT COLONY OPTIMIZATION
ijcsit
 

Similaire à AI 7 | Constraint Satisfaction Problem (20)

TOC 3 | Different Operations on DFA
TOC 3 | Different Operations on DFATOC 3 | Different Operations on DFA
TOC 3 | Different Operations on DFA
 
Unsteady MHD Flow Past A Semi-Infinite Vertical Plate With Heat Source/ Sink:...
Unsteady MHD Flow Past A Semi-Infinite Vertical Plate With Heat Source/ Sink:...Unsteady MHD Flow Past A Semi-Infinite Vertical Plate With Heat Source/ Sink:...
Unsteady MHD Flow Past A Semi-Infinite Vertical Plate With Heat Source/ Sink:...
 
Optimized Classroom Scheduling at LaGrange College
Optimized Classroom Scheduling at LaGrange CollegeOptimized Classroom Scheduling at LaGrange College
Optimized Classroom Scheduling at LaGrange College
 
Satisfaction And Its Application To Ai Planning
Satisfaction And Its Application To Ai PlanningSatisfaction And Its Application To Ai Planning
Satisfaction And Its Application To Ai Planning
 
AI 11 | Markov Model
AI 11 | Markov ModelAI 11 | Markov Model
AI 11 | Markov Model
 
ConstraintSatisfaction.ppt
ConstraintSatisfaction.pptConstraintSatisfaction.ppt
ConstraintSatisfaction.ppt
 
AI 4 | Informed Search
AI 4 | Informed SearchAI 4 | Informed Search
AI 4 | Informed Search
 
Introduction to Graph Theory
Introduction to Graph TheoryIntroduction to Graph Theory
Introduction to Graph Theory
 
Visual Impression Localization of Autonomous Robots_#CASE2015
Visual Impression Localization of Autonomous Robots_#CASE2015Visual Impression Localization of Autonomous Robots_#CASE2015
Visual Impression Localization of Autonomous Robots_#CASE2015
 
Hydraulic similitude and model analysis
Hydraulic similitude and model analysisHydraulic similitude and model analysis
Hydraulic similitude and model analysis
 
Graphical method
Graphical methodGraphical method
Graphical method
 
Highly Constrained University Class Scheduling using Ant Colony Optimization
Highly Constrained University Class Scheduling using Ant Colony OptimizationHighly Constrained University Class Scheduling using Ant Colony Optimization
Highly Constrained University Class Scheduling using Ant Colony Optimization
 
HIGHLY CONSTRAINED UNIVERSITY CLASS SCHEDULING USING ANT COLONY OPTIMIZATION
HIGHLY CONSTRAINED UNIVERSITY CLASS SCHEDULING USING ANT COLONY OPTIMIZATIONHIGHLY CONSTRAINED UNIVERSITY CLASS SCHEDULING USING ANT COLONY OPTIMIZATION
HIGHLY CONSTRAINED UNIVERSITY CLASS SCHEDULING USING ANT COLONY OPTIMIZATION
 
DS & Algo 2 - Recursion
DS & Algo 2 - RecursionDS & Algo 2 - Recursion
DS & Algo 2 - Recursion
 
Fixed point theorem between cone metric space and quasi-cone metric space
Fixed point theorem between cone metric space and quasi-cone metric spaceFixed point theorem between cone metric space and quasi-cone metric space
Fixed point theorem between cone metric space and quasi-cone metric space
 
Quantitative Aptitude Concepts
Quantitative Aptitude ConceptsQuantitative Aptitude Concepts
Quantitative Aptitude Concepts
 
Exam100412
Exam100412Exam100412
Exam100412
 
DS & Algo 4 - Graph and Shortest Path Search
DS & Algo 4 - Graph and Shortest Path SearchDS & Algo 4 - Graph and Shortest Path Search
DS & Algo 4 - Graph and Shortest Path Search
 
TOC 5 | Regular Expressions
TOC 5 | Regular ExpressionsTOC 5 | Regular Expressions
TOC 5 | Regular Expressions
 
CHN and Swap Heuristic to Solve the Maximum Independent Set Problem
CHN and Swap Heuristic to Solve the Maximum Independent Set ProblemCHN and Swap Heuristic to Solve the Maximum Independent Set Problem
CHN and Swap Heuristic to Solve the Maximum Independent Set Problem
 

Plus de Mohammad Imam Hossain

Plus de Mohammad Imam Hossain (20)

DS & Algo 6 - Offline Assignment 6
DS & Algo 6 - Offline Assignment 6DS & Algo 6 - Offline Assignment 6
DS & Algo 6 - Offline Assignment 6
 
DS & Algo 6 - Dynamic Programming
DS & Algo 6 - Dynamic ProgrammingDS & Algo 6 - Dynamic Programming
DS & Algo 6 - Dynamic Programming
 
DS & Algo 5 - Disjoint Set and MST
DS & Algo 5 - Disjoint Set and MSTDS & Algo 5 - Disjoint Set and MST
DS & Algo 5 - Disjoint Set and MST
 
DS & Algo 3 - Offline Assignment 3
DS & Algo 3 - Offline Assignment 3DS & Algo 3 - Offline Assignment 3
DS & Algo 3 - Offline Assignment 3
 
DS & Algo 3 - Divide and Conquer
DS & Algo 3 - Divide and ConquerDS & Algo 3 - Divide and Conquer
DS & Algo 3 - Divide and Conquer
 
DS & Algo 2 - Offline Assignment 2
DS & Algo 2 - Offline Assignment 2DS & Algo 2 - Offline Assignment 2
DS & Algo 2 - Offline Assignment 2
 
DS & Algo 1 - Offline Assignment 1
DS & Algo 1 - Offline Assignment 1DS & Algo 1 - Offline Assignment 1
DS & Algo 1 - Offline Assignment 1
 
DS & Algo 1 - C++ and STL Introduction
DS & Algo 1 - C++ and STL IntroductionDS & Algo 1 - C++ and STL Introduction
DS & Algo 1 - C++ and STL Introduction
 
DBMS 1 | Introduction to DBMS
DBMS 1 | Introduction to DBMSDBMS 1 | Introduction to DBMS
DBMS 1 | Introduction to DBMS
 
DBMS 10 | Database Transactions
DBMS 10 | Database TransactionsDBMS 10 | Database Transactions
DBMS 10 | Database Transactions
 
DBMS 3 | ER Diagram to Relational Schema
DBMS 3 | ER Diagram to Relational SchemaDBMS 3 | ER Diagram to Relational Schema
DBMS 3 | ER Diagram to Relational Schema
 
DBMS 2 | Entity Relationship Model
DBMS 2 | Entity Relationship ModelDBMS 2 | Entity Relationship Model
DBMS 2 | Entity Relationship Model
 
DBMS 7 | Relational Query Language
DBMS 7 | Relational Query LanguageDBMS 7 | Relational Query Language
DBMS 7 | Relational Query Language
 
DBMS 4 | MySQL - DDL & DML Commands
DBMS 4 | MySQL - DDL & DML CommandsDBMS 4 | MySQL - DDL & DML Commands
DBMS 4 | MySQL - DDL & DML Commands
 
DBMS 5 | MySQL Practice List - HR Schema
DBMS 5 | MySQL Practice List - HR SchemaDBMS 5 | MySQL Practice List - HR Schema
DBMS 5 | MySQL Practice List - HR Schema
 
TOC 10 | Turing Machine
TOC 10 | Turing MachineTOC 10 | Turing Machine
TOC 10 | Turing Machine
 
TOC 9 | Pushdown Automata
TOC 9 | Pushdown AutomataTOC 9 | Pushdown Automata
TOC 9 | Pushdown Automata
 
TOC 8 | Derivation, Parse Tree & Ambiguity Check
TOC 8 | Derivation, Parse Tree & Ambiguity CheckTOC 8 | Derivation, Parse Tree & Ambiguity Check
TOC 8 | Derivation, Parse Tree & Ambiguity Check
 
TOC 7 | CFG in Chomsky Normal Form
TOC 7 | CFG in Chomsky Normal FormTOC 7 | CFG in Chomsky Normal Form
TOC 7 | CFG in Chomsky Normal Form
 
TOC 6 | CFG Design
TOC 6 | CFG DesignTOC 6 | CFG Design
TOC 6 | CFG Design
 

Dernier

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 

Dernier (20)

Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 

AI 7 | Constraint Satisfaction Problem

  • 1. Constraint Satisfaction Problem CSI 341 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 2. CSP – Constraint Satisfaction Problem Standard Search Problem >> ▸Searches a space of states for the solution. ▸Heuristics are domain specific. ▸Each state is atomic/indivisible i.e. a black box with no internal structure. CSP >> ▸CSP uses a factored representation for each state: a set of variables, each of which has a value. ▸A problem is solved when each variable has a value that satisfies all the constraints in the variable. ▸A problem described this way is called a constraint satisfaction problem. Advantages ▸Uses general-purpose rather than problem-specific heuristics to enable the solution of complex problems. ▸Represents each state as a set of variables and takes advantage of the structure of states. ▸Eliminates large portions of the search space all at once by identifying variable/value combinations that violate the constraints. 2 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 3. CSP >> Formal Definition A constraint satisfaction problem consists of three components, X, D, and C: ▸X is the set of variables, { X1, . . . , Xn } ▸D is a set of domains, { D1, . . . , Dn }, one for each variable. ▸C is a set of constraints that specify allowable combinations of values. Here, ▸Each domain Di consists of a set of allowable values, { v1, . . . , vk } for each variable Xi ▸Each constraint Ci consists of a pair 𝑠𝑐𝑜𝑝𝑒, 𝑟𝑒𝑙 , where scope is a tuple of variables that participate in the constraint and rel is a relation that defines the values that those variables can take on. ▸A relation can be represented as an explicit list of all tuples of values that satisfy the constraint, or as an abstract relation. For example, 𝑋1, 𝑋2 , [ 𝐴, 𝐵 , (𝐵, 𝐴)] or 𝑋1, 𝑋2 , 𝑋1 ! = 𝑋2 3 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 4. CSP >> Solution ▸Each state in a CSP is defined by an assignment of values to some or all of the variables. { Xi = vi , Xj = vj , . . . } ▸An assignment that does not violate any constraints is called a consistent or legal assignment. ▸A complete assignment is one in which every variable is assigned. ▸A partial assignment is one that assigns values to only some of the variables. ▸A solution to a CSP is consistent and complete assignment. Advantages of formulating a problem as a CSP ▸CSPs yield natural representation for a wide variety of problems. ▸CSP solvers can be faster than state-space searchers because the CSP solver can quickly eliminate large swatches of the search space. ▸With CSP, once we find out that a partial assignment is not a solution, we can immediately discard further refinements of the partial assignment. ▸We can see why a assignment is not a solution – which variables violate a constraint – we can focus attention on the variables that matter. 4 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 5. CSP >> Problem Formulation Map Coloring Problem >> your task is to color each region either red, green, or blue in such a way that no neighboring regions have the same color. CSP Formulation Each region is a variable, X = { WA, NT, Q, NSW, V, SA, T } Domain of each variable, Di = { red, green, blue } Set of constraints, C = { SA ≠ WA, SA ≠ NT, SA ≠ Q, SA ≠ NSW, SA ≠ V, WA ≠ NT, NT ≠ Q, Q ≠ NSW, NSW ≠ V } Here, SA ≠ WA is a shortcut for 𝑠𝑐𝑜𝑝𝑒, 𝑟𝑒𝑙 = 𝑆𝐴, 𝑊𝐴 , 𝑆𝐴 ≠ 𝑊𝐴 5 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 6. CSP >> Possible Solution There are many possible solutions to this problem, Such as { WA = red, NT = green, Q = red, NSW = green, V = red, SA = blue, T = green } 6 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 7. CSP >> Constraint Graph Binary CSP >> each constraint relates at most two variables. Constraint Graph >> ▸Nodes correspond to the variables of the problem. ▸An edge connects any two variables that participate in a constraint. 7 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 8. CSP >> Job-shop Scheduling Let’s consider a small part(wheel installation) of the car assembly, consisting of 15 tasks. ▸Install axles (front and back) – requires 10 mins to install ▸Affix all four wheels (right and left, front and back) – takes 1 mins ▸Tighten nuts for each wheel – takes 2 mins ▸Affix hubcaps and – requires 1 mins ▸Inspect the final assembly – takes 3 mins And get the whole assembly done in 30 mins 8 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU I n s p e c t
  • 9. CSP >> Job-shop Scheduling We can represent the tasks with 15 variables: X = { AxleF, AxleB, WheelRF, WheelLF, WheelRB, WheelLB, NutsRF, NutsLF, NutsRB, NutsLB, CapRF, CapLF, CapRB, CapLB, Inspect } Precedence constraints >> whenever a task T1 must occur before task T2 and task T1 takes duration d1 to complete, then we can represent the constraint as T1 + d1 <= T2 So the constraints are, C = { AxleF + 10 <= WheelRF , AxleF + 10 <= WheelLF , AxleB + 10 <= WheelRB , AxleB + 10 <= WheelLB , WheelRF + 1 <= NutsRF , WheelLF + 1 <= NutsLF , WheelRB + 1 <= NutsRB , WheelLB + 1 <= NutsLB , NutsRF + 2 <= CapRF , NutsLF + 2 <= CapLF , NutsRB + 2 <= CapRB , NutsLB + 2 <= CapLB , CapRF + 1 <= Inspect, CapLF + 1 <= Inspect, CapRB + 1 <= Inspect, CapLB + 1 <= Inspect, AxleF + 10 <= Inspect, AxleB + 10 <= Inspect, WheelRF + 1 <= Inspect , WheelLF + 1 <= Inspect , WheelRB + 1 <= Inspect , WheelLB + 1 <= Inspect , NutsRF + 2 <= Inspect , NutsLF + 2 <= Inspect , NutsRB + 2 <= Inspect , NutsLB + 2 <= Inspect } As inspection takes 3 mins to complete and the total task need to complete within 30 minutes, So domain of each variable, Di = { 1, 2, 3, . . . . . . , 27 } 9 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 10. CSP >> N-Queens Set of variables, X = { Q1, Q2, … …, QN } Each variable Qi represents the position of each queen in columns 1, 2, … …, N Domains for each variable, Di = { 1, 2, … …, N } Constraints: implicit form: ∀𝑖, 𝑗 no-threatening (Qi, Qj) explicit form: (Q1, Q2) ∈ { (1,3), (1,4), … … } … … 10 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 11. CSP >> Cryptarithmetic puzzle Variables, X = { F, T, U, W, R, O, X1, X2, X3 } Domains for variables X1, X2, X3 is, { 0, 1 } Domains for all other variables, Di = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } Constraints: alldiff (F, T, U, W, R, O) O + O = R + 10 . X1 X1 + W + W = U + 10 . X2 X2 + T + T = O + 10 . X3 X3 = F, T ≠ 0, F ≠ 0 11 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU Constraint hypergraph
  • 12. CSP >> Sudoku Variables, X = each open square Domains for each variable, Di = { 1, 2, 3, 4, 5, 6, 7, 8, 9 } Constraints: 9-way alldiff for each column 9-way alldiff for each row 9-way alldiff for each region 12 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 13. CSP >> Example 1 You are in charge of scheduling for computer science classes that meet Mondays, Wednesdays and Fridays. There are 5 classes that meet on these days and 3 professors who will be teaching these classes. You are constrained by the fact that each professor can only teach one class at a time. The classes are: ▸Class 1 - Intro to Programming: meets from 8:00-9:00am ▸Class 2 - Intro to Artificial Intelligence: meets from 8:30-9:30am ▸Class 3 - Natural Language Processing: meets from 9:00-10:00am ▸Class 4 - Computer Vision: meets from 9:00-10:00am ▸Class 5 - Machine Learning: meets from 9:30-10:30am The professors are: ▸Professor A, who is available to teach Classes 3 and 4. ▸Professor B, who is available to teach Classes 2, 3, 4, and 5. ▸Professor C, who is available to teach Classes 1, 2, 3, 4, 5 13 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 14. CSP >> Example 1 Solution 14 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU Variables Domains C1 C C2 B, C C3 A, B, C C4 A, B, C C5 B, C Constraints: C1≠C2 C2≠C3 C3≠C4 C4≠C5 C2≠C4 C3≠C5
  • 15. CSP >> Constraint Graph Practice 1 Suppose that a delivery robot must carry out a number of delivery activities, a, b, c, d, and e. Suppose that each activity happens at any of times 1, 2, 3, or 4. Let A be the variable representing the time that activity a will occur, and similarly for the other activities. Suppose the following constraints must be satisfied: ▸Activity b cannot be done at time 3. ▸Activity c cannot be done at time 2. ▸Activity a and d must be done at the same time. ▸Activity a and b cannot be done at the same time. ▸Activity b and c cannot be done at the same time. ▸Activity b and d cannot be done at the same time. ▸Activity c must be done before activity d. ▸Activity e must be done before all other activities. 15 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 16. CSP >> Constraint Graph Practice 2 Imagine the following scenario: You are trying to divide eight students in three groups for a project show. The three groups are for Machine learning, Software engineering and Networking. The assignment of groups to students is subject to the following constraints: ▸Student 1, 2 and 3 must be in different groups as they will be group leaders. ▸Student 4 and 7 want the same group as they are close friends. ▸Student 5 will not be in Software engineering group. ▸Student 3 and 6 don’t like each other and won’t be in the same group. 16 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 17. CSP >> Constraint Graph Practice 3 Suppose you are designing a CSP for a job shop scheduling problem with five jobs namely J1, J2, J3, J4 and J5. The required time to complete each job is given below. In the job shop scheduling problem, the task is to order or schedule the jobs. ▸J1 has to be completed before starting all other jobs. ▸J2 has to be completed before starting J3 and J4. ▸J4 and J5 cannot be done parallelly (one has to be completed before the other can be started). ▸All jobs must be completed within one hour. 17 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU Job 1 2 3 4 5 Required Time(mins) 10 5 15 10 20
  • 18. CSP >> Types of Variables Discrete variables >> ▸Finite domains: ▹n variables, each domain size d; so O(dn) complete assignments. ▹e.g. Map coloring problem, 8-queens problem. ▸Infinite domains: ▹Set of integers, strings, etc. ▹e.g. job scheduling problem with no deadline, variables are start/end days for each job. ▹Need a constraint language to describe constraints, ex. StartJob1 + 5 ≤ StartJob3 Continuous variables >> ▸e.g., start/end times for Hubble Telescope observations ▸linear constraints solvable in poly time by LP methods 18 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 19. CSP >> Types of Constraints ▸Unary constraints involve a single variable, e.g., SA ≠ green ▸Binary constraints involve pairs of variables, e.g., SA ≠ WA only binary constraints can be represented as a constraint graph. ▸Higher-order constraints involve 3 or more variables, e.g., SA ≠ WA ≠ NT ▸Global constraints involve arbitrary number of variables, e.g. alldiff that represents all of the variables involved in the constraint must have different values. 19 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 20. CSP >> Solving CSPs We can formulate CSP problems as standard search problems. ▸States: defined by the values assigned so far ▸Initial state: the empty assignment { } ▸Successor function: assign value to variable without conflict -fail, if no legal assignments possible ▸Goal test: the current assignment is complete ▸Path cost: constant step cost Standard search algorithms can be applied directly to solve CSPs. Let, n variables and the domain size for each variable is d For BFS: Branching factor, b = nd Nodes at level 1 = nd Nodes at level 2 = nd * (n-1) d Nodes/leaves at level n = nd * (n-1)d * … … * d = n! * dn 20 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 21. CSP >> Backtracking Search A crucial property to all CSPs: commutativity ▸The order of application of any given set of actions has no effect on the outcome. ▸Variable assignments are commutative, i.e. [WA=red then NT=green] same as [NT=green then WA=red] So new need to consider only assignments to a single variable at each node. So branching factor becomes b=d and total no of leaves reduces to bd Depth-first search for CSPs with single-variable assignment and backtracks when a variable has no legal values left to assign is called Backtracking search. ▸Backtracking search is used for a depth-first search that chooses values for one variable at a time and backtracks when a variable has no legal values left to assign. ▸Backtracking search is the basic uninformed algorithm for CSPs. 21 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 22. CSP >> How Backtrack Works! 22 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 23. CSP >> Backtracking Search Algorithm 23 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 24. CSP >> Backtracking Search Example 1 24 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 25. CSP >> Backtracking Search Example 1 25 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 26. CSP >> Backtracking Search Example 1 26 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 27. CSP >> Backtracking Search Example 1 27 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 28. CSP >> Backtracking Search Example 2 28 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 29. CSP >> Backtracking Search Practice Let, X = { A, B, C} D = { DA, DB, DC } where DA = DB = DC = { 1, 2, 3 } C = { A > B, B ≠ C, A ≠ C } Draw the Constraint Graph and perform Backtrack Search. 29 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 30. CSP >> Improving Backtracking Efficiency General-purpose methods can give huge gains in speed: Issue 1 >> Which variable should be assigned next? sol >> Minimum remaining values heuristic sol >> Degree heuristic Issue 2 >> In what order should its values be tried? sol >> Least constraining value heuristic Issue 3 >> Can we detect inevitable failure early? sol >> Forward checking constraint propagation sol >> Maintaining Arc-Consistency inference 30 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 31. CSP >> Variable Selection [MRV Heuristic] Minimum remaining values / Most constrained variable / Fail-first heuristic >> ▸Choose the variable with the fewest legal values. Can’t answer the following questions: ▸Which variable to choose first? ▸Which variable to choose if they have the same minimum remaining number of legal values? 31 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU MRV MRVMRV
  • 32. CSP >> Variable Selection [Degree Heuristic] Degree / Most constraining variable heuristic >> ▸Selecting the variable that has the largest number of constraints on other unassigned variables. ▸Tie-breaker among MRV 32 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU MRV+DH MRV+DH MRV
  • 33. CSP >> Value Ordering [Least-constraining-value] Least-constraining-value heuristic >> ▸Choose the value that rules out fewest choices for the neighboring variables in the constraint graph. ▸Leaves maximum flexibility for the neighbors. 33 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU LCV suggests RED
  • 34. CSP >> Early Failure Detection [Forward-checking] Forward-checking Inference >> ▸Keep track of remaining legal values for unassigned variables. ▸Terminate search when any variable has no legal values. 34 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 35. CSP >> Early Failure Detection [Forward-checking] Forward-checking Inference >> ▸Keep track of remaining legal values for unassigned variables. ▸Terminate search when any variable has no legal values. 35 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 36. CSP >> Early Failure Detection [Forward-checking] Forward-checking Inference >> ▸Keep track of remaining legal values for unassigned variables. ▸Terminate search when any variable has no legal values. 36 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 37. CSP >> Early Failure Detection [Forward-checking] Forward-checking Inference >> ▸Keep track of remaining legal values for unassigned variables. ▸Terminate search when any variable has no legal values. Problems >> ▸FC only propagates information from assigned to unassigned variables, but doesn’t provide early detection for all failures. ▸For example, NT and SA can’t both be blue! 37 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 38. CSP >> Problem 1 [Backtrack + MRV + DH + FC] Consider the constraint graph on the right. The domain for every variable is [1,2,3,4]. There are 2 unary constraints: ▸variable “a” cannot take values 3 and 4. ▸variable “b” cannot take value 4. There are 8 binary constraints stating that variables connected by an edge cannot have the same value. Find a solution for this CSP by using backtracking search with the following heuristics: minimum value heuristic, degree heuristic, forward checking. Explain each step of your answer. 38 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 39. CSP >> Problem 2 [Backtrack + Forward Checking] 39 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 40. CSP >> Problem 2 (Backtrack + Forward Checking) 40 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 41. CSP >> Problem 2 (Backtrack + Forward Checking) 41 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 42. CSP >> Problem 2 (Backtrack + Forward Checking) 42 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 43. CSP >> Problem 2 (Backtrack + Forward Checking) 43 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 44. CSP >> Problem 2 (Backtrack + Forward Checking) 44 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 45. CSP >> Problem 2 (Backtrack + Forward Checking) 45 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 46. CSP >> Problem 2 (Backtrack + Forward Checking) 46 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 47. CSP >> Problem 2 (Backtrack + Forward Checking) 47 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 48. CSP >> Problem 2 (Backtrack + Forward Checking) 48 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 49. CSP >> Problem 2 (Backtrack + Forward Checking) 49 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 50. CSP >> Problem 2 (Backtrack + Forward Checking) 50 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 51. CSP >> Practice 1 Suppose that a delivery robot must carry out a number of delivery activities, a, b, c, d, and e. Suppose that each activity happens at any of times 1, 2, 3, or 4. Let A be the variable representing the time that activity a will occur, and similarly for the other activities. Suppose the following constraints must be satisfied: ▸Activity b cannot be done at time 3. ▸Activity c cannot be done at time 2. ▸Activity a and d must be done at the same time. ▸Activity a and b cannot be done at the same time. ▸Activity b and c cannot be done at the same time. ▸Activity b and d cannot be done at the same time. ▸Activity c must be done before activity d. ▸Activity e must be done before all other activities. Show the steps followed by the backtracking algorithm with the minimum remaining values heuristic, the degree heuristic and forward checking inference. 51 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 52. CSP >> Practice 2 You want to color the vertices of the graph shown below with the colors red, green and blue in a way that adjacent vertices have different colors. Construct this problem as a CSP, show the steps followed by the backtracking algorithm with minimum value, degree heuristic and forward checking inference. 52 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 53. CSP >> Practice 3 You want to color the vertices of the graph shown given below with the colors red, green and blue in a way that adjacent vertices have different colors. Construct this problem as a CSP, show the steps followed by the backtracking algorithm with the minimum remaining values heuristic, degree heuristic and forward checking inference. 53 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 54. CSP >> Arc Consistency 54 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU Out of Syllabus
  • 55. CSP >> Local Search ▸Local search use complete-state formulation - The initial state assigns a value to every variable ▸Variable selection: randomly select any conflicted variable ▸Value selection: min-conflicts heuristic - Select the value that results in the minimum number of conflicts with other variables 55 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 56. CSP >> Local Search 56 Mohammad Imam Hossain | Lecturer, Dept. of CSE | UIU
  • 57. 57 THANKS! Any questions? You can find me at imam@cse.uiu.ac.bd