CSC411Artificial Intelligence1 Chapter 6 Building Control Algorithms For State Space Search Contents...

28
CSC411 CSC411 Artificial Intelligence Artificial Intelligence 1 Chapter 6 Building Control Algorithms For State Space Search Contents • Recursion-Based Search • Production Systems • The Blackboard Architecture for Problem Solving

Transcript of CSC411Artificial Intelligence1 Chapter 6 Building Control Algorithms For State Space Search Contents...

Page 1: CSC411Artificial Intelligence1 Chapter 6 Building Control Algorithms For State Space Search Contents Recursion-Based Search Production Systems The Blackboard.

CSC411CSC411 Artificial IntelligenceArtificial Intelligence 11

Chapter 6

Building Control Algorithms For State Space Search

Contents

• Recursion-Based Search• Production Systems• The Blackboard Architecture for

Problem Solving

Page 2: CSC411Artificial Intelligence1 Chapter 6 Building Control Algorithms For State Space Search Contents Recursion-Based Search Production Systems The Blackboard.

CSC411CSC411 Artificial IntelligenceArtificial Intelligence 22

Recursive SearchRecursive SearchRecursive searchRecursive search– A recursive step: procedure calls itselfA recursive step: procedure calls itself– A terminating conditionA terminating condition

Depth-first recursive search algorithmDepth-first recursive search algorithm

Page 3: CSC411Artificial Intelligence1 Chapter 6 Building Control Algorithms For State Space Search Contents Recursion-Based Search Production Systems The Blackboard.

CSC411CSC411 Artificial IntelligenceArtificial Intelligence 33

Recursive Search with Global VariablesRecursive Search with Global VariablesGlobal variables : open and closed

Page 4: CSC411Artificial Intelligence1 Chapter 6 Building Control Algorithms For State Space Search Contents Recursion-Based Search Production Systems The Blackboard.

CSC411CSC411 Artificial IntelligenceArtificial Intelligence 44

Pattern-Driven ReasoningPattern-Driven ReasoningProblem:Problem:– Given a set of assertions (predicate Given a set of assertions (predicate

expressions)expressions)– Determine whether a given goal is a logical Determine whether a given goal is a logical

consequence of the given set of assertionsconsequence of the given set of assertionsSolutionSolution– Use unification to select the implications (rules) Use unification to select the implications (rules)

whose conclusions match the goalwhose conclusions match the goal– Unify the goal with the conclusion of the ruleUnify the goal with the conclusion of the rule– Apply the substitutions throughout the ruleApply the substitutions throughout the rule– Transform the rule premise into a new subgoalTransform the rule premise into a new subgoal– If the subgoal matches a fact, terminateIf the subgoal matches a fact, terminate– Otherwise recur on the subgoalOtherwise recur on the subgoalRecursive algorithm – next pageRecursive algorithm – next page

Page 5: CSC411Artificial Intelligence1 Chapter 6 Building Control Algorithms For State Space Search Contents Recursion-Based Search Production Systems The Blackboard.

CSC411CSC411 Artificial IntelligenceArtificial Intelligence 55

Pattern-driven Reasoning

Page 6: CSC411Artificial Intelligence1 Chapter 6 Building Control Algorithms For State Space Search Contents Recursion-Based Search Production Systems The Blackboard.

CSC411CSC411 Artificial IntelligenceArtificial Intelligence 66

Some IssuesSome Issues

The order of assertionsThe order of assertions

Logical connectives in the rule Logical connectives in the rule premisespremises

Logical negationLogical negation

Page 7: CSC411Artificial Intelligence1 Chapter 6 Building Control Algorithms For State Space Search Contents Recursion-Based Search Production Systems The Blackboard.

CSC411CSC411 Artificial IntelligenceArtificial Intelligence 77

Page 8: CSC411Artificial Intelligence1 Chapter 6 Building Control Algorithms For State Space Search Contents Recursion-Based Search Production Systems The Blackboard.

CSC411CSC411 Artificial IntelligenceArtificial Intelligence 88

Page 9: CSC411Artificial Intelligence1 Chapter 6 Building Control Algorithms For State Space Search Contents Recursion-Based Search Production Systems The Blackboard.

CSC411CSC411 Artificial IntelligenceArtificial Intelligence 99

A production system. Control loops until working memory pattern no longer matches the conditions of any productions.

Page 10: CSC411Artificial Intelligence1 Chapter 6 Building Control Algorithms For State Space Search Contents Recursion-Based Search Production Systems The Blackboard.

CSC411CSC411 Artificial IntelligenceArtificial Intelligence 1010

Trace of a simple production system.

Page 11: CSC411Artificial Intelligence1 Chapter 6 Building Control Algorithms For State Space Search Contents Recursion-Based Search Production Systems The Blackboard.

CSC411CSC411 Artificial IntelligenceArtificial Intelligence 1111

The 8-puzzle as a production system

Page 12: CSC411Artificial Intelligence1 Chapter 6 Building Control Algorithms For State Space Search Contents Recursion-Based Search Production Systems The Blackboard.

CSC411CSC411 Artificial IntelligenceArtificial Intelligence 1212

The 8-puzzle searched by a production system with loop detection and depth-bound.

Page 13: CSC411Artificial Intelligence1 Chapter 6 Building Control Algorithms For State Space Search Contents Recursion-Based Search Production Systems The Blackboard.

CSC411CSC411 Artificial IntelligenceArtificial Intelligence 1313

• Problem: find a series of legal moves in which the knight lands on each square of the chessboard exactly once

• Legal moves of a chess knight.

The Knight’s Tour ProblemThe Knight’s Tour Problem

Page 14: CSC411Artificial Intelligence1 Chapter 6 Building Control Algorithms For State Space Search Contents Recursion-Based Search Production Systems The Blackboard.

CSC411CSC411 Artificial IntelligenceArtificial Intelligence 1414

A 3 x 3 chessboard with move rules for the simplified knight tour problem.

Page 15: CSC411Artificial Intelligence1 Chapter 6 Building Control Algorithms For State Space Search Contents Recursion-Based Search Production Systems The Blackboard.

CSC411CSC411 Artificial IntelligenceArtificial Intelligence 1515

Production rules for the 3 x 3 knight problem.

Page 16: CSC411Artificial Intelligence1 Chapter 6 Building Control Algorithms For State Space Search Contents Recursion-Based Search Production Systems The Blackboard.

CSC411CSC411 Artificial IntelligenceArtificial Intelligence 1616

A production system solution to the 3 x 3 knight’s tour problem.

Page 17: CSC411Artificial Intelligence1 Chapter 6 Building Control Algorithms For State Space Search Contents Recursion-Based Search Production Systems The Blackboard.

CSC411CSC411 Artificial IntelligenceArtificial Intelligence 1717

Control AlgorithmsControl Algorithms

The general recursive path definitionThe general recursive path definitionX path(X,X)X path(X,X)

X,Y[path(X,Y) X,Y[path(X,Y) Z[move(X,Z) Z[move(X,Z) path(Z,Y)]] path(Z,Y)]]

The revised path definition to avoid The revised path definition to avoid infinite loopinfinite loop

X path(X,X)X path(X,X)

X,Y[path(X,Y) X,Y[path(X,Y) Z[move(X,Z) Z[move(X,Z) (been(Z)) (been(Z)) assert(been(Z)) assert(been(Z)) path(Z,Y)]] path(Z,Y)]]

Page 18: CSC411Artificial Intelligence1 Chapter 6 Building Control Algorithms For State Space Search Contents Recursion-Based Search Production Systems The Blackboard.

CSC411CSC411 Artificial IntelligenceArtificial Intelligence 1818

The recursive path algorithm as production system.

Page 19: CSC411Artificial Intelligence1 Chapter 6 Building Control Algorithms For State Space Search Contents Recursion-Based Search Production Systems The Blackboard.

CSC411CSC411 Artificial IntelligenceArtificial Intelligence 1919

A Production System in PrologA Production System in PrologFarmer, wolf, goat, and cabbage problemFarmer, wolf, goat, and cabbage problem– A farmer with his wolf, goat, and cabbage come to the edge of A farmer with his wolf, goat, and cabbage come to the edge of

a river they wish to cross. There is a boat at the river’s edge, a river they wish to cross. There is a boat at the river’s edge, but, of course, only the farmer can row. The boat also can but, of course, only the farmer can row. The boat also can carry only two things, including the rower, at a time. If the wolf carry only two things, including the rower, at a time. If the wolf is ever left alone with the goat, the wolf will eat the goat; is ever left alone with the goat, the wolf will eat the goat; similarly if the goat is left alone with the cabbage, the goat will similarly if the goat is left alone with the cabbage, the goat will eat the cabbage. Devise a sequence of crossings of the river so eat the cabbage. Devise a sequence of crossings of the river so that all four characters arrives safely on the other side of the that all four characters arrives safely on the other side of the river.river.

RepresentationRepresentation– state(F, W, G, C) describes the location of Farmer, Wolf, Goat, state(F, W, G, C) describes the location of Farmer, Wolf, Goat,

and Cabbageand Cabbage– Possible locations are e for east, w for west, bankPossible locations are e for east, w for west, bank– Initial state is state(w, w, w, w)Initial state is state(w, w, w, w)– Goal state is state(e, e, e, e)Goal state is state(e, e, e, e)– Predicates opp(X, Y) indicates that X and y are opposite sides Predicates opp(X, Y) indicates that X and y are opposite sides

of the riverof the river– Facts: Facts:

opp(e, w).opp(e, w).opp( w, e).opp( w, e).

Page 20: CSC411Artificial Intelligence1 Chapter 6 Building Control Algorithms For State Space Search Contents Recursion-Based Search Production Systems The Blackboard.

CSC411CSC411 Artificial IntelligenceArtificial Intelligence 2020

Sample crossings for the farmer, wolf, goat, and cabbage problem.

Page 21: CSC411Artificial Intelligence1 Chapter 6 Building Control Algorithms For State Space Search Contents Recursion-Based Search Production Systems The Blackboard.

CSC411CSC411 Artificial IntelligenceArtificial Intelligence 2121

Portion of the state space graph of the farmer, wolf, goat, and cabbage problem, including unsafe states.

Page 22: CSC411Artificial Intelligence1 Chapter 6 Building Control Algorithms For State Space Search Contents Recursion-Based Search Production Systems The Blackboard.

CSC411CSC411 Artificial IntelligenceArtificial Intelligence 2222

Unsafe statesUnsafe statesunsafe(state(X, Y, Y, C)) :- opp(X, Y).unsafe(state(X, Y, Y, C)) :- opp(X, Y).unsafe(state(X, W, Y, Y)) :- opp(X, Y).unsafe(state(X, W, Y, Y)) :- opp(X, Y).

Move rulesMove rulesmove(state(X, X, G, C), state(Y, Y, G, C))) :- opp(X, Y), not(unsafe(state(Y, Y, G, move(state(X, X, G, C), state(Y, Y, G, C))) :- opp(X, Y), not(unsafe(state(Y, Y, G,

C))), writelist([‘farms takes wolf’, Y, Y, G, C]).C))), writelist([‘farms takes wolf’, Y, Y, G, C]).move(state(X, W, X, C), state(Y, W, Y, C)) :- opp(X, Y), not(unsafe(state(Y, W, Y, move(state(X, W, X, C), state(Y, W, Y, C)) :- opp(X, Y), not(unsafe(state(Y, W, Y,

C))), writelist([‘farmers takes goat’, Y, W, Y,C]).C))), writelist([‘farmers takes goat’, Y, W, Y,C]).move(state(X, W, G, X), state(Y, W, G, Y)) :- opp(X, Y), not(unsafe(state(Y, W, move(state(X, W, G, X), state(Y, W, G, Y)) :- opp(X, Y), not(unsafe(state(Y, W,

G, Y))), writelist(‘farmer takes cabbage’, Y, W, G, Y]).G, Y))), writelist(‘farmer takes cabbage’, Y, W, G, Y]).move(state(X, W, G, C), state(Y, W, G, C)) :-opp(X, Y), not(unsafe(state(Y, W, move(state(X, W, G, C), state(Y, W, G, C)) :-opp(X, Y), not(unsafe(state(Y, W,

G, C))), writelist([‘farmer takes self’, Y, W, G, C]).G, C))), writelist([‘farmer takes self’, Y, W, G, C]).move(state(F, W, G, C), state(F, W, G, C)) :- writelist([‘Backtrack from ‘, F, W, move(state(F, W, G, C), state(F, W, G, C)) :- writelist([‘Backtrack from ‘, F, W,

G, C]), fail.G, C]), fail.Path rulesPath rulesPath(Goal, Goal, Stack) :- write(‘Solution Path Is: ‘), nl, Path(Goal, Goal, Stack) :- write(‘Solution Path Is: ‘), nl,

reverse_print_stack(Stack).reverse_print_stack(Stack).Path(State, Goal, Stack) :- move(State, Next), not(member_stack(Next, Path(State, Goal, Stack) :- move(State, Next), not(member_stack(Next,

Stack)), stack(Next, Stack, NewStack), path(Next, Goal, NewStack), !.Stack)), stack(Next, Stack, NewStack), path(Next, Goal, NewStack), !.Start ruleStart ruleGo(Start, Goal) :- empty_stack(EmptyStack), stack(Start, EmptyStack, Stack), Go(Start, Goal) :- empty_stack(EmptyStack), stack(Start, EmptyStack, Stack),

path(Start, Goal, Stack).path(Start, Goal, Stack).QuestionQuestion?- go(state(w, w, w, w), state(e, e, e, e)?- go(state(w, w, w, w), state(e, e, e, e)

Production Rules in PrologProduction Rules in Prolog

Page 23: CSC411Artificial Intelligence1 Chapter 6 Building Control Algorithms For State Space Search Contents Recursion-Based Search Production Systems The Blackboard.

CSC411CSC411 Artificial IntelligenceArtificial Intelligence 2323

Data-driven search in a production system.

Page 24: CSC411Artificial Intelligence1 Chapter 6 Building Control Algorithms For State Space Search Contents Recursion-Based Search Production Systems The Blackboard.

CSC411CSC411 Artificial IntelligenceArtificial Intelligence 2424

Goal-driven search in a production system.

Page 25: CSC411Artificial Intelligence1 Chapter 6 Building Control Algorithms For State Space Search Contents Recursion-Based Search Production Systems The Blackboard.

CSC411CSC411 Artificial IntelligenceArtificial Intelligence 2525

Bidirectional search missing in both directions, resulting in excessive search.

Page 26: CSC411Artificial Intelligence1 Chapter 6 Building Control Algorithms For State Space Search Contents Recursion-Based Search Production Systems The Blackboard.

CSC411CSC411 Artificial IntelligenceArtificial Intelligence 2626

Bidirectional search meeting in the middle, eliminating much of the space examined by unidirectional search.

Page 27: CSC411Artificial Intelligence1 Chapter 6 Building Control Algorithms For State Space Search Contents Recursion-Based Search Production Systems The Blackboard.

CSC411CSC411 Artificial IntelligenceArtificial Intelligence 2727

Major advantages of production systems for artificial intelligence

• Separation of Knowledge and Control

• A Natural Mapping onto State Space Search

• Modularity of Production Rules

• Pattern-Directed Control

• Opportunities for Heuristic Control of Search

• Tracing and Explanation

• Language Independence

• A Plausible Model of Human Problem-Solving

Page 28: CSC411Artificial Intelligence1 Chapter 6 Building Control Algorithms For State Space Search Contents Recursion-Based Search Production Systems The Blackboard.

CSC411CSC411 Artificial IntelligenceArtificial Intelligence 2828

Blackboard architectureBlackboard architecture• Extend production systems• Separate productions into modules• Each module is an agent -- knowledge source• A single global structure -- blackboard