Reasoning and Planning - pages.cpsc.ucalgary.ca

69
CPSC 433 Articial Intelligence: An Introduction Christian Jacob, University of Calgary CPSC 433 Christian Jacob Dept. of Computer Science Dept. of Biochemistry & Molecular Biology University of Calgary Reasoning and Planning

Transcript of Reasoning and Planning - pages.cpsc.ucalgary.ca

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

CPSC 433

Christian JacobDept. of Computer Science

Dept. of Biochemistry & Molecular BiologyUniversity of Calgary

Reasoning and Planning

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

Knowledge Engineering

What we lookat now

What we lookat later

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

1. Reasoning with Predicate Logic

2. Planning

Knowledge Representation, Reasoning and Planning

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

• A logic system consists of four parts:

• Alphabet: a set of basic symbols from which more complex sentences are made.

• Syntax: a set of rules or operators for constructing expressions (sentences).

• Semantics: for defining the meaning of the sentences

• Inference rules: for constructing semantically equivalent but syntactically different sentences

Logic System

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

• The following types of symbols are allowed in predicate logic:

• Terms

• Predicates

• Connectives

• Quantifiers

Predicate Logic

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

• Terms:

• Constant symbols: symbols, expressions, or entities which do not change during excecution (e.g., true / false)

• Variable symbols: represent entities that can change during excecution

• Function symbols: represent functions which process input values on a predefined list of parameters and obtain resulting values

Predicate Logic

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

• Predicates:

• Predicate symbols: represent true/false-type relations between objects.

Objects are represented by constant symbols.

Predicate Logic

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

• Connectives:

• Conjunction ( ∧ )

• Disjunction ( ∨ )

• Negation ( ¬ )

• Implication ( ⇒ )

• Equivalence ( = )

• ... (same as for propositional calculus)

Predicate Logic

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

• Quantifiers:

• valid for variable symbols

• Existential quantifier ( ∃ ): “There exists at least one value for x from its domain.”

• Universal quantifier ( ∀ ): “For all x in its domain.”

Predicate Logic

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

• First-order logic allows quantified variables to refer to objects, but not to predicates or functions.

• For applying an inference to a set of predicate expressions, the system has to process matches of expressions.

• The process of matching is called unification.

First-Order Logic

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

• In PROLOG, a quantifier-free Horn-clausal notation is adopted.

• ∀x, Human(x) ⇒ Mortal(x)

• mortal(X) :- human(X).

• Human(Socrates)

• human(Socrates).

PROLOGProgramming in Logic

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

• A rule

• (A1, A2, ..., An) ⇒ B

as a Horn clause has the following form:

• B :- A1, A2, ..., An.

• The goal B is true if all the sub-goals A1, A2, ..., An are true. (Remember: AND/OR Trees)

• A1, A2, ..., An are predicate expressions.

PROLOG: Horn Clauses

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

• A fact is represented as a literal clause with the right side being the constant true.

• Therefore, a clause representing a fact is always true.

• Example:

• human(Socrates) :- true.

• human(Socrates).

PROLOG: Facts

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

• In PROLOG knowledge is represented as a set of clauses with

• premises (right side of the clause) and

• one conclusion (left side).

• AND is denoted by the character “,”.

• OR is denoted by the character “;”.

• NOT is denoted by “¬” or “-”.

Knowledge Representation

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

PROLOG Architecture

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

PROLOG Architecture

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

• father(John, Mary).

• father(Jack, Andy).

• father(Jack, Tom).

• mother(Helen, Jack).

• mother(Mary, Jilly).

• grandfather(Barry, Jim).

Family Example: Facts

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

grandfather(X,Y)

:- father(X,Z), parent(Z,Y).

grandmother(X,Y)

:- mother(X,Z), parent(Z,Y).

parent(X,Y) :- mother(X,Y).

parent(X,Y) :- father(X,Y).

Family Example: Rules

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

grandfather(X,Y)

:- father(X,Z), parent(Z,Y).

grandmother(X,Y)

:- mother(X,Z), parent(Z,Y).

parent(X,Y) :- mother(X,Y); father(X,Y).

Family Example: RulesAND

OR

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

Goal?- grandfather(John, Jilly).

yes

Goal?- grandmother(Helen, X).

2 solutions

X = Andy; X = Tom

Goal?- grandmother(X,Y), X = Y.

fail

PROLOG Sample Dialoguefather(John, Mary).father(Jack, Andy).father(Jack, Tom).mother(Helen, Jack).mother(Mary, Jilly).grandfather(Barry, Jim).

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

PROLOG Sample Inference

Goal?– grandfather(John, Jilly).

grandfather(John, Jilly)

father(John, Z) parent(Z, Jilly)

mother(Z, Jilly) father(Z, Jilly)

AND

ORMary

Mary

yes

father(John, Mary).father(Jack, Andy).father(Jack, Tom).

mother(Helen, Jack).mother(Mary, Jilly).

grandfather(Barry, Jim).

father(John, Mary).father(Jack, Andy).father(Jack, Tom).mother(Helen, Jack).mother(Mary, Jilly).grandfather(Barry, Jim).

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

PROLOG Sample Inference

Goal?– grandmother(Helen, X).

grandmother(Helen, X)

mother(Helen, Z) parent(Z, X)

mother(Z, X) father(Z, X)

AND

ORJack

Jack

2 solutions: X= Andy or X= Tom

AndyTom

father(John, Mary).father(Jack, Andy).father(Jack, Tom).

mother(Helen, Jack).mother(Mary, Jilly).

grandfather(Barry, Jim).

father(John, Mary).father(Jack, Andy).father(Jack, Tom).mother(Helen, Jack).mother(Mary, Jilly).grandfather(Barry, Jim).

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

1. Reasoning with Predicate Logic

2. Planning

Knowledge Representation, Reasoning and Planning

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

a. Simple Planning Agents

b. From Searching to Planning

c. Planning through Logical Inference

d. Representations for Planners

e. Example: Partial Order Planner (POP)

Planning

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

• A planning agent uses its percepts of the world state to form a model of the world.

• The agent first generates a goal to achieve.

• Then the agent constructs a plan to achieve it from its current state.

• Once it has a plan, it keeps executing it until the plan is finished.

• Then the agent begins again with a new goal.

Simple Planning Agent

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

• Suppose we are at home and we want to go to school, and we must take the bus to do so.

• A simple plan would likely be:

• Start state: We are at home.

• Actions:

- Go to the bus stop.

- Get on the bus. ...

A Simple Example Plan

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

•• Actions

- Go to the bus stop.

- Get on the bus.

- Ride the bus to school.

- Get off the bus.

- Walk from the bus stop to your classroom.

• Goal state: We are at school.

A Simple Example Plan

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

a. Simple Planning Agents

b. From Searching to Planning

c. Planning through Logical Inference

d. Representations for Planners

e. Example: Partial Order Planner (POP)

Planning

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

• Actions

• Actions are described by programs that generate successor state descriptions.

• States

• State representations are used for

- successor generation,

- heuristic function evaluation, and

- goal testing.

From Searching to Planning

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

• Goals

• The goal test and heuristic function are the only way to test for a goal state.

• Plans

• A solution (a special plan) is an unbroken sequence of actions from an initial state to a goal state.

From Searching to Planning

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

• First-order Logic

• States and goals: sets of sentences

• Actions: logical descriptions of preconditions and effects.

• Consequently, we get direct connections between states and actions.

Utilizing First-Order Logic

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

• Use first-order logic to select an appropriate action for a plan:

• Goal: Have(Milk)

• Database: Buy(x) ⇒ Have(x)

• Chosen action (by inference): Buy(Milk)

States and Actions: Example

Just like the family relationships example!

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

• A planner is free to add actions to the plan wherever they are needed.

• Example: Choose Buy(Milk) even before knowing where and how to get Milk.

• There is no necessary connection between the order of planning and the order of execution.

• Representing states as sets of logical sentences is essential for making this freedom possible.

Planning Order

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

a. Simple Planning Agents

b. From Searching to Planning

c. Planning through Logical Inference

d. Representations for Planners

e. Example: Partial Order Planner (POP)

Planning

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

• Situation Calculus

• Initial state: an arbitrary logical sentence about a situation S. (= True)

- At(Home, S) ∧ ¬Have(Milk, S) ∧ ¬Have(Bananas, S) ∧ ¬Have(Dri#, S)

• Goal state: a logical query asking for a suitable situation s such that:

- ∃s At(Home, s) ∧ Have(Milk, s) ∧ Have(Bananas, s) ∧

Have(Dri#, s) (= True)

Logical Inference Planning

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

• Operators: a set of descriptions of actions.

- ∀ a, s: Have(Milk, Result(a, s)) :⇔

  [( a = Buy(Milk) ∧ At(Supermarket, s) ∨

  (Have(Milk, s) ∧ a ≠ Drop(Milk)) ]

- Result(a, s): the situation resulting from executing action a in situation s.

Logical Inference Planning

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

• ResultSeq([a1,...,an], s): the situation resulting from executing the sequence of actions k, starting in situation s.

- ∀ s: ResultSeq( [], s) = s

- ∀ A, a, s: ResultSeq( [A | an], s) = Result(an, ResultSeq(A, s))

Logical Inference Planning

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

• A solution to the shopping problem is a plan p that, when applied to the start state S, yields a situation satisfying the goal query.

• Therefore, we search for a plan p such that

• At(Home, ResultSeq( p, S)) ∧

Have(Milk, ResultSeq( p, S)) ∧

Have(Bananas, ResultSeq( p, S)) ∧

Have(Dri#, ResultSeq( p, S))

Shopping Example

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

The plan

• p = [ Go(Supermarket), Buy(Milk), Buy(Bananas),   Go(HardwareStore), Buy(Dri#), Go(Home) ]

is a solution for the goal

• At(Home, ResultSeq(p, S)) ∧

Have(Milk, ResultSeq(p, S)) ∧

Have(Bananas, ResultSeq(p, S)) ∧

Have(Dri#, ResultSeq(p, S))

Shopping Example

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

a. Simple Planning Agents

b. From Searching to Planning

c. Planning through Logical Inference

d. Representations for Planners

e. Example: Partial Order Planner (POP)

Planning

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

• An action, embedded in a plan

• Action description: name for a possible action

• Precondition for an operator: a conjunction of atoms (positive literals) stating what must be true before the operator can be applied.

• Effect of an operator: a conjunction of literals (positive or negative) that describe how the situation changes when the operator is applied.

Representing Actions

• Op( ACTION: Go(there),

PRECOND: At(here) ∧ Path(here, there),

EFFECT: At(there) ∧ ¬At(here))

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

Operator Example

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

• Least Commitment Principle — As a planner, don’t make a decision until you have to.

• If a decision is not important at a given stage, leave it undecided.

- Allows for greater flexibility in the planning process.

- Results in less backtracking.

• This leads to a partial order of the action sequences within a plan.

Total and Partial Order Plans

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

Example: Putting Shoes On

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

Data Structure for Plans• A set of plan steps. Each step is one of the

operators.

• A set of step ordering constraints.

• Each constraint is of the form Si < S$

• “Step Si must occur some time before step Sk.”

• A set of variable binding constraints of the form v = x. (v: variable, x: constant / variable)

• A set of causal links.

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

• Plan( STEPS: {

S1: Op( ACTION: Start),

S2: Op( ACTION: Finish,

PRECOND: RightShoeOn + Le'ShoeOn)),

ORDERINGS: { S1 < S2 } )

Data Structure: Shoe Example

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

• Causal links are formed based on the fulfilling of preconditions.

• A causal link is created when a given state S1 contains a precondition c for state S2.

• S1 ⇒ S2

• “S1 achieves c for S2.”

• Causal links are protected.

Causal Links

c

S1S3

S2

c

¬c

S3 threatens a condition c established by S1 and protected by the causal link from S1 to S2.

When linearizing a plan, threats that may delete a precondition are ordered either

- before the first state (demoted) or - after the second (promoted)when linearizing the plan.

This prevents removing the link.

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

Threatened Causal Link

S1S3

S2

c

¬c

S3 threatens a condition c established by S1 and protected by the causal link from S1 to S2.

S1S3

S2

c

¬c

S3 threatens a condition c established by S1 and protected by the causal link from S1 to S2.

When linearizing a plan, threats that may delete a precondition are ordered either

- before the first state (demoted) or - after the second (promoted)when linearizing the plan.

This prevents removing the link.

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

Linearizing a Plan with Causal Links

S1S3

S2

c

¬c

When linearizing a plan, threats that may delete a precondition are ordered either

- before the first state (demoted) or - after the second (promoted)

when linearizing the plan.

This prevents removing the link.

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

Linearizing a Plan with Causal Links

S1S3

S2

c

¬c

promote

S1

S3

S2

¬c

c

demote

S1

S3

S2

¬c

c

before the first

state

after the first

state

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

a. Simple Planning Agents

b. From Searching to Planning

c. Planning through Logical Inference

d. Representations for Planners

e. Example: Partial Order Planner (POP)

Planning

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

• POP uses regressive planning to create a solution.

1. Start with a minimal partial plan and extend it at each step by achieving the precondition of a state s.

2. Set up causal links and eliminate threats.

3. If an applicable operator cannot be found, backtrack to previous choice point.

• POP is sound (truth-preserving) and complete, i.e., it always finds a solution if one exists.

Partial Order Planner (POP)

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

POP Shopping ExampleSM: Supermarket

HWS: Hardware Store

Facts:

Goal:

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

POP Shopping Example

Op(ACTION: Buy(x), PRECOND: At(store) ∧ Sells(store, x), EFFECT: Have(x) )

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

POP Shopping Example

Op(ACTION: Buy(x), PRECOND: At(store) ∧ Sells(store, x), EFFECT: Have(x) )

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

POP Shopping Example

Op(ACTION: Buy(x), PRECOND: At(store) ∧ Sells(store, x), EFFECT: Have(x) )

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

POP Shopping Example

Op(ACTION: Start, EFFECT: At(Home) ∧ Sells(HWS, Drill) ∧ Sells(SM, Milk) ∧ Sells(SM, Banana))

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

POP Shopping Example

Op(ACTION: Start, EFFECT: At(Home) ∧ Sells(HWS, Drill) ∧ Sells(SM, Milk) ∧ Sells(SM, Banana))

Causal links

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

POP Shopping Example

A partial plan achieving At preconditions of the three Buy actions.

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

POP Shopping Example

A flawed plan, getting the agent to the HWS and SM.⇒ Change causal link and add causal link protection

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

POP Shopping Example

Causal link protection ...?

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

POP Shopping Example

Causal link protection.

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

POP Shopping Example

Again: Causal link protections are needed!

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

POP Shopping Example

Causal link protection.

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

POP Shopping Example

A Solution Plan

: causal link protection

http://www.cs.ubc.ca/labs/lci/CIspace/index.htmlCPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

Tools for Computational Intelligence

Tools for learning

Computational

Intelligence

Home NewsOlder

VersionsDownloads

Supported

PlatformsPeople

Report a

bug!

Terms of

Use

Here are some applets that are designed as tools for learning and exploring concepts in artificial intelligence.They are part of the online resources for Computational Intelligence. If you are teaching or learning aboutAI, you may use these applets freely. Feedback is welcome.

Graph Searching Search is an important part of CI; many problems can be cast as the problem of finding apath in a graph. This graph-searching applet is designed to help you learn about differentsearch strategies. [Help] [Bugs & Enhancements]

Consistency Based CSP Solver Constraint satisfaction problems (CSPs) are pervasive in AI problems. A constraintsatisfaction problem is the problem of assigning values to variables that satisfy someconstraints. This applet lets you investigate arc consistency and domain splitting withbacktracking as ways to solve these problems. [Help] [Bugs & Enhancements]

Stochastic Local Search Based CSP Solver This applet is designed to help you learn another strategy for solving CSPs. This appletdemonstrates stochastic local search (various mixes of hill climbing and random moves)that walks through the space of total assignments trying to find an assignment withminimal error. [Help] [Bugs & Enhancments]

Decision Trees Learning is the ability to improve one's behaviour based on experience and represents animportant element of computational intelligence. Decision trees are a simple yetsuccessful technique for supervised classification learning. This applet demonstrates howto build a decision tree using a training data set and then use the tree to classify unseenexamples in a test data set. [Help] [Bugs & Enhancements]

Belief and Decision Networks Belief networks (also called Bayesian networks or causal networks) are a representationfor independence amongst random variables for probabilistic reasoning under uncertainty.

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

Blocksworld• A robot gripper must arrange a set of blocks into a particular configuration on

the table.

• A block may be on the table, or placed on top of another block.

• The gripper can only hold one block at a time, and can only pick up blocks that have no other blocks on top of them.

The problem is modeled by the following propositions:

• holding(B): the gripper is holding block B

• empty: the gripper is not holding a block• on(B1,B2): block B1 is on top of block

B2• ontable(B): block B is on the table• clear(B): block B has no blocks on top of

it and is not being held by the gripper

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

Blocksworld: Actions

Action Preconditions Add List Delete List

pickup(B1, B2) empty & clear(B1) & on(B1, B2)

holding(B1), clear(B2)

empty, on(B1, B2), clear(B1)

pickuptable(B) empty & clear(B) & ontable(B) holding(B) empty, ontable(B),

clear(B)

putdown(B1, B2) holding(B1) & clear(B2)

empty, on(B1, B2), clear(B1)

clear(B2), holding(B1)

putdowntable(B) holding(B) empty, ontable(B), clear(B) holding(B)

Add List: added to the world’s current stateDelete Lust: deleted from the world’s current state

CPSC 433 — Artificial Intelligence: An Introduction Christian Jacob, University of Calgary

• Kasabov, N. (1996). Foundations of Neural Networks, Fuzzy Systems, amd Knowledge Engineering. Cambridge, MA, MIT Press.

• Nilsson, N. (1998). Artificial Inte#igence — A New Synthesis. San Francisco, CA, Morgan Kaufmann.

• Russel, S., and Norvig, P. (1995). Artificial Inte#igence — A Modern Approach. Upper Saddle River, NJ, Prentice Hall.

References