Session- 1 2 Co-2 Constrained Satisfaction Based Search Algorithms (1)
Session- 1 2 Co-2 Constrained Satisfaction Based Search Algorithms (1)
MACHINE LEARNING
CONSTRAINED SATISFACTION BASED SEARCH
ALGORITHMS
INTRODUCTION TO
CONSTRAINT SATISFACTION PROBLEMS (CSP)
2
EXAMPLE CSP: MAP-COLORING PROBLEM
Variables WA, NT, Q, NSW, V, SA, T
Domains Di = {red, green, blue}
Constraints: adjacent regions must have different colors
e.g., WA ≠ NT, or (WA, NT) in {(red, green),(red, blue),(green, red),
(green, blue),(blue, red),(blue, green)}.
3
EXAMPLE CSP: MAP-COLORING PROBLEM
Solutions are complete and consistent assignments (WA = red, NT =
green, Q = red, NSW = green, V = red, SA = blue, T = green.
4
REPRESENTING CONSTRAINTS AS A GRAPH
Constraint graph: nodes are variables, arcs/edges are constraints
5
TYPES OF VARIABLE USED IN A CSP PROBLEM
Discrete variables
Continuous Variable
6
DISCREET VARIABLES IN CSP
Discrete variables with Finite Domains (Color Graphing, 8 Queen)
If the domain size of any variable is d, then the possible number of complete
assignments will be O(dn), where n is the number of variables
Finite domains include Boolean values
7
CONTINUOUS VARIABLES IN CSP
8
LANGUAGE OF CONSTRAINTS
A constraint can be defined using a language must be used to
define the constraints
Example: The job1, which can be taken after 5 days, must precede
Job3, which can be represented using constraint language such as
9
TYPES OF CONSTRAINTS– CSP PROBLEM
Linear Constraints
Nonlinear Constraints
Absolute Constraints
Preference constraints
10
TYPES OF CONSTRAINTS
Linear Constraints: Linear combination of Variables expressed in
Mathematical expressions (Linear Equations, Linear Inequalities, Logical
Expressions)
Non-Linear Constraints (Polynomial, Exponential, Trigonometric and
Logarithmic )
Absolute Constraints: Constraints are imposed on the variables using
either absolute values or inequalities
Preference Constraints: Constrained imposed based on the user
preferences (Ex. In a university timetabling problem, Prof. X might prefer
teaching in the morning, whereas Prof. Y prefers teaching in the
afternoon). 11
CLASSIFICATION OF CONSTRAINTS
Unary constraints involve a single variable(SA ≠ green)
12
EXAMPLE APPLICATION IMPLEMENTED USING CSP
13
CRYPTOGRAPHIC ARITHMETIC PROBLEM
Each Letter stands for a distinct digit. The aim is to find a substitution of digits for
letters such that the resulting sum is arithmetically correct with the added restriction
that no leading zeros are allowed
14
CONSTRAINT GRAPH
CRYPTOGRAPHIC ARITHMETIC PROBLEM
15
IDENTIFYING CONSTRAINTS
CRYPTOGRAPHIC ARITHMETIC PROBLEM
The constraint Graph shows all diff constraints as well as column addition
constraints. Each Square Box is a Constraint connected to the variables that
it constrains.
Variables F, T, U, W, R, O
Constraints
16
REAL-WORLD APPLICATIONS REQUIRING CSP SEARCHES
17
STANDARD SEARCH FORMULATION
States are defined by the values assigned.
Initial state: the empty assignment in which all variables are unassigned.
Successor function: a value can be assigned to any unassigned variable, if it does not
Some observations
The solution Appears at a depth n where n is the number of variables existing in the
problem 19
CSP SEARCH ALGORITHMS
Forword Search
Backword Tracking
20
FORWARD CHECKING ALGORITHM
1. Initialize:
Start with the initial assignment of variables and their domains.
Create an empty set to store the list of constrained variables.
2. Select Variable: Choose a variable to assign a value to. This can be based on
heuristics like Minimum Remaining Values (MRV) or Degree
Heuristic.
3. Select Value: Choose a value from the domain of the selected variable. This
can be based on heuristics like Least Constraining Value (LCV).
4. Assign Value: Assign the selected value to the selected variable.
5. Update Domain: For each unassigned variable adjacent to the variable just
assigned, remove the selected value from their domains.
21
FORWORD CHECKING ALGORITHM
22
FORWORD CHECKING ALGORITHM
24
REPRESENTING CONSTRAINTS AS A GRAPH
Constraint graph: nodes are variables, arcs/edges are constraints
25
SOLVING THE PROBLEMS THROUGH FORWARD
CHECKING
Idea:
Keep track of remaining legal values for unassigned variables
Terminate search when any variable has no legal values
26
SOLVING THE PROBLEMS THROUGH FORWARD
CHECKING
Idea:
Keep track of remaining legal values for unassigned variables
Terminate search when any variable has no legal values
27
SOLVING THE PROBLEMS THROUGH FORWARD
CHECKING
Idea:
Keep track of remaining legal values for unassigned variables
Terminate search when any variable has no legal values
28
SOLVING THE PROBLEMS THROUGH FORWARD
CHECKING
Idea:
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 algorithms repeatedly enforce constraints locally
29
CONSTRAINT PROPAGATION
30
LOCAL CONSISTENCY
31
LOCAL CONSISTENCY
32
NODE CONSISTENCY
33
ARCH CONSISTENCY
35
BACKTRACKING SEARCH IN CSP
INTRODUCTION - BACKTRACKING SEARCH
37
INTRODUCTION - BACKTRACKING SEARCH
The term 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.
An unassigned variable is chosen, and then all values in that variable's
domain are tried to find a solution.
If an inconsistency is detected, then BACKTRACK returns failure, causing
the previous call to try another value
Backtracking considers assignments to a single variable at each node
Depth-first search for CSPs with single-variable assignments is called
backtracking search
38
STEP BY STEP PROCEDURE – BACKTRACKING ALGORITHM
39
STEP BY STEP PROCEDURE – BACKTRACKING ALGORITHM
4. Value Assignment:
For each value in the domain of the selected variable:
i. Assign the value to the variable.
ii. Check if the assignment violates any constraints with the already assigned
variables. If a constraint is violated, backtrack to step 2.
5. Constraint Propagation:
After assigning a value, apply constraint propagation techniques. This could
involve revising the domains of other variables based on the newly assigned
variable and the constraints. Common techniques include arc consistency and
domain reduction.
40
STEP BY STEP PROCEDURE – BACKTRACKING ALGORITHM
41
STEP BY STEP PROCEDURE – BACKTRACKING ALGORITHM
42
BACKTRACKING EXAMPLE – COLOR GRAPH
43
BACKTRACKING EXAMPLE
44
BACKTRACKING EXAMPLE
45
BACKTRACKING EXAMPLE
46
IMPROVING BACKTRACKING EFFICIENCY
General-purpose methods can give huge gains
in speed:
Which variable should be assigned next?
In what order should its values be tried?
Can we detect inevitable failure early?
47
MINIMUM REMAINING VALUE HEURISTICS
By default, the SELECT-UNASSIGNED-VARIABLE function selects the
next unassigned variable in the order given by the list
This static variable ordering seldom results in the most efficient search.
For example, after the assignments for WA = red and NT = green, there is
only one possible value for SA, so it makes sense to assign blue to SA next
rather than to Q.
In fact, after SA is assigned, the choices for Q, NSW, and V are all forced.
This intuitive idea of choosing the variable with the fewest "legal" values is
called the remaining values (MRV) heuristic.
48
MINIMUM REMAINING VALUE
It is also has been called the "most constrained variable" or "fail-first"
heuristic because it picks a variable that is most likely to cause a failure
soon, thereby pruning the search tree.
49
SELECTING VARIABLES WITH HIGHEST DEGREE
The MRV heuristic doesn't help choose the first region to colour in
Australia because, initially, every region has three legal colours.
In this case, the degree heuristic comes in handy. It attempts to
reduce the branching factor on future choices by selecting the variable
involved in the largest number of constraints on other unassigned
variables.
SA is the variable with the highest degree, 5; the other variables have
degrees 2 or 3, except for T, which has 0.
50
SELECTING VARIABLES WITH HIGHEST DEGREE
In fact, once SA is chosen, applying the degree heuristic solves the
problem without any false steps-you can choose any consistent colour
at each choice point and still arrive at a solution with no backtracking
The minimum remaining values heuristic is usually a more powerful
guide, but the degree heuristic can be useful as a tie-breaker.
Once a variable has been selected, the algorithm must decide on the
order in which to examine its values.
51
SELECTING VARIABLES WITH HIGHEST DEGREE
The minimum remaining values heuristic is usually a more powerful
guide, but the highest degree heuristic can be useful as a tie-breaker.
Once a variable has been selected, the algorithm must decide how to
examine its values.
For this, the least-constraining-value heuristic can be effective in
some cases. It prefers the value that rules out the fewest choices for
the neighbouring variables in the constraint graph.
For example, suppose we have generated the partial assignment with
WA = red and NT = green, and our next choice is for Q. Blue would be
a bad choice because it eliminates the last legal value left for Q's
neighbour, SA.
52
SELECTING VARIABLES WITH HIGHEST DEGREE
The least-constraining-value heuristic, therefore, prefers red to blue.
In general, the heuristic is trying to leave the maximum flexibility for
subsequent variable assignments. Of course, 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. The same
holds if there are no solutions to the problem.
53
CSP SUMMARY
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
Iterative min-conflicts is usually effective in practice
54