Outline
- Constraint Satisfaction Problems
- CSP Variants
- In-Class Exercise
What is a Constraint Satisfaction Problem?
- So far when discussing search, we have looked at environments where the states were indivisible,
that is, atomic.
- We now consider states which are allowed to have field variables. i.e., we consider environments
with factored representations.
- For factored representations, we say a state solves the problem when each field variable
satisfies all the constraints on that variable.
- A problem described in this way is called a constraint satisfaction problems, or CSP.
- Sometimes using a factored representation allows one to eliminate large portions of the search space all
at once by identifying variable/value combinations that violate the constraints.
CSP Definition
- A constraint satisfaction problem consists of three components `X`, `D`, and `C` where:
- `X` is a set of variables, `{X_1, ... X_n}`
- `D` is a set of domains, `{D_1, ..., D_n}`, one for each variable.
- `C` is a set of constraints that specify allowable combinations of values.
- Each domain `D` consists of a set of allowable values, `{v_1, ..., v_k}` for `X_i`.
- Each constraint in `C` consists of a pair `langle scope, rel rangle`, where `scope` is a tuple of variables that
participate in the constraint and `rel` is a relation that those variables can take on.
Definition Example
- Suppose `X = {X_1, X_2}` and `D={{A,B}, {A,B}}`.
- We would like to have the constraint that `X_1` and `X_2` take different values.
- To do this we could set `C = {langle (X_1, X_2), rel rangle}` where `rel` is the relation
`{ (A,B), (B,A) }`.
- It is often convenient to use common abbreviations for well-known relations.
- I.e., we could write `C` as `{langle (X_1, X_2), X_1 ne X_2 rangle}`.
- Notice the variables themselves are obvious from the relation, so we often abbreviate
`langle (X_1, X_2), X_1 ne X_2 rangle` further as just `X_1 ne X_2`.
A CSP Solution
- To solve a CSP we need to define a state space and the notion of a solution.
- Each state in a CSP is defined by an assignment of values to some or all of the variables,
`{X_i = v_i, X_j = v_j, ...}`.
- An assignment which does not violate any constraints is called a consistent or legal assignment.
- A complete assignment is one in which every variable is assigned; an assignment which only assigns values
to some of the variables is called a partial assignment.
- A solution to a CSP is a complete, consistent assignment.
Example: Map Coloring
- Australia consists of seven states and territories. Let's call a state or territory, a region.
- We are given the task of coloring each region red, green, or blue on a map in such a way that no neighboring regions
have the same color.
- For this problem, `X = {WA, NT, Q, NSW, V, SA, T}`
- The domain `D_i` for each of these variables is `{red, green, blue}`.
- `C = {SA ne WA, SA ne NT, SA ne Q, SA ne NW, SA ne V, WA ne NT, NT ne Q, Q ne NSW, NSW ne V}`
- An example solution to the problem might be:
`{WA = red, NT = green, Q = red, NSW = green, V = red, SA = blue, T = red}`.
Remarks
- There exist general-purpose CSP-solving systems. So if you can formulate your program as a CSP, you can
just run one of these systems on your problem to get an answer.
- We could have formulated the map problem as a state-space search problem.
- However, in the CSP formulation we can eliminate large portions of the search space more quickly.
- For example, we might start with the empty map, then choose `SA = blue`, due to the constraints, we can conclude immediately
that none of the five neighbors can take on the value blue.
- On the other hand a state space searcher would have `3^5` assignments to the neighbors, rather than the reduced `2^5`
we get because of this constraint.
In-Class Exercises
- One of the most vexing social concerns in North America is not whether you sit on a couch, sofa, or chesterfield to watch TV, but rather whether a carbonated beverage should be called pop, soda, or coke.
- Here is a map of pop, soda, coke usage.
- It has eight distinct regions where one term dominates over the others.
- Come up with your own (reasonable) name for each region and then express the map coloring problem for your map with your names as a CSP.
- Please post your solution to the Sep 28 In-Class Exercise Thread.
Example: Job-shop Scheduling
- Factories have the job of scheduling a day's worth of jobs, subject to various constraints.
- Consider the problem of scheduling the assembly of a car.
- The whole job is composed of tasks, and each task can be modeled as a variable, the value of each variable
is the time the task starts, expressed as an integer number of minutes.
- Constraints for job scheduling express things like one task must occur before another task (put wheel on
before hubcap), and that certain jobs take a certain amount of time to complete.
- As a concrete example of job scheduling, our variables `X` might be:
`X = {Axl\e_F, Axl\e_B, Wheel_(RF), Wheel_(LF), Wheel_(RB), Wheel_(LB), Nuts_(RF),`
`quad quad Nuts_(LF), Nuts_(RB), Nuts_(LB), Cap_(RF), Cap_(LF), Cap_(RB), Cap_(LB), Inspect}`
- Next we model the precedence constraints between tasks. These are constraints of the form:
`T_1 + d_1 le T_2`
indicating that `T_1` must be done before `T_2` and takes at least `d_1` time.
- For our example, the precedence constraints look like:
`Axl\e_F + 10 le Wheel_(RF), quad quad Axl\e_F + 10 le Wheel_(LF)`
`Axl\e_B + 10 le Wheel_(RB), quad quad Axl\e_B + 10 le Wheel_(LB)`
`Wheel_(RF) +1 le Nuts_(RF), quad quad Nuts_(RF) + 2 le Cap_(RF)`
`Wheel_(LF) +1 le Nuts_(LF), quad quad Nuts_(LF) + 2 le Cap_(LF)`
`Wheel_(RB) +1 le Nuts_(RB), quad quad Nuts_(RB) + 2 le Cap_(RB)`
`Wheel_(LB) +1 le Nuts_(LB), quad quad Nuts_(LB) + 2 le Cap_(LB)`
More Job-shop scheduling
- Suppose we had four workers to install wheels, but they have to share one tool that puts the axle in place.
- We need a disjunctive constraint to say `Axl\e_F` and `Axl\e_B` must not overlap in time; either one
come first or the other does:
`(Axl\e_F + 10 le Axl\e_B) or (Axl\e_B + 10 le Axl\e_F)`
- We also might need to assert that the inspection comes last and takes 3 minutes.
- To do this for every variable except Inspect we add a constraint of the form `X +d_X le Inspect`.
- As final constraint, we might have the requirement that the whole assembly be done in 30 minutes.
- We can achieve this by limiting the domain of all the variables to:
`D_i = {1,2,3, ...27}.`
Variations on the CSP Formalism
- The simplest kind of CSP variables have discrete, finite domains.
- Map-coloring and job-scheduling with time limits are both of this kind.
- The 8-queens problem can be formulated in this way where the variables are `Q_1, ... Q_8` which
range over the domains `D_i = {1,...,8}`, the position for a given queen.
- A discrete domain can be infinite, for example, it might be the integers.
- In such cases, a constraint language such as `T_1 + d le T_2` must be used to understand constraint without
have to enumerate the set of pairs of allowable values `(T_1, T_2)`.
- There are special solution algorithms for linear constraints on integers, but the book doesn't discuss them (look
up ellipsoid method).
- The situation where the domain is the integers and the constraints are nonlinear can be shown to be undecidable.
- If we take the domains to be an complete, totally-ordered field such as the reals, the domain is said continuous.
- Continuous CSPs with linear constraints are known as linear programming problems.