Constraint Satisfaction Problems
identification problem - a problem in which the agent must identify whether it is a goal state or not, with no regards of how it arrives at that goal
- In identification problems, the goal itself it important, not the path of reaching the goal
- All paths have the same depth, which is the number of variables in the problem
constraint satisfaction problem (CSP) - an identification search problem in which each state must satisfy a number of constraints (limitations) in order to be a valid goal state
- In CSPs, states are partial assignments of variables (i.e. some variables have been assigned values while others have not)
constraint graph - a graph whose nodes represent a CSP's variables and edges represent the constraints between the variables/nodes
Components of a CSP
- variables - a set of $N$ variables ($X_1,...,X_N$) that can each take on a single value from the domain
- domain - a set ${x_1,...,x_d}$ representing all possible values that a CSP variable can take on ($d$ is the size of the domain)
- constraints - restrictions on values of variables, potentially with regard to other variables
- Constraints reduce the domain for certain variables in the problem
- The goal test of a CSP is defined by the constraints
- The goal test is a set of constraints specifying allowable combinations of values for subsets of variables
- The goal found if all constraints are satisfied
- Types of constraints
- unary constraint - a constraint that involves only a single variable in the CSP
- Unary constraints are not represented in constraint graphs, but instead are simply used to prune the domain of the variable they constrain when necessary
- binary constraint - a constraint that involves just 2 variables
- Binary constraints are represented as traditional graph edges in the constraint graph
- higher-order constraint - a constraint involving more than 2 variables
- Higher-order constraints can be represented as multiple graph edges on a constraint graph
Solving CSPs
- Note: using standard search (e.g. DFS, BFS, etc.) on a CSP takes too long to find a solution
- Backtracking search
- backtracking search - a search algorithm that increases the speed of the search on a CSP by "undoing" a bad assignment of variables
- A bad assignemnt of variables is a state in which not all variables cannot be assigned a value
- Backtracking search is essentially an optimized version of DFS: backtracking search = DFS + variable ordering optimization + "fail on violation" optimization
- Variable ordering
- Variable ordering fixes an ordering for variables and selects values for variables in this order
- Only assignments to a single variable needs to be considered at each step (as opposed to needing to consider the different number of ways the variable can take on certain values and the different number of ways certain variables can come after it)
- "Fail on violation"
- "Fail on violation" simply means checking constraints as we go
- When selecting values for a variable, only select values that do not conflict with any previously assigned values. If no such value exists, backtrack and return to the previous variable, changing its value.
- tldr: only consider values which do not conflict with assignments to previous variables
- Optimizations for backtracking search
- forward checking - a naive filtering technique for evaluating the effect of a specific assignment to a variable
- filtering - checks ahead of time whether the domains of unassigned variable can be pruned by removing values that we know will result in backtracking (prevents unnecessary backtracking)
- Given the current partial solution and a candidate assignment to evaluate, forward checking checks whether another variable can take a consistent value
- Whenever a new variable is assigned, forward checking prunes the domains of next (unassigned) variables adjacent to the newly assigned variable in the constraint graph
- arc consistency - a filtering technique that ensures consistent "arcs" between variables
- arc - a directed edge between 2 variables in a CSP
- consistent arc - an arc $X \rightarrow Y$ is consistent if and only if for every value $x$ in the tail variable's domain, there is some value in the head variable's domain which could be assigned without violating a constraint (i.e. an arc is consistent if the tail variable only contains valid value options)
- Ordering of variables and values
- Variable ordering/selection
- minimum remaining variables (MRV) policy - choose whichever unassigned variable has the fewest remaining valid values (i.e. the most constrained variable)
- It is best to assign a value to the most constrained variables sooner because they are likely to run out of possible options and result in backtracking if left unassigned (we will know sooner if an assignment fails)
- Value ordering/selection
- least constraining value (LCV) policy - when selecting which value to assign next to a variable, select the value that prunes the fewest values from the domains of the remaining unassigned variables
Backtracking search implementation
{} is used for variable ordering.
order-domain-values fixes the ordering of the variables and at each step, the variable is selected based on that ordering.
"if value is consistent with assignment" is the "fail on violation" optimization
Forward checking procedure
- Based on the ordering of variables and values that the forward checking technique follows, pick a variable $X_i$ and assign an initial value to it
- Check its neighboring variables $X_j$ (those that share a constraint with $X_i$) and eliminate values from the domains of $X_j$ that break a constraint
- Repeat for the next variable in the variable ordering (and assign the value to that variable based on the value ordering)
- Repeat until we have a solution or until we need to backtrack
- Forward checking backtracks when all domain values have been eliminated from its list of options (if this happens before we have reached the goal state)
- Forward checking finds a solution we have reached a state that satisfies all constraints
Arc consistency procedure
- Check unary constraints to form the initial domains
- The initial domains of all variables are formed after checking the unary constraints (the initial domains are made consistent with the unary constraints)
- Examine all arcs between all pairs of variables and remove the values from the tail node's domain which are not consistent with the constraints between the head and tail variables/nodes
- The algorithm keeps a fringe of arcs that must yet be checked for consistency
- At the start of the algorithm, all possible arcs are on the fringe
- A value from the tail's domain is removed if a binary constraint is not met
- When a value is removed from the tail variable's domain, all arcs where the tail variable is the head is put onto the fringe
- The arcs where the tail variable is the head must be rechecked for consistency
Comments
Post a Comment