Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques...

34
Basic Search Methods Basic Search Methods How to solve the control problem in How to solve the control problem in production-rule systems? production-rule systems? Basic techniques to find paths Basic techniques to find paths through state- through state- nets nets . . For the moment: For the moment: - no attempt to find optimal - no attempt to find optimal solutions solutions - a ‘tree-search’ approach - a ‘tree-search’ approach

Transcript of Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques...

Page 1: Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques to find paths through state- nets. For the moment: -

Basic Search MethodsBasic Search Methods

How to solve the control problem in production-How to solve the control problem in production-rule systems?rule systems?

Basic techniques to find paths through Basic techniques to find paths through state-state-netsnets..

For the moment:For the moment:

- no attempt to find optimal solutions- no attempt to find optimal solutions

- a ‘tree-search’ approach- a ‘tree-search’ approach

Page 2: Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques to find paths through state- nets. For the moment: -

2

A running example:A running example:

Two possible tasks:Two possible tasks:1. FIND a (the) path. 1. FIND a (the) path. = computational cost= computational cost

2. TRAVERSE the path. 2. TRAVERSE the path. = travel cost= travel cost

2. relates to finding optimal paths (next chapter). 2. relates to finding optimal paths (next chapter).

Implicit networkImplicit network

AA

DD

BB

EE

CC

FFGG

SS

33

44

44

44

55 55

44

3322

Page 3: Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques to find paths through state- nets. For the moment: -

3

AA

DD

BB

EE

CC

FFGGSS

33

44

44

44

55 55

44

33

The associated loop-free The associated loop-free tree of partial pathstree of partial paths

22

SSAA DD

BB DD EEAA

CC EE EE BB BB FF

DD FF BB FF CC EE AA CC GG

GG CC GG FF

GG

33

33 33

33

33

22

22

2244

44

4444

44

4444

44

44

44

44

44

5555

55 55

5555

Page 4: Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques to find paths through state- nets. For the moment: -

4

Comments:Comments: We are not interested in optimal paths in this We are not interested in optimal paths in this

chapter, so we can drop the costs.chapter, so we can drop the costs.

SSAA DD

BB DD EEAA

CC EE EE BB BB FF

DD FF BB FF CC EE AA CC GG

GG CC GG FF

GG

Nodes do not denote themselves, but denote the Nodes do not denote themselves, but denote the partial path from the root to themselves!!partial path from the root to themselves!!

Denotes:Denotes:SASA Denotes:Denotes:SDSD

AA

DenotesDenotes:: SDEBASDEBA

Page 5: Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques to find paths through state- nets. For the moment: -

5

Terminology:Terminology:

Node, link (or edge), branchNode, link (or edge), branch Parent, child, ancestor, descendantParent, child, ancestor, descendant Root node, goal nodeRoot node, goal node Expand / Open node / Closed node / Branching factorExpand / Open node / Closed node / Branching factor

SSAA DD

BB DD EEAA

CC EE EE BB BB FF

DD FF BB FF CC EE AA CC GG

GG CC GG FF

GG

Page 6: Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques to find paths through state- nets. For the moment: -

BLIND Search MethodsBLIND Search Methods

Methods that do not use any specific knowledge Methods that do not use any specific knowledge about the problem:about the problem:

Depth-firstDepth-first

Breadth-firstBreadth-first

Non-deterministic searchNon-deterministic search

Iterative deepeningIterative deepening

Bi-directional searchBi-directional search

Page 7: Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques to find paths through state- nets. For the moment: -

Depth-first searchDepth-first search

Expand the tree as deep as possible, Expand the tree as deep as possible,

returning to upper levels when needed.returning to upper levels when needed.

Page 8: Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques to find paths through state- nets. For the moment: -

8

Depth-first searchDepth-first search= Chronological backtracking= Chronological backtracking

Select a child Select a child convention: left-to-rightconvention: left-to-right

Repeatedly go to next Repeatedly go to next child, as long as child, as long as possible.possible.

Return to left-over Return to left-over alternatives (higher-up) alternatives (higher-up) only when needed.only when needed.

BB

CC EE

DD FF

GG

SS

AA

Page 9: Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques to find paths through state- nets. For the moment: -

9

Depth-first algorithm:Depth-first algorithm:

1. 1. QUEUEQUEUE <-- path only containing the root; <-- path only containing the root;

2. 2. WHILEWHILE QUEUEQUEUE is not empty is not empty ANDAND goal is not reached goal is not reached

DODO remove the first path from the remove the first path from the QUEUEQUEUE;; create new paths (to all children);create new paths (to all children); reject the new paths with loops;reject the new paths with loops; add the new paths to front of add the new paths to front of QUEUEQUEUE;;

3. 3. IFIF goal reached goal reached THENTHEN success; success; ELSEELSE failure; failure;

Page 10: Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques to find paths through state- nets. For the moment: -

10

AA

DD

BB

EE

CC

FFGGSS

33

44

44

44

55 55

44

3322

1. 1. QUEUEQUEUE <-- path only containing the root; <-- path only containing the root;

2. 2. WHILEWHILE QUEUEQUEUE is not empty is not empty ANDAND goal is not reached goal is not reached

DODO remove the first path from the remove the first path from the QUEUEQUEUE;; create new paths (to all children);create new paths (to all children); reject the new paths with loops;reject the new paths with loops; add the new paths to front of add the new paths to front of QUEUEQUEUE;;

3. 3. IFIF goal reached goal reached THENTHEN success; success; ELSEELSE failure; failure;

Page 11: Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques to find paths through state- nets. For the moment: -

11

Trace of depth-first Trace of depth-first for running example:for running example:

(S) (S) S removed, (SA,SD) computed and added S removed, (SA,SD) computed and added (SA, SD)(SA, SD) SA removed, (SAB,SAD,SAS) computed, SA removed, (SAB,SAD,SAS) computed,

(SAB,SAD) added(SAB,SAD) added (SAB,SAD,SD) (SAB,SAD,SD) SAB removed, (SABA,SABC,SABE) SAB removed, (SABA,SABC,SABE)

computed, computed, (SABC,SABE) added(SABC,SABE) added (SABC,SABE,SAD,SD) (SABC,SABE,SAD,SD) SABC removed, (SABCB) computed, SABC removed, (SABCB) computed,

nothing addednothing added (SABE,SAD,SD)(SABE,SAD,SD) SABE removed, (SABEB,SABED,SABEF) SABE removed, (SABEB,SABED,SABEF)

computed, (SABED,SABEF)addedcomputed, (SABED,SABEF)added (SABED,SABEF,SAD,SD) (SABED,SABEF,SAD,SD) SABED removed, SABED removed,

(SABEDS,SABEDA.SABEDE) computed, (SABEDS,SABEDA.SABEDE) computed, nothing addednothing added

((SABEF,SAD,SD) SABEF,SAD,SD) SABEF removed, (SABEFE,SABEFG) SABEF removed, (SABEFE,SABEFG) computed, (SABEFG) addedcomputed, (SABEFG) added

(SABEFG,SAD,SD)(SABEFG,SAD,SD) goal is reached: reports successgoal is reached: reports success

Page 12: Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques to find paths through state- nets. For the moment: -

12

Evaluation criteria:Evaluation criteria:

Completeness:Completeness: Does the algorithm always find a path?Does the algorithm always find a path?

(for every NET such that a path exits)(for every NET such that a path exits) SpeedSpeed (worst time complexity)(worst time complexity) ::

What is the highest number of nodes that may What is the highest number of nodes that may need to be created?need to be created?

MemoryMemory (worst space complexity)(worst space complexity) : : What is the largest amount of nodes that may What is the largest amount of nodes that may

need to be stored?need to be stored?

Expressed in terms of: Expressed in terms of: d = depth of the treed = depth of the tree b = (average) branching factor of the treeb = (average) branching factor of the tree m = depth of the shallowest solution m = depth of the shallowest solution

Page 13: Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques to find paths through state- nets. For the moment: -

13

Note: approximations !!Note: approximations !!

In our complexity analysis, we do not take the In our complexity analysis, we do not take the built-in built-in loop-detectionloop-detection into account. into account.

The results only ‘formally’ apply to the variants The results only ‘formally’ apply to the variants of our algorithms of our algorithms WITHOUTWITHOUT loop-checks. loop-checks.

Studying the effect of the loop-checking on the Studying the effect of the loop-checking on the complexity is hard: complexity is hard: overhead of the checking MAY or MAY NOT be overhead of the checking MAY or MAY NOT be

compensated by the reduction of the size of the compensated by the reduction of the size of the tree.tree.

AlsoAlso: our analysis : our analysis DOES NOTDOES NOT take the length take the length (space) of representing paths into account !!(space) of representing paths into account !!

Page 14: Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques to find paths through state- nets. For the moment: -

14

Completeness Completeness (depth-first)(depth-first)

Complete for FINITE (implicit) NETS.Complete for FINITE (implicit) NETS. (= NETS with finitely many nodes)(= NETS with finitely many nodes)

IMPORTANT:IMPORTANT: This is due to integration of LOOP-checking in This is due to integration of LOOP-checking in

this version of Depth-First (and in all other this version of Depth-First (and in all other algorithms that will follow) !algorithms that will follow) ! IF we do not remove paths with loops, then IF we do not remove paths with loops, then

Depth-First is not complete (may get trapped Depth-First is not complete (may get trapped in loops of a finite NET)in loops of a finite NET)

Note:Note: does NOT find the shortest path. does NOT find the shortest path.

Page 15: Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques to find paths through state- nets. For the moment: -

15

AA

DD

BB

EE

CC

FFGGSS

33

44

44

55 55

44

3322

SSAA DD

BB DD EEAA

CC EE EE BB BB FF

DD FF BB FF CC EE AA CC GG

GG CC GG FF

GG

33

33 33

33

33

22

22

2244

44

4444

44

4444

44

44

44

44

44

5555

55 55

5555

Page 16: Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques to find paths through state- nets. For the moment: -

16

Speed Speed (depth-first)(depth-first)

In the worst case: In the worst case: the (only) goal node may be on the right-most the (only) goal node may be on the right-most

branch, branch,

GG

ddbb

Time complexity == bTime complexity == bd d ++ bbd-1 d-1 + … + + … + 11 = = bbd+1 d+1 --11 Thus: O(bThus: O(bdd) ) b - 1b - 1

Page 17: Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques to find paths through state- nets. For the moment: -

17

Memory Memory (depth-first)(depth-first)

Largest number of nodes in QUEUE is reached Largest number of nodes in QUEUE is reached in bottom left-most node.in bottom left-most node.

Example: d = 3, b = 3 :Example: d = 3, b = 3 :

......

QUEUE contains all nodes. Thus: 7.QUEUE contains all nodes. Thus: 7. In General: ((b-1) * d) + 1In General: ((b-1) * d) + 1 Order: O(d*b)Order: O(d*b)

Page 18: Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques to find paths through state- nets. For the moment: -

Breadth-first searchBreadth-first search

Expand the tree layer by layer, Expand the tree layer by layer,

progressing in depth.progressing in depth.

Page 19: Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques to find paths through state- nets. For the moment: -

19

Breadth-first search:Breadth-first search:

Move Move downwardsdownwards, level by , level by level, until level, until goal is goal is reached.reached.

SS

AA DD

BB DD AA EE

CC EE EE BB BB FF

DD FF BB FF CC EE AA CC GG

GG

GGGG FFCC

Page 20: Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques to find paths through state- nets. For the moment: -

20

ONLY ONLY DIFFERENCE !DIFFERENCE !

Breadth-first algorithm:Breadth-first algorithm:

1. 1. QUEUEQUEUE <-- path only containing the root; <-- path only containing the root;

2. 2. WHILEWHILE QUEUEQUEUE is not empty is not empty ANDAND goal is not reached goal is not reached

DODO remove the first path from the remove the first path from the QUEUEQUEUE;; create new paths (to all children);create new paths (to all children); reject the new paths with loops;reject the new paths with loops; add the new paths to back of add the new paths to back of QUEUEQUEUE;;

3. 3. IFIF goal reached goal reached THENTHEN success; success; ELSEELSE failure; failure;

Page 21: Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques to find paths through state- nets. For the moment: -

21

Trace of breadth-first Trace of breadth-first for running example:for running example:

(S) (S) S removed, (SA,SD) computed and added S removed, (SA,SD) computed and added (SA, SD)(SA, SD) SA removed, (SAB,SAD,SAS) computed, SA removed, (SAB,SAD,SAS) computed,

(SAB,SAD) added(SAB,SAD) added (SD,SAB,SAD) (SD,SAB,SAD) SD removed, (SDA,SDE,SDS) computed, SD removed, (SDA,SDE,SDS) computed,

(SDA,SDE) added(SDA,SDE) added (SAB,SAD,SDA,SDE) (SAB,SAD,SDA,SDE) SAB removed, (SABA,SABE,SABC) SAB removed, (SABA,SABE,SABC)

computed, (SABE,SABC) addedcomputed, (SABE,SABC) added (SAD,SDA,SDE,SABE,SABC)(SAD,SDA,SDE,SABE,SABC) SAD removed, (SADS,SADA, SAD removed, (SADS,SADA,

SADE) computed, (SADE) addedSADE) computed, (SADE) added etc, until QUEUE contains:etc, until QUEUE contains:

(SABED,SABEF,SADEB,SADEF,SDABC,SDABE,SDEBA,SDEBC, (SABED,SABEF,SADEB,SADEF,SDABC,SDABE,SDEBA,SDEBC, SDEFG) SDEFG) goal is reached: reports successgoal is reached: reports success

Page 22: Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques to find paths through state- nets. For the moment: -

22

Completeness Completeness (breadth-first)(breadth-first)

COMPLETECOMPLETE even for infinite implicit NETS !even for infinite implicit NETS !

Would even remain complete without our loop-Would even remain complete without our loop-checking.checking.

Note:Note: ALWAYS finds the shortest path. ALWAYS finds the shortest path.

Page 23: Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques to find paths through state- nets. For the moment: -

23

Speed Speed (breadth-first)(breadth-first)

If a goal node is found on depth If a goal node is found on depth mm of the tree, all of the tree, all nodes up till that depth are created. nodes up till that depth are created.

ddGGbb

mm

ThusThus: O: O((bbmm) ) note: depth-first would also visit deeper nodes.note: depth-first would also visit deeper nodes.

Page 24: Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques to find paths through state- nets. For the moment: -

24

Memory Memory (breadth-first)(breadth-first)

Largest number of nodes in QUEUE is reached Largest number of nodes in QUEUE is reached on the level on the level mm of the goal node. of the goal node.

GGddbb

mm

GG QUEUE contains all and nodes. QUEUE contains all and nodes. (Thus: 4)(Thus: 4) . . In General: bIn General: bmm

This usually is This usually is MUCHMUCH worse than depth-first !! worse than depth-first !!

Page 25: Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques to find paths through state- nets. For the moment: -

25

Practical evaluation:Practical evaluation:

Depth-first:Depth-first:IF the search space contains very deep branches IF the search space contains very deep branches

without solution, THEN Depth-first may waist without solution, THEN Depth-first may waist much time in them.much time in them.

Breadth-first:Breadth-first: Is VERY demanding on memory !Is VERY demanding on memory !

Solutions ??Solutions ??Non-deterministic searchNon-deterministic search Iterative deepeningIterative deepening

Page 26: Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques to find paths through state- nets. For the moment: -

26

Non-deterministic search:Non-deterministic search:

1. 1. QUEUEQUEUE <-- path only containing the root; <-- path only containing the root;

2. 2. WHILEWHILE QUEUEQUEUE is not empty is not empty ANDAND goal is not reached goal is not reached

DODO remove the first path from the remove the first path from the QUEUEQUEUE;; create new paths (to all children);create new paths (to all children); reject the new paths with loops;reject the new paths with loops; add the new paths in random places in add the new paths in random places in QUEUEQUEUE;;

3. 3. IFIF goal reached goal reached THENTHEN success; success; ELSEELSE failure; failure;

Page 27: Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques to find paths through state- nets. For the moment: -

27

Iterative deepening searchIterative deepening search

Restrict a depth-first search to a fixed depth.Restrict a depth-first search to a fixed depth.

If no path was found, increase the depth and If no path was found, increase the depth and restart the search.restart the search.

Page 28: Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques to find paths through state- nets. For the moment: -

28

Depth-limited search:Depth-limited search:1. 1. DEPTHDEPTH <-- <some natural number> <-- <some natural number> QUEUEQUEUE <-- path only containing the root; <-- path only containing the root;

2. 2. WHILEWHILE QUEUEQUEUE is not empty is not empty ANDAND goal is not reached goal is not reached

DODO remove the first path from the remove the first path from the QUEUEQUEUE;; IFIF path has length smaller than path has length smaller than DEPTHDEPTH create new paths (to all children);create new paths (to all children); reject the new paths with loops;reject the new paths with loops; add the new paths to front of add the new paths to front of QUEUEQUEUE;;

3. 3. IFIF goal reached goal reached THENTHEN success; success; ELSEELSE failure; failure;

Page 29: Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques to find paths through state- nets. For the moment: -

29

Iterative deepening algorithm:Iterative deepening algorithm:

1. 1. DEPTHDEPTH <-- 1 <-- 1 2. 2. WHILEWHILE goal is not reached goal is not reached

DODO perform Depth-limited search; perform Depth-limited search; increase increase DEPTH DEPTH by 1;by 1;

Page 30: Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques to find paths through state- nets. For the moment: -

30

Iterative deepening:Iterative deepening:the best ‘blind’ search.the best ‘blind’ search.

Complete: yes - even finds the shortest path Complete: yes - even finds the shortest path (like (like breadth first)breadth first) . .

b - 1b - 1 bbm-1m-1 ++ bbm-2m-2 + … + + … + 11 = = bbmm --1 = O(b1 = O(bm-1m-1))

In general: VERY good trade-offIn general: VERY good trade-off

While the work spent at While the work spent at DEPTHDEPTH = = mm itself is O(b itself is O(bmm))

Memory: b*Memory: b*m m (combines advantages of depth- and (combines advantages of depth- and breadth-first)breadth-first)

Speed:Speed: If the path is found for If the path is found for DepthDepth = = mm, then how much , then how much

time was waisted constructing the smaller trees??time was waisted constructing the smaller trees??

Page 31: Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques to find paths through state- nets. For the moment: -

31

Bi-directional searchBi-directional search

Compute the tree both from the start-node and Compute the tree both from the start-node and from a goal node, until these meet.from a goal node, until these meet.

Page 32: Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques to find paths through state- nets. For the moment: -

32

Bi-directional searchBi-directional search IFIF you are able to EXPLICITLY describe the you are able to EXPLICITLY describe the

GOAL state, GOAL state, ANDAND you have BOTH rules for FORWARD reasoning you have BOTH rules for FORWARD reasoning

AND BACKWARD reasoning:AND BACKWARD reasoning:

GoalGoalStartStart

Page 33: Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques to find paths through state- nets. For the moment: -

33

Bi-directional algorithm:Bi-directional algorithm:

1. 1. QUEUE1QUEUE1 <-- path only containing the root; <-- path only containing the root; QUEUE2QUEUE2 <-- path only containing the goal; <-- path only containing the goal;

2. 2. WHILEWHILE both both QUEUEiQUEUEi are not empty are not empty ANDAND QUEUE1QUEUE1 and and QUEUE2 QUEUE2 do NOT share a statedo NOT share a state

DODO remove their first paths; remove their first paths; create their new paths (to all children);create their new paths (to all children); reject their new paths with loops;reject their new paths with loops; add their new paths to back;add their new paths to back;

3. 3. IFIF QUEUE1QUEUE1 and and QUEUE2 QUEUE2 share a stateshare a state THENTHEN success; success; ELSEELSE failure; failure;

Page 34: Basic Search Methods How to solve the control problem in production-rule systems? Basic techniques to find paths through state- nets. For the moment: -

34

Properties Properties (Bi-directional)(Bi-directional)::

Complete: Yes.Complete: Yes.

Speed: If the test on common state can be Speed: If the test on common state can be done in constant time (hashing):done in constant time (hashing): 2 * O(b2 * O(bm/2m/2) = O(b) = O(bm/2m/2) )

Memory: similarly: O(bMemory: similarly: O(bm/2m/2))