Presentation is loading. Please wait.

Presentation is loading. Please wait.

Constraint Satisfaction

Similar presentations


Presentation on theme: "Constraint Satisfaction"— Presentation transcript:

1 Constraint Satisfaction
R & N Chapter 5

2 Constraint Satisfaction – Early Use
From From

3 The Waltz Algorithm

4 More on Waltz Algorithm
The constraints come from the fact that a line must have the same label at both ends.

5 Crossword Puzzles

6 Latin Squares Using only the numbers 1, 2, 3, and 4, arrange four sets of these numbers into a four-by-four array so that no column or row contains the same two numbers. The result is known as a Latin square. Here are two examples of Latin squares of order 4: Such arrays have proved useful for a variety of purposes. Suppose, for example, you wanted to check the resistance to wear of four brands of automobile tires. Putting one tire of each brand on the four wheels of one car isn't good enough because the amount of wear may differ in those four positions and vary from week to week owing to different weather conditions. A better experiment would be to use four tires for four weeks and to interchange the four positions from week to week according to a four-by-four Latin square.

7 Satisfiability (P  Q  S)  (A   Q  B)  (P   B  C) 
( A  B  C)  (Q  A  C) Example applications: 3-SAT: all disjuncts contain exactly three terms The general problem is NP-hard. Examples:

8 Real Examples Scheduling What else?

9 Algorithms for CSPs Branching
State space: usually incremental formulation Straight line State space: usually complete-state formulation

10 Cryptarithmetic SEND +MORE PEAS description: MONEY
State space when formulated as a CSP: variables, domain, constraints Incremental state space formulation: Complete state formulation: Performance measure, Environment, Actuators, Sensors Note that in the state space description, probably only the final answer may be visible to the world. So the only actuator in the PEAS description is “solve”. Need one variable for each letter plus one for each carry digit. Constraints on the next slide

11 Cryptarithmetic SEND Representing the constraints: +MORE As formulas:
MONEY Representing the constraints: As formulas: As a graph: Using special constraints: Alldiff Formulas: D + E = Y + 10*C1 Graph: Use one square for each constraint. One circle for each variable. Connect each square to each circle that participates in it. See R & N Figure 5.2

12 Cryptarithmetic – Best First Search
SEND +MORE MONEY M = 1 M = 2 M = 2 Does this make sense? Should we ever be following competing paths at once? If we did do this, what heuristic function would we use? Suppose we used the complete state formulation (next slide)? Then could we do this? It turns out that a straight line algorithm will perform so well, using a complete state formulation, that it isn’t worth it.

13 Cryptarithmetic – Best First Search
SEND +MORE MONEY M = 1 M = 2 M = 2 M = 1 S = 2 O =3 … Does this make sense? Should we ever be following competing paths at once? If we did do this, what heuristic function would we use? Suppose we used the complete state formulation? Then could we do this? It turns out that a straight line algorithm will perform so well, using a complete state formulation, that it isn’t worth it.

14 Cryptarithmetic – Branching Algorithms
Backtracking Minimum remaining values Degree heuristic Least-constraining value SEND +MORE MONEY Minimum remaining values: Choose the variable with the fewest remaining legal values Degree heuristic: Select the variable that is involved in the largest number of constraints with other, unassigned variables. The idea is that if this is a bad plan, we’ll discover it soon. Use as a tie breaker for Minimum remaining values. Least-constraining value: prefer the value that rules out the fewest choices for related variables. Tries to leave the most flexibility. A big win if there are lots of solutions and we only care about finding one. Why do we choose the most constrained variable but the least constraining value? Because we must consider every variable. But if we’re lucky, we won’t consider every value. M = 1 M = 2 M = 2

15 Cryptarithmetic – Constraint Propagation
Forward checking: After assigning a value to a variable X, look at all the variables connected to X and prune inconsistent values. Constraint propagation using arc consistency: The tradeoff: how much time to spend propagating vs. searching. How much do we do before we even start? In general, will we be able to eliminate combinatorial explosion? No. SEND +MORE MONEY

16 Backtracking – Chronological vs. Dependency Directed

17 Straight-Line Algorithms: Min-Conflicts
function Min-Conflicts(csp, max_steps) returns a solution or failure inputs: csp, a constraint satisfaction problem max_steps, the number of steps allowed before giving up current  an initial assignment for csp for i = 1 to max_steps do if current is a solution for csp then return current var  a randomly chosen, conflicted variable from Variables[csp] value  the value v for var that minimizes Conflicts(var, v, current, csp) set var = value in current return failure Remember the problem we had with the 4 Queens problem when we tried hill climbing? We got stuck at a local maximum. Will Min-Conflicts have this same problem? Could we restate the 4 queens problem as a CSP and use this?

18 Do Straight-Line Algorithms Work?
Does Min-Conflicts work? From:

19 Do Straight-Line Algorithms Work?
You’ll see this same phenomenon in the Latin squares problem on the homework.

20 Another Win of Straight Line Algorithms
They can be used to perturb a solution that ceases to be correct: Most scheduling problems


Download ppt "Constraint Satisfaction"

Similar presentations


Ads by Google