foundations of computational agents
In many domains, not all possible assignments of values to variables are permissible. A hard constraint, or simply constraint, specifies legal combinations of assignments of values to some of the variables.
A scope is a set of variables. A relation on a scope $S$ is a function from assignments on $S$ to $\{\text{true},\text{false}\}$. That is, it specifies whether each assignment is true or false. A constraint $c$ is a scope $S$ and a relation on $S$. A constraint is said to involve each of the variables in its scope.
A constraint can be evaluated on any assignment that extends its scope. Consider constraint $c$ on $S$. Assignment $A$ on ${S}^{\prime}$, where $S\subseteq {S}^{\prime}$, satisfies $c$ if $A$, restricted to $S$, is mapped to true by the relation. Otherwise, the constraint is violated by the assignment.
A possible world $w$ satisfies a set of constraints if, for every constraint, the values assigned in $w$ to the variables in the scope of the constraint satisfy the constraint. In this case, we say that the possible world is a model of the constraints. That is, a model is a possible world that satisfies all of the constraints.
Constraints are defined either by their intension, in terms of formulas, or by their extension, listing all the assignments that are true. Constraints defined extensionally can be seen as relations of legal assignments as in relational databases.
A unary constraint is a constraint on a single variable (e.g., $B\le 3$). A binary constraint is a constraint over a pair of variables (e.g., $A\le B$). In general, a $k$-ary constraint has a scope of size $k$. For example, $A+B=C$ is a 3-ary (ternary) constraint.
Suppose a robot needs to schedule a set of activities for a manufacturing process, involving casting, milling, drilling, and bolting. Each activity has a set of possible times at which it may start. The robot has to satisfy various constraints arising from prerequisite requirements and resource use limitations. For each activity there is a variable that represents the time that it starts. For example, it could use ${D}$ to represent the start time for the drilling, ${B}$ for the start time of the bolting, and ${C}$ the start time for the casting. Some constraints are that drilling must start before bolting, which translates into the constraint $$. If casting and drilling must not start at the same time, this corresponds to the constraint ${C}{\mathrm{\ne}}{D}$. If bolting must start exactly 3 time units after casting starts this corresponds to the constraint ${B}{\mathrm{=}}{C}{\mathrm{+}}{\mathrm{3}}$.
Consider a constraint on the possible dates for three activities. Let ${A}$, ${B}$, and ${C}$ be variables that represent the date of each activity. Suppose the domain of each variable is ${\mathrm{\{}}{\mathrm{1}}{\mathrm{,}}{\mathrm{2}}{\mathrm{,}}{\mathrm{3}}{\mathrm{,}}{\mathrm{4}}{\mathrm{\}}}$.
A constraint with scope ${\mathrm{\{}}{A}{\mathrm{,}}{B}{\mathrm{,}}{C}{\mathrm{\}}}$ could be described by its intension, using a logical formula to specify the legal assignments, such as
$$ |
where ${\mathrm{\wedge}}$ means and, and ${\mathrm{\neg}}$ means not. This formula says that ${A}$ is on the same date or before ${B}$, and ${B}$ is before day ${\mathrm{3}}$, ${B}$ is before ${C}$, and it cannot be that ${A}$ and ${B}$ are on the same date and ${C}$ is on or before day 3.
This constraint could instead have its relation defined its extension, as a table specifying the legal assignments:
A | B | C |
---|---|---|
2 | 2 | 4 |
1 | 1 | 4 |
1 | 2 | 3 |
1 | 2 | 4 |
The first assignment is ${\mathrm{\{}}{A}{\mathrm{=}}{\mathrm{2}}{\mathrm{,}}{B}{\mathrm{=}}{\mathrm{2}}{\mathrm{,}}{C}{\mathrm{=}}{\mathrm{4}}{\mathrm{\}}}$, which assigns ${A}$ the value 2, ${B}$ the value 2, and ${C}$ the value 4. There are four legal assignments of the variables.
The assignment ${\mathrm{\{}}{A}{\mathrm{=}}{\mathrm{1}}{\mathrm{,}}{B}{\mathrm{=}}{\mathrm{2}}{\mathrm{,}}{C}{\mathrm{=}}{\mathrm{3}}{\mathrm{,}}{D}{\mathrm{=}}{\mathrm{3}}{\mathrm{,}}{E}{\mathrm{=}}{\mathrm{1}}{\mathrm{\}}}$ satisfies this constraint because that assignment restricted to the scope of the relation, namely ${\mathrm{\{}}{A}{\mathrm{=}}{\mathrm{1}}{\mathrm{,}}{B}{\mathrm{=}}{\mathrm{2}}{\mathrm{,}}{C}{\mathrm{=}}{\mathrm{3}}{\mathrm{\}}}$, is one of the legal assignments in the table.
Consider the constraints for the two representations of crossword puzzles of Example 4.3:
For the case in which the domains are words, the constraint is that the letters where a pair of words intersect must be the same.
For the representation in which the domains are the letters, the constraint is that each contiguous sequence of letters must form a legal word.