using search in problem solving

31
Using Search in Using Search in Problem Solving Problem Solving Part II Part II

Upload: aurora-witt

Post on 01-Jan-2016

34 views

Category:

Documents


0 download

DESCRIPTION

Using Search in Problem Solving. Part II. Search and AI. Generate and Test Planning techniques Mini Max algorithm Constraint Satisfaction search. The Search Space. The search space is known in advance e.g. finding a map route - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Using Search in Problem Solving

Using Search in Using Search in Problem SolvingProblem Solving

Part IIPart II

Page 2: Using Search in Problem Solving

2

Search and AISearch and AI

Generate and TestGenerate and Test Planning techniquesPlanning techniques Mini Max algorithmMini Max algorithm Constraint Satisfaction searchConstraint Satisfaction search

Page 3: Using Search in Problem Solving

3

The Search SpaceThe Search Space

The search space is known in The search space is known in advance e.g. finding a map routeadvance e.g. finding a map route

The search space is created The search space is created while solving the problem - e.g. while solving the problem - e.g. game playinggame playing

Page 4: Using Search in Problem Solving

4

Generate and Test Generate and Test ApproachApproach

Search tree - built during the search process

Root - corresponds to the initial state

Nodes: correspond to intermediate states (two different nodes may correspond to one and the same state)

Links - correspond to the operators applied to move from one state to the next state

Node description

Page 5: Using Search in Problem Solving

5

Node DescriptionNode Description

The corresponding stateThe corresponding state The parent nodeThe parent node The operator applied The operator applied The length of the path from the root to The length of the path from the root to

that nodethat node The cost of the pathThe cost of the path

Page 6: Using Search in Problem Solving

6

Node GenerationNode Generation

To expand a node means to apply operators to the node and obtain next nodes in the tree i.e. to generate its successors.

Successor nodes: obtained from the current node by applying the operators

Page 7: Using Search in Problem Solving

7

AlgorithmAlgorithmStore root (initial state) in stack/queue

While there are nodes in stack/queue DO:

Take a node

While there are applicable operators DO:

Generate next state/node (by an operator)

If goal state is reached - stop

If the state is not repeated - add into stack/queue

To get the solution: Print the path from the root to the found goal state

Page 8: Using Search in Problem Solving

8

Example - the Jugs Example - the Jugs problemproblem

We have to decide:

• representation of the problem state, initial and final states

• representation of the actions available in the problem, in terms of how they change the problem state.

• what would be the cost of the solution

Path costSearch cost

Page 9: Using Search in Problem Solving

9

Problem representationProblem representation

Problem state: a pair of numbers (X,Y): X - water in jar 1 called A, Y - water in jar 2, called B.

Initial state: (0,0)

Final state: (2, _ ) here "_" means "any quantity"

Page 10: Using Search in Problem Solving

10

Operations for the Jugs Operations for the Jugs problemproblem

Operators: PreconditionsEffects

O1. Fill A X < 4 (4, Y)

O2. Fill B Y < 3 (X, 3)

O3. Empty A X > 0 (0, Y)

O4. Empty B Y > 0 (X, 0)

O5. Pour A into B X > 3 - Y ( X + Y - 3 , 3)

X 3 - Y ( 0, X + Y)

O6. Pour B into A Y > 4 - X (4, X + Y - 4)

Y 4 - X ( X + Y, 0)

Page 11: Using Search in Problem Solving

11

Search tree built in a Search tree built in a breadth-first mannerbreadth-first manner

0,0

3,0 0,4

3,4 0,3 3,4 3,1

O1

O2

O2

O5

O1

O6

Page 12: Using Search in Problem Solving

12

ComparisonComparison

Breadth-first finds the best solution but requires more memory In the Jugs problem:

63 nodes generated, solution in 6 steps

Depth first uses less memory but the solution maybe not the optimal one. In the Jugs problem:

23 nodes generated, solution in 8 steps

Page 13: Using Search in Problem Solving

13

The A* AlgorithmThe A* Algorithm

To use A* with generate and

test approach, we need a

priority queue and an

evaluation function.The basic algorithm is the same

except that the nodes are evaluated

Example: The Eight Puzzle problem

Page 14: Using Search in Problem Solving

14

Planning TechniquesPlanning Techniques

Means-Ends analysisInitial state, Goal state, intermediate states.

Operators to change the states.Each operator:

PreconditionsEffects

Go backwards : from the goal to the initial state.

Page 15: Using Search in Problem Solving

15

Put the goal state in a list of subgoals

While the list is not empty, doTake a subgoal.

Is there an operation that has as an effect this goal state?

If no - the problem is not solvable.If yes - put the operation in the plan.

Are the preconditions fulfilled?If yes - we have constructed the planIf no - put the preconditions in the list of subgoals

Basic AlgorithmBasic Algorithm

Page 16: Using Search in Problem Solving

16

More Complex ProblemsMore Complex Problems

Goal state - a set of sub-states

Each sub-state is a goal.

To achieve the target state we have to achieve each goal in the Target state.

(The algorithm is modified as described on p. 89.)

Page 17: Using Search in Problem Solving

17

Extensions of the Basic Extensions of the Basic MethodMethod

Planning with goal protectionPlanning with goal protection Nonlinear planningNonlinear planning Hierarchical planningHierarchical planning Reactive planningReactive planning

Page 18: Using Search in Problem Solving

18

Game PlayingGame Playing

Special feature of games: there is an opponent that tries to destroy our plans.

The search tree (game tree) has to reflect the possible moves of both players

Page 19: Using Search in Problem Solving

19

Player1

Player2

Player1

Page 20: Using Search in Problem Solving

20

MiniMax procedureMiniMax procedureBuild the search tree. Assign scores to the leavesAssign scores to intermediate nodes

If node is a leaf of the search tree - return its score Else:

If it is a maximizing node return maximum of scores of the successor nodes

Else - return minimum of scores of the successor nodes

After that, choose nodes with highest score

Page 21: Using Search in Problem Solving

21

Alpha-Beta PruningAlpha-Beta Pruning

At maximizing level the score is at least the score of any successor.

At minimizing level the score is at most the score of any successor.

Page 22: Using Search in Problem Solving

22

A:10

B:10 C: 0

E:10 F:10 G: 0 H:10

I:10 J: 0 K:10 L:-10

M:-10 N:0 O:10 P:-10

Maximizing score

Minimizing score

P1's move

P2's move

P1's minimax tree

Page 23: Using Search in Problem Solving

23

Alpha-Beta Cutoff function MINIMAX-AB(N, A, B) is begin Set Alpha value of N to A and Beta value of N to B; if N is a leaf then return the estimated score of this leaf else For each successor Ni of N loop

Let Val be MINIMAX-AB(Ni, Alpha of N, Beta of N); if N is a Min node then

Set Beta value of N to Min { Beta value of N, Val }; if Beta value of N <= Alpha value of N then

exit loop; Return Beta value of N; else

Set Alpha value of N to Max{Alpha value of N, Val}; if Alpha value of N >= Beta value of N then exit loop; Return Alpha value of N;

end MINIMAX-AB;

Page 24: Using Search in Problem Solving

24

A

C

B

D

E

10

F

11

G

H I

J

K

L M

N

O P

Q

R

S

T U

V

W X

Y

Z

9 12 14 15 13 14 5 2 4 1 3 24 10 18

Circles are maximizing nodes

The shadowed nodes are cut off

Page 25: Using Search in Problem Solving

25

Constraint Satisfaction Constraint Satisfaction SearchSearch

State description: a set of variables. A set of constraints on the assigned values of

variables.

Each variable may be assigned a value within its domain, and the value must not violate the constraints.

Initial state - the variables do not have values Goal state: Variables have values and the

constraints are obeyed.

Page 26: Using Search in Problem Solving

26

ExampleExample

WEEKWEEK

LOANLOAN WEEKWEEK

++ LOAN +LOAN + WEEKWEEK

LOANLOAN WEEKWEEK

------------ -------------------------- --------------

DEBT MONTHDEBT MONTH

Constraints for the second problem:

• All letters should correspond to different digits

• M not equal to zero, as a starting digit in a number

• W not equal to zero as a starting digit in a number

• 4 * K = n1 * 10 + H , where n1 can be

0, 1, 2, 3. Hence K cannot be 0. • 4 * E = n2 * 10 + n1 + T • 4 * E = n3 * 10 + n2 + N • 4 * W = n4 * 10 + n3 + O • M = n4

Page 27: Using Search in Problem Solving

27

Page 28: Using Search in Problem Solving

28

Page 29: Using Search in Problem Solving

29

SummarySummary Search SpaceSearch Space

Initial state Initial state

Goal state Goal state

intermediate states intermediate states

operatorsoperators

costcost

Page 30: Using Search in Problem Solving

30

SummarySummary

Search methodsSearch methods Exhaustive (depth-first, breadth-Exhaustive (depth-first, breadth-

first)first)

InformativeInformative

Hill climbingHill climbing

Best-firstBest-first

A*A*

Page 31: Using Search in Problem Solving

31

SummarySummary

Problem solving methods Problem solving methods using searchusing search Generate and TestGenerate and Test Means-Ends Analysis (Planning)Means-Ends Analysis (Planning) Mini-Max with Alpha-Beta Cut Off Mini-Max with Alpha-Beta Cut Off

(2-player determined games) (2-player determined games) Constraint satisfaction searchConstraint satisfaction search