foundations of computational agents
The third edition of Artificial Intelligence: foundations of computational agents, Cambridge University Press, 2023 is now available (including full text).
Instead of just having possible worlds satisfy constraints or not, we often have a preference relation over possible worlds, and we want a best possible world according to the preference.
An optimization problem is given
a set of variables, each with an associated domain
an objective function that maps total assignments to real numbers, and
an optimality criterion, which is typically to find a total assignment that minimizes or maximizes the objective function.
The aim is to find a total assignment that is optimal according to the optimality criterion. For concreteness, we assume that the optimality criterion is to minimize the objective function.
A constrained optimization problem is an optimization problem that also has hard constraints specifying which variable assignments are possible. The aim is to find an optimal assignment that satisfies the hard constraints.
A huge literature exists on optimization. There are many techniques for particular forms of constrained optimization problems. For example, linear programming is the class of constrained optimization where the variables are real valued, the objective function is a linear function of the variables, and the hard constraints are linear inequalities. If the problem you are interested in solving falls into one of the classes for which there are more specific algorithms, or can be transformed into one, it is generally better to use those techniques than the more general algorithms presented here.
In a constraint optimization problem, the objective function is factored into a set of soft constraints. A soft constraint has a scope that is a set of variables. The soft constraint is a function from the domains of the variables in its scope into a real number, a cost. A typical optimality criterion is to choose a total assignment that minimizes the sum of the costs of the soft constraints.
Suppose a number of delivery activities must be scheduled, similar to Example 4.9, but, instead of hard constraints, there are preferences on times for the activities. The soft constraints are costs associated with combinations of times. The aim is to find a schedule with the minimum total sum of the costs.
Suppose variables ${A}$, ${C}$, ${D}$, and ${E}$ have domain ${\mathrm{\{}}{\mathrm{1}}{\mathrm{,}}{\mathrm{2}}{\mathrm{\}}}$, and variable ${B}$
has domain ${\mathrm{\{}}{\mathrm{1}}{\mathrm{,}}{\mathrm{2}}{\mathrm{,}}{\mathrm{3}}{\mathrm{\}}}$.
The soft constraints are
${{c}}_{{\mathrm{1}}}$:
${A}$
${B}$
Cost
1
1
5
1
2
2
1
3
2
2
1
0
2
2
4
2
3
3
${{c}}_{{\mathrm{2}}}$:
${B}$
${C}$
Cost
1
1
5
1
2
2
2
1
0
2
2
4
3
1
2
3
2
0
${{c}}_{{\mathrm{3}}}$:
${B}$
${D}$
Cost
1
1
3
1
2
0
2
1
2
2
2
2
3
1
2
3
2
4
Thus, the scope of ${{c}}_{{\mathrm{1}}}$ is ${\mathrm{\{}}{A}{\mathrm{,}}{B}{\mathrm{\}}}$, the scope of ${{c}}_{{\mathrm{2}}}$ is ${\mathrm{\{}}{B}{\mathrm{,}}{C}{\mathrm{\}}}$, and the scope of ${{c}}_{{\mathrm{3}}}$ is ${\mathrm{\{}}{B}{\mathrm{,}}{D}{\mathrm{\}}}$. Suppose there are also constraints ${{c}}_{{\mathrm{4}}}{\mathit{}}{\mathrm{(}}{C}{\mathrm{,}}{E}{\mathrm{)}}$ and ${{c}}_{{\mathrm{5}}}{\mathit{}}{\mathrm{(}}{D}{\mathrm{,}}{E}{\mathrm{)}}$.
Soft constraints can be added pointwise. The sum of two soft constraints is a soft constraint with scope that is the union of their scopes. The cost of any assignment to variables in the scope is the sum of the costs of the constraints being added on that assignment.
Consider functions ${{c}}_{{\mathrm{1}}}$ and ${{c}}_{{\mathrm{2}}}$ in the previous example. ${{c}}_{{\mathrm{1}}}{\mathrm{+}}{{c}}_{{\mathrm{2}}}$
is a function with scope ${\mathrm{\{}}{A}{\mathrm{,}}{B}{\mathrm{,}}{C}{\mathrm{\}}}$, given by
${{c}}_{{\mathrm{1}}}{\mathrm{+}}{{c}}_{{\mathrm{2}}}$:
${A}$
${B}$
${C}$
Cost
1
1
1
10
1
1
2
7
1
2
1
2
…
…
…
…
The second value is computed as follows:
${(}{{c}}_{{1}}{+}{{c}}_{{2}}{)}{(}{A}{=}{1}{,}{B}{=}{1}{,}{C}{=}{2}{)}$ | ${=}{{c}}_{{1}}{(}{A}{=}{1}{,}{B}{=}{1}{)}{+}{{c}}_{{2}}{(}{B}{=}{1}{,}{C}{=}{2}{)}$ | ||
${=}{5}{+}{2}$ | |||
${=}{7}$ |
Hard constraints can be modeled as having a cost of infinity for violating a constraint. As long as the cost of an assignment is finite, it does not violate a hard constraint. An alternative is to use a large number – larger than the sum of the soft constraints could be – as the cost of violating a hard constraint. Then optimization can be used to find a solution with the fewest number of violated hard constraints and, among those, one with the lowest cost.
Optimization problems have one difficulty that goes beyond constraint satisfaction problems. It is difficult to know whether an assignment is optimal. Whereas, for a CSP, an algorithm can check whether an assignment is a solution by just considering the assignment and the constraints, in optimization problems an algorithm can only determine whether an assignment is optimal by comparing it to other assignments.
Many of the methods for solving hard constraints can be extended to optimization problems, as outlined in the following sections.