Finish CSPs




CS156

Chris Pollett

Oct 1, 2014

Outline

Introduction

Sudoku

Formulating Sudoku as a CSP

Effects of consistency checks on Sudoku

Example Sudoku Board

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