Presentation is loading. Please wait.

Presentation is loading. Please wait.

Artificial Intelligence

Similar presentations


Presentation on theme: "Artificial Intelligence"— Presentation transcript:

1 Artificial Intelligence
Lecture 13 – Constraint Satisfaction Problems Dr. Muhammad Adnan Hashmi 3 January 2019

2 Outline Constraint Satisfaction Problems (CSP)
Backtracking search for CSPs Local search for CSPs

3 Constraint Satisfaction Problems (CSPs)
Standard search problem: State is a "black box“ – any data structure that supports a successor function, heuristic function, and goal test CSP: 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 Simple example of a formal representation language Allows useful general-purpose algorithms with more power than standard search algorithms

4 Example: Map-Coloring
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)}

5 Example: Map-Coloring
Solutions are complete and consistent assignments, e.g., WA = red, NT = green,Q = red,NSW = green,V = red,SA = blue,T = green Complete: all variables must be assigned Consistent: no constraints should be violated.

6 Constraint graph Binary CSP: Each constraint relates two variables
Constraint graph: Nodes are variables, arcs are constraints

7 Varieties of CSPs Discrete variables
Finite domains: n variables, domain size d  O(dn) complete assignments e.g., Boolean CSPs for NP-complete problems Infinite domains: integers, strings, etc. E.g., job scheduling: start/end days for each job Rather than enumerating all possible variable combination, we need a constraint language, e.g., StartJob1 + 5 ≤ StartJob3 Continuous variables: very common in real-world E.g., start/end times for Hubble Space Telescope observations Linear constraints (inequalities) are solvable in polynomial time by linear programming

8 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 E.g., crypt-arithmetic column constraints

9 Crypt-Arithmetic A mathematical puzzle in which each letter represents a digit (for example, if X=3, then XX=33) The object is to find the value of each letter Constraints: No two letters represent the same digit (If X=3, Y cannot be 3). And the first letter cannot be 0 (Given the value ZW, Z cannot be 0). They can be quite challenging, often involving many steps Solver Program: 3 January 2019

10 Example: Crypt-arithmetic
Variables: F T U W R O X1 X2 X3 Domains: {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 Constraint Hypergraph X1 X2 X3 are auxiliary variables

11 Important Result Every higher-order, finite-domain constraint can be broken down into a set of binary constraints, if enough auxiliary variables are introduced E.g., F ≠ T, F ≠ U etc.

12 Real-world CSPs Teacher Assignment problems, e.g., who teaches what class Timetabling problems, e.g., which class is offered when and where? Transportation scheduling, e.g., which transport should be scheduled for delivery at a given location Notice that many real-world problems involve real-valued variables

13 Standard Search Formulation (incremental)
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: this fails if there are no legal assignments Goal test: the current assignment is complete and consistent This is the same for all CSPs Every solution appears at depth n with n variables  use depth-first search Path is irrelevant, so we can also use complete-state formulation.

14 Backtracking search Variable assignments are commutative}, i.e., [ WA = red then NT = green ] same as [ NT = green then WA = red ] We only need to consider assignments to a single variable at each node Otherwise, we will have n! dn leaves, rather than only dn leaves (which are the total no. of complete assignments) 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

15 Backtracking search

16 Backtracking example

17 Backtracking example

18 Backtracking example

19 Backtracking example

20 Improving backtracking efficiency
Pure backtracking is typically inefficient, because it is an uninformed algorithm We can think of heuristics but instead, we use three 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?

21 Minimum Remaining Value (MRV)
MRV selects the next variable to assign: That variable which has the fewest number of legal values remaining for assignment, i.e., we select the variable with minimum MRV Legal values: those which satisfy the respective constraint(s) In this step, we could have assigned color to this province as well, i.e., either red or blue. Here, MRV=2 However, this province has the MRV=1, i.e., only blue can be assigned to it. So, we color it.

22 Degree Heuristic (DH) MRV doesn’t tell which variable to select at the beginning: Can be done using DH DH: At each step, choose the variable with the maximum degree, i.e., the maximum no. of constraints with the remaining variables The good thing is that there won’t be any tie. 2 constraints Initially, we color this: degree = 5 (variable with max degree) 3 constraints

23 Least Constraining Value (LCV)
MRV and DH concentrate on choosing variables LCV is concerned with choosing the values of variables Given a variable, choose its LCV: the one that rules out the fewest values in the remaining variables The one that imposes minimum constraints on the remaining variables. SA SA can’t be assigned any color now.

24 Questions 3 January 2019


Download ppt "Artificial Intelligence"

Similar presentations


Ads by Google