40 likes | 163 Vues
This document details the implementation of the Maintaining Arc Consistency (MAC) algorithm, integrated with backtracking for solving Constraint Satisfaction Problems (CSP). Unlike traditional backtracking, MAC utilizes interleaved calls to the AC-3 algorithm to maintain consistency during the search process. The Recursive-Backtracking function is defined to explore variable assignments based on given constraints, while the Min-Conflicts heuristic offers an efficient approach to find solutions by minimizing conflicts in a specified number of steps.
E N D
Maintaining Arc Consistency (MAC) MAC is the same as Back-tracking, but with calls to AC-3 interleaved... function Backtracking-Search(csp) returns solution/failure return Recursive-Backtracking({ }, csp, domains) function Recursive-Backtracking(assignment,csp,domains) returns domains/failure if assignment is complete then return assignment var Select-Unassigned-Variable(Variables[csp], assignment, csp) for each value in Order-Domain-Values(var, assignment, csp) do if value is consistent with assignment given Constraints[csp] then add {var = value} to assignment reduced_domains AC-3(assignment,csp) // check for failure too result Recursive-Backtracking(assignment, csp, reduced_domains) if result failure then return result remove {var = value} from assignment return failure
function Min-Conflicts(csp,max_steps) returns soln/failure current complete, random initial var assignment for i=1 to max_steps do if current is a solution (satisfies all constraints) then return current var randomly chosen conflicted variable val value that minimizes Conflicts(var,val,current,csp) current current {var=val} return failure (or best assignment found)