Session 5
Session 5
ARTIFICIAL
INTELLIGENT SYSTEMS
SESSION NO: 5
• CSP
• Backtracking
• Forward checking
2
TOPICS TO BE COVERED
• 1.CSP
• 2.Backtracking
• 3. Forward checking
3
DEFINITION OF CSP (CONSTRAINT
SATISFACTION PROBLEM)
CSP:
A state is an assignment of values to some variables.
• state is defined by variables Xi with values from domain Di
• goal test is a set of constraints specifying allowable combinations of
values for subsets of variables
4
SOME TERMS IN CSP
6
CONSTRAINT SATISFACTION PROBLEM
• A CSP is defined by
• a set of variables ex: Xi
• a domain of values for each variable ex: Vi
• a set of constraints between variables i.e. set of conditions
• A solution is
• an assignment of a value to each variable that satisfies the constraints
i.e. an answer to a problem.
7
EXAMPLE: MAP-COLORING
8
MAP-COLORING
9
CONSTRAINT GRAPH
10
TYPES OF CONSTRAINTS
11
• Variables-set of characters
• Code – Domain (set of
values)
• Constraint- any value must
be in the range-0-9 and no
value should be repeated.
12
• Initial state: none of the
variables has a value (color)
• Successor state (intermediate):
one of the variables without a
value will get some value.
• Goal(solution): all variables
have a value and none of the
constraints is violated.
13
BACKTRACKING SEARCH
14
• Backtracking search uses a brute force approach for finding the desired output.
• Brute force finds all solutions to a problem.
• Solutions that do not meet constraints will be removed.
• A search tree known as the state-space tree is used to find these solutions.
• building a solution step by step, increasing levels over time, using recursion.
• A backtracking algorithm also uses the depth-first search method.
15
ALGORITHM
16
HOW DOES A BACKTRACKING ALGORITHM WORK?
• The algorithm seeks a path leading to a feasible solution with some intermediate
checkpoints.
• If the checkpoints do not lead to a viable solution, the problem can return to the
checkpoints and take another path to find a feasible solution.
17
HOW DOES A BACKTRACKING ALGORITHM WORK?
18
WHEN TO USE A BACKTRACKING ALGORITHM?
19
TYPES OF BACKTRACKING ALGORITHM
20
APPLICATIONS OF BACKTRACKING ALGORITHM
21
TO FIND ALL HAMILTONIAN PATHS PRESENT IN A GRAPH. (ABFECD
IS A HAMILTON PATH)
22
TO SOLVE THE N QUEEN PROBLEM.
23
DEPTH-FIRST SEARCH
24
DEPTH FIRST SEARCH
B C D E
F G
K L
25
IMPROVING BACKTRACKING EFFICIENCY
26
WHAT ARE THE PROS OF BACKTRACKING?
29
FORWARD CHECKING
30
FORWARD CHECKING
31
• When a value is assigned to the current variable, any value in
the domain of a "future" variable which conflicts with this
assignment is (temporarily) removed from the domain.
• If the domain of a future variable becomes empty, the current
partial solution is inconsistent. It reduces the domains and
removes possible conflicts
32
• The branches of the search tree that will lead to failure to be
pruned earlier than with simple backtracking.
• When a new variable is considered, all its remaining values are
guaranteed to be consistent with the past variables, so the
checking an assignment against the past assignments is no
longer necessary.
33
FORWARD CHECKING IN GRAPH COLORING
34
35
36
37
38
MERITS AND DEMERITS OF FORWARDS
CHECKING
39
• But forward checking does more work when each assignment is added to the current
partial solution.
• It does not perform full arc consistency.
40
SELF-ASSESSMENT QUESTIONS
a) n-queen problem
b) subset sum problem
c) Hamiltonian circuit problem
d) Travelling salesman problem
a) State-space tree
b) State-chart tree
c) Node tree
d) Backtracking tree
Self-Assessment Questions
a) Non-promising
b) Promising
c) Succeeding
d) Preceding
REFERENCES FOR FURTHER LEARNING OF THE
SESSION
1. https://www.interviewbit.com/
2. https://www.sanfoundry.com/backtracking-multiple-choice-questions-answers-mcqs/
3. https://www.geeksforgeeks.org/introduction-to-backtracking-data-structure-and-algorithm-
tutorials/
4. https://www.hackerearth.com/practice/basic-programming/recursion/recursion-and-backtracking/t
utorial/
5. https://ktiml.mff.cuni.cz/~bartak/constraints/propagation.html
Textbook: Artificial Intelligence A Modern Approach Third Edition Stuart J. Russell and Peter Norvig
(Page No-202 chapter No-06)
THANK YOU
Team – DDAIS