Finish CSPs




CS156

Chris Pollett

Mar 5, 2012

Outline

Introduction

Sudoku

Formulating Sudoku as a CSP

Effects of consistency checks on Sudoku

Example Sudoku Board

Quiz

Which of the following is true?

  1. Any complete assignment is a solution to a CSP.
  2. 1-consistency of a CSP is the same as arc-consistency.
  3. One consistency check for the AllDiff constraint is to see if the number of inputs to Alldiff is more than the number of values in the domains of the variables.

Backtracking Search for CSPs

Backtracking-Search

Here is some pseudo-code for backtracking search:

function Backtracking-Search(csp) returns a solution, or failure
    return Backtrack({},csp)

function Backtrack(assignment, csp) returns a solution, failure
   if(assignment is complete) then return assignment
   var := Select-Unassigned-Variable(csp)
   for each value in Order-Domain-Values(var, assignment, csp) do
        if value is consistent with assignment then
            add {var= value} to assignment
            inferences := INFERENCE(csp, var, value) 
                //this might do AC-3 or the like
            if inferences != failure then
                add inferences to assignment
                result := Backtrack(assignment, csp)
                if result != failure then
                    return result
        remove {var = value} and inferences from assignment
   return failure

Making Backtracking Search More Sophisticated

Performance of backtracking can be improved by focusing on:

Variable and Value Ordering

Interleaving search and Inference

Intelligent Backtracking