Uploaded by Guru Chandra

AI Module 4

advertisement
ECS 302: ARTIFICIAL INTELLIGENCE
LECTURE NOTES
LECTURE
NOTES–UNIT IV
INFERENCE IN
FIRST-ORDER
LOGIC
ECS302
ARTIFICIAL
INTELLIGENCE
3/4 B.Tech [
]
DEPARTMENT OF
CSE,GIT,GU
ECS 302: ARTIFICIAL INTELLIGENCE
LECTURE NOTES
Module IV Lecture Notes [Inference in First-Order Logic]
Syllabus
Knowledge and Reasoning: Inference in First-Order Logic: Propositional vs first order inference,
unification and lifting, forward chaining, backward chaining, resolution.
1. Propositional Vs First Order Inference
Earlier inference in first order logic is performed with Propositionalization which is a process of
converting the Knowledgebase present in First Order logic into Propositional logic and on that
using any inference mechanisms of propositional logic are used to check inference.
Inference rules for quantifiers:
There are some Inference rules that can be applied to sentences with quantifiers to obtain
sentences without quantifiers. These rules will lead us to make the conversion.
Universal Instantiation (UI):
The rule says that we can infer any sentence obtained by substituting a ground term (a term
without variables) for the variable. Let SUBST (θ) denote the result of applying the substitution θ
to the sentence a. Then the rule is written
For any variable v and ground term g.
For example, there is a sentence in knowledge base stating that all greedy kings are Evils
For the variable x, with the substitutions like {x/John},{x/Richard}the following sentences can be
inferred.
Thus a universally quantified sentence can be replaced by the set of all possible instantiations.
ECS 302: ARTIFICIAL INTELLIGENCE
LECTURE NOTES
Existential Instantiation (EI):
The existential sentence says there is some object satisfying a condition, and the instantiation
process is just giving a name to that object, that name must not already belong to another object.
This new name is called a Skolem constant. Existential Instantiation is a special case of a more
general process called “skolemization”.
For any sentence a, variable v, and constant symbol k that does not appear elsewhere in the
knowledge base,
For example, from the sentence
So, we can infer the sentence
As long as C1 does not appear elsewhere in the knowledge base. Thus an existentially quantified
sentence can be replaced by one instantiation
Elimination of Universal and Existential quantifiers should give new knowledge base which can
be shown to be inferentially equivalent to old in the sense that it is satisfiable exactly when the
original knowledge base is satisfiable.
Reduction to propositional inference:
Once we have rules for inferring non quantified sentences from quantified sentences, it becomes
possible to reduce first-order inference to propositional inference. For example, suppose our
knowledge base contains just the sentences
ECS 302: ARTIFICIAL INTELLIGENCE
LECTURE NOTES
Then we apply UI to the first sentence using all possible ground term substitutions from the
vocabulary of the knowledge base-in this case, {xl John) and {x/Richard). We obtain
We discard the universally quantified sentence. Now, the knowledge base is essentially
propositional if we view the ground atomic sentences-King (John), Greedy (John), and Brother
(Richard, John) as proposition symbols. Therefore, we can apply any of the complete
propositional algorithms to obtain conclusions such as Evil (John).
Disadvantage:
If the knowledge base includes a function symbol, the set of possible ground term substitutions is
infinite. Propositional algorithms will have difficulty with an infinitely large set of sentences.
NOTE:
Entailment for first-order logic is semi decidable which means algorithms exist that say yes to every
entailed sentence, but no algorithm exists that also says no to every non entailed sentence
2. Unification and Lifting
Consider the above discussed example, if we add Siblings (Peter, Sharon) to the knowledge base
then it will be
Removing Universal Quantifier will add new sentences to the knowledge base which are not
necessary for the query Evil (John)?
ECS 302: ARTIFICIAL INTELLIGENCE
LECTURE NOTES
Hence we need to teach the computer to make better inferences. For this purpose Inference rules
were used.
First Order Inference Rule:
The key advantage of lifted inference rules over propositionalization is that they make only those
substitutions which are required to allow particular inferences to proceed.
Generalized Modus Ponens:
If there is some substitution 8 that makes the premise of the implication identical to sentences
already in the knowledge base, then we can assert the conclusion of the implication, after
applying 8. This inference process can be captured as a single inference rule called General ized
Modus Ponens which is a lifted version of Modus Ponens-it raises Modus Ponens from
propositional to first-order logic
For atomic sentences pi, pi ', and q, where there is a substitution θ such that SUBST( θ , pi ) =
SUBST(θ , pi '), for all i,
p1 ', p2 ', …, pn ', (p1 ∧ p2 ∧ … ∧ pn ⇒ q)
SUBST (θ, q)
There are N + 1 premises to this rule, N atomic sentences + one implication.
Applying SUBST (θ, q) yields the conclusion we seek. It is a sound inference rule.
Suppose that instead of knowing Greedy (John) in our example we know that everyone is greedy:
∀y Greedy(y)
We would conclude that Evil(John).
Applying the substitution {x/John, y / John) to the implication premises King ( x ) and Greedy ( x
) and the knowledge base sentences King(John) and Greedy(y) will make them identical. Thus,
we can infer the conclusion of the implication.
ECS 302: ARTIFICIAL INTELLIGENCE
LECTURE NOTES
For our example,
Unification:
It is the process used to find substitutions that make different logical expressions look identical.
Unification is a key component of all first-order Inference algorithms.
UNIFY (p, q) = θ where SUBST (θ, p) = SUBST (θ, q) θ is our unifier value (if one exists).
Ex: “Who does John know?”
UNIFY (Knows (John, x), Knows (John, Jane)) = {x/ Jane}.
UNIFY (Knows (John, x), Knows (y, Bill)) = {x/Bill, y/ John}.
UNIFY (Knows (John, x), Knows (y, Mother(y))) = {x/Bill, y/ John}
UNIFY (Knows (John, x), Knows (x, Elizabeth)) = FAIL
➢ The last unification fails because both use the same variable, X. X can’t equal both John
and Elizabeth. To avoid this change the variable X to Y (or any other value) in Knows(X,
Elizabeth)
Knows(X, Elizabeth) → Knows(Y, Elizabeth)
Still means the same. This is called standardizing apart.
➢ sometimes it is possible for more than one unifier returned:
UNIFY (Knows (John, x), Knows(y, z)) =???
This can return two possible unifications: {y/ John, x/ z} which means Knows (John, z) OR {y/
John, x/ John, z/ John}. For each unifiable pair of expressions there is a single most general
unifier (MGU), In this case it is {y/ John, x/z).
ECS 302: ARTIFICIAL INTELLIGENCE
LECTURE NOTES
An algorithm for computing most general unifiers is shown below.
Figure 2.1 The unification algorithm. The algorithm works by comparing the structures of the inputs,
element by element. The substitution 0 that is the argument to UNIFY is built up along the way and is
used to make sure that later comparisons are consistent with bindings that were established earlier. In a
compound expression, such as F (A, B), the function OP picks out the function symbol F and the function
ARCS picks out the argument list (A, B).
The process is very simple: recursively explore the two expressions simultaneously "side by side,"
building up a unifier along the way, but failing if two corresponding points in the structures do
not match. Occur check step makes sure same variable isn’t used twice.
ECS 302: ARTIFICIAL INTELLIGENCE
LECTURE NOTES
Storage and retrieval
➢ STORE(s) stores a sentence s into the knowledge base
➢ FETCH(s) returns all unifiers such that the query q unifies with some sentence in the
knowledge base.
Easy way to implement these functions is Store all sentences in a long list, browse list one
sentence at a time with UNIFY on an ASK query. But this is inefficient.
To make FETCH more efficient by ensuring that unifications are attempted only with sentences
that have some chance of unifying. (i.e. Knows(John, x) vs. Brother(Richard, John) are not
compatible for unification)
➢ To avoid this, a simple scheme called predicate indexing puts all the Knows facts in one
bucket and all the Brother facts in another.
➢ The buckets can be stored in a hash table for efficient access. Predicate indexing is useful
when there are many predicate symbols but only a few clauses for each symbol.
But if we have many clauses for a given predicate symbol, facts can be stored under multiple
index keys.
For the fact Employs (AIMA.org, Richard), the queries are
Employs (A IMA. org, Richard) Does AIMA.org employ Richard?
Employs (x, Richard) who employs Richard?
Employs (AIMA.org, y) whom does AIMA.org employ?
Employs Y(x), who employs whom?
We can arrange this into a subsumption lattice, as shown below.
Figure 2.2 (a) The subsumption lattice whose lowest node is the sentence Employs (AIMA.org, Richard).
(b) The subsumption lattice for the sentence Employs (John, John).
ECS 302: ARTIFICIAL INTELLIGENCE
LECTURE NOTES
A subsumption lattice has the following properties:
✓ child of any node obtained from its parents by one substitution
✓ the “highest” common descendant of any two nodes is the result of applying their most
general unifier
✓ predicate with n arguments contains O(2n ) nodes (in our example, we have two
arguments, so our lattice has four nodes)
✓ Repeated constants = slightly different lattice.
3. Forward Chaining
First-Order Definite Clauses:
A definite clause either is atomic or is an implication whose antecedent is a conjunction of
positive literals and whose consequent is a single positive literal. The following are first-order
definite clauses:
Unlike propositional literals, first-order literals can include variables, in which case those
variables are assumed to be universally quantified.
Consider the following problem;
“The law says that it is a crime for an American to sell weapons to hostile nations. The country
Nono, an enemy of America, has some missiles, and all of its missiles were sold to it by Colonel
West, who is American.”
We will represent the facts as first-order definite clauses
". . . It is a crime for an American to sell weapons to hostile nations":
--------- (1)
ECS 302: ARTIFICIAL INTELLIGENCE
LECTURE NOTES
"Nono . . . has some missiles." The sentence 3 x Owns (Nono, .rc) A Missile (x) is transformed into
two definite clauses by Existential Elimination, introducing a new constant M1:
Owns (Nono, M1) ----------------- (2)
Missile (Ml) ------------------------- (3)
"All of its missiles were sold to it by Colonel West":
Missile (x) A Owns (Nono, x) =>Sells (West, z, Nono) ----------------- (4)
We will also need to know that missiles are weapons:
Missile (x) => Weapon (x) ---------- (5)
We must know that an enemy of America counts as "hostile":
Enemy (x, America) =>Hostile(x) ----------- (6)
"West, who is American":
American (West) --------------- (7)
"The country Nono, an enemy of America ":
Enemy (Nono, America) ------------ (8)
A simple forward-chaining algorithm:
➢ Starting from the known facts, it triggers all the rules whose premises are satisfied, adding
their conclusions lo the known facts
➢ The process repeats until the query is answered or no new facts are added. Notice that a
fact is not "new" if it is just renaming of a known fact.
We will use our crime problem to illustrate how FOL-FC-ASK works. The implication sentences
are (1), (4), (5), and (6). Two iterations are required:
✓ On the first iteration, rule (1) has unsatisfied premises.
Rule (4) is satisfied with {x/Ml), and Sells (West, M1, Nono) is added.
Rule (5) is satisfied with {x/M1) and Weapon (M1) is added.
Rule (6) is satisfied with {x/Nono}, and Hostile (Nono) is added.
✓ On the second iteration, rule (1) is satisfied with {x/West, Y/MI, z /Nono), and Criminal
(West) is added.
ECS 302: ARTIFICIAL INTELLIGENCE
LECTURE NOTES
It is sound, because every inference is just an application of Generalized Modus Ponens, it is
complete for definite clause knowledge bases; that is, it answers every query whose answers are
entailed by any knowledge base of definite clauses
Figure 3.1 A conceptually straightforward, but very inefficient, forward-chaining
algorithm. On each iteration, it adds to KB all the atomic sentences that can be inferred in
one step from the implication sentences and the atomic sentences already in KB.
Figure 3.2 The proof tree generated by forward chaining on the crime example. The initial
facts appear at the bottom level, facts inferred on the first iteration in the middle level, and
facts inferred on the second iteration at the top level.
ECS 302: ARTIFICIAL INTELLIGENCE
Efficient forward chaining:
LECTURE NOTES
(EXTRA MATERIAL)
The above given forward chaining algorithm was lack with efficiency due to the the three sources
of complexities:
✓ Pattern Matching
✓ Rechecking of every rule on every iteration even a few additions are made to rules
✓ Irrelevant facts
1. Matching rules against known facts:
For example, consider this rule,
Missile(x) A Owns (Nono, x) => Sells (West, x, Nono).
The algorithm will check all the objects owned by Nono in and then for each object, it could check
whether it is a missile. This is the conjunct ordering problem:
“Find an ordering to solve the conjuncts of the rule premise so that the total cost is minimized”.
The most constrained variable heuristic used for CSPs would suggest ordering the conjuncts to
look for missiles first if there are fewer missiles than objects that are owned by Nono.
The connection between pattern matching and constraint satisfaction is actually very close. We
can view each conjunct as a constraint on the variables that it contains-for example, Missile(x) is a
unary constraint on x. Extending this idea, we can express every finite-domain CSP as a single
definite clause together with some associated ground facts. Matching a definite clause against a
set of facts is NP-hard
2. Incremental forward chaining:
On the second iteration, the rule
Missile (x) => Weapon (x)
Matches against Missile (M1) (again), and of course the conclusion Weapon(x/M1) is already
known so nothing happens. Such redundant rule matching can be avoided if we make the
following observation:
ECS 302: ARTIFICIAL INTELLIGENCE
LECTURE NOTES
“Every new fact inferred on iteration t must be derived from at least one new fact inferred on
iteration t – 1”.
This observation leads naturally to an incremental forward chaining algorithm where, at iteration
t, we check a rule only if its premise includes a conjunct p, that unifies with a fact p: newly
inferred at iteration t - 1. The rule matching step then fixes p, to match with p’, but allows the
other conjuncts of the rule to match with facts from any previous iteration.
3. Irrelevant facts:
➢ One way to avoid drawing irrelevant conclusions is to use backward chaining.
➢ Another solution is to restrict forward chaining to a selected subset of rules
➢ A third approach, is to rewrite the rule set, using information from the goal.so that only
relevant variable bindings-those belonging to a so-called magic set-are considered during
forward inference.
For example, if the goal is Criminal (West), the rule that concludes Criminal (x) will be rewritten
to include an extra conjunct that constrains the value of x:
Magic(x) A American(z) A Weapon(y)A Sells(x, y, z) A Hostile(z) =>Criminal(x )
The fact Magic (West) is also added to the KB. In this way, even if the knowledge base contains
facts about millions of Americans, only Colonel West will be considered during the forward
inference process.
4. Backward Chaining
This algorithm work backward from the goal, chaining through rules to find known facts that
support the proof. It is called with a list of goals containing the original query, and returns the set
of all substitutions satisfying the query. The algorithm takes the first goal in the list and finds
every clause in the knowledge base whose head, unifies with the goal. Each such clause creates a
ECS 302: ARTIFICIAL INTELLIGENCE
LECTURE NOTES
new recursive call in which body, of the clause is added to the goal stack .Remember that facts
are clauses with a head but no body, so when a goal unifies with a known fact, no new sub goals
are added to the stack and the goal is solved. The algorithm for backward chaining and proof tree
for finding criminal (West) using backward chaining are given below.
Figure 4.1 A simple backward-chaining algorithm.
.
Figure 4.2 Proof tree constructed by backward chaining to prove that West is a criminal. The tree should
be read depth first, left to right. To prove Criminal (West), we have to prove the four conjuncts below it.
Some of these are in the knowledge base, and others require further backward chaining. Bindings for each
successful unification are shown next to the corresponding sub goal. Note that once one sub goal in a
conjunction succeeds, its substitution is applied to subsequent sub goals.
ECS 302: ARTIFICIAL INTELLIGENCE
LECTURE NOTES
5. Resolution
As in the propositional case, first-order resolution requires that sentences be in conjunctive
normal form (CNF) that is, a conjunction of clauses, where each clause is a disjunction of literals.
Literals can contain variables, which are assumed to be universally quantified. Every sentence of
first-order logic can be converted into an inferentially equivalent CNF sentence. We will illustrate
the procedure by translating the sentence
"Everyone who loves all animals is loved by someone," or
The steps are as follows:
➢ Eliminate implications:
➢ Move Negation inwards: In addition to the usual rules for negated connectives, we need
rules for negated quantifiers. Thus, we have
Our sentence goes through the following transformations:
➢ Standardize variables: For sentences like
which use the same
variable name twice, change the name of one of the variables. This avoids confusion later
when we drop the quantifiers. Thus, we have
ECS 302: ARTIFICIAL INTELLIGENCE
LECTURE NOTES
➢ Skolemize: Skolemization is the process of removing existential quantifiers by elimination.
Translate 3 x P(x) into P(A), where A is a new constant. If we apply this rule to our sample
sentence, however, we obtain
Which has the wrong meaning entirely: it says that everyone either fails to love a particular
animal A or is loved by some particular entity B. In fact, our original sentence allows each person
to fail to love a different animal or to be loved by a different person.
Thus, we want the Skolem entities to depend on x:
Here F and G are Skolem functions. The general rule is that the arguments of the Skolem function
are all the universally quantified variables in whose scope the existential quantifier appears.
➢ Drop universal quantifiers: At this point, all remaining variables must be universally
quantified. Moreover, the sentence is equivalent to one in which all the universal
quantifiers have been moved to the left. We can therefore drop the universal quantifiers
➢ Distribute V over A
This is the CNF form of given sentence.
The resolution inference rule:
The resolution rule for first-order clauses is simply a lifted version of the propositional resolution
rule. Propositional literals are complementary if one is the negation of the other; first-order
ECS 302: ARTIFICIAL INTELLIGENCE
LECTURE NOTES
literals are complementary if one unifies with the negation of the other. Thus we have
Where UNIFY (li, m j) == θ.
For example, we can resolve the two clauses
By eliminating the complementary literals Loves (G(x), x) and ¬Loves (u, v), with unifier
θ = {u/G(x), v/x), to produce the resolvent clause
Example proofs:
Resolution proves that KB /= a by proving KB A la unsatisfiable, i.e., by deriving the empty
clause. The sentences in CNF are
The resolution proof is shown in below figure;
ECS 302: ARTIFICIAL INTELLIGENCE
LECTURE NOTES
Figure 5.1 A resolution proof that West is a criminal.
Notice the structure: single "spine" beginning with the goal clause, resolving against clauses from
the knowledge base until the empty clause is generated. Backward chaining is really just a special
case of resolution with a particular control strategy to decide which resolution to perform next.
Completeness of resolution:
Resolution is refutation-complete, which means that if a set of sentences is unsatisfiable, then
resolution will always be able to derive a contradiction. Resolution cannot be used to generate all
logical consequences of a set of sentences, but it can be used to establish that a given sentence is
entailed by the set of sentences.
➢ So we have to prove that “if S is an unsatisfiable set of clauses, then the application of
finite number of resolution steps to S will yield a contradiction”
The basic structure of the proof is shown below
ECS 302: ARTIFICIAL INTELLIGENCE
LECTURE NOTES
Figure 5.2 Structure of a completeness proof for resolution
It proceeds as follows:
✓ First, we observe that if S is unsatisfiable, then there exists a particular set of ground
instances of the clauses of S such that this set is also unsatisfiable (Herbrand's theorem).
✓ We then appeal to the ground resolution theorem given in Chapter 7, which states that
propositional resolution is complete for ground sentences.
✓ We then use a lifting lemma to show that, for any propositional resolution proof using the
set of ground sentences, there is a corresponding first-order resolution proof using the
first-order sentences from which the ground sentences were obtained.
****
Topic for the class:
Module-IV
KNOWLEDGE and REASONING
Chapter 9: Inference in First-Order Logic
M.S.N.V.Jitendra
Assistant Professor
Department of CSE
GITAM Institute of Technology (GIT)
Visakhapatnam – 530045
Email: jmukkama@gitam.edu
Department of CSE, GIT
ECS302: AI
1
9.1 Propositional vs. First-Order Inference
(1) Inference Rules for Quantifiers:
Suppose we have:
‘All greedy kings are evil’.
∀ x King(x) Ʌ Greedy(x) → Evil(x)
Then we can infer any of the following sentences:
Universal Instantiation (UI):
This rule says that we can infer any sentence obtained by substituting a ground term (a term without variables) for
the variable.
Let SUBST (θ, α) denote the result of applying the substitution θ to the sentence α.
Department of CSE, GIT
ECS302: AI
2
Continued...
Then the rule is written:
for any variable ‘v’ and ground term ‘g’.
Ex:
The three sentences given earlier (in slide 2) are obtained with the substitutions:
{ x / John },
{ x / Richard },
{ x / Father(John) }
Existential Instantiation:
For any sentence α, variable v and constant symbol k that does not appear elsewhere in KB,
For example, from the sentence
Ǝ x Crown(x) Ʌ OnHead(x, John)
we can infer the sentence
Crown(C1) Ʌ OnHead(C1, John)
as long as C1 does not appear elsewhere in the KB.
Department of CSE, GIT
ECS302: AI
3
Continued...
(2) Reduction to Propositional Inference:
It becomes possible to reduce first-order inference to propositional inference.
As an existentially quantified sentence can be replaced by one instantiation,
a universally quantified sentence can be replaced by the set of all possible instantiations.
Ex: Suppose the KB is:
We apply UI to the first sentence using all possible ground term substitutions from the vocabulary of the KB,
in this case, { x / John } and { x / Richard }.
We obtain:
King(John) Ʌ Greedy(John) → Evil(John)
King(Richard) Ʌ Greedy(Richard) → Evil(Richard)
and we discard the universally quantified sentence.
Department of CSE, GIT
ECS302: AI
4
Continued...
(2) Reduction to Propositional Inference:
It becomes possible to reduce first-order inference to propositional inference.
As an existentially quantified sentence can be replaced by one instantiation,
a universally quantified sentence can be replaced by the set of all possible instantiations.
Ex: Suppose the KB is:
We apply UI to the first sentence using all possible ground term substitutions from the vocabulary of the KB,
in this case, { x / John } and { x / Richard }.
We obtain:
King(John) Ʌ Greedy(John) → Evil(John)
King(Richard) Ʌ Greedy(Richard) → Evil(Richard)
and we discard the universally quantified sentence.
Department of CSE, GIT
ECS302: AI
5
Continued...
Now the KB is essentially propositional if we view the ground atomic sentences -- King(John), Greedy(John) and so on
as propositional symbols.
(2) Unification and Lifting:
➢ The inference of Evil(John) from the sentences
∀x King(x) Ʌ Greedy(x) → Evil(x)
King(John)
Greedy(John)
seems completely obvious to a human being.
➢ How to make it completely obvious to a computer?
A first-order inference rule:
For this to work, we find some x such that x is a king and x is greedy.
In this case, the substitution { x / John } achieves that aim.
Department of CSE, GIT
ECS302: AI
6
Continued...
Suppose that instead of knowing Greedy(John), we know that everyone is greedy.
∀y Greedy(y)
Then, we would still be able to conclude that: Evil(John).
(because we know that John is a king (given) and John is greedy (because everyone is greedy).
i.e., the substitution is { x / John, y / John }
This inference process can be captured as a single inference rule that we call Generalized Modus Ponens.
Generalized Modus Ponens:
For atomic sentences pi , pi ‘ and q, where there is a substitution θ such that
SUBST(θ, pi ‘) = SUBST(θ, pi ) for all i,
There are n atomic sentences pi ‘ and one implication to this rule.
Department of CSE, GIT
ECS302: AI
7
Continued...
The conclusion is the result of applying the substitution θ to the consequent q.
For our example:
p1 ‘ is King(John)
p1 is King(x)
p2‘ is Greedy(y)
p2 is Greedy(x)
θ is { x / John, y / John } q is Evil(x)
SUBST(θ , q) is Evil(John)
Generalized Modus Ponens is a lifted version of Modus Ponens.
Unification:
❖ It is a process of finding substitutions that make different logical expressions look identical.
❖ It takes two sentences and returns a unifier for them, if one exists.
UNIFY (p, q) = θ where SUBST (θ, p) = SUBST (θ, q).
Department of CSE, GIT
ECS302: AI
8
Continued...
Exs:
UNIFY (Knows(John, x), Knows(John, Jane)) = { x / Jane }
UNIFY (Knows(John, x), Knows(y, Bill)) = { x / Bill, y / John}
UNIFY (Knows(John, x), Knows(y, Mother(y)) = { y / John, x / Mother(John) }
UNIFY (Knows(John, x), Knows(x, Elizabeth)) = FAIL
In the last one, the problem arises because of the usage of the same variable x in both the sentences.
If we standardize apart one of the two sentences (that is, renaming its variables to avoid clashes),
then we have: UNIFY (Knows(John, x), Knows(z, Elizabeth)) , then the substitution is
{ x / Elizabeth, z / John }.
Department of CSE, GIT
ECS302: AI
9
Continued...
Most General Unifier (MGU):
There could be more than one unifier in some cases.
Ex: UNIFY (Knows(John, x), Knows(y, z))
could return
{ y / John, x / z } or { y / John, x / John, z / John }.
✓ The first unifier gives Knows(John, z),
✓ The second unifier gives Knows(John, John).
-- could be obtained from the first by an additional substitution { z / John }.
❑ We say that the first unifier is more general than the second,
because it places fewer restrictions on the values of the variables.
❑ For every unifiable pair of expressions, there is a single Most General Unifier (MGU).
In this case, it is { y / John, x / z }.
An algorithm for computing MGUs is follows.
Department of CSE, GIT
ECS302: AI
10
Continued...
Algorithm:
Department of CSE, GIT
ECS302: AI
11
Continued...
Explanation:
1. If x and y are both variables or constants, if x and y are identical, then return NIL.
θ is empty or θ is as it is.
Ex:
King(John), King(John)
or
King(x), King(x)
2. If x is a variable and y is a constant, then return constant for variable
Ex: King(x), King(John)
return { x / John }
3. If x is a constant and y is a variable, then return constant for variable
Ex: Evil(Richard), Evil(x)
return { x / Richard }
4. If x and y are COMPOUND expressions, call UNIFY with
first arguments of x and y,
second arguments of x and y,
……………….
nth arguments of x and y.
Department of CSE, GIT
ECS302: AI
12
Continued...
Ex:
Father(m, David, Bill)
(m is the father of David and Bill)
(args[x] : m, David and Bill)
Father(Taylor, p, Bill)
(Taylor is the father of p and Bill)
(args[y] : Taylor, p and Bill)
θ is { m / Taylor, p / David, NIL }
5. If x is a list and y is a list, then
UNIFY First elements of x and y
and then Rest of the elements of x and y.
Ex:
[m, David, Bill] [Taylor, p, Bill]
first rest
first
rest
θ is { m / Taylor, p / David, NIL }
8. OCCUR-CHECK
(if a variable itself occurs inside a complex term)
Ex: F(x, x), F(G(x), G(x))
If G(x) is written for x, we have: F(G(x), G(x)), F(G(G(x)), G(G(x))) -- never possible to eliminate x
Department of CSE, GIT
ECS302: AI
13
Continued...
Algorithm: Unify(L1, L2)
(From: AI – Elaine Rich & Kevin Knight)
1. If L1 or L2 are both variables or constants, then
(a) If L1 and L2 are identical, then return NIL.
(b) Else if L1 is a variable, then if L1 occurs in L2 then return { FAIL }, else return (L2 / L1)
(return L2 for L1)
(c) Else if L2 is a variable, then if L2 occurs in L1 then return { FAIL }, else return (L1 / L2)
(return L1 for L2)
(d) Else return FAIL.
2. If the initial predicate symbols in L1 and L2 are not identical, then return { FAIL }.
3. If L1 and L2 have a different number of arguments, then return { FAIL }.
4. Set SUBST to NIL. (At the end of the procedure, SUBST will contain all the substitutions used to unify L1 and L2.)
5. For i 1 to number of arguments in L1:
(a) Call Unify with the ith argument of L1 and ith argument of L2, putting result in S.
(b) If S contains FAIL, then return { FAIL }.
(c) If S is not equal to NIL, then
(i) Apply S to the remainder of both L1 and L2.
(ii) SUBST := APPEND(S, SUBST)
6. Return SUBST.
Department of CSE, GIT
ECS302: AI
14
Continued...
Explanation:
1.(a)
Step
Teacher(x), ¬Teacher(x) or
Teacher(Pradeep), ¬Teacher(Pradeep)
Algorithm returns
NIL
1.(b)
f(x, x), f(g(x), g(x))
FAIL
(if we write g(x) for x, then it will be: f(g(x), g(x)), f(g(g(x)), g(g(x))),
it will never be possible to eliminate x (OCCUR_CHECK))
f(x), f(John)
{ x / John }
f(x), f(g(y))
{ x / g(y) }
1.(c)
f(g(x)), f(x)
f(John), f(z)
1.(d)
Return FAIL.
FAIL
{ z / John }
Department of CSE, GIT
ECS302: AI
(OCCUR_CHECK, same as above)
15
Continued...
Step
2. Man(John), Teacher(Bob)
3. StudentOf(Lalitha, Btech), Student(Lalitha)
4. SUBST = NIL
5. FounderOf(BillGates, Microsoft), FounderOf(x, y)
Algorithm returns
FAIL
FAIL
S = { x / BillGates }
S = { x / BillGates, y / Microsoft }
6. Return SUBST.
Storage and Retrieval:
(primitive functions underlying TELL and ASK)
STORE (s) -- stores a sentence s into the KB
FETCH(q) -- returns all unifiers such that the query q unifies with some sentence in the KB
Ex: Knows(John, x) -- a query, an instance of fetching
(finds all facts that unify with Knows(John, x)
Department of CSE, GIT
ECS302: AI
16
9.3 Forward Chaining
(i) First-Order Definite Clauses:
❖ A definite clause either is atomic or is an implication whose antecedent is a conjunction of positive literals and
whose consequent is a single positive literal.
Ex:
∀x King(x) Ʌ Greedy(x) → Evil(x)
King(John)
Greedy(y)
➢ Unlike propositional literals, first-order literals can include variables in which case, those variables are assumed to
be universally quantified. (usually, we omit them)
➢ Many of the KBs can be converted into a set of definite clauses.
Example Problem:
‘The law says that it is a crime for an American to sell weapons to hostile nations. The country Nono, an enemy of
America, has some missiles, and all of its missiles were sold to it by Colonel West, who is American.’
We will prove that ‘West is a Criminal.
Department of CSE, GIT
ECS302: AI
17
Continued...
Sentences in FOL:
1. It is a crime for an American to sell weapons to hostile nations.
American(x) Ʌ Weapon(y) Ʌ Sells(x, y, z) Ʌ Hostile(z) → Criminal(x)
✓
Nono has some missiles.
Ǝx Owns(Nono, x) Ʌ Missile(x) is transformed into two definite clauses.
2. Owns(Nono, M1 )
3. Missile(M1)
4. All of its missiles were sold to it by Colonel West.
Missile(x) Ʌ Owns(Nono, x) → Sells(West, x, Nono)
5. Missiles are weapons.
Missile(x) → Weapon(x)
Department of CSE, GIT
ECS302: AI
18
Continued...
6. An enemy of America counts as “hostile”.
Enemy(x, America) → Hostile(x)
7. West is an American.
American(West)
8. The country Nono is an enemy of America.
Enemy(Nono, America)
Forward chaining considers atomic sentences and tries to satisfy the premises of rules.
This leads to inference of new sentences and thereby proof of a goal.
To prove ‘West is Criminal’, all of the premises of 1 have to be satisfied.
Department of CSE, GIT
ECS302: AI
19
Continued...
Use 3 in 4 and infer:
9. Sells(West, M1, Nono)
Use 3 in 5 and infer:
10. Weapon(M1)
Use 8 in 6 and infer:
11. Hostile(Nono)
Now use 7, 10, 9 and 11 in 1 and infer:
12. Criminal(West)
Hence, ‘West is Criminal’ is proved.
The substitutions are:
{ x / West, y / M1 , z / Nono }
Department of CSE, GIT
ECS302: AI
20
Continued...
(ii) A simple Forward Chaining Algorithm:
Department of CSE, GIT
ECS302: AI
21
Continued...
Explanation:
➢ Starting from the known facts, it triggers all the rules whose premises are satisfied, adding their conclusions to
the known facts.
➢ The process repeats until the query is answered or new facts are added.
A fact is not new if it is just renaming of a known fact.
Ex: Likes(x, IceCream) and Likes(y, IceCream) are renaming of each other.
Their meanings are identical (everyone likes ice cream).
FOL-FC-ASK is:
❖ Sound, because every inference is just an application of Generalized Modus Ponens, which is sound.
❖ Complete for definite clause KBs; i.e., it answers every query whose answers are entailed by any KB of definite
clauses.
Department of CSE, GIT
ECS302: AI
22
The Proof Tree:
➢Forward chaining -- from bottom to top in the diagram
➢Bottom level -- initial facts
➢Middle level -- facts inferred on the first iteration
➢Top level -- facts inferred on the second iteration
Department of CSE, GIT
ECS302: AI
23
9.4 Backward Chaining
Algorithm:
Department of CSE, GIT
ECS302: AI
24
9.4 Backward Chaining
Explanation:
➢ The algorithm uses compositions of substitutions.
➢ Compose(θ1, θ2) is the substitution whose effect is identical to the effect of applying each substitution in turn.
➢ That is,
SUBST(Compose(θ1, θ2) , p) = SUBST(θ2, SUBST(θ1, p))
➢ In the algorithm, the current variable bindings, which are stored in θ, are composed with the bindings resulting
from unifying the goal with the clause head, giving a new set of current bindings for the recursive call.
Department of CSE, GIT
ECS302: AI
25
Continued...
Proof Tree:
To prove that ‘West is Criminal’.
Department of CSE, GIT
ECS302: AI
26
Continued...
➢ Backward chaining -- from top to bottom in the diagram
➢ Middle and Bottom level -- read from left to right
➢ To prove ‘Criminal(West)’ -- prove the conjuncts (four) in the middle level
➢ To prove any middle-level goal -- go down to its next lower level
General Examples for Forward and Backward Chaining:
Consider:
Forward Chaining
(5) (2) (combine A and use 4)
1. A Ʌ B Ʌ C → Z
A (given, proved) → Y (given, proved) → M → K
→
2. M → K
A Ʌ K → B (proved)
→
C (given, proved) →
Z (proved)
3. A
(4)
Consider 7
from 1
4. A Ʌ K → B
Backward Chaining
5. Y → M
(1)
(3)
(7) (4)
(3)
(2)
(5)
6. Y
Z  A Ʌ B Ʌ C  B Ʌ C  B  A Ʌ K  K  M  Y  Y proved from 6.
7. C
Prove Z.
Department of CSE, GIT
ECS302: AI
27
9.5 Resolution
Conjunctive Normal Form (CNF):
As in the propositional case, first-order resolution requires that sentences be in CNF -- that is a conjunction of
clauses, where each clause is a disjunction of literals.
Literals can contain variables, which are assumed to be universally quantified.
Every sentence of first-order logic can be converted into an inferentailly equivalent CNF sentence.
Procedure:
Ex: Everyone who loves all animals is loved by someone.
Department of CSE, GIT
ECS302: AI
28
Continued...
Steps:
1. Eliminate Implications
2. Move ¬ inwards
We have
Our sentence goes through the following transformations:
Department of CSE, GIT
ECS302: AI
29
Continued...
3. Standardize variables:
Sentences like (∀x P(x)) V (Ǝx Q(x)) can be written as
Thus we have,
(∀x P(x)) V (Ǝy Q(y))
4. Skolemize:
Skolemization is the process of removing existential quantifiers by elimination.
Ǝx P(x) can be written as
P(A) where A is a new constant.
So, our sentence becomes:
which has the wrong meaning entirely: it says that –‘everyone either fails to love a particular animal A or is loved
by some particular entity B’.
In fact, our original sentence allows –
‘each person to fail to love a different animal or to be loved by a different person’.
Department of CSE, GIT
ECS302: AI
30
Continued...
Thus, we want the Skolem entities to depend on x. A better way is:
( F and G are Skolem Functions)
General Rule: The arguments of the Skolem function are all the universally quantified variables in whose scope
the existential quantifier appears.
5. Drop Universal quantifiers:
At this point, all remaining variables must be universally quantified. We can drop the universal quantifiers.
6. Distribute Ʌ over V:
The sentence is now in CNF and consists of two clauses.
Department of CSE, GIT
ECS302: AI
31
Continued...
The Resolution Inference Rule:
We have
• where UNIFY(li , ¬mj )= θ . For example, we can resolve the two clauses
Ex:
Consider
[Animal (F(x)) ∨ Loves(G(x), x)] and [¬Loves(u, v) ∨ ¬Kills(u, v)]
•
•
by eliminating the complementary literals Loves(G(x), x) and ¬Loves(u, v),
with unifier θ={u/G(x), v/x}, to produce the resolvent clause
Now the unifier is :
θ = { u / G(x) , v / x }
and the resolvent is :
Department of CSE, GIT
ECS302: AI
32
Continued...
The sentences (in Slides 17 & 18 ) :
1. American(x) Ʌ Weapon(y) Ʌ Sells(x, y, z) Ʌ Hostile(z) → Criminal(x)
2. Owns(Nono, M1 )
3. Missile(M1)
4. Missile(x) Ʌ Owns(Nono, x) → Sells(West, x, Nono)
5. Missile(x) → Weapon(x)
6. Enemy(x, America) → Hostile(x)
7. American(West)
8. Enemy(Nono, America)
Department of CSE, GIT
ECS302: AI
33
Department of CSE, GIT
ECS302: AI
34
Continued...
The sentences (in Slides 17 & 18 ) in Clause Form:
1.
2. Owns(Nono, M1 )
3. Missile(M1)
4.
5.
6.
7.
8.
9.
American(West)
Enemy(Nono, America)
¬Criminal(West)
(Goal is negated [refutation], converted to a clause and added)
Department of CSE, GIT
ECS302: AI
35
Continued...
Proof:
¬Criminal(West)
7
Nil
1
x / West
¬American(West) V ¬Weapon(y) V ¬Sells(West, y, z) V ¬Hostile(z)
¬Weapon(y) V ¬Sells(West, y, z) V ¬Hostile(z)
3
y / M1
5
x/y
¬Missile(y) V ¬Sells(West, y, z) V ¬Hostile(z)
¬Sells(West, M1, z) V ¬Hostile(z)
Department of CSE, GIT
ECS302: AI
36
Continued...
Proof Continued:
¬Sells(West, M1, z) V ¬Hostile(z)
3
4
x / M1 , z / Nono
¬Missile(M1) V ¬Owns(Nono, M1 ) V ¬Hostile(Nono)
Nil
¬Owns(Nono, M1 ) V ¬Hostile(Nono)
¬Hostile(Nono)
8
2
Nil
6
x / Nono
¬Enemy(Nono, America)
Contradiction
Hence, ‘West is Criminal’ is proved.
Department of CSE, GIT
ECS302: AI
37
ECS 302: ARTIFICIAL INTELLIGENCE
LECTURE NOTES
LECTURE
NOTES–UNIT IV
PLANNING
ECS302
ARTIFICIAL
INTELLIGENCE
3/4 B.Tech [
]
DEPARTMENT OF
CSE,GIT,GU
ECS 302: ARTIFICIAL INTELLIGENCE
LECTURE NOTES
Module IV Lecture Notes [Planning]
Syllabus
The Planning Problem, Planning with State-Space Search, Partial-Order Planning
1. The Planning Problem:
Planning is the task of coming up with a sequence of actions that will achieve Goal. Consider
what can happen when an ordinary problem-solving agent using standard search algorithms like
depth-first, A*, and so on-comes up against large, real-world problems. So, better planning
agents are required.
1) Consider an internet buying Agent whose task is to buy a textbook (search based)
So planner should works back from goal to BUY(x) we need to have a plan Have(x).
2) Finding Good Heuristic function
Finally the problem solver is inefficient because it can’t take advantage of problem
decomposition. i.e.,
For example: problem of delivering a set of overnight packages to their respective
destinations, which are scattered across a country. So planning system will do;
-
Open up action & goal representation to allow selection.
-
Divide & Conquer by sub goals
-
Relax Requirement for sequential construction of solutions
1.1 The language of planning problems:
Consider the basic representation language of classical planners, known as STRIPS language.
Representation of states:
➢ Decompose the world in to logical conditions and represent a state as conjunction of
positive literals
➢ Must be grounded & function free.
For example: At (Plane1, Melbourne)  At (Plane2, Sydney)
ECS 302: ARTIFICIAL INTELLIGENCE
LECTURE NOTES
➢ Literals such as At (x, y) or At (Father (Fred), Sydney) are not allowed.
Representation of goals:
➢ A goal is a partially specified state, represented as a conjunction of positive ground
literals, such as Rich  Famous
or
At (P2, LAS).
➢ A propositional state s satisfies a goal g if s contains all the atoms in g.
➢ For example, the state Rich  Famous  Miserable satisfies the goal Rich  Famous.
Representation of actions:
➢ An action is specified in terms of the preconditions that must hold before it can be
executed and the effects that ensue when it is executed.
➢ For example, an action for flying a plane from one location to another is:
Action (Fly (p, from, to),
PRECOND: At (p, from)  Plane (p)  Airport (from)  Airport (to)
EFFECT:  At (p, from)  At (p, to))
This is called as “Action Schema”, which consists of three parts:
a) The action name and parameter list.
For example, Fly (p, from, to)-serves to identify the action.
b) The precondition is a conjunction of function-free positive literals stating what must be
true in a state before the action can be executed. Any variables in the precondition must
also appear in the action's parameter list.
c) The effect is a conjunction of function-free literals describing how the state changes when
the action is executed. A positive literal P in the effect is asserted to be true in the state
resulting from the action, whereas a negative literal P is asserted to be false. Variables in
the effect must also appear in the action's parameter list.
→To improve readability, some planning systems divide the effect into the add list for positive
literals and the delete list for negative literals.
→An action is applicable in any state that satisfies the precondition; otherwise, the action has no
effect.
ECS 302: ARTIFICIAL INTELLIGENCE
LECTURE NOTES
For a first-order action schema, establishing applicability will involve a substitution  for the
variables in the precondition. For example, suppose the current state is described by
At(Pl, JFK)  At(P2, SFO)  Plane(P1)  Plane(P2)  Airport (JFK)  Airport (SFO).
This state satisfies the precondition;
At (p, from)  Plane (p)  Airport (from)  Airport (to)
With substitution {p/Pl, from/JFK, to/SFO)
So, the action Fly (Pl, JFK, SFO) is applicable.
Starting in state‘s’, the result of executing an applicable action ‘a’ is a state‘s’ that is the same as s
except that any positive literal P in the effect of a is added to s and any negative literal P is
removed from s’. Thus, after Fly (Pl, JFK, SFO), the current state becomes
At(Pl, SFO)  At(P2, SFO)  Plane(Pl)  Plane(P2)  Airport (JFK)  Airport (SFO) .
STRIPS assumption: Stands for [Standard Research Institute Problem Solver]
Here every literal not mentioned in the effect remains unchanged. It is a restricted language for
planning and the representation is chosen to make planning Algorithms simpler and efficient.
In recent years, it has become clear that STRIPS is insufficiently expressive for some real
domains. As a result, many language variants have been developed. Figure 1.1 briefly describes
one important one, the Action Description Language or ADL, by comparing it with the basic
STRIPS language. In ADL, the Fly action could be written as;
Action(Fly(p : Plane, from : Airport, to : Airport),
PRECOND: At(p, from)  (from ≠to)
EFFECT:  At(p, from)  At(p, t o) ).
ECS 302: ARTIFICIAL INTELLIGENCE
LECTURE NOTES
Figure 1.1 Comparison of STRIPS and ADL languages for representing planning problems.
STRIPS Problems:
1) Transportation of “Air Cargo between Airports”
Init(At(Cl, SFO) ^ At(C2, JFK) ^ At(P1, SFO) ^ At(P2, JFK)
^ Cargo(Cl) ^ Cargo(C2) ^ Plane(P1) ^ Plane(P2)
^ Airport(JFK) ^ Airport(SF0))
Goal (At (CI , JFK) A At (C2, SFO))
Action(Load(c, p, a),
PRECOND: At(c, a) ^ At(p, a) ^ Cargo(c) ^ Plane(p) ^ Airport(a)
EFFECT: ¬ At(c, a) ^ In(c, p))
Action( Unload(c, p, a),
PRECOND: In(c, p) ^ At(p, a) ^ Cargo(c) ^ Plane(p) ^ Airport(a)
EFFECT: At(c, a) ^ ¬ In(c, p))
Action(Fly(p, from, to),
PRECOND: At(p, from) ^ Plane(p) ^ Airport(from) ^ Airport(to)
EFFECT: ¬At(p, from) ^ At(p, to))
Figure 1.2 A STRIPS problem involving transportation of air cargo between airports.
ECS 302: ARTIFICIAL INTELLIGENCE
LECTURE NOTES
The following plan is a solution to the problem:
1) The Spare Tire Problem:
Problem of changing a flat tire. The goal is to have a good spare tire properly mounted onto the
car's axle, where the initial state has a flat tire on the axle and a good spare tire in the trunk.
There are just four actions:
Removing the spare from the trunk,
Removing the flat tire from the axle,
Putting the spare on the axle, and
Leaving the car unattended overnight.
The ADL description of the problem is shown below;
Init(At (Flat, Axle) ^ At(Spare, Trunk))
Goal (At (Spare, Axle))
Action(Remove(Spare, Trunk),
PRECOND: At(Spare, Trunk)
EFFECT: ¬ At (Spare, Trunk) ^ At (Spare, Ground))
Action(Remove(Flat, .Axle),
PRECOND: At(Flat, Axle)
EFFECT: 1 At(Flat, Axle) ^ At(Flat, Ground))
Action( Put On (Spare, Axle),
PRECOND: At(Spare, Ground) ^ ¬ At (Flat, Axle)
EFFECT: ¬ At(Spare, Ground) ^ At(Spare, Axle))
Action(Leave Overnight,
PRECOND:
EFFECT: ¬ At(Spare, Ground) ^ ¬ At(Spam, Axle) ^ ¬ At(Spare, Trunk)
^ ¬ At(Flat, Ground) ^ ¬ At(Flat, Axle))
Figure 1.3 The simple spare tire problem.
ECS 302: ARTIFICIAL INTELLIGENCE
LECTURE NOTES
2) The Blocks world Problem:
This domain consists of a set of cube-shaped blocks sitting on a table. The blocks can be stacked,
but only one block can fit directly on top of another. A robot arm can pick up a block and move it
to another position, either on the table or on top of another block. The arm can pick up only one
block at a time, so it cannot pick up a block that has another one on it. The goal will always be to
build one or more stacks of blocks, specified in terms of what blocks are on top of what other
blocks. For example, a goal might be to get block A on B and block C on D.
We will use On (b, x) to indicate that block b is on x, where x is either another block or the table.
The action for moving block b from the top of x to the top of y will be Move (b, x, y). The action
Move moves a block b from x to y if both b and y are clear. After the move is made, x is clear but y
is not. A formal description of Move in STRIPS is
Action (Move (b, z, y) ,
PRECOND: On(b, x) ^ Clear(b) ^ Clear(y),
EFFECT: On (b, y) ^ Clear(x) ^ ¬On (b, x) ^ ¬Clear(y))
Unfortunately, this action does not maintain Clear properly when x or y is the table. To fix this,
we do two things. First, we introduce another action to move a block b from x to the table:
Action (Move To Table (b, x) ,
PRECOND: On(b, x) ^ Clear(b),
EFFECT: On (b, Table) ^ Clear(x) A ¬On (b, x))
Second, we take the interpretation of Clear (b) to be "there is a clear space on b to hold a block."
Under this interpretation, Clear (Table) will always be true.
Init(On(A, Table) ^ On(B, Table) ^ On(C, Table)
A Block(A) ^ Block(B) ^ Block(C)
Clear(A) ^ Clear(B) ^ Clear(C))
Goal(On(A, B) ^ On(B, C))
Action(Move(b, x, y),
PRECOND: On(b, x) ^ Clear(b) ^ Clear(y) ^ Block(b) ^ (b # x) ^ (b # y) ^ (x # y),
EFFECT: On(b, y) ^ Clear(x) ^ ¬On(b, x) ^ ¬ Clear(y))
ECS 302: ARTIFICIAL INTELLIGENCE
LECTURE NOTES
Action(Move To Table(b, x ) ,
PRECOND: On(b, x) ^ Clear(b) ^ Block(b) ^ (b # x),
EFFECT: On(b, Table) ^ Clear(x) ^ ¬ On(b, x))
Figure 1.4 A planning problem in the blocks world: building a three-block tower. One solution
is the sequence [Move (B, T able, C), Move (A, Table, B)].
2. Planning With State Space Search:
Because the descriptions of actions in a planning problem specify both preconditions and effects,
it is possible to search in either direction: either forward from the initial state or backward from
the goal, as shown in Figure 1.5.
Figure 1.5 Two approaches to searching for a plan. (a) Forward (progression) state-space
search, starting in the initial state and using the problem's actions to search forward for the
goal state. (b) Backward (regression) state-space search: a belief-state search starting at the goal
state(s) and using the inverse of the actions to search backward for th e initial state.
2.1 Forward state-space search:
It is a problem solving approach also called as “Progression Planning”, because it moves in
forward direction.
ECS 302: ARTIFICIAL INTELLIGENCE
LECTURE NOTES
Procedure:
1) The initial state of the search is the initial state from the planning problem. In general,
each state will be a set of positive ground literals; literals not appearing are false.
2) The actions that are applicable to a state are all those whose preconditions are satisfied.
The successor state resulting from an action is generated by adding the positive effect
literals and deleting the negative effect literals.
3) The goal test checks whether the state satisfies the goal of the planning problem.
4) The step cost of each action is typically 1. Although it would be easy to allow different
costs for different actions, this is seldom done by STRIPS planners.
First, forward search does not address the irrelevant action problem-all applicable actions are
considered from each state. Second, the approach quickly bogs down without a good heuristic.
Consider “an air cargo problem with 10 airports, where each airport has 5 planes and 20 pieces of cargo”.
The goal is to move all the cargo at airport A to airport B.
There is a simple solution to the problem: load the 20 pieces of cargo into one of the planes at A,
fly the plane to B, and unload the cargo. But finding the solution can be difficult because the
average branching factor is huge.
2.2 Backward state-space search:
It is how to generate a description of the possible predecessors of the set of goal states. We will
see that the STRIPS representation makes this quite easy because sets of states can be described
by the literals that must be true in those states.
Advantage: It allows us to consider only relevant actions. An action is relevant to a conjunctive
goal if it achieves one of the conjuncts of the goal.
For example, the goal in our 10-airport air cargo problem is to have 20 pieces of cargo at airport B
At (C1, B) ^ At (C2, B) ^ . . . ^ At (C20, B).
ECS 302: ARTIFICIAL INTELLIGENCE
LECTURE NOTES
Now consider the conjunct At (C1, B).Working backwards, we can seek actions that have this as
an effect. There is only one: Unload (C1, p, B), where plane p is unspecified.
Searching backwards is sometimes called regression planning. To see how to do it, consider the
air cargo example. We have the goal
The relevant action Unload (C1, p, B), which achieves the first conjunct. i.e.,
In (C1, p) ^ At (p, B)
Moreover, the sub goal At (C1, B) should not be true in the predecessor state. Thus, the
predecessor description is;
In (C1, p) ^ At (p, B) ^ At (C2, B) ^ . . . ^ At (C20, B)
If we insist that the actions not undo any desired literals. An action that satisfies this restriction is
called consistent. For example, the action Load (C2, p) would not be consistent with the current
goal, because it would negate the literal At (C2, B).
Heuristics for state-space search:
We might also be able to derive an admissible heuristic-one that does not overestimate. This could
be used with A* search to find optimal solutions. There are two approaches that can be tried.
a) The first is to derive a relaxed problem from the given problem specification.
b) The second approach is to pretend that a pure divide-and-conquer algorithm will work. This
is called the sub goal independence assumption: the cost of solving a conjunction of sub goals
is approximated by the sum of the costs of solving each sub goal independently.
The simplest idea is to relax the problem by removing all preconditions from the actions. Then
every action will always be applicable, and any literal can be achieved in one step. It is also
possible to generate relaxed problems by removing negative effects without removing
preconditions. That is, if an action has the effect A ^ ¬B in the original problem, it will have the
effect A in the relaxed problem.
ECS 302: ARTIFICIAL INTELLIGENCE
LECTURE NOTES
3. Partial Order Planning
Forward and backward state-space search are particular forms of totally ordered plan search. They
explore only strictly linear sequences of actions directly connected to the start or goal. So, Rather
than work on each sub problem separately, they must always make decisions about how to
sequence actions from all the sub problems. We would prefer an approach that works on several
sub goals independently, solves them with several sub plans, and then combines the sub plans.
This is called “Partial – Order Planning”.
Advantage: Flexibility in order that which it constructs.
Consider an example of “Putting on a pair of Shoes”.
Goal (Right Shoe On ^ Left Shoe On)
Init ()
Action(Right Shoe, PRECOND: Right Sock On, EFFECT: Right Shoe On)
Action(Right Sock, EFFECT: Right Sock On)
Action(Left Shoe; PRECOND: Left Sock on, EFFECT: Left Shoe on)
Action (Left Sock, EFFECT: Left sock ON)
→A planner should be able to come up with the two-action sequence;
Right sock followed by Right shoe to achieve the first conjunct of the goal and the sequence
Left sock followed by Left Shoe for the second conjunct.
Then the two sequences can be combined to yield the final plan.
→Any planning algorithm that can place two actions into a plan without specifying which
PLANNER comes first is called a partial-order planner [POP].
Figure 3.1 shows the partial-order plan that is the solution to the shoes and socks problem. Note
that the solution is represented as a graph of actions, not a sequence. Note also the "dummy"
actions called Start and Finish, which mark the beginning and end of the plan. Calling them
actions simplifies things, because now every step of a plan is an action. The partial-order solution
ECS 302: ARTIFICIAL INTELLIGENCE
LECTURE NOTES
corresponds to six possible total-order plans; each of these is called a linearization of the partialorder plan.
Figure 3.1 A partial-order plan for putting on shoes and socks, and the six corresponding
linearization’s into total-order plans.
Each plan has the following four components;
1) A set of actions that make up the steps of the plan. These are taken from the set of actions
in the planning problem. The "empty" plan contains just the Start and Finish actions.
Start has no preconditions and has as its effect
Finish has no effects and has as its preconditions
2) A set of ordering constraints. Each ordering constraint is of the form A
B, which is read
as "A before B" and means that action A must be executed sometime before action B, but
not necessarily immediately before. The ordering constraints must describe a proper
partial order. Any cycle-such as A
B and B
A-represents a contradiction, so an
ordering constraint cannot be added to the plan if it creates a cycle.
3) A set of causal links. A causal link between two actions A and B in the plan is written as A
B and is read as "A achieves p for B." For example, the causal link
Asserts that Right Sock On is an effect of the Right Sock action and a precondition of Right Shoe.
ECS 302: ARTIFICIAL INTELLIGENCE
LECTURE NOTES
A plan may not be extended by adding a new action C that conflicts with the causal link. An
action C conflicts with A
B if C has the effect ¬p and if C could come after A and before B.
Some authors call causal links protection intervals, because the link A
B protects p from
being negated over the interval from A to B.
4) A set of open preconditions. A precondition is open if it is not achieved by some action in
the plan.
Consider the following components resemble the above plan;
Consistent plan: It is a plan in which there are no cycles in the ordering constraints and no
conflicts with the causal links. A consistent plan with no open preconditions is a solution. It
should convince the reader with the following fact: “every linearization of a partial-order solution is a
total-order solution whose execution from the initial state will reach a goal state”.
Now formulate the search problem that POP solves. We will begin with a formulation suitable
for propositional planning problems, leaving the first-order complications for later. As usual, the
definition includes the initial state, actions, and goal test.
The initial plan contains Start and Finish, the ordering constraint Start
Finish, and no causal
links and has all the preconditions in Finish as open preconditions.
The successor function arbitrarily picks one open precondition p on an action B and generates a
successor plan for every possible consistent way of choosing an action A that achieves p.
Consistency is enforced as follows:
1. The causal link A
B and the ordering constraint A
B are added to the plan. Action A
may be an existing action in the plan or a new one. If it is new, add it to the plan and also add
Start
A and A
Finish.
ECS 302: ARTIFICIAL INTELLIGENCE
LECTURE NOTES
2. We resolve conflicts between the new causal link and all existing actions and between the
action A (if it is new) and all existing causal links. A conflict between A
B and C is resolved
by making C occur at some time outside the protection interval, either by adding B
C
C or
A. We add successor states for either or both if they result in consistent plans.
The goal test checks whether a plan is a solution to the original planning problem. Because only
consistent plans are generated, the goal test just needs to check that there are no open
preconditions.
A partial-order planning example:
Figure 3.2 The simple flat tire problem description.
The search for a solution begins with the initial plan, containing; Start action with the effect At
(Spare, Trunk) ^ At (Flat, Axle) and Finish action with the sole precondition At (Spare, Axle). Then
we generate successors by picking an open precondition to work on (irrevocably) and choosing
among the possible actions to achieve it.
ECS 302: ARTIFICIAL INTELLIGENCE
LECTURE NOTES
The sequence of events is as follows:
1. Pick the only open precondition, At (Spare, Axle) of Finish. Choose the only applicable action,
Put On (Spare, Axle).
2. Pick the At (Spare, Ground) precondition of PutOn (Spare, Axle). Choose the only applicable
action, Remove (Spare, Trunk) to achieve it. The resulting plan is shown in Figure 3.3.
Figure 3.3 The incomplete partial-order plan for the tire problem, after choosing actions
for the first two open preconditions. Boxes represent actions, with preconditions on the left
and effects on the right. Dark arrows represent causal links protecting the proposition at
the head of the arrow.
3. Pick the ¬At (Flat, Axle) precondition of PutOn (Spare, Axle). Just to be contrary, choose the
Leave Overnight action rather than the Remove (Flat, Axle) action. Notice that Leave Overnight also
has the effect ¬At (Spare, Ground), which means it conflicts with the causal link
To resolve the conflict we add an ordering constraint putting Leave Overnight before Remove
(Spare, Trunk).
Figure 3.4 The plan after choosing Leave Overnight as the action for achieving ~At (Flat, Axle).
To avoid a conflict with the causal link from Remove (Spare, Trunk) that protects At (Spare,
Ground), Leave Overnight is constrained to occur before Remove (Spare, Trunk), as shown by the
dashed arrow.
ECS 302: ARTIFICIAL INTELLIGENCE
LECTURE NOTES
4. The only remaining open precondition at this point is the At (Spare, Punk) precondition of the
action Remove (Spare, Trunk). The only action that can achieve it is the existing Start action, but the
causal link from Start to Remove (Spare, Trunk) is in conflict with the ~At (Spare, Trunk) effect of
Leave Overnight. This time there is no way to resolve the conflict with Leave Overnight: we cannot
order it before Start (because nothing can come before Start), and we cannot order it after Remove
(Spare, Trunk) (because there is already a constraint ordering it before Remove (Spare, Trunk)). So
we are forced to back up, remove the Leave Overnight action and the last two causal links, and
return to the state in Figure 3.3. In essence, the planner has proved that Leave Overnight doesn't
work as a way to change a tire.
5. Consider again the ¬At (Flat, Axle) precondition of PutOn (Spare, Axle). This time, we choose
Remove (Flat, Axle).
6. Once again, pick the At (Spare, Trunk) precondition of Remove (Spare, Trunk) and choose Start to
achieve it. This time there are no conflicts.
7. Pick the At (Flat, Axle) precondition of Remove (Flat, Axle), and choose Start to achieve it. This
gives us a complete, consistent. Plan-in other words a solution-as shown in Figure 3.5.
Figure 3.5 The final solution to the tire problem. Note that Remove (Spare, Trunk) and Remove (Flat,
Axle) can be done in either order, as long as they are completed before the Put On (Spare, Axle) action.
Partial-order planning with unbound variables:
Here we consider the complications that can arise when POP is used with first order action
representations that include variables. Suppose we have a blocks world problem with the open
precondition On (A, B) and the action
ECS 302: ARTIFICIAL INTELLIGENCE
LECTURE NOTES
Action(Move(b, x, y),
PRECOND: On(b, x) ^ Clear(b) ^ Clear(y),
EFFECT: On (b, y) ^ Clear(x) ^ ¬On (b, x) ^ ¬Clear(y))
This action achieves On (A, B) because the effect On (b, y) unifies with On (A, B) with the
substitution {b/A, y/B). We then apply this substitution to the action, yielding;
Action(Move(A, x, B),
PRECOND: On(A, x) ^ Clear(A) ^ Clear(B),
EFFECT: On(A, B) ^ Clear(x) ^¬ On(A, x ) ^ ¬Clear(B))
This leaves the variable x unbound. That is, the action says to move block A from somewhere,
without yet saying whence. This is another example of the least commitment principle: we can
delay making the choice until some other step in the plan makes it for us. For example, suppose
we have On (A, D) in the initial state. Then the Start action can be used to achieve On (A, x),
binding x to D. This strategy of waiting for more information before choosing x is often more
efficient than trying every possible value of x and backtracking for each one that fails.
The presence of variables in preconditions and actions complicates the process of detecting and
resolving conflicts. For example, when Move (A, x, B) is added to the plan, we will need a causal
link
If there is another action M2 with effect ¬On (A, z), then M2 conflicts only if z is B. To
accommodate this possibility, we extend the representation of plans to include a set of inequality
constraints of the form z # X where z is a variable and X is either another variable or a constant
symbol. In this case, we would resolve the conflict by adding z # B, which means that future
extensions to the plan can instantiate z to any value except B. Anytime we apply a substitution to
a plan, we must check that the inequalities do not contradict the substitution.
For example, a substitution that includes x/y conflicts with the inequality constraint x # y. Such
conflicts cannot be resolved, so the planner must backtrack.
ECS 302: ARTIFICIAL INTELLIGENCE
LECTURE NOTES
Heuristics for partial-order planning:
Compared with total-order planning, partial-order planning has a clear advantage in being able
to decompose problems into sub problems. It also has a disadvantage in that it does not represent
states directly, so it is harder to estimate how far a partial-order plan is from achieving a goal.
➢ The most obvious “heuristic is to count the number of distinct open preconditions”. This can be
improved by subtracting the number of open preconditions that match literals in the Start
state. As in the total-order case, this overestimates the cost when there are actions that
achieve multiple goals and underestimates the cost when there are negative interactions
between plan steps.
➢ The heuristic function is used to choose which plan to refine. Given this choice, the
algorithm generates successors based on the selection of a single open precondition to
work on. As in the case of variable selection on constraint satisfaction algorithms, this
selection has a large impact on efficiency.
➢ The most-constrained-variable heuristic from CSPs can be adapted for planning
algorithms and seems to work well. The idea is to select the open condition that can be
satisfied in the fewest number of ways.
There are two special cases of this heuristic.
1) First, if an open condition cannot be achieved by any action, the heuristic will select it; this
is a good idea because early detection of impossibility can save a great deal of work.
2) Second, if an open condition can be achieved in only one way, then it should be selected
because the decision is unavoidable and could provide additional constraints on other
choices still to be made.
-------------------------------------------------------The End--------------------------------------------------------------
Download