Unit-IV Planning
Unit-IV Planning
Introduction to Planning
• Planning is an important topic in AI.
• Planning is required for every task , for example reaching a
particular destination requires planning.
• To reach a particular destination , first we should find the best
route and then identify a set of actions to be done at a particular
time , is called planning.
• Planning is deciding a set of actions to be performed , in an agent
environment based on the perception to achieve the decided goal.
• For any planning system , we need the domain description, action
specification and goal description.
2
1
7/3/2024
Introduction to Planning
• Planning is assumed to be sequence of actions.
• Each action has its own set of preconditions, All the preconditions
to be satisfied before performing the action.
• Some effect can be either +ve or –ve
• Two types of planning
• Classical Planning Environment
• Fully Observable, Deterministic, Finite, Static and Discrete.
• Non-Classical Planning is for partially observable or stochastic
environments
• It involves a different set of algorithms and agent designs
3
Planning Problem
• Agent environment states are represented as valuations of
variables.
• An action can be represented as a procedure or program.
• The procedures are used to compute values of state variables.
• After the execution of procedure (i,.e after action ), the
environment state will be changed , towards the goal.
2
7/3/2024
Planning Algorithms
• Representation of Planning problems – states, actions and goals- should
make it possible for planning algorithms.
• Algorithms are nothing but logical structure of the problem.
• To define an efficient algorithm , a language is very important.
• STRIPS Language- The language of classical planner
• Planner decompose the agent world into logical conditions , and represent a
state as conjunction of +ve literals.
• In first order state descriptions , literals must be Ground and function free.
• At(x,) or At (Father(red, Sydney) are not allowed
• The closed world assumption , that is any conditions that are not mentioned
in a state are assumed false.
5
3
7/3/2024
4
7/3/2024
10
5
7/3/2024
11
12
6
7/3/2024
13
Representation of Goals
• A goal is a partially represented state , represented as conjunction
of positive ground literals such as
• Rich ∧ Famous , At( P2,Delhi)
• A propositional state s, satisfies a goal g, if s contains all the atoms
in g
• The propositional state Rich ∧ Famous ∧ Happy
Satisfies the goal state Rich ∧ Famous
14
7
7/3/2024
Representation of Actions
• To perform an action , we need Precondition (how
environment should be to perform this action) and effect
(how the environment will be after performing this action)
• An action for flying a pane 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)
• The variables p, from, to are different constants
15
Action Schema
• It represents a number of different actions can be derived
• Action schema consists of three parts
• The action name and parameter list
• Fly(p, from, to) - Fly is action, and p, from, to are parameters
• The precondition is a conjunction of function free positive literals , and it must be true before the action can
be executed
• Variables in the precondition must also appear in the actions parameter list
• The effect is a conjunction of function free literals describing how the state changes , when the action is
executed.
• A positive literal p are declared to be true in the state , and all the negative literals p is declared to be
false
• Variables in the effect must also appear in the actions parameter list
• Planning System divide the effect into two categories
• Add List, and Delete List
• Add List for Positive literals and Delete List negative literals
16
8
7/3/2024
Applicable Action
• An action is applicable in any state , iff that satisfies the precondition ,
otherwise the action has no effect.
• A first-order action schema , first all the variables in precondition will be
substituted.
• At(P1,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 the substitution {p=P1,from=JFK, to=SFO}
• Thus the concrete action Fly(P!,JFK, SFO) is applicable
17
18
9
7/3/2024
10
7/3/2024
• Initial State:
• Initial state of the problem
• Actions:
• Applicable to the current state
• First actions preconditions are satisfied ,successor states are generated
• Add positive literals to add list and negative literals to delete list
• Goal Test:
• Whether the state satisfies the goal of the planning
• Step cost:
• Each action is 1(assumed)
21
22
11
7/3/2024
23
• Starting from the initial state and using the problems action to search
forward for the goal state
24
12
7/3/2024
25
26
13
7/3/2024
• Initial State:
• Initial state of the problem
• Actions:
• Applicable to the current state
• First actions preconditions are satisfied ,successor states are generated
• Add positive literals to add list and negative literals to delete list
• Goal Test:
• Whether the state satisfies the goal of the planning
• Step cost:
• Each action is 1(assumed)
27
28
14
7/3/2024
29
30
15
7/3/2024
16
7/3/2024
33
17
7/3/2024
35
18
7/3/2024
37
38
19
7/3/2024
39
40
20
7/3/2024
41
42
21
7/3/2024
43
44
22
7/3/2024
45
46
23
7/3/2024
47
48
24
7/3/2024
49
50
25
7/3/2024
26
7/3/2024
• Propositional problem will look at , what the starting state, what the objects in
the domains are ,and it will produce all the possible actions , and works with
those actions.
• We construct the planning graph from left to right
• We keep inserting actions and propositions
• Then actions and propositions
• Until we get the goal proposition appear on the proposition layer ,and
• They are not mutually exclusive
• There are two states in the planning graph problem
• Construct the Planning Graph
• Search for Solution
• If you cannot get solution , then extend the planning graph and search for
solution , and keep doing that until you get the solution.
53
54
27
7/3/2024
55
56
28
7/3/2024
57
58
29
7/3/2024
59
60
30
7/3/2024
61
62
31
7/3/2024
63
64
32
7/3/2024
65
66
33
7/3/2024
67
68
34
7/3/2024
69
70
35
7/3/2024
72
36
7/3/2024
• Propositionalize the actions: replace each action schema with a set of ground actions formed by
substituting constants for each of the variables.
• Define the initial state: assert F0 for every fluent F in the problem’s initial state, and ¬F for every
fluent not mentioned in the initial state.
• Propositionalize the goal: for every variable in the goal, replace the literals that contain the
variable with a disjunction over constants. For example, the goal of having block A on another
block, On(A, x) ∧ Block(x) in a world with objects A,B and C, would be replaced by the goal
(On(A,A) ∧ Block (A)) ∨ (On(A,B) ∧ Block (B)) ∨ (On(A,C) ∧ Block (C)) .
• Add successor-state axioms: For each fluent F, add an axiom of the form
Ft+1 ⇔ ActionCauses Ft ∨ (Ft ∧ ¬ActionCausesNot Ft) , where ActionCausesF is a disjunction of
all the ground actions that have F in their add list, and ActionCausesNotF is a disjunction of all the
ground actions that have F in their delete list.
• Add precondition axioms: For each ground action A, add the axiom At ⇒ PRE(A)t, that is, if an
action is taken at time t, then the preconditions must have been true.
• Add action exclusion axioms: say that every action is distinct from every other action.
73
Planning in situational
calculus
74
37
7/3/2024
Situation Calculus
• The idea behind situation calculus is that (reachable) states are
definable in terms of the actions required to reach them.
• These reachable states are called situations. What is true in a
situation can be defined in terms of relations with the situation as an
argument.
• Situation calculus is defined in terms of situations. A situation is
either
• init, the initial situation, or
• do(A,S), the situation resulting from doing action A in situation S, if it
is possible to do action A in situation S.
75
Contd..
• Situations are connected by the Result function
• e.g. s1= Result(a,s0) is the function giving the situation that results
from doing action a while in situation s0
• Here, we represent an action sequence (plan) by a list [first | rest ]
where
• first is the initial action and rest is a list of remaining actions.
• PlanResult(p,s) generalizes Result to give the situation resulting from
executing p starting from state s:
• ∀s PlanResult([],s) = s
• ∀s,a,p PlanResult([a | p], s) = PlanResult(p, Result(a,s))
76
38
7/3/2024
Contd..
• Provides a framework for representing change, actions and reasoning
about them.
• Situational calculus:
• - is based on FOPL;
• - a situation variable models new stars of the world;
• - action objects model activities;
• - uses inference methods developed for FOPL to do the reasoning.
77
78
39
7/3/2024
SITUATIONAL CALCULUS
Situational calculus is based on FOPL plus:
Special variables: s,a – objects of type situation and action
situation s.
Situation-dependent functions and relations
also called fluents
79
80
40
7/3/2024
81
• Solutions
• solution : a plan that an agent guarantees achievement of the goal
• a solution is a complete and consistent plan
• a complete plan : every precondition of every step is achieved by some other
step
• a consistent plan : no contradictions in the ordering or binding constraints. When
we meet a inconsistent plan we backtrack and try another branch
82
41
7/3/2024
• A solution to the shopping problem is a plan P, applied to so, that yields a situation
satisfying the goal query :
at(Home, Result’(p,s0)) have(Milk,Result’(p, s0)) have(Bananas, result’(p, s0)
have(Drill,Result’ (p, s0))
P = [Go(Supermarket),Buy(Bananas),Go(HardwareStore),Buy(Drill),
Go(Home)]
83
84
42
7/3/2024
• All the approaches we have seen so far construct totally ordered plans
consisting of a strictly linear sequences of actions.
• An alternative is to represent plans as partially ordered structures: a plan is a
set of actions and a set of constraints of the form Before(ai, aj) saying that
one action occurs before another.
85
86
43
7/3/2024
• Planning combines the two major areas of AI we have covered so far: search and logic.
• A planner can be seen either as a program that searches for a solution or as one that
(constructively) proves the existence of a solution.
• Each of the major approaches to planning has its adherents, and there is as yet no consensus on
which is best. Competition and cross-fertilization among the approaches have resulted in
significant gains in efficiency for planning systems.
• full decomposability of the problem—we get an exponential speedup.
• Sometimes it is possible to solve a problem efficiently by recognizing that negative interactions
can be ruled out.
• We say that a problem has serializable sub goals if there exists an order of sub goals such that the
planner can achieve them in that order without having to undo any of the previously achieved sub
goals.
• Planners such as GRAPHPLAN, SATPLAN, and FF have moved the field of planning forward, by
raising the level of performance of planning systems, by clarifying the representational and
combinatorial issues involved, and by the development of useful heuristics.
87
44
7/3/2024
89
45
7/3/2024
91
92
46
7/3/2024
• To minimize makespan (plan duration), we must find the earliest start times for all the
actions
• critical path method (CPM) to this graph to determine the possible start and end times
of each action.
• A path through a graph representing a partial-order plan is a linearly ordered sequence
of actions beginning with Start and ending with Finish.
• The critical path is that path whose total duration is longest; the path is “critical”
because it determines the duration of the entire plan.
• The window is specified in terms of an earliest possible start time, ES, and a latest possible
start time, LS.
• The quantity LS – ES is known as the slack of an action.
• ES(Start) = 0
• ES(B) = maxA≺B ES(A) + Duration(A)
• LS(Finish) = ES(Finish)
• LS(A) = minB A LS(B) − Duration(A) .
93
94
47
7/3/2024
95
96
48
7/3/2024
97
98
49
7/3/2024
99
• Properties of HTN:
100
50
7/3/2024
101
102
51
7/3/2024
103
• Example for HTN with POP Planner(The Gift of the Magi Problem)
104
52
7/3/2024
• Example for HTN with POP Planner(The Gift of the Magi Problem)
105
• Example for HTN with POP Planner(The Gift of the Magi Problem)
106
53
7/3/2024
54