search and backtracking (slides5) Flashcards
CSP Standard Incremental Search Formulation (SISF)
- Initial state
- Successor function
- State
- Goal test
same for all CSP’s
every soln appears at depth n with n variables
-depth first search used
path is irrelevant, so complete state formulation is used
for CSP with n variables of domain size d:
b=(n-l)d at depth l, hence n! * d leaves
SISF initial state
the empty assignment{}
SISF successor function
assign a value to an unassigned variable that does not conflict with the current assignment
-fail if no legal assignments
SISF state
partial assignment
SISF goal test
the current assignment is complete
Backtracking search
- variable assignments are commutative
- only need to consider assignments to a single variable at each node
- -b = d and there are d^n leaves
- 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 approx. 25
commutative
ex:
[WA = red then NT = green] same as [NT = green then WA = red]
Backtracking search implementation
function Backtracking search(csp) returns a solution or failure return Recursive-Backtracking(assignments, csp) Function Recursive-backtracking returns a solution or failure -if assignment is complete then return assignment -var<-- Recursive-Backtracking(assignment, csp) ---if result != failure then return result ---remove {var = value} from assignment --return failure
minimum remaining values (MRV) heuristic
improves backtracking efficiency
general purpose
Most constrained variable: FIRST FAIL
Choose the variable with the fewest legal values (i.e. the variable with the least number of successors)
-for tiebreakers, choose the variable with the most constraints on remaining variables
-combining with choosing of the least constraining
Least constraining value
given a variable, choose the least constraining value to SUCCEED FIRST
-choose the one that rules out the fewest values in the remaining
cons of backtracking
thrashing
redundant work
late detection of conflict
backtracking thrashing
throws away the reason of conflict
Ex: A,B,C,D.E:: 1..10 A>E
-BT tries all the assignments for BCD before finding that A != 1
-soln: backjumping (jump to the source of failure)
backtracking redundant work
unnecessary constraint checks are repeated
ex: A,B,C,D,E:: 1..10, B+8<D, C=5*E
- when assigning C,E the values 1,…,9 are repeatedly checked for D
- Soln: rememember (no-)good assignments
backtracking late detection of conflict
- constraint violation is discovered only when values for all variables in constraints are known
- Example: A,B,C,D,E::1..10, A=3*E
- -the fact that A>2 is discovered when labeling E
- -Soln: forward checking(forward check of constraints)