foundations of computational agents
Chapter 4 shows how to reason with constraints. Logical formulas provide a concise form of constraints with structure that can be exploited.
There are a number of reasons for using propositions for specifying constraints and queries:
It is often more concise and readable to give a logical statement about the relationship among some variables than to use an extensional representation.
The form of the knowledge can be exploited to make reasoning more efficient.
They are modular, so small changes to the problem result in small changes to the knowledge base. This also means that a knowledge base is easier to debug than other representations.
The kind of queries may be richer than single assignments of values to variables.
This language can be extended to reason about individuals (things, entities) and relations; see Chapter 15.
The class of propositional satisfiability or SAT problems have
Boolean variable. A Boolean variable is a variable with domain $\{true,false\}$. If $X$ is a Boolean variable, $X=true$ is written as its lower-case equivalent, $x$, and $X=false$ as $\neg x$.
For example, the proposition $happy$ means Boolean variable $Happy$ is true ($Happy=true$), and $\neg happy$ means $Happy=false$.
Clausal constraints. A clause is an expression of the form ${l}_{1}\vee {l}_{2}\vee \mathrm{\cdots}\vee {l}_{k}$, where each ${l}_{i}$ is a literal. A literal is an atom or the negation of an atom; thus a literal is an assignment of a value to a Boolean variable. A clause is true in an interpretation if and only if at least one of the literals that make up the clause is true in that interpretation.
If $\neg a$ appears in a clause, the atom $a$ is said to appear negatively in the clause. If $a$ appears unnegated in a clause, it is said to appear positively in a clause.
In terms of the propositional calculus, a set of clauses is a restricted form of logical formula. Any propositional formula can be converted into clausal form. A total assignment corresponds to an interpretation.
In terms of constraints, a clause is a constraint on a set of Boolean variables that rules out one of the assignments of the literals in the clause. The clause ${l}_{1}\vee {l}_{2}\vee \mathrm{\cdots}\vee {l}_{k}$ corresponds to the statement $\neg (\neg {l}_{1}\wedge \neg {l}_{2}\wedge \mathrm{\cdots}\wedge \neg {l}_{k})$, which says that not all of the ${l}_{i}$ are false.
The clause $happy\vee sad\vee \neg living$ is a constraint among the variables $Happy$, $Sad$, and $Living$, which is true if $Happy$ has value $true$, $Sad$ has value $true$, or $Living$ has value $false$. The atoms $happy$ and $sad$ appear positively in the clause, and $living$ appears negatively in the clause.
The assignment $\neg happy$, $\neg sad$, $living$ violates the constraint of clause $happy\vee sad\vee \neg living$. It is the only assignment of these three variables that violates this clause.
It is possible to convert any finite constraint satisfaction problem (CSP) into a propositional satisfiable problem:
A variable $Y$ with domain $\{{v}_{1},\mathrm{\dots},{v}_{k}\}$ can be converted into $k$ Boolean variables $\{{Y}_{1},\mathrm{\dots},{Y}_{k}\}$, where ${Y}_{i}$ is true when $Y$ has value ${v}_{i}$ and is false otherwise. Each ${Y}_{i}$ is called an indicator variable. Thus, $k$ atoms, ${y}_{1},\mathrm{\dots},{y}_{k}$, are used to represent the CSP variable.
There are constraints that specify that ${y}_{i}$ and ${y}_{j}$ cannot both be true when $i\ne j$, namely the clause $\neg {y}_{i}\vee \neg {y}_{j}$ for $$. There is also a constraint that one of the ${y}_{i}$ must be true, namely the clause ${y}_{1}\vee \mathrm{\cdots}\vee {y}_{k}$.
To translate the constraints, notice that $\neg {x}_{1}\vee \mathrm{\cdots}\vee \neg {x}_{k}$ is equivalent to $\neg ({x}_{1}\wedge \mathrm{\cdots}\wedge {x}_{k})$ for any atoms ${x}_{1},\mathrm{\dots},{x}_{k}$. One way to represent a constraint is to use a clause for each assignment of values that violates the constraint. Thus, for example, the clause $\neg {x}_{5}\vee \neg {y}_{7}$ represents that $X={v}_{5}$ and $Y={v}_{7}$ is a combination that violates a constraint.
Often we can use many fewer clauses than by applying this naively.
Consider two variables $A$ and $B$ each with domain $\{1,2,3,4\}$. For the variable $A$, construct four Boolean variables ${a}_{1}$, ${a}_{2}$, ${a}_{3}$, and ${a}_{4}$, where ${a}_{1}$ is true just when $A=\mathrm{\hspace{0.17em}1}$, ${a}_{2}$ is true just when $A=\mathrm{\hspace{0.17em}2}$, etc. Variables ${a}_{1}$, ${a}_{2}$, ${a}_{3}$, and ${a}_{4}$ are disjoint and covering which leads to the seven clauses
$\neg {a}_{1}\vee \neg {a}_{2},\neg {a}_{1}\vee \neg {a}_{3},\neg {a}_{1}\vee \neg {a}_{4},\neg {a}_{2}\vee \neg {a}_{3},\neg {a}_{2}\vee \neg {a}_{4},\neg {a}_{3}\vee \neg {a}_{4},$ | ||
${a}_{1}\vee {a}_{2}\vee {a}_{3}\vee {a}_{4}.$ |
Similarly for $B$.
The constraint $$ implies that ${a}_{4}$ is false, ${b}_{1}$ is false, and the pairs that violate the constraint are also false, which gives the five clauses
$\neg {a}_{4},\neg {b}_{1},\neg {a}_{2}\vee \neg {b}_{2},\neg {a}_{3}\vee \neg {b}_{3},\neg {a}_{3}\vee \neg {b}_{2}.$ |
Note that you don’t need the clause $\neg {a}_{1}\vee \neg {b}_{1}$ because this is implied by $\neg {b}_{1}$.
Consistency algorithms can be made more efficient for propositional satisfiability problems than for general CSPs. When there are only two values, pruning a value from a domain is equivalent to assigning the opposite value. Thus, if $X$ has domain $\{true,false\}$, pruning $true$ from the domain of $X$ is the same as assigning $X$ to have value $false$.
Arc consistency can be used to prune the set of values and the set of constraints. Assigning a value to a Boolean variable can simplify the set of constraints:
If $X$ is assigned $true$, all of the clauses with $X=true$ become redundant; they are automatically satisfied. These clauses can be removed from consideration. Similarly, if $X$ is assigned $false$, clauses containing $X=false$ can be removed.
If $X$ is assigned $true$, any clause with $X=false$ can be simplified by removing $X=false$ from the clause. Similarly, if $X$ is assigned $false$, then $X=true$ can be removed from any clause it appears in. This step is called unit resolution.
If, after pruning the clauses, there is a clause that contains just one assignment, $Y=v$, the other value can be removed from the domain of $Y$. This is a form of arc consistency. If all of the assignments are removed from a clause, the constraints are unsatisfiable.
Consider the clause $\neg x\vee y\vee \neg z$. If $X$ is assigned to $true$, the clause can be simplified to $y\vee \neg z$. If $Y$ is then assigned to $false$, the clause can be simplified to $\neg z$. Thus, $true$ can be pruned from the domain of $Z$.
If, instead, $X$ is assigned to $false$, the clause can be removed.
If a variable has the same value in all remaining clauses, and the algorithm must only find one model, it can assign that value to that variable. For example, if variable $Y$ only appears as $Y=true$ (i.e., $\neg y$ is not in any clause), then $Y$ can be assigned the value $true$. That assignment does not remove all of the models; it only simplifies the problem because the set of clauses remaining after setting $Y=true$ is a subset of the clauses that would remain if $Y$ were assigned the value $false$. A variable that only has one value in all of the clauses is called a pure literal.
Pruning the domains and constraints, domain splitting, and assigning pure literals is the Davis–Putnam–Logemann–Loveland (DPLL) algorithm. It is a very efficient algorithm, as long as the data structures are indexed to carry out these tasks efficiently.
Stochastic local search can be faster for CSPs in the form of propositional satisfiability problems than for general CSPs, for the following reasons:
Because only one alternative value exists for each assignment to a variable, the algorithm does not have to search through the alternative values.
Changing any value in an unsatisfied clause makes the clause satisfied. As a result, it is easy to satisfy a clause, but this may make other clauses unsatisfied.
If a variable is changed to be true, all of the clauses where it appears positively become satisfied, and only clauses where it appears negatively can become unsatisfied. Conversely, if a variable is changed to be false, all of the clauses where it appears negatively become satisfied, and only those clauses where it appears positively can become unsatisfied. This enables fast indexing of clauses.
The search space is expanded. In particular, before a solution has been found, more than one of the indicator variables for a variable $Y$ could be true (which corresponds to $Y$ having multiple values) or all of the indicator variables could be false (which corresponds to $Y$ having no values). This can mean that some assignments that were local minima in the original problem may not be local minima in the new representation.
Satisfiability has been studied much more extensively than most other types of CSPs and more efficient solvers exist because more of the space of potential algorithms has been explored by researchers.
Whether converting a particular CSP to a satisfiability problem makes search performance better is an empirical question, depending on the problem and the tools available.