ARTIFICAL INTELLIGENCE
(R18 III(II Sem))
Department of computer science and
engineering (AI/ML)
Session 19
by
Asst.Prof.M.Gokilavani
VITS
4/25/2023 Dpaertment of CSE ( AL & ML) 1
TEXTBOOK:
• Artificial Intelligence A modern Approach, Third
Edition, Stuart Russell and Peter Norvig, Pearson
Education.
REFERENCES:
• Artificial Intelligence, 3rd Edn, E. Rich and
K.Knight (TMH).
• Artificial Intelligence, 3rd Edn, Patrick Henny
Winston, Pearson Education.
• Artificial Intelligence, Shivani Goel, Pearson
Education.
• Artificial Intelligence and Expert Systems-
Patterson, Pearson Education.
4/25/2023 Dpaertment of CSE ( AL & ML) 2
Topics covered in session 19
• Adversarial Search: Games, Optimal Decisions in Games, Alpha–
Beta Pruning, Imperfect Real-Time Decisions.
• Constraint Satisfaction Problems: Defining Constraint
Satisfaction Problems, Constraint Propagation, Backtracking
Search for CSPs, Local Search for CSPs, The Structure of
Problems.
• Propositional Logic: Knowledge-Based Agents, The Wumpus
World, Logic, Propositional Logic, Propositional Theorem
Proving: Inference and proofs, Proof by resolution, Horn clauses
and definite clauses, Forward and backward chaining, Effective
Propositional Model Checking, Agents Based on Propositional
Logic.
4/25/2023 Dpaertment of CSE ( AL & ML) 3
Constraint Propagation
• In local state-spaces, the choice is only one,
i.e., to search for a solution. But in CSP, we
have two choices either:
– We can search for a solution or
– We can perform a special type of inference
called constraint propagation.
4/25/2023 4
Dpaertment of CSE ( AL & ML)
Constraint Propagation
• Constraint propagation is a special type of inference
which helps in reducing the legal number of values
for the variables.
• The idea behind constraint propagation is local
consistency.
• In local consistency, variables are treated as nodes,
and each binary constraint is treated as an arc in the
given problem.
4/25/2023 5
Dpaertment of CSE ( AL & ML)
There are following local consistencies which are
discussed below:
• Node Consistency: A single variable is said to be node
consistent if all the values in the variable’s domain satisfy
the unary constraints on the variables.
4/25/2023 6
Dpaertment of CSE ( AL & ML)
• Arc Consistency: A variable is arc consistent if every
value in its domain satisfies the binary constraints of the
variables.
4/25/2023 7
Dpaertment of CSE ( AL & ML)
Path Consistency: When the evaluation of a set of two
variable with respect to a third variable can be extended over
another variable, satisfying all the binary constraints. It is
similar to arc consistency.
k-consistency: This type of consistency is used to define the
notion of stronger forms of propagation. Here, we examine
the k-consistency of the variables.
Backtracking Search for CSPs
• In CSP’s, variable assignments are commutative
For example:
[WA = red then NT = green]
is the same as
[NT =green then WA = red]
• We only need to consider assignments to a single
variable at each level (i.e., we fix the order of
assignments)
• Depth-first search for CSPs with single-variable
assignments is called backtracking search.
4/25/2023 8
Dpaertment of CSE ( AL & ML)
Example
4/25/2023 9
Dpaertment of CSE ( AL & ML)
Example
4/25/2023 Dpaertment of CSE ( AL & ML) 10
Example
4/25/2023 11
Dpaertment of CSE ( AL & ML)
Example
4/25/2023 Dpaertment of CSE ( AL & ML) 12
Example
4/25/2023 Dpaertment of CSE ( AL & ML) 13
Backtracking Searching Algorithm
4/25/2023 Dpaertment of CSE ( AL & ML) 14
Problem in ordering
4/25/2023 Dpaertment of CSE ( AL & ML) 15
• Ordering
– How should we order variables for assignment?
– How should we order values from the domains?
Need Improving Backtracking Efficiency Ordering
Improving Backtracking Efficiency
Ordering
• Ordering
– How should we order variables for assignment? –
– How should we order values from the domains?
Filtering
Can we detect inevitable failures early?
4/25/2023 Dpaertment of CSE ( AL & ML) 16
Early detection of failure
4/25/2023 Dpaertment of CSE ( AL & ML) 17
Early detection of failure- Forward
Checking
• Forward checking Keep track of remaining legal values
for unassigned variables.
• Terminate search when any variable has no legal values.
4/25/2023 Dpaertment of CSE ( AL & ML) 18
Arc Consistency
4/25/2023 Dpaertment of CSE ( AL & ML) 19
Arc Consistency
4/25/2023 Dpaertment of CSE ( AL & ML) 20
Problem structure
• Tasmania and the mainland are separate structures. We can
solve them independently and then combine their solutions.
• More generally, we can decompose the CSP into separate
connected components (sub-problems of the CSP).
• Then the solution is the union of the sub- problem solutions.
This can be much more efficient than solving the entire CSP
as one problem.
4/25/2023 Dpaertment of CSE ( AL & ML) 21
Algorithm for tree structure CSP’s
• Choose one variable as root, order variables from root to
leaves such that every node's parent precedes it in the ordering.
• Backward removal phase: check arc consistency starting
from the rightmost node and going backwards.
• Forward assignment phase: select an element from the
domain of each variable going left to right. We are guaranteed
that there will be a valid assignment because each arc is arc
consistent.
4/25/2023 Dpaertment of CSE ( AL & ML) 22
Local search methods
• Improve what you have until you can’t make it better.
• Generally much faster and more memory efficient
than back-tracking search (but not necessarily
complete).
4/25/2023 Dpaertment of CSE ( AL & ML) 23
Local search for CSP’s
• Start with an initial assignment of variables to values
• Allow states with unsatisfied constraints
• Attempt to improve states by reassigning variable
values.
4/25/2023 Dpaertment of CSE ( AL & ML) 24
Local search for CSP’s
Hill-climbing search:
• In each iteration, randomly select any conflicted variable
and choose value that violates the fewest constraints
• I.e., attempt to greedily minimize total number of violated
constraints h = number of conflicts.
• Problem: local minima h = 1
4/25/2023 Dpaertment of CSE ( AL & ML) 25
Hill climbing state space diagram
4/25/2023 Dpaertment of CSE ( AL & ML) 26
Topics to be covered in next
session 20
• Propositional Logic
Thank you!!!
4/25/2023 Dpaertment of CSE ( AL & ML) 27

AI_Session 19 Backtracking CSP.pptx

  • 1.
    ARTIFICAL INTELLIGENCE (R18 III(IISem)) Department of computer science and engineering (AI/ML) Session 19 by Asst.Prof.M.Gokilavani VITS 4/25/2023 Dpaertment of CSE ( AL & ML) 1
  • 2.
    TEXTBOOK: • Artificial IntelligenceA modern Approach, Third Edition, Stuart Russell and Peter Norvig, Pearson Education. REFERENCES: • Artificial Intelligence, 3rd Edn, E. Rich and K.Knight (TMH). • Artificial Intelligence, 3rd Edn, Patrick Henny Winston, Pearson Education. • Artificial Intelligence, Shivani Goel, Pearson Education. • Artificial Intelligence and Expert Systems- Patterson, Pearson Education. 4/25/2023 Dpaertment of CSE ( AL & ML) 2
  • 3.
    Topics covered insession 19 • Adversarial Search: Games, Optimal Decisions in Games, Alpha– Beta Pruning, Imperfect Real-Time Decisions. • Constraint Satisfaction Problems: Defining Constraint Satisfaction Problems, Constraint Propagation, Backtracking Search for CSPs, Local Search for CSPs, The Structure of Problems. • Propositional Logic: Knowledge-Based Agents, The Wumpus World, Logic, Propositional Logic, Propositional Theorem Proving: Inference and proofs, Proof by resolution, Horn clauses and definite clauses, Forward and backward chaining, Effective Propositional Model Checking, Agents Based on Propositional Logic. 4/25/2023 Dpaertment of CSE ( AL & ML) 3
  • 4.
    Constraint Propagation • Inlocal state-spaces, the choice is only one, i.e., to search for a solution. But in CSP, we have two choices either: – We can search for a solution or – We can perform a special type of inference called constraint propagation. 4/25/2023 4 Dpaertment of CSE ( AL & ML)
  • 5.
    Constraint Propagation • Constraintpropagation is a special type of inference which helps in reducing the legal number of values for the variables. • The idea behind constraint propagation is local consistency. • In local consistency, variables are treated as nodes, and each binary constraint is treated as an arc in the given problem. 4/25/2023 5 Dpaertment of CSE ( AL & ML)
  • 6.
    There are followinglocal consistencies which are discussed below: • Node Consistency: A single variable is said to be node consistent if all the values in the variable’s domain satisfy the unary constraints on the variables. 4/25/2023 6 Dpaertment of CSE ( AL & ML)
  • 7.
    • Arc Consistency:A variable is arc consistent if every value in its domain satisfies the binary constraints of the variables. 4/25/2023 7 Dpaertment of CSE ( AL & ML) Path Consistency: When the evaluation of a set of two variable with respect to a third variable can be extended over another variable, satisfying all the binary constraints. It is similar to arc consistency. k-consistency: This type of consistency is used to define the notion of stronger forms of propagation. Here, we examine the k-consistency of the variables.
  • 8.
    Backtracking Search forCSPs • In CSP’s, variable assignments are commutative For example: [WA = red then NT = green] is the same as [NT =green then WA = red] • We only need to consider assignments to a single variable at each level (i.e., we fix the order of assignments) • Depth-first search for CSPs with single-variable assignments is called backtracking search. 4/25/2023 8 Dpaertment of CSE ( AL & ML)
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
    Backtracking Searching Algorithm 4/25/2023Dpaertment of CSE ( AL & ML) 14
  • 15.
    Problem in ordering 4/25/2023Dpaertment of CSE ( AL & ML) 15 • Ordering – How should we order variables for assignment? – How should we order values from the domains? Need Improving Backtracking Efficiency Ordering
  • 16.
    Improving Backtracking Efficiency Ordering •Ordering – How should we order variables for assignment? – – How should we order values from the domains? Filtering Can we detect inevitable failures early? 4/25/2023 Dpaertment of CSE ( AL & ML) 16
  • 17.
    Early detection offailure 4/25/2023 Dpaertment of CSE ( AL & ML) 17
  • 18.
    Early detection offailure- Forward Checking • Forward checking Keep track of remaining legal values for unassigned variables. • Terminate search when any variable has no legal values. 4/25/2023 Dpaertment of CSE ( AL & ML) 18
  • 19.
  • 20.
  • 21.
    Problem structure • Tasmaniaand the mainland are separate structures. We can solve them independently and then combine their solutions. • More generally, we can decompose the CSP into separate connected components (sub-problems of the CSP). • Then the solution is the union of the sub- problem solutions. This can be much more efficient than solving the entire CSP as one problem. 4/25/2023 Dpaertment of CSE ( AL & ML) 21
  • 22.
    Algorithm for treestructure CSP’s • Choose one variable as root, order variables from root to leaves such that every node's parent precedes it in the ordering. • Backward removal phase: check arc consistency starting from the rightmost node and going backwards. • Forward assignment phase: select an element from the domain of each variable going left to right. We are guaranteed that there will be a valid assignment because each arc is arc consistent. 4/25/2023 Dpaertment of CSE ( AL & ML) 22
  • 23.
    Local search methods •Improve what you have until you can’t make it better. • Generally much faster and more memory efficient than back-tracking search (but not necessarily complete). 4/25/2023 Dpaertment of CSE ( AL & ML) 23
  • 24.
    Local search forCSP’s • Start with an initial assignment of variables to values • Allow states with unsatisfied constraints • Attempt to improve states by reassigning variable values. 4/25/2023 Dpaertment of CSE ( AL & ML) 24
  • 25.
    Local search forCSP’s Hill-climbing search: • In each iteration, randomly select any conflicted variable and choose value that violates the fewest constraints • I.e., attempt to greedily minimize total number of violated constraints h = number of conflicts. • Problem: local minima h = 1 4/25/2023 Dpaertment of CSE ( AL & ML) 25
  • 26.
    Hill climbing statespace diagram 4/25/2023 Dpaertment of CSE ( AL & ML) 26
  • 27.
    Topics to becovered in next session 20 • Propositional Logic Thank you!!! 4/25/2023 Dpaertment of CSE ( AL & ML) 27