lecture 2 search and weak methods - university of oxforddwm/courses/4ai_2000/4ai_n2.pdf · lecture...

29
Lecture 2 Search and Weak Methods Reading for first part Rich and Knight (1991) §2.5 and Chapter 3 Winston (1992): Chapters 4, 5 and 6. Introduction to Algorithms, Cormen, Leiserson and Rivest (MIT Press 1990) Reading for second part Constraint satisfaction: Rich and Knight §3.5. Winston (1992) Chapters 11 and 12. Robot path planning: Winston (1992) Chapter 5, pp95–99. 2.1 Background In Lecture 1 we looked at the trivial Chaperone’s problem, but even this was too complicated to solve by some direct method. To reach a solution or goal involved a process of search through the problem’s state space. One might guess that there is a need for the application of some ordered strategy for apply- ing operations in the search for goal states and, further, that the precise order chosen affects the efficiency of search. In this lecture we look at some techniques for imposing such order. They fall into three groups: 1. Methods which find any start – goal path, 2. Methods which find the best path, and finally 3. Search methods in the face of adversaries. 16

Upload: phungcong

Post on 30-Nov-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

Lecture 2

Search and Weak Methods

Reading for first part

Rich and Knight (1991) §2.5 and Chapter 3Winston (1992): Chapters 4, 5 and 6.Introduction to Algorithms, Cormen, Leiserson and Rivest (MIT Press 1990)

Reading for second part

Constraint satisfaction: Rich and Knight §3.5. Winston (1992) Chapters 11 and 12. Robotpath planning: Winston (1992) Chapter 5, pp95–99.

2.1 Background

In Lecture 1 we looked at the trivial Chaperone’s problem, but even this was too complicatedto solve by some direct method. To reach a solution or goal involved a process of searchthrough the problem’s state space.

One might guess that there is a need for the application of some ordered strategy for apply-ing operations in the search for goal states and, further, that the precise order chosen affectsthe efficiency of search.

In this lecture we look at some techniques for imposing such order. They fall into threegroups:

1. Methods which find any start – goal path,

2. Methods which find the best path, and finally

3. Search methods in the face of adversaries.

16

2.2. GRAPHS OR NETS VERSUS TREES 17

Before becoming embroiled in the intricasies of the various search processes, remember that,as in real life, search usually results from a lack of knowledge. Search is merely a offensiveinstrument with which to attack problems that we can’t seem to solve any better way. Ourmethods here will merely outline that there are ways and better ways of bludgeoning aproblem.

Finally, many of these algorithms exist in the computer science literature under differentnames. See Introduction to Algorithms by Cormen, Leiserson and Rivest (MIT Press 1990)for a feast of tree search, dynamic programming and optimization algorithms.

2.2 Graphs or nets versus trees

For much of this lecture on search we will use the example of a road network shown infigure ??. Here the state space comprises several places connected by road. Let us supposethat high load wishes to travel from start state Southamption to goal state Grantham. Onlycertain routes are passable, as shown, with a certain effort. The effort will certainly be relatedto distance, but could also involve number of steep hills, road width, number of bridges, andso on — a heuristic measure of the effort.

S

O

L

B

N

D

M

G

4

4

3

4

2

3

45

Figure 2.1: The road and place graph or net. (Southampton, Oxford, Birmingham, Derby,London, Northampton, Melton Mowbray, Grantham.)

Now if we trace out all possible paths through the net, and terminate paths before theyreturn to nodes already visited on that path, we produce a search tree, shown in figure ??.

Like nets, trees have nodes and links. The links are branches. The start node is called theroot and nodes at the other ends are leaves. Nodes have generations of descendents. The firstgeneration are children. These children have a single parent node, and the list of nodes backto the root is their ancestry. A node and its descendents form a subtree of the node’s parent.If a node’s subtrees are unexplored or only partially explored, the node is open, otherwise itis closed. If all nodes have the same number of children, this number is the branching factor.A special case of this is a binary tree which has a branching factor of 2. Some of these termsare clarified in figure ??

There are a couple of points to note.

1. The aim of search is not to produce complete physical trees in memory, but ratherexplore as little of the virtual tree as possible looking for root-goal paths.

18 LECTURE 2. SEARCH AND WEAK METHODS

G

S

M L B M

D G M

G

D N O D G

MN

O

O L

N

B BND

B L

11

19 19 17

17

25

15 15 1314

Figure 2.2: The full tree.

Subtree

Parent

Child

Figure 2.3: Family relationships in a tree. The braching factor here is three.

2.3. SEARCHING FOR ANY ROOT-GOAL PATH 19

2. The way we developed the full tree in figure 2.2 is unique in its genealogy, but thechoice of which was the first, leftmost, child and so on was quite arbitrary.

2.3 Searching for any Root-Goal Path

2.3.1 Depth-first search

Given that one path to the goal is as good as any other, one possible search method whichwould traverse the tree is to make an orderly choice at a node, follow the branch to the nextnode and make another orderly choice, and so on, until there are no more choices. At thispoint, return or backtrack to the most recent node where there is still an unexplored choiceand carry on until either the goal is reached or there are no more choices.

The depthfirst algorithm is:

1. Form a one element queue Q consisting of the root node.2. Until the Q is empty or the goal has been reached, determine if the first elementin the Q is the goal.

2a. If it is, do nothing.2b. If is isn’t, remove the first elment from the Q and add the firstelement’s children, if any, to the FRONT of the Q.

3. If the goal is reached, success; else failure.

By convention, the orderly search is “left heavy”, the leftmost child being expanded first. Asshown in figure ??, we explore

S, SO, SOB, SOBD (non-goal leaf, so backtrack to B)SOB, SOBN, SOBNM, SOBNMG (goal leaf, so stop).

Depth-first search is simple, but is very unsatisfactory if the tree is unbalanced, with someleaves being at the end of much longer branches than others. Suppose that dangling fromthe Birmingham node had been a route to Manchester, Carlisle and points north, with noavailable routes to Grantham, as suggested in figure 2.5. All this subtree would be exploredbefore backtracking returns us to Birmingham.

2.3.2 Hill climbing

Depth-first search is orderly but, in many cirmcumstances, rather lacking in discrimina-tion. Often, search efficiency can be dramatically improved if you can estimate whether onechoice is likely to be better than another, and order the choices accordingly. This is achievedby obtaining some measure of distanceDn between a node n and the goal. Sitting at a parent

20 LECTURE 2. SEARCH AND WEAK METHODS

at Goal

Dead−end

S

O

B

D N

M

G Search terminates

Backtracking to

most recent decision

at Goal

Dead−end

S

O

B

D N

M

G Search terminates

Backtracking to

most recent decision

Figure 2.4: Depth first search

G

M

D

N

B

L

O

S

Figure 2.5: Dangers in depth first search if the tree is unbalanced. The entire subtree dan-gling from Birmingham would be expanded before reaching a route to Grantham.

2.3. SEARCHING FOR ANY ROOT-GOAL PATH 21

node we would determine the distancesDc1, ... of all its children from the goal. Then expandthem in ascending order of D.

The hillclimbing algorithm is:

1. Form a one element queue Q consisting of the root node.2. Until the Q is empty or the goal has been reached, determine if the first elementin the Q is the goal.

2a. If it is, do nothing.2b. If is isn’t, remove the first element from the Q, sort the first ele-ment’s children, if any, by estimating remaining distance, and add thissorted list to the FRONT of the Q.

3. If the goal is reached, success; else failure.

This procedure is useful, but you should be wary of it. Going back to the road problem,suppose we used straight line distances as our estimates of how much effort was requiredto go from one place to another. From Southampton, London is nearer Grantham thanOxford, so we move to L. Now suppose there is another town Xtown, very near Grantham,accessible from L. We will naturally choose to go there. Unfortunately, there is no link from Xto G in the graph, and we shoot on to explore Ytown and all points north, before eventuallyrunning out of road and backtracking to L, whereupon the next nearest child is N, whichwill (eventually) get us to G.

Y

X

S

L

N M

G

Figure 2.6: X is near G and is attractive to a hill climber. Unfortunately, it is a local peak anda lot of search is required to get back onto a useful path

We can visualize this pitfall by pursuing the hill-climbing analogy. Imagine a mountaineerdetermined to climb Mt Everest somehow, his motto at every decision point being choose“the most upwards from one step north, south, east and west”. Eventually he is bound toreach some summit, but only then does he look to see if it is Everest. If it isn’t he returns tohis most recent decision point and take the next most upwards choice. Now, if he starts onthe side of Everest — strictly, if the cost function is convex, all will work smoothly. However,there are three cost function landscapes he will have trouble with.

22 LECTURE 2. SEARCH AND WEAK METHODS

1. If he starts in foothills, he spends a lot of time climbing to the foothill summits andbeing disappointed that they are not Everest.

2. If he start on a flat plain somewhere will wander aimlessly, and will only reach a sum-mit by chance.

3. If he finds himself on the top a gently sloping NE (say) ridge. Every NSEW step goesdown, but he is not at a summit. His only hope is to take very much smaller steps.

Foothills Single peak in a flatlandscape

Aimless wandering Sitting on ridge

Figure 2.7: Perilous landscapes in hill climbing

2.3.3 Breadth-first search

In this technique you search for the goal node among all nodes of a particular generationbefore expanding further, as in figure ??. This way you always catch the node nearest theroot in generations. This is of value if the tree is unbalanced, but is wasteful if all the goalnodes are at similar levels.

Why? Consider a tree with branching factor b. At level k there are bk nodes, which can bevery large — we must be wary of anything involving exponential size and time.

The breadthfirst algorithm is:

1. Form a one element queue Q consisting of the root node.2. Until the Q is empty or the goal has been reached, determine if the first elementin the Q is the goal.

2a. If it is, do nothing.2b. If is isn’t, remove the first element from the Q, and add the firstelement’s children, if any, to the BACK of the Q.

3. If the goal is reached, success; else failure.

2.3.4 Beam search

Beam search gets round the exponential problem by expanding only the p most promisingnodes at any level, and so at any level k there are only a total of pb nodes, as shown in figure??. However, this technique is not guaranteed to find a goal. Beam search would only havea reasonable chance of success if there are a many goal states.

2.3. SEARCHING FOR ANY ROOT-GOAL PATH 23

NO

L

LB

O

S

Figure 2.8: Breadth-first search

pb nodes, only p expanded

pb nodes, only p expanded

Only p nodes expanded

Figure 2.9: Beam search

24 LECTURE 2. SEARCH AND WEAK METHODS

2.3.5 Best-first search

Recall that in hill-climbing one explores the most promising child node first. In figure ?? wesaw that one X had been opened, we then went on to expand the children of X in best order(Y,Z) say, and so on with their children. But if Y is further from the goal than L, why notexpand L first? This is the idea of best-first search: expansion is resumed from the best opennode visited so far, no matter where it is in the partially explored tree. Thus it would explore

S, SL, SLX, SLXY, SLXY (at which point X is closed)SLN, etc.

The bestfirst algorithm is:

1. Form a one element queue Q consisting of the root node.2. Until the Q is empty or the goal has been reached, determine if the first elementin the Q is the goal.

2a. If it is, do nothing.2b. If is isn’t, remove the first element from the Q, and add the firstelement’s children, if any, to the Q. Sort Q by estimated remaining dis-tance. (Note as the Q is sorted before addition, we need only performan O(n) sort.)

3. If the goal is reached, success; else failure.

The Lisp code is given in the handout.

This is like having a several mountaineers in radio contact. The mountaineer doing the bestat the time is allowed to proceed one step.

Note that Best-first search does NOT find the best path! Finding the optimum path is thesubject of the next section.

2.4 Searching for the optimum Root-Goal path

The methods of the previous section found some path between root and goal. A rather harderproblem is to find the best path. For this we need to exploit the cost figures in the graphfigure.

2.4.1 British Museum

Quite the worst method of finding the optimum root-goal path is to expand all such pathsthen choose the best. This exhaustive method is known flatteringly as British MuseumSearch. To find all goals you obviously need to expand the entire tree (which we earlier

2.4. SEARCHING FOR THE OPTIMUM ROOT-GOAL PATH 25

S

V

W

G

8

34

3

7

S

V

G

M N

G

10

57

G

W

8

32

<57???

TO G?

Figure 2.10: Branch and bound

argued wasn’t quite the aim of search), so there is no point doing any clever search: youmight as well use plain depth-first or breadth-first search, with the proviso that now searchmust not terminate when after the first root-goal path is found.

This method of search obviously has to be limited to small problems because trees grow likebk where b is the branching factor and k the generation. This figure grows rapidly to literallyastronomical size (eg 2020 is of order 1026).

2.4.2 Branch and Bound

The branch and bound method, illustrated in figure ??, is rather cleverer. The basis routineis best-first. From S we dive down into V because it has a shorter path length than W. Vis expanded and we arrive at G. The path length SG is 7, so there is absolutely no pointreturning to S to expand from W because that in itself has a path length of 8 and so any pathto G via Y is bouns to have a path length longer than that already found.

So, during search there are many incomplete paths bidding for further expansion. The short-est one is expanded one generation, creating as many new incomplete paths as there werechildren. These paths are considered along with the originals. (If there were p paths beforethere are now p−1+c paths, where c is number of children.) Again the shortest is expanded.

The question is, when search reaches a goal should it stop? In that we always expandedthe shortest path, is not the first root-goal path guaranteed to be the shortest? No, becausethe last bit of path to this goal could be of any length. Search can stop only when it hasdiscovered at least one goal and there are no unexplored paths of shorter length than theshortest root-goal path found. (Indeed, stopping after the first root-goal path was foundwould be best-first search.)

2.4.3 Branch and Bound with underestimates

You might think that in some cases, branch and bound efficiency can be greatly improvedby using estimates of distances remaining to the goal. Adding this to the actual distance

26 LECTURE 2. SEARCH AND WEAK METHODS

S

O

B L

L3

7 8

4

1

2 3

NEVER EXPAND

Figure 2.11: Dynamic programming

travelled gives an estimate of the total path length. Now one expands the path with theshortest estimate by one generation.

If all estimates were perfect, this would always ensure the optimal path was followed — butof course in practice there will be errors. A danger exists if we overestimate a path length: wecould terminate the optimal path. This is because search stops when the actual distance tosome goal is shorter than the estimates of all other paths.

The ludicrously obvious way to avoid this is to consistently underestimate path lengths. Thenthe actual distance to some goal can never be shorter than the underestimate of the optimalpath, so there can be no premature termination.

Fortunately, it is often possible to make underestimates. For example, in our present prob-lem involving node positions (x, y), the straight line distance to the goal from the currentpositions must be less than or equal to the distance via the graph, so that E = [(xgoal −xcurrent)

2 + (ygoal − ycurrent)2]1/2 is a good underestimate.

2.4.4 Branch and Bound with Dynamic Programming

Figure ?? shows that S was expanded one level to O and L. Distance SO < SL, so O wasexpanded to SOB and SOL. Now SL is less than these paths, so it is about to be expanded.But if a path to the goal SOL...G exists, it must be longer than SL...G, so there is absolutelyno point expanding SOL.

This is an instance of the general dynamic programming principal, which uses the fact thatif the path SI from S to some intermediate point I does not affect the path IG to the goal G,then the minimum path length from SG via I is the sum of the minimum path lengths SIand IG.

2.4.5 A* search

The A* search method is a straightforward combination of branch and bound, with (under-)estimation of remaining distances, and with dynamic programming techniques.

2.5. ADVERSARIAL SEARCH 27

The A* algorithm is:

1. Form a queue Q of partial paths. Let the initial Q consist of the zero lengthpath from the root to nowhere.2. Until the Q is empty or the first path on the Q reaches the goal:

2b1. Remove the first path from the Q.2b2. Form new paths from the removed one by extending one step.2b3. Look at the end nodes of the new paths. If the paths loop backs,remove them.2b4. Look at the end nodes of the new paths. If any other path on the Qreaches the same node, remove all but the lowest cost path to that node.(Note [1] this could remove a new path and [2] the duplicate node inthe Q does not have to be at the end of a path.)2b5. Re-insert the new paths on the Q in order of decreasing actual costso far + the lower-bound estimate of the cost remaining.

3. If the first path reached the goal, success; else failure.

2.5 Adversarial Search

Although adversarial search is again a problem of moving around state space, it differssubstantially from “one-sided” search. The assumption is that you and an adversary take itin turns to move, and your adversary has goal states which don’y coincide with yours.

2.5.1 Minimax

This basic game-playing search strategy was devised by Claude Shannon around 1950. Itrelies on the ability to describe how good overall a particular state is for a particular player.This process is called static evaluation. When you run the static evaluator, the higher thescore the better the state is for you.

The search strategy is based on the assumption that you are intent on maximizing yourevaluation score, while your adversary is intent on minimizing your evaluation score.

A search for possible states is opened up for a few moves ahead, as shown in figure ??.Suppose you following move decision a1. Your opponent knows that after his move, youwill try to maximize your score, so he takes decision b2, so your choice (c4) gives you theminimum-maximum. You apply the same process to decisions a2 and a3, and you realizethat the maximum minimum-maximum (=9) occurs for a1. So that is the move you make.

28 LECTURE 2. SEARCH AND WEAK METHODS

OPP

YOU

YOU

b9b8b7b6

817121332744642

a3

a2

8

6

9

1571091131152491371

c7c4c1

b5b4b3b2b1

a1

Figure 2.12: Minimax. The static evaluation here is carried out after a move, countermove,move sequence.

a1

b1 b2 b3 b4 b5

a2

a3

b6 b7 b8 b9

3 4 7 2 x y 19 1 z

YOU

OPP

Figure 2.13: Redundant evalations

2.5.2 Alpha-Beta pruning

Static evalation is likely to be a fairly expensive task. In the example, did you need to applythe evaluator to all 27 possibilities?

Look at the smaller move-countermove example in figure ??. We apply the evaluator left toright. Via decision a1, your opponent would take b1 giving you a score of 3. Now considera2. Suppose the first evaluation via b4 yields 2. Now, if x and/or y were larger than 2, youropponent would choose 2, which is less than the 3 obtained via a1. If x and/or y were lessthan 2, your opponent would choose the lower, but this would still be less than 3. So, you don’tcare what x and y are — you are already committed to not taking this route. Similarly, if youchoose a3, your opponent would be able to make your score 1 or z if z < 1, but in any caseless than 3. Thus you don’t care what z is.

How few static evaluations can we get away?

First, we know that in the worst case, alpha-beta does nothing for us at all. The static eval-uator has to be used at every node, so this grows as bk where k is the number of generationsyou look ahead.

The best case is more interesting. Let us suppose that the tree is by chance perfectly orderedfor the best-case when evaluation left to right. (Of course, you and your opponent don’t

2.5. ADVERSARIAL SEARCH 29

know it.)

• You consider a1. Your opponent counters with one of b1, 2, 3.

1. Consider b1. You could move c1, 2, 3. They evaluate, say, to 9,8,7.

2. Consider b2. You could move c4, 5, 6. You choose c4 and evaluate 27 (say). This isbigger than 9, and so your opponent would never let you have the opportunity,and would choose b1 in preference.

3. Let a similar thing happen for b3 and c7.

• You consider a2. Opponent could counter b4, 5or6.

1. Consider b4. You could move c10, 11, 12. Suppose these evaluate to 8,7,5. Youwould choose c10 therefore (but it is still not as attractive as choosing a1).

2. Consider b5, 6. If your opponent chose these, it would be because you could sub-sequently only achieve something less than 8. Thus the detailed evaluation is ofno interest to you.

So, in this best case scenario only 11 out of 27 states need static evaluation. One can go on toprove that in general the number of evaluations required is

{2bd/2 − 1 if d evenb(d+1)/2 + b(d−1)/2 − 1 if d odd

Unfortunately, even this best case figure is still combinatorial, so alpha-beta search can onlymuffle combinatorial explosions, rather than quench them altogether.

OPP

YOU

YOU

b9b8b7b6

a3

a2

c7c4c1

b5b4b3b2b1

a1

9 8 7 27 x x 22 x x 8 7 5 x x x x x x 7 2 2 x x x x x x

Figure 2.14: Best case alpha-beta pruning.

30 LECTURE 2. SEARCH AND WEAK METHODS

2.5.3 Progressing Deepening

Choosing a fixed depth k to search to can cause difficulties if playing against a clock. Thereare two solutions. Either choose some very conservative value of k, or do all the calculationsat one depth before progressing to the next depth. When you run out of time, use the deepestcomplete set. This might seem incredibly wasteful, but the ratio of the total number of nodesin a tree before level k is only a factor of about (b − 1) as large as the number of nodes inthe kth level itself. Ie for a branching factor of 11, all the previous work is only 10% of thecurrent level’s work.

2.6 Forward vs backward reasoning

Recall that the object of search is to discover a path through a problem’s search from initialstate to goal state. So far, we have discussed search in terms of forward motion from thestart state. But we could just as well have used backwards search, starting at the goal andworking back. For that matter, we could do both at the same time.

For example, think how we apply production rules as in the Water Cans problem?

• In forward reasoning, we start at the root and ask “which left-hand-side matches”, andthen apply the right hand side to produce the next state.

• In backward reasoning, we do exactly the reverse. Starting at the goal, we ask “whichright-hand sides match”, then apply the reverse operation to get the state on the left-hand side. If we reach a start goal we stop.

Which is it better to choose? Three factors might influence the choice of search direction.

1. Are there more goal or start states? Move from the smaller to the larger.

2. In which direction is the branching factor smaller? Proceed in the direction with thelower branching factor.

3. Will the program have to justify its choices to a user? If so, choose the direction ofreasoning which more accurately reflects that used in human reasoning.

2.6.1 Bi-directional search

One can search in both directions at the same time. There are obvious advantages, andobvious pitfalls, both based on tunneling analogies. It is important for the two halves tomeet somewhere around halfway, failure to do so results in the problem shown in the sketch.

2.7. SUMMARY SO FAR 31

States

GoalStart

States

Figure 2.15: Missing during bi-directional search.

2.7 Summary so far

We have discussed various search methods for

• Finding a path

• Finding the best path

• Finding a good path against an adversary

In addition we outlined the issues in

• Forward vs backward search.

Although some methods of search are better than others, all search is computationally ex-pensive. Remember the tradeoff. The use of search should be balanced with care against theuse of knowledge.

2.8 Two applications of search

2.8.1 Application I: Robot path planning

In Lecture 2 we considered the search for paths through a road network. Suppose now wehave the problem of moving an autonomous guided vehicle (AGV) round a room clutteredwith obstacles, as happens in the Jenkin basement. Could we adapt our techniques and useA* search to find an optimal path in this more unconstrained environment?

Figure ?? shows the layout of the room with the AGV’s initial and desired final position.

To make life a simple as possible we will assume that the AGV has turnable wheels thatallow it to steer in any direction without the body of the AGV turning. There is a nice trick

32 LECTURE 2. SEARCH AND WEAK METHODS

S

G

Start position

Goal position

Figure 2.16: Cluttered room layout.

to convert to AGV into a point position in configuration space. First you choose a referencepoint on the AGV, and then move round each obstacle with the AGV just touching the ob-stacle. Trace the shape that the reference point follows, and use these as the configurationspace obstacles. Now one can consider the AGV as just the reference point, and its bulk istransferred to the obstacles, as in Figure ??.

Now we use the fact that the shortest distance must be made up a set of straight lines toreplace the configuration space obstacles’ boundaries with nodes in the visibility net, as inFigure ??. This problem is now exactly like the road net problem.

boundary

Trace point

around

S

G

Start position

Goal position

Figure 2.17: Transferring the AGV’s bulk to the obstacles.

2.8.2 Application II: Matching for object recognition

Suppose you have built a vision system that is able to recover partial 3D structure of theworld (straight lines, curves, surface normals, depths etc). How might you use this infor-mation to recognize objects?

The key is to represent the objects as a collection of primitives of similar nature to thosewhich you have recovered from imagery and then match datum to model feature. The prob-lem of course is that this creates a combinatorial search space of enormous size. The size is

2.8. TWO APPLICATIONS OF SEARCH 33

S

G

Figure 2.18: The boundaries replaced by nodes of the visibility net.

enormous even if you know which model to match to, and astronomic if you have to choosebetween many objects in any position. Clearly there is a need for powerful constraints toreduce the size of the search space.

In the mid 1980’s Grimson and Lozano-Perez devised a simple method which grows feasiblematches using depth first search. This generator stage is designed to cut down an astromicnumber of possibilities down to a few, and the few are then tested by evaluating the poseand making sure everything fits.

The overall paradigm of generate and test used is was an AI classic.

Grimson and Lozano-Perez used sparse local measurements of the surface orientation atinfinitesimal planar patches with known 3D positions. These normals and positions arein theory computable all over the body (using shape-from-X processes, such as stereo orstructure-from-motion, or laser range or tactile sensing data) and so not are not sparse andshould therefore not suffer from problems of occlusions. However, the use of many tokensin matching demands that stringent constraints be applied to the search, whose efficiencybecomes critical. The models used by Grimson and Lozano-Perez are CAD-type models,comprising planar faces. The faces need not however be connected to each other. Curvedsurfaces might be approximated as a set of planar patches or, if of small extent, omitted fromthe model entirely.

The matching search space explored in Grimson and Lozano-Perez can be drawn out as aninterpretation tree, which is explored by depth first search. The data are arranged depthwiseand the model faces breadthwise, as shown in figure ??. In the absence of constraints, themaximum number of leaves on the tree would be fd where f is the number of faces and dthe number of data. It is worth considering an example of the growth of fd for even the mosttrivial of models. In figure ?? we show a facet model of a UK electrical plug. It has a total of22 faces, of which 14 are visible in the picture. As the number of data per visible face risesfrom one to two and so on, fd ascends in powers of 1019, ie., 1019, 1038 and so on.

Such explosive growth of the tree is prevented by establishing local constraints betweenpairs of data and the pair of model faces to which the two data are tentatively matched. Factsof the form

34 LECTURE 2. SEARCH AND WEAK METHODS

1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4

1

2

3

Model Faces

Data1 2 3 4

Figure 2.19: The interpretation tree of Grimson and Lozano-Perez. In the absence of con-straints the width of the tree grows as fd where f is the number of faces on the model and dthe number of data. Shown in bold is the partial interpretation where datum 1 is matched tomodel edge 2, datum 2 is matched to model edge 4, and datum 3 is matched to model edge3.

Figure 2.20: Even if there were only one piece of data to match to each visible face of thissimple model of an electrical plug fd would be ∼ 1019

2.8. TWO APPLICATIONS OF SEARCH 35

IF datum a is matched to model face iTHEN datum b (can/cannot) be matched to model face k

are established by demanding consistency between viewpoint independent metrics on thedata and model.

The easiest pairwise constraint to understand is their “angle constraint”.

You know the surface normals to the data patches, and so can derive the angle between todata. Equivalent, you find the dot product:

ua · ub , (2.1)

where ua is the normal to data patch a and ub is the normal to patch b. as illustrated in figure??. Note that because of sensing errors in the measured surface normals (given by angles αa

and αb), each metric has a range of allowed values.

On the model the metrics are similarly described as

ui · uj , (2.2)

where ui is a surface normal to model face i. The metrics on the model are precomputedoff-line and the numbers stored in two-dimensional look-up tables for fast reference whenmatching on-line.

The data metric exhibits a range of values. In this case the model metric is fixed, but thereare other constraints for which a model range exists too. The essential requirement for avalid pairwise match is that there is overlap between the ranges.

u

^a

ub

^

Cone of

uncertainty

Model faces i and j

ui u

j^^

Data patches a and b

Figure 2.21: The geometry involved in the constraints for planar surface matching used byGrimson and Lozano-Perez.

By way of example consider the use of the angle constraint with reference to figure ??. If themeasured angle between data patches 1 and 2 was 60◦ ± 5◦, say, and the angle computed onthe model between model faces 2 and 4 was 45degree then the pairing is forbidden — the treecan be pruned, and an entire sub-tree need not be explored. Notice too that the constraintsbegin to bite harder as deeper levels of the tree are explored. To place a new branch at datalevel j requires j − 1 pairwise ‘CAN’ facts to support an unblemished ancestry back to theroot of the tree.

The search space is examined quasi-exhaustively, that is all the feasible interpretations of thedata are produced — feasible, that is, under the constraints used to prune the tree. It is only

36 LECTURE 2. SEARCH AND WEAK METHODS

1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4

1

2

3

Model Faces

Data1 2 3 4

i=2

k=4

0

270 30 90

0 45 45

60

Model Angle L.U.T

Figure 2.22: The angle constraint at work. Suppose that the angle between the data patches 1and 2 were 60±5◦ and hence incompatible with that between the model faces 2 and 4 whichis found from the model’s angle look-up table to be 45◦. An entire sub-tree can be prunedfrom the interpretation tree and need not be explored.

after an entire match, i.e., root-to-leaf path, is generated that it is verified by computing thelocalization of the object in sensor space, by deriving the rotation matrix, translation and,possibly, scaling that globally transform the model into the data.

2.9 Another Weak Method: Constraint satisfaction

Constraints and constraint satisfaction are interesting in two ways.

1. Constraints supply a different method of imposing knowledge on a problem.2. Constraint propagation enables on to reach a global solution using only localsearch, with obvious savings in the search space.

Again, (2) shows the interdependency of knowledge and search.

In practice one typically has a set of parameters whose values you are after, and a set ofconstraints which when applied to a single parameter do not determine it uniquely, butwhen applied to all the parameters do provide a unique global solution.

According to Winston’s hierarchy, constraint propagation occurs on a contraction net, whichis a kind of frame system, which is a kind of semantic net. We will circumvent the definition

2.9. ANOTHER WEAK METHOD: CONSTRAINT SATISFACTION 37

of a frame system for the time being, and define the contraction net to be a represention inwhich

1. Lexically and structurally the nodes and links represent a finite set of interpretations.

2. Procedurally, demon procedures enforce compatibilty constraints among connected frames

The algorithm goes like:

Until a complete solution is found or all paths are deadends

1. Select an unexpanded node of the net.2. Apply the constraint inference rules to the selected node to generate all possi-ble new constraints.3. If the set of constraints contains a contradiction announce this path is deadend.4. Else if the set of constraints describes a complete solution announce SUCCESS.5. Else apply the problem space rules to generate new partial solutions which areconsistent with the latest constraints. Insert these solutions in the net.

Let’s look at an everyday example, a crossword. Actually it is quite involved because wehave constraints at two levels. First, there are clue and word length constraints which giveus a finite pool of words from a dictionary. Second there are intra-word contraints createdby rules in the English language, then there are inter-word constraints, such as the 3rd letterof 1 down is the 1st letter of 4 across.

There are various approaches. We might start by allowing the letters to take on their 26possibilities A–Z. Suppose we start at 1 Down. The clue solver generates five letter realtrees: Apple, Beech, Birch, Cedar, Larch, Thuja, etc. So we can already eliminate, say, D,E,Fand so on as first letters of 1 across. Suppose the clue solver (it is not very good!) comesup with two possible answers Batch or French: the constraint on the first letter rules outFrench, so 1 Across is Batch. This in turn supplies a new constraint on 1 Down: it is Beechor Birch. This says the first letter of 5 across is H, so according to language rules the secondis A,E,I,O,U,Y, and so on.

1 2 3

4

5

Across

1. Job lot of loaves?

interest at the bank.

Down

1. Real rather than search tree

2. The word is complete

3. Fire extinguishers used in

part−built houses?5. Each clue does this.

2. Confused stare causes

Figure 2.23: Crossword

2.9.1 Constraints for line labelling

A most elegant application of constraint propagation is that of junction and line labelling incomputer vision, an example of symbolic constraint propagation.

38 LECTURE 2. SEARCH AND WEAK METHODS

Consider the set of simple polyhedral objects (we will be less vague about what simplemeans in a moment). Human beings have been shown to have an in-built ability to makesense of the 3D shape implications of 2D line drawings, especially polyhedra. For example,something tells use that the drawing on the left of figure ?? is fine, but the drawing on theright is nonsense. This ability comes about because there are provably very few ways ofinterpretating line drawings. This ability has been captured in machine vision programs,the simplest of which we outline now.

Figure 2.24: Realizable and nonsense polyhedra

Now let’s be less vague about simple. It means the objects

• are without cracks

• with only 3-faced junctions

• and are in general position.

And let’s be less vague about general position. Image a sphere fixed around our object andimage we move our eye around the sphere staring at the centre of the sphere. At a fewspecial points, our view of the object might change dramatically. A face suddenly becomesvisible or hidden. The set of general viewing positions does not include these special points.

Non−generalview

Figure 2.25: On thee left is a non-general view of a cube. A tiny displacement causes theview to change dramatically.

If we make these restrictions (and, NB, they can be lifted), it turns out hat there are onlyfour types of corner to be considered. These are L-junctions, Y- or fork-junctions, W- orarrow-junctions and T-junctions, shown in figure ??

Let us now look at edges on a polyhedral object. These can be convex, concave or occluding(two sorts), so there are four ways of labelling a line. We label these with a plus, a minus,or left or right arrows. For example, look we shall label the feasible polyhedron above.

2.9. ANOTHER WEAK METHOD: CONSTRAINT SATISFACTION 39

T−junction

Example of each typePolyhedral drawing

L junction W or Arrow Y junction

Figure 2.26: The junction types in our restricted domain.

Notice that as we travel along the arrowed direction on an occluding edge, the face of thepolyhedron is on our right, and the occluded region on our left.

Figure 2.27: A labelled feasible polyhedron

The question is, can we do this automatically. The answer is yes, and very easily, becausethere are some powerful constraints on the possible junction type. These are related to theway surfaces can be arranged in the 3D world. You will have dealt with this aspect in yourcomputer vision course. You will recall that if there are four ways of labeling a line, thereshould be 16 ways of describing an L-junction and 64 ways for each of W,Y and T. So therecould be 208 labelled junction types in all. In fact there are only 18 allowed junction types,as shown in the figure ??

Now we want to do the labelling automatically. We have a dictionary of the 18 availablejunctions. Take the line drawing and on each vertex heap up the possible junctions. Nowsuppose we exit the junction along an edge via a (+) label, for example. This would meanwe must enter the next junction via a (+) label. Suppose there was no such possibility: weshould obviously discount the initial choise of junction and so on. Thus we travel aroundvertex-edge net propagating the constraints, until we can do no more. For example, andrather informally, in figure ?? we find

At [1]. 1–2 can be +,-. Hence 2.c and 2.e out.At [2], no new constraint on [1]. 2–3 can be +,-,V.

40 LECTURE 2. SEARCH AND WEAK METHODS

Figure 2.28: The 18 possible labelled junctions.

At [3] doesn’t allow V from [2], so 2.d removed. 3–4 can be +,-,¡, so 4.b and 4.cremoved.At [4], 4–1 gives 4.d removed and 1.a removed.At [1], without 1.a, 2.b must go.At [2] 3.c goes.

Formally, there are various ways of ordering the exploration. The program Waltz.l in (∼labdwm/ai/Waltz) makes a list of all the vertices. It removes the first, and if it unvisited, itinitializes its junction label pile. It then looks to see if any of the labels are inconsistent withany of its neigbours. Any inconsistent label is removed, and the vertex’s neighbours addedto the front of the list. This continues until there are no more junctions on the list.

2.10 Problem Reduction and And/Or goal trees

Up to now we have looked at search in OR-trees. Even if there were multiple goal states (eg,the (2,*) goals in the water jugs problem), the assumption was that reaching one goal wassufficient.

There are problems however that can be decomposed into a set of subgoals, each of whichrequires solving. For example a symbolic maths solver might decompose

∫(x + 1)2dx into

three subgoals∫x2dx,

∫xdx and

∫dx. This would be create an AND tree. Sometimes though

there are competing to the goal each involving subgoals. For example, getting to PaddingtonStation requires either (catch-X190 AND hail-taxi) OR (hail-taxi AND catch-train).

2.10. PROBLEM REDUCTION AND AND/OR GOAL TREES 41

a

b

c

1

2

3

4

a

bc

d

e

f

a

b

c

a

b

c

d

e

Figure 2.29: Before and after Constraint progagation around one loop.

15 14 3

2 2

12 93

29

31

Figure 2.30: Problem reduction creates and/or trees

42 LECTURE 2. SEARCH AND WEAK METHODS

This creates an AND/OR tree, or goal tree, using Winston’s hierarchy (Figure 1.4).

Obviously, OR tree search algorithms we have been using to date will not work in AND/ORtrees. For example in Figure ?? it is seen that the best node doesn’t correspond to the bestpath.

The problem reduction algorithm will. Throughout, you will find it helpful to consider thenodes as tasks or subgoals that you need to complete to achieve the goal.

Problem reduction algorithm

Let E(C) be an estimate of the cost of going from the current node, C to the goal. If a node(ie subgoal) is solved, then it has E(N)=0. Let us also define a threshold cost F above whichthe route to the goal is deemed too expensive. If at any point it becomes to expensive tosolve a particular (sub)goal node N it is given E(N) = F. Let the initial node be I.

1. Initialize the net to I.

2. Until the starting node is labelled solved (ie E(I)=0)or is deemed unsolvable (ie E(I)>F) {

2.1 Follow the current best path, and grow a set of nodesthat are on the path but are as yet unexpanded and areunsolved.

2.2 Pick one of these nodes, U say, and expand it.

2.3 If there are no successors {Set E(U)=F. }

else {Add the successors of U to the net.For each, compute E and if E is zero for a node,label that node as solved.

}2.4 Alter the E value of U, the newly expanded node, using

the information from its successors.2.5 Propagate this information backwards through the net.

If any node has an arc whose successors are all solved,label that node as solved (ie set E=0).

At each node visited while returning up the graph,decide which of its successor arcs is the current best path,and mark it.

}

The important difference between this and search in OR nets is information has to be per-colated back from the current node towards the start. The reason for this is of course that

2.10. PROBLEM REDUCTION AND AND/OR GOAL TREES 43

the best path is determined by ANDed arcs, and the cost information from the two or morepaths linked by an arc has to find its way back to that point.

A drawback with the technique just described is that it cannot deal with interacting goals —see the lecture on planning.

AO*

There is an advance on the previous algorithm, called AO* which is described below. Itrequires a good deal of thought to see what is going on. (If you are interested read Principlesof Artificial Intelligence by Nilsson, Morgan Kaufmann, Palo Alto, CA (1980).)

1. Compute E(I).

2. Until I is solved (ie E(I)=0), or E(I)>F {

2.1 Trace the links from I and locate an unexpanded node U.

2.2 Generate the successor nodes S (if any) of U.

2.3 If there are no successors {set E(U)=F.

}else {

for those successors S which are not ancestors of U {add successor S to the net.if S is a terminal node {

label it solved by setting E(S)=0.}else {

evaluate estimate of cost S to goal, E(S).}

}}

2.4 Propagate expansion information back through the net to theinitial state. Let D be a set of nodes that have been labelledas solved or which have changed their E values.

2.4.1 Initialize D to U.2.4.2 Until D is empty {

i.Select a node from D. Preferably this should be onewith no descendents in D, but failing this take any node.Label the node as C and remove it from set D.

ii.Compute the costs of each of the arcs emerging from C.This cost is equal to the sum of the E values of eachof the nodes at the end of the arc plus whatever thecost of the arc is itself. Give C a new E value, equalto the minimum of the costs of the arcs emerging from it.

44 LECTURE 2. SEARCH AND WEAK METHODS

iii.Mark the best arc out of C.iv.Label C as solved (ie set E(C)=0) if all the nodes connected

to it via the marked best arc have been labelled as solved.v.If C is solved, or if the E(C) was just changed, then

add all the ancestors of C to D.}

}}

2.11 Summary

• Path planning using configuration space and A* search

• Using generate and test and depth first search for model matching

• Constraint propagation

• Explored problem reduction and And/Or trees