Optimisation for Artificial Intelligence, a 4-day course
« Previous | Up ↑ | Next »
A constraint satisfaction problem consists of:
The objective is to find an instantiation of values to variables within their domains, which satisfies all the expressed constraints.
A problem of two variables $x, y \in {0, 1, 2}$ subject to the constraint $x \neq y$ is a constraint satisfaction problem.
You may recall the mathematical theorem stating that at most four colours are necessary for a proper colouring of such maps. We can use $n=4$ for a start (upper bound) and choose to decrease $n$ until no solution is found.
A more complicated—albeit general—approach would be to add an minimising criterion (optimisation) on the total number of colours used in a satisfying colouring.
Constraints as we state them do not necessarily apply to all variables which we use to define the problem.
Each constraint is associated with:
A common resolution process implements a depth-first search algorithm in a tree that is built on the fly:
In the worst case, the tree is of an exponential size: efficient algorithms try to prune sub-trees as early as possible in the depth-first search process.
The basic backtracking algorithm we implemented on the toy problem shows several issues:
A basic implementation of constraint propagation consists of maintaining arc-consistency, i.e. pruning the domains of variables which are not yet assigned but linked to assigned variables through binary constraints.
We can illustrate the benefits of this forward-checking approach with the 8-queen problem. When the first (red) queen is placed, we prune the domain of all the other queens (red dots).
Then, instead of trying position 1 and 2, the second (green) queen is directly placed on the first value of its subsequent domain, i.e. position 3.
When the third (blue) queen is placed, the domain of the sixth queen is reduced a single value (i.e. position 4);
however, the placement of the fourth (violet) queen eliminates all values of the domain of this queen. A backtrack can be triggered at that point.
Note that with this arc-consistency technique, the first backtrack occurs for instance $(1,3,5,2,\cdot,\cdot,\cdot,\cdot)$. Without this optimisation, we would have already backtracked 7 times before reaching this partial instantiation, and would still need to make several attempts/backtracks for queens #5 and #6 before realising they lead to no solution.
There are many algorithms designed to maintain arc-consistency and detect irrelevant sub-trees as soon as possible.
Consider the n-queen problem. A chessboard that is rotated by 90°, 180° or 270° yields queens positions that are different yet equivalent.
If the former chessboard is a solution to our problem, the latter also is. Conversely, if the former violates any constraint, the latter does so as well. A mirrored chessboard follows the same logics.
Formally speaking, a symmetry may be a permutation on the variables ($q_1 \rightleftharpoons q_4$) and/or on the values ($1 \rightleftharpoons 4$) of the problem.
There are several ways to exploit the symmetries of a problem:
reformulate a problem into a simpler one without symmetries. The tree to be searched is of a smaller size than the symmetrical one, leading to significantly better performance.
As a matter of fact, it is important to find a good balance when writing models: avoid symmetries yet still be readable.
add constraints to the problem so as to break the symmetries. The constraints may be added statically (before the search) or dynamically (during the search by the solver).
Tip: when several variables $x_i$ can be swapped in a problem, consider constraining them with an ordering: $x_1 \leq x_2 \leq \cdots x_n$.
the solver may dynamically use symmetry information during search: if the depth-first search process hits a partial instantiation that is symmetrical to an instantiation which already triggered a backtrack, then it is of no use to go deeper: the solver backtracks.
The bottom line when considering symmetries is to only try to exploit them if detecting them costs less than the speedup you can get from exploiting them.
« Previous | Up ↑ | Next »