an improved bidirectional heuristic search algorithmasa/courses/cs440/fall09/assignments/...tional...

15
An Improved Bidirectional Heuristic Search Algorithm DENNIS DE CHAMPEAUX AND LENIE SINT Umversitett van Amsterdam, Amsterdam, Holland ABSTRACT A modification of Pohl's bidirectional heuristic search algorithm is described together with a simplified implementation. Theorems are proved about conditions yielding shortest paths The results are given of a worst-case analysis of different algorithms, suggesting a rank order of their quahty Results that Pohl had obtained with a unidirectional heuristic search algorithm on the 15-puzzle are compared with the results obtained with the new-simplified-algorithm KEY WORDSAND PHRASES artificial intelligence, bidirectional heuristic search, front-to-front grading, path finding CR CATEGORIES 3 64, 3 66 1. Introduction In this paper we limit ourselves to those problems (a) which are representable m the statei-operator-state2 paradigm, (b) in which the goal can be explicitly represented as a state in a set of states, (c) whose problem space can be described as a labeled graph, (d) for which it is equally possible to work from the start state to the goal state as the other way around, and (e) for which there is a heuristic function available which can be used to guide the search process. As IS well known (see, e.g. [3]), a heuristic function can be used to guide a unidirec- tional search. The property of ending with a shortest path between start state and goal state, as can be found with breadth-first search without heuristic function, can even be preserved if the heuristic function is a lower bound on the real minimum effort to be made. In [4] and [5] an algorithm ts described which generahzes to the bidirectional case. This algorithm in fact performs two independent unidirectional searches, a forward search guided to the goal node and a backward search graded to the start node. The disadvantage of this is that in a search space where more than one path exists from the start node to the goal node, the two searches often proceed along two different paths, and so the two sets of closed nodes (for an explanation of "closed," "nodes," and other techmcal jargon see [3]) grow into nearly complete unidirectional trees before intersect- mg each other, instead of meeting in the "middle" of the space. In Section 2 we discuss another algorithm that remedies this defioency, and we give a simphfication of that algorithm which has been implemented in a Fortran program. In Section 3 we compare our results with the results of Pohl's unidirectional heuristic search on the 15-puzzle. In Section 4 we mention some possible improvements of the implemented algorithm. Copyright © 1977, Association for Computing Machinery, lnc General permission to repubhsh, but not for profit, all or part of this material is granted provided that ACM's copyright notice is given and that reference is made,.to the publication, to its date of ~ssue, and to the fact that reprinting privileges were granted by permission of the Association for Computing Machinery A former version of this paper was presented at the Fourth International Joint Conference on Artificial Intelligence, 1975. This research originated from a grant of the Netherlands Organization for the Advancement of Pure Research (Z W O ), whlch enabled the first author to visit the University of Texas, Austin, Texas, where L Slklossy introduced him to this. field Authors' address Umversiteit van Amsterdam, Jodenbreestr 23 k 3123, Amsterdam-1001, Holland Journalof the Association for Computing Machinery, Vol 24, No 2, Aprd1977,pp 177-191

Upload: hakiet

Post on 09-Mar-2018

218 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: An Improved Bidirectional Heuristic Search Algorithmasa/courses/cs440/fall09/assignments/...tional search. The property of ending with a shortest path between start state and goal

An Improved Bidirectional Heuristic Search Algorithm

DENNIS DE CHAMPEAUX AND LENIE SINT

Umversitett van Amsterdam, Amsterdam, Holland

ABSTRACT A modification of Pohl's bidirectional heuristic search algorithm is described together with a simplified implementation. Theorems are proved about conditions yielding shortest paths The results are given of a worst-case analysis of different algorithms, suggesting a rank order of their quahty Results that Pohl had obtained with a unidirectional heuristic search algorithm on the 15-puzzle are compared with the results obtained with the new-simplified-algorithm

KEY WORDS AND PHRASES artificial intelligence, bidirectional heuristic search, front-to-front grading, path finding

CR CATEGORIES 3 64, 3 66

1. In t roduct ion

In this pape r we limit ourse lves to those p rob l ems (a) which are r ep r e s en t ab l e m the

s ta te i -opera tor -s ta te2 pa rad igm, (b) in which the goal can be explicit ly r e p r e s e n t e d as a state in a set of s tates , (c) whose p rob l em space can be desc r ibed as a labeled g raph , (d) for which it is equally possible to work f rom the star t s tate to the goal s ta te as the o the r way a round , and (e) for which the re is a heuris t ic funct ion available which can be used to guide the search process .

As IS well known (see, e .g. [3]), a heuris t ic funct ion can be used to guide a unidirec- t ional search. The p rope r ty of end ing with a shor tes t pa th b e t w e e n s tar t s ta te and goal s ta te , as can be found with bread th- f i r s t search wi thout heuris t ic funct ion , can even be p re se rved if the heuris t ic funct ion is a lower b o u n d on the real m i n i mu m ef for t to be made . In [4] and [5] an a lgor i thm ts desc r ibed which gene rahzes to the b id i rec t ional case. This a lgor i thm in fact pe r fo rms two i n d e p e n d e n t unidi rec t ional searches , a fo rward search guided to the goal node and a backward search graded to the s tar t n o d e . T h e d isadvantage of this is that in a search space where more than one pa th exists f rom the start node to the goal n o d e , the two searches of ten p roceed along two d i f fe ren t pa ths , and so the two sets of c losed nodes (for an exp lana t ion of " c l o s e d , " " n o d e s , " and o t h e r t echmca l j a rgon see [3]) grow into near ly comple t e unid i rec t ional t rees be fo re in tersect - mg each o the r , ins tead of mee t ing in the " m i d d l e " of the space.

In Sect ion 2 we discuss a n o t h e r a lgor i thm that r emed ie s this d e f i o e n c y , and we give a s imphf ica t ion of that a lgor i thm which has b e e n i m p l e m e n t e d in a Fo r t r an p ro g ram.

In Sect ion 3 we compare our results with the results o f Poh l ' s unid i rec t ional heuris t ic search on the 15-puzzle. In Sect ion 4 we men t ion some possible i m p r o v e m e n t s of the i m p l e m e n t e d a lgor i thm.

Copyright © 1977, Association for Computing Machinery, lnc General permission to repubhsh, but not for profit, all or part of this material is granted provided that ACM's copyright notice is given and that reference is made,.to the publication, to its date of ~ssue, and to the fact that reprinting privileges were granted by permission of the Association for Computing Machinery A former version of this paper was presented at the Fourth International Joint Conference on Artificial Intelligence, 1975. This research originated from a grant of the Netherlands Organization for the Advancement of Pure Research (Z W O ), whlch enabled the first author to visit the University of Texas, Austin, Texas, where L Slklossy introduced him to this. field Authors' address Umversiteit van Amsterdam, Jodenbreestr 23 k 3123, Amsterdam-1001, Holland

Journal of the Association for Computing Machinery, Vol 24, No 2, Aprd 1977, pp 177-191

Page 2: An Improved Bidirectional Heuristic Search Algorithmasa/courses/cs440/fall09/assignments/...tional search. The property of ending with a shortest path between start state and goal

178 D. DE CHAMPEAUX AND L. SINT

2. Bidirectional, Heuristic, Front-to-Front Algorithm (BHFFA) Before going into a precise description of the B H F F A , we give an intuitive sketch. Suppose we have the sRuation shown in Figure 1, where S and T are the sets of closed nodes and S and i" are the two fronts of open nodes, and we decide to expand a node from S. In Pohl 's Bidirectional Heuristic Path Algor i thm (BHPA) a node was chosen in

which had a minimum value of the functiongs + hs, where g8 was the current minimum to the start node s and h s was an est imator of the distance from the node to the goal node t. The hs we use is different. For a node n, hs(n) is a minimum of f t ( n , y ) + gt(Y), where y ranges over all nodes in the opposi te front T; gt is like gs but with respect to the goal node t, a n d / - / i s an est imator of the shortest distance between pairs of nodes.

The disadvantage of this algorithm with respect to the B H P A must be immediately clear, since the calculation of the function hs in our algorithm is much more complicated ~ a n the calculation of the distance to t in the B H P A . On the other hand, there are gains, but we defer discussing them until Section 3.

In order to describe the B H F F A , we have to give some definitions, in which we follow as closely as possible the terminology of [5]:

s is the start node; t is the goal node; S is the collecUon of nodes reached from s which were expanded; T is the collection of nodes reached from t which were expanded;

is the collecUon of nodes which are not in S but are direct successors of nodes in S; is the collection of nodes which are not in T but are direct successors of nodes in T;

H(x, y) is the minimum distance between node x and node y ; fi/(x, y) is a nonnegative est imator of the distance between x and y with f/(x, y) = fi/(y, x); gs(Y) is the minimum distance be tweens andy fory ~ S U S, with path in S U S, along the

current pointers; gt(Y) Is like gs(Y) wRh respect to t and T U T; hs(n) = mmu~¢(f/(n, y) + gt(Y)); ht(n) = minv~(/-/(n, y) + gs(Y)); A(x) = g~(x) + hs(x);

FIG 1

"q%. \

\

t

D i ag ram showing which dis tances are es t imated by heuristic funcuons m Pohl ' s a lgor i thm and m ours

Page 3: An Improved Bidirectional Heuristic Search Algorithmasa/courses/cs440/fall09/assignments/...tional search. The property of ending with a shortest path between start state and goal

An Improved Bidirectional Heuristic Search Algorithm 179

ft(x) = gt(x) + hi(x); F(x) is the f imte set of n o d e s o b t a i n a b l e by app l icab le o p e r a t o r s o n x ; F-~(x) is l ike F(x), b u t wi th inve r se o p e r a t o r s i n s t ead ; l(n, x) is the n o n n e g a t i v e edge l eng th b e t w e e n n a n d x .

We now def ine the B H F F A : (1) Placex in S andt in 'l', S .= T = O (2) If S t3 7" = O then stop without a solution, otherwise deode to go forward, step (3), or backward, step

(10) (3) Select n m S wlthf~(n) = mm~gf~(y), remove n from S and put n in S, let descendants(n) .= F(n) (If more

than one can be selected try to find a node n for which n E i" holds) (4) If n ~ T then halt with a solution path. (5) If descendants(n) = ~ then go to step (2) (6) Select x from descendants(n) and remove It

(7) Ifx C S then (lfg,(n) + l(n, x) < g,(x) then {redirect the pointer to n}, go to step (5))

(8) If x E S then (If g,(n) + l(n, x) < gs(x) then {redirect the pointer to n, remove x from S, and put x in $}; go to step (5)).

(9) Put x m S, provtde a pointer to n, and go to step (5) (10) Do steps (3) through (9) with (s, S, S, F) replaced by (t, T, T, F-0

In s tep (2) no th i ng is said a b o u t the dec is ion to go fo rwa rd or b a c k w a r d . A s inves t iga ted by Pohl , t he mos t p romis ing p roced t t r e is to c o u n t the n u m b e r of n o d e s in and i" a n d to select the f r o n t which has the f ewes t (bu t at leas t o n e ) .

Remark. U n h k e the case wi th the un id i r ec t iona l a lgo r i thm, the h - v a l u e c a n n o t be s to red at a n o d e since this va lue changes dynamica l ly as a c o n s e q u e n c e of m u t a t i o n s m the oppos i t e f ront .

2.1 SOME THEOREMS ABOUT THE B H F F A . W e give some t h e o r e m s and p roofs a b o u t the B H F F A which para l le l the t h e o r e m s and proofs a b o u t the u m d i r e c t i o n a l A * a lgo r i t hm of [3].

THEOREM 1. I f Ill(x, y) --< H(X, y) and tf all edge labels are not less than some positive ~, then the BHFFA halts with a shortest path between s and t (provided there is one).

PROOF. A s in the un id i r ec t iona l case, we first p rove a l e m m a . LEMMA 1 I f ill(x, y) --< H(x, y), then, for every iteration o f the BHFFA and for every

optimal path P from s to t, there exist open nodes n ~ S, m ~ T, on P with fs(n) -< H(s, t) and ft(m) -< H(s, t).

PROOF. Le t n be the first n o d e on P, c o u n t e d f rom s , wi th n ~ ,~. L e t m b e the first n o d e on P , c o u n t e d f rom t, wi th m E 7" ( they exist because o t h e r w i s e all n o d e s o n P would be c losed and the B H F F A h a d a l r eady ha l t ed wi th the s o l u n o n p a t h P).

fs(n) = gs(n) + hs(n), = gs(n) + [I(n, y) + gt(Y) for some y E T, --< gs(n) + [I(n, m) + gt(m) by def in i t ion of hs, --< gs(n) + n(n , m) + gt(m), = H(s, t) since we are o n an op t ima l pa th .

ft(m) <- H(s, t) is p r o v e d in the same way. [] Now suppose T h e o r e m 1 d o e s n ' t hold . T h e n we have t h r ee cases: (1) the B H F F A

d o e s n ' t ha l t ; (2) the B H F F A hal t s w i thou t a so lu t ion pa th ; (3) the B H F F A hal t s w i t h o u t a sho r t e s t pa th .

Case (1) . Le t P b e an op t i m a l pa th f rom s to t. A c c o r d i n g to L e m m a 1 t he re a lways exists an o p e n n o d e n in S U 7" on P wi th fs(n) or ft(n) -< H(s, t). T h e r e f o r e the n o d e s e x p a n d e d mus t have an f - v a l u e less t h a n or equa l to H(s, t). C o n s e q u e n t l y the i r g -va lues are less t h a n or equa l to H(s, t). Thus the B H F F A only expands n o d e s at mos t H(s, t)/8 s teps away f rom s or t , a n d this is a f ini te n u m b e r . Le t Ms and Mt b e t he se ts of all n o d e s which are eve r g e n e r a t e d f rom s a n d t, respect ive ly . A s eve ry n o d e has on ly a f ini te

Page 4: An Improved Bidirectional Heuristic Search Algorithmasa/courses/cs440/fall09/assignments/...tional search. The property of ending with a shortest path between start state and goal

180 D. DE CHAMPEAUX AND L. SINT

number of successors, and as the maximum number of steps any node is away from s or t is finite, both Ms and Mt can only contain a finite number of nodes, and so M = M~ t_J Mt is of finite size. Let the number of nodes in M be Y- Let Pm be the (necessarily finite) number of different paths from s to m if m ~ M~, and from t to m if m ~ M , and let p be the maximum over all Pro. Then p is the maximum number of different times a node can be reopened. Af t e rp • Y iterations of the B H F F A , all nodes of M are permanent ly closed. So S tAT = O and the B H F F A halts, which produces a contradiction.

Case (2). We have just proved that the B H F F A eventually halts, and it can only do so for two reasons: It has found a solution path, or S tA T is empty. Lemma 2, however, prohibits that S tA T = 0 .

Case (3) Just before ending with a node m, there would, by Lemma 1, be a node n in S with .fs(n) -< H(s, t) < fs(m) + gt(m), and thus n would be chosen for expansion instead of re. []

The next theorem proved m [3] for the umdirectional algorithm is the optimality theorem, which states that if two heuristics H and H* are related by H*(n, t) < H(n, t) -~ H(n, t) for all n, and if H(n, t) + H(n, x) -< [I(x, t) for all n and x (this property is called the consistency property) , then every node expanded by H will also be expanded by H*. The analogue of this theorem for the B H F F A doesn ' t hold. For a counterexample and an alternative optimality theorem see [1].

2.2 WORsT-CAsE ANALYSIS. A first-order comparison of these algorithms can be done by investigating how they behave in worst-case situations. For a certain search space we give formulas for the number of expanded nodes for the unidirectional and bidirectional Pohl algorithms and the B H F F A , assuming that the heuristic function used gives a maximum error between relative bounds.

Let the search space be an undirected graph containing a countable collection of nodes; two nodes, the start and goal nodes, have m edges (m > 1), and there is a path of length K between them. From all other nodes emanate m + 1 edges; there are no cycles; and all the edge lengths are one. So all nodes except the start and the goal nodes have m + 1 successors, of which one is the direct ancestor. Since for the unidirectional and bidirectional Pohl algorithms and the B H F F A , the direct ancestor will be found in the set of closed nodes and will consequently be ignored (in this space there is only one g-value possible, so that can' t be improved) , we only consider the remaining m successors. From a unidirectional point of view, the space is a tree with branching rate m since the algorithm will not look beyond the goal node.

Suppose that for each node x on the solution path (s.p.) , nodes off the s.p. are expanded till some depth n, and that this n is a function of the real distance R to the goal node in the unidirectional case, to the start respectively goal node in the case of Pohl 's bidirectional algorithm, and to the opposite front in the B H F F A case: n = u(R). At depth 1 of f the s.p. there are m - 1 nodes, at depth i there are m~-~(m - 1) nodes, and so the total number of nodes in one such sldetree of depth u(R) is given by

utR)--I

VR= ~ (m'(m-- 1 ) ) = ( m - - 1 ) (m u(n)- 1)/(m -- 1) = m u(R)- 1. z=O

If we denote by fA the total number of nodes erroneously expanded by Algor i thm A, we get the following results:

1. Unidirectional: R is the distance to the goal node, going from s to t on the s.p.; R decreases in steps of 1 from K till 1 and so

= ~ V.. (1) idlrectlonal R=I

2. Bidirectional Pohl: For some node lying on the s.p. and expanded by the forward algorithm, R is the distance to the goal node, and this distance decreases in steps of 1 from K for the start node to K/2 + 1 for the intersection node. So the forward algorithm expands a total of ~=K~2+1 VR nodes off the s.p.; the same number is expanded by the

Page 5: An Improved Bidirectional Heuristic Search Algorithmasa/courses/cs440/fall09/assignments/...tional search. The property of ending with a shortest path between start state and goal

An Improved Bidtrectional Heuristic Search Algortthm 181

backward algorithm (for convenience we assume for all the bidirectional cases that K is even and strict alternation; slight changes are required when K is odd), and so

=2 ~ VR. (2) ]directional P o h l R = K I 2 + I

3. BHFFA: Firsts is expanded, then t. Suppose a is the successor ofs lying on the s.p. and b is the predecessor of t on the s.p. Then for the sidetree of s, R = R(s, b) = K - 1, and so the depth of the sidetree hanging off s t s u(K - 1). The same goes for the tree hanging off t. When a and b are expanded after the sidetrees at s and t are completed, the distances from a and b to the opposite front are K - 3, etc So in this case R is decreasing in steps of 2 from K - 1 until 1 is reached; therefore the total number of nodes in all the sldetrees is gwen by

K/2

= 2 ~ V2R--1. (3) HFFA R=I

These results hold independently of the form of u(R). It is reasonable to assume that the smaller the real distance, the more accurate (or the

less erroneous) will be the estimated distance. Thus we expect that the depth of the stdetree hanging off a node on the s.p. will become smaller as R becomes smaller. In that case u(R) is a monotonically decreasing function. Figures 2, 3, and 4 give an idea of the depths of the sidetrees (represented by the lengths of the bars) for all nodes on the solution path tf this assumption holds.

If R1 < R2 "--> u(R1) < u(R~), then also R1 < R2 ~ VR1 < VR2 (V R denotes the number of nodes in the sidetree with depth R), and so

KI2 KI2 KI2 K K K

2 E V 2 . - , < ~.V2R-,+ E V 2 . = 2 V R < E VR+ E Vn R=I R=I R=I R=I R = K / 2 + I R=K]2+I

o r fBHFFA < fun,dxrectlonal < fbidxrectlonal Pohl"

Now we show that u(R) is indeed a monotonically decreasing function if we assume that the heuristic [ t gives a maximum error between relative bounds; that is, if for some 8 > O,

n=u(K-1) n=u(K) s n=u(K-1)

\ \

\

\ \

\ \ \

Fie 2

\ n=u(K-3) \

BHFFA. R decreases with steps of 2 FIG 3, Umdirecnonal R (t = the mtersectmn node ) decreases with steps of 1

Page 6: An Improved Bidirectional Heuristic Search Algorithmasa/courses/cs440/fall09/assignments/...tional search. The property of ending with a shortest path between start state and goal

182 D. DE CHAMPEAUX AND L. SINT

n=u(K)

\ n=u(K/2)

FIG 4 Bldlrectmnal Pohl Since at t, R is stdl Fm 5 H(s, t) = K, umdl- K/2, n never gets very small rectlonal

S

K-R

Z

t

~H(n, m). (1 + 8) if b o t h n a n d m are on the s.p. , f / (n , m) = [H(n, m)/(1 + 8) if at least one o fn a n d m is not on the s.p.

Unidirectional and bidirectional Pohl (Figure 5): I f x E s .p. , y E s .p. , y E F(x ) , and z ~ s.p. , z ~ Fn(x) , then z will be expanded i f fg(z) + h(z) -< g(y) + h(y), or K - R + n -+ ( R + n ) / ( I + 8 ) - < K - R + 1 + ( R - 1)(1 + 8 ) , o r n ( 1 + 1 / ( 1 + 8 ) ) ~ - - R / ( 1 + 8 ) + (R - 1)(1 + 6) + 1, orn(1 + 8 + 1)--< - R + (1 + 8) + (R - 1)(1 + 6) 2, o rn (2 + 8)-< - R + l + 8 + R + 2 R S + R 8 2 - 1 - 2 8 - 8 2 , o r n ( 2 + 8 ) - - < R S ( 2 + 8 ) - 8 ( l + 8 ) , o r n - < R 8 - 8(8 + 1)/(8 + 2), or n = INT(R8 - 8(8 + 1)/(8 + 2)), if INT(x) denotes the largest integer smaller than or equal to x. And so we see that in this case the monotone condi- tion holds, h(y) = it(y, t) andh(z) = H(z, t) in the unidirectional case. h(y) equals either H(y , t) or H(y , s) and h(z) equals either f/(z, t) or H(z, s) in the bidirectional case, but that doesn ' t change the formula.

B H F F A : When the B H F F A expands nodes coming alternatively from S and T, and when it uses the heuristic H(x, y) = H(x, y)(1 + 8) if both x a n d y are on the s.p. , and H(x, y) = H(x, y)/(1 + 8) m all other cases, then

(a) when a nodex , x E s.p. , x E S, is expanded, it realizes its minimum in a n o d e y E s.p., y ~ i " ,

(b) whenever a node x ~ S, x ~ s.p. , is expanded, then at the next i teration a node y 7", y ~ s.p., will be expanded with H(t, y) = H(s, x), (c) a node in the sldetree hanging off x ~ s.p. wdl always realize its minimum in a

node y ' E F(y), y E s.p. , y ' ~ s.p. , and a node in the sidetree o f y E s.p. wdl always realize its minimum in a node x ' E F(x), x ~ s.p. , x ' E s.p. ,

(d) after expansion o f x ' E F(x), x a n d x ' ~ s.p. , a n d y ' E F(y), y a n d y ' ~ s.p. , no other nodes in the sldetrees of x and y wdl be expanded.

In Appendix A we give proofs for these four statements. Suppose we have x ~ S, x ' E F(x), z ~ Fn(x), x ~ s.p. , x ' ~ s.p. , z ~ s.p. , y ~ 7", y ' ~ I-'(y), y E s.p. , y ' E s.p.

Page 7: An Improved Bidirectional Heuristic Search Algorithmasa/courses/cs440/fall09/assignments/...tional search. The property of ending with a shortest path between start state and goal

A n I m p r o v e d B i d i r e c t i o n a l Heur i sUc S e a r c h A l g o r i t h m 183

(see Figure 6); then z will be expanded iffgs(z) + h, (z ) -< gs(x) + h,(x'), orgs ( z ) + gt (Y ' ) +

f-I(z, y ' ) -< g , ( x ' ) + g t ~ ' ) + f t ( x ' , y ' ) , or

[ K - ( R + 1 ) ] / 2 + n + [ K - ( R + 1 ) ] / 2 + l + ( R + n ) / ( l + 8 ) - < Z ( [ K - ( R + 1 ) ] / 2 + l ) + (R - 1)(1 + 8),

and this yields n = I N T ( R 8 - 8(8 + 1)/(8 + 2)), the same as for the unidirectional and bidirectional Pohl algorithms.

If we denote 8(8 + 1)/(8 + 2) by ca, the complete formulas for the j:A's become (we assume n = R8 - c8 instead of n = I N T ( R 8 - c~))

1. = VR ~ m~-%- , + m28-%-~ + ' ' ' -t- mKS-%-~ = m(~-% ) nldlreetlonal R= 1

(m K~ - 1)/(mS - 1) - K,

2 . ~ = 2 ~ V R ~ 2 ( m ( K / 2 + l ) ~ - c s - ~ - I - m ( K / 2 + 2 ) ~ - c a - ~ " t ' ' ' ' + l d l r e c t l o n a l Poll l R=KI2+I

m K8-c8-') = 2 m ('+~i2'8-c8 (m (Ki2)a - 1)/(m a - 1) - K,

~B K I 2 3. = 2 E V2R-1 ~ 2(m 8-c~-' + m38-%-' + "" • + m (g-1)8-e*-' = 2 m 8-e~

H F F A R=I

(m K~- 1)/(m z ~ - 1 ) - K .

Examples for K = 4, m = 2, 8 = 1 are shown m Figures 7(a) (unidirectional), 7(b) (bidirectional), and 7(c) (BHFFA)

3. E x p e r i m e n t s w i th the B H F F A

3.1 THE PROGRAM. A modified BHFFA algorithm is implemented as a Fortran program geared toward solving the 15-puzzle. In this search space all edge lengths are taken as unity. The modlficattons made are the following:

(1) If the program has not found a solution path after expanding 1000 nodes, it gives up.

(2) The number of open nodes in a front is restricted to some maximum m, whmh is given to the program as an input parameter but must be less than 100. This restriction is

s

iR !

yq

y(

t

FiG 6 H(s, t) = K, BHFFA

Page 8: An Improved Bidirectional Heuristic Search Algorithmasa/courses/cs440/fall09/assignments/...tional search. The property of ending with a shortest path between start state and goal

1 8 4 D DE CHAMPEAUX AND L. SINT

s

6 6

5O'-"--"

FIG 7 Examples of worst-case situations ~/(x,y) = H ( x , y)(1 + 6) if bo thx and y are on the soluUon path, and [-/(x, y) = H ( x , y)/(1 + ~5) otherwise (unldlrecUonal, y = t always; btdlrecuonal Pohl, y = s or t) Filled-m circles are nodes vtslted and expanded, empty circles are nodes visited but not expanded For all the examples K = 4, m = 2, and 6 = 1. The numbers beside the nodes are the f-values, the order of expansion for the first two algorithms is then easdy derived INT IS a functton that produces the integer part of the expression foUowmg it (a) Unidirectional. J: = mINr~-e~(rn ~:° -- l ) / (m ° -- 1) -- K = 20 × (24 - 1)/(2 ~ - 1) - 4 = 11 See below for part (b) and see next page for part (c)

s

/ ~ / ~ 8 7 8 8 7 8 8 7 8 8 7 8

8 8 8 8 8 8 8 8 5 ' / 5 \/s-5

35 -- 8

Fm 7(b). B1tdlrectlonal Pohl. jc = 2m,~{~1+m2~-%~ m~Ki~ _ 1)/(m~ _ 1) - K = 2 × 2 × (22 - I)/(2 ~ - I) - 4

= 20 t must be expanded before the algorithm termmates

realized by deleting the worst node of a front whenever inserting a new one would mean that the front would contain more than m nodes. We call this operation "pruning," a term also used in [3]. The pruning ts mainly necessary to save time, as the number of comparisons needed to calculate hs(x) for a node x m ,5 is equal to the number of nodes m

and vice versa. But this also means that the algorithm is not admissible anymore (an algorithm satisfying Theorem 1 is called admissible), since it is possible that some node on the optimal path will be thrown away because tt looked bad at some Iteration. In a

Page 9: An Improved Bidirectional Heuristic Search Algorithmasa/courses/cs440/fall09/assignments/...tional search. The property of ending with a shortest path between start state and goal

A n Improved Bidtrecttonal Heuristic Search Algorithm

s

185

. . _ _ - - - - - - O

5 5 ~ _ / / ~ ,I 5 (2)

t

FIG 7(c) B H F F A The o rde r of expans ion is shown m brackets , the f -va lues are those at the m o m e n t o f

expans ion f 2mINa'(a-cn)(m ^a - 1)/(m 28 - 1) -- K = 2 x 2 x (24 - 1)/(22 - 1) - 4 = 6

search space where only one path exists from start to goal node, some backtracking mechanism would be required to ascertain that this path is found. In the case of the 15- puzzle, the actual influence didn't appear to be very large lfm was set at 50 (or larger), as will be seen in Section 3.2.

(3) Step (8) of the BHFFA, in which occurrence of a new node in the collection of closed nodes in its own front is checked, was eliminated. This was done because we thought the time gained in possibly expanding a few nodes less would not balance the loss caused by searching through the set of closed nodes for every new open node.

(4) Step (4), the terminating condition, was eliminated and replaced by a test in step (6): "If x ~ 7" tO T then halt with a solution path." That the testing of x is in ?" tO T, instead of just in T, is a necessary consequence of the pruning, as it ~s possible that a descendant of a closed node is deleted from the front of open nodes.

Step (9) was done by estimating all distances to the opposite front and inserting node x m one of the ordered fronts of open nodes, where the ordering is given by the f-values of the open nodes. A nasty side effect was that the insertion of a new node in S could imply a reordering of 7" and vice versa. The ordering was done by using a square matrix m which all combinations of the/:/(x, y)-values of the front were stored.

Three heuristic functions were implemented in the program: (1) P(a, b) = 2 , P,, with p, being the Manhattan distance between the positions of tile

l in a and in b. (2) S(a, b) = ~ , p~ h, ° 5, where p, is as m (1) and h, is the distance in a from tile i to the

empty square. (3) R(a, b) is the number of reversals in a with respect to b, where a reversal has the

meaning that a(i) -- b(j) and a(j) = b(i), and t and j are adjacent tiles.

Of these functions the first two originally come from [2] and the third comes from [4]. 3.2 RESULTS, C O N C L U S I O N S , AND REMARKS. In order to compare our results with

the unidirectional case, the program was run with the same 15-puzzle problems as were used by Pohl in [4] (see Table I), with the same heuristic function with the to-values:

f l = g + toP with to = 1, 2, 3, 4, 8, 16, ~, f 2 = g + t o ( P + 2 0 R ) with to= 1, 2, 3, 4, 8, 16 ,~ , f3 = g + toS with to = .5, .75, 1, 1.5, 2, 3, 4, 16, 0% f 4 = g + t o ( S + 2 0 R ) with t o = 0 . 5 , 0 . 7 5 , 1 , 1 . 5 , 2 , 3 , 4 , 1 6 ,

Page 10: An Improved Bidirectional Heuristic Search Algorithmasa/courses/cs440/fall09/assignments/...tional search. The property of ending with a shortest path between start state and goal

186 D. DE CHAMPEAUX AND L. SINT

(which in fact meansfl(x) = g~(x) + minv~i. (P(x, y) + gt(Y)) for x in S; ~tc.). As there were ten different 15-puzzles, this amounts to a total of 320 problems, of which our program solved 240, whereas the unidirectional program of Pohl solved 203 of them. It can be seen that in nearly all these cases the heuristic is not a lower bound on the real effort to be made. This is the main reason why ~aany of the solutions found are not optimal, both for Pohl's program and ours.

The results are given in Tables I - IV. Table I gives the number of problems solved for each of the ten puzzles with each function. Subtotals are made for each puzzle and for each function. Table II gives a score for the path lengths. It was obtained as follows: The program with the shortest path for some problem scored 1 and the other program scored 0 (and any path is counted shorter than no path at all); if the same path length was found, both programs scored 1 ; if a problem wasn't solved by either of them they both scored 0. Table III gives a similar score for the number of nodes expanded. Table IV gives for each problem the shortest path found, the average path length over all solved cases, and the average number of expanded nodes over all solved cases.

Insofar as the solution quality is concerned, the B H F F A is an improvement over the unidirectional algorithm: It solves more problems, finds in general shorter paths, and expands less nodes on the average, although the last effect is less prominent than we expected. The BHFFA performs particularly well with a strong heuristic funcUon; with f4 the total number of nodes expanded by our program was 32 percent less than that by Pohl's program.

The front length adequate for the problems was found empirically. Experimental runs were made with front lengths of 25, 32, and 50. An increasing number of problems was solved and a higher stability was reached. (By stability we mean the chance that a longer front length preserves a solution obtained with a shorter front length; pruning tricks are the obstructing force here.) As could be expected, the performance with respect to the front length depends on both the solution path length and the heuristic used: The better the estimator, the smaller the front length required (a length of 1 would suffice for a perfect heuristic). All problems were run with a front length of 50, and the least satisfactorily solved were run again with a front length of 99, in order to see whether the maximum number of 1000 expanded nodes or the pruning in the fronts was the bottleneck. In general the first seems to be the case, since no significant improvement was made (with the excepUon o f f l on A9 where six instead of one out of seven problems were solved).

The main disadvantage of Pohl's bidirectional algorithm, mentioned in Section 1, appeared to be remedied. The fronts now did meet near the middle of the search space, which we could see by comparing gs and gt of the intersection nodes.

The large disadvantage of our algorithm is the very time consuming calculauon of the distance estimator. How much more expensive the B H F F A is depends on the heuristic used: The more complicated this function is, the larger will be its share in the total computation time needed for a solution, and the smaller will be the share of the other computations, which have to be done equally for the BHFFA and for the unidirectional algorithm. So, with a front length of m, the B H F F A will be in the limit (with an infinitely complicated heuristic) m times as expensive as the unidirectional algorithm when they end up with a solution path of the same length. In general the loss of efficiency will not be sufficiently set off by the shorter paths found. Nevertheless, it may pay off in, for example, an ABSTRIPS-like environment (see [7]), where it is crucial to find an optimal path from among many different existing paths, as the number of subproblem searches depends on the path length found in the dominating problem space. There the B H F F A or a similar algorithm (in Section 4 we suggest ways to make it cheaper) with a strong heuristic function may find an optimal path more efficiently than a unidirectional program with a heuristic satisfying the lower bound condition, because this kind of heuristic tends to be rather weak and results in a fast explosion of the number of nodes expanded.

Page 11: An Improved Bidirectional Heuristic Search Algorithmasa/courses/cs440/fall09/assignments/...tional search. The property of ending with a shortest path between start state and goal

An Improved Bidirectional Heuristic Search Algorithm 187

Page 12: An Improved Bidirectional Heuristic Search Algorithmasa/courses/cs440/fall09/assignments/...tional search. The property of ending with a shortest path between start state and goal

1 8 8 D. DE CHAMPEAUX AND L. SINT

T A B L E IV COMPARISON OF PATH LENGTHS

Problem Shortest path found Average path length for each problem

Average number of nodes expanded (only over the

solved problems)

Pohl Our Pohl Our Pohl Our

A1 12 12 12 12 12.6 12.9 A2 26 26 42.8 27.3 161.5 54 4 A3 36 34 64.8 44 0 389.1 320 9 A4 20 20 21 8 24.3 90.2 108 6 A5 38 32 56 7 39 7 310.4 250.1 A6 32 32 42.8 37.1 335 7 333 4 A7 36 36 56 6 53.7 365 4 429 3 A8 85 61 132.0 93.0 605 6 485 9 A9 86 88 152 9 118.5 551 2 563 5 A10 64 60 92 3 90 0 609 3 532 3

4. Open Problems and Loose Ends

The BHFFA can be simphfied by not calculating the heuristic distance to every node in the opposite front but only to the best half or even less of them. This idea Is inspired by the fact that, in the limited number of cases where we checked it, a node realized its mlmmum nearly always m a node which belonged to the best ten of the opposite front. A further simplification would be to delete the resequencing of the opposite front as the consequence of addmg a node to a front. The sensitivity of the solution quality to these computation times and memory savings should be tested.

The partly expanded node techmque, as suggested in [6], needs investigating. A less technical question, however, concerns the selection of the most interesting of the vast amount of potential macrooperator sequences that appear in a solution path. But the real artificial intelhgence question is still: How can the program improve its heuristic function beyond simply optimizing some coefficients 9 Heavily related to this is the question: How does one find automatically the best representation for a problem to be treated by heuristic algorithms?

Appendix

First we repeat the statements made in Secuon 2.2 concerning the BHFFA, and then we give proofs for them. When the BHFFA expands nodes coming alternatwely from S and from T, and when it uses the heuristic lfI(x,y) = H(x,y)(1 + 8) if bo thx andy are on the s.p., and H(r, y) = H(x, y)/(1 + 8) in all other cases, then

(a) when a nodex, x C s.p., x E S, is expanded, it realizes its minimum in a nodey s.p., y ~ 7";

(b) whenever a node x E S, x ~ s,p., is expanded, then at the next ~teration a node y E T, y ~ s.p., will be expanded with H(t, y) = H(s, x);

(c) a node m the sidetree hanging off x E s.p. will always realize its minimum in a n o d e y ' E F(y), y ~ s.p., y ' ~ s.p., and a node in the sidetree o f y E s.p. wdl always realize its minimum in a node x ' E F(x), x E s.p., x ' ~ s.p.;

(d) after expansion o f x ' ~ F(x), x a n d x ' ~ s.p., a n d y ' E F(y), y a n d y ' ~ s.p., no other nodes m the sldetrees of x and y will be expanded.

(a), (b), and (c) will be proved by induction. First we check the statements for s and t. (a) at the moment s is expanded it realizes it minimum in t; (b) s and t are expanded immediately after each other; (c) for x ~ F"(x), y E Fn(t), s ' ~ F(s), t ' ~ F(t), x, y E s.p., s ' , t ' E s.p.,

gs(x) + tel(x, t') + gt(t') = n + (K - 1 + n)/(1 + 8) + 1 < n + (K + n + n ) / ( 1 +~5) + n

= gs(X) + .f/(x, y) + gt(Y).

Sox realizes its mimmum m t ' and not iny E F-n(t). The same holds fory with respect to S t "

Page 13: An Improved Bidirectional Heuristic Search Algorithmasa/courses/cs440/fall09/assignments/...tional search. The property of ending with a shortest path between start state and goal

A n Improved Bidirectional Heuristic Search Algorithm 189

Now we proceed with the reduction steps (see Figure 8). Suppose (a), (b), and (c) hold for nodesx a n d y , x ~ ,~, x ~ s.p. , y ~ 7", y E s.p.; then we prove that they also hold f o r x ' ~ F(x), x ' E s.p., and f o r y ' ~ F(y), y ' E s.p.

Let H(x, y ') be R, then H(s, x) = H(t, y) = [K - (R + 1)]/2 (they are equal according to (b)). Inductive proofs for (a), (b), (c), and (d) follow.

(a) As the branching rate is a constant, and as x and y were expanded immediately after each other, the sidetrees at x and y will grow m exactly the same way and so, for some nodes z l E F"(x) and z2 E F"(y), at even iterationsfs(zl) = ft(z2). Since according to (c) they realize their minimum in y ' respectively x ' , expansion of z l doesn ' t change the value of z2; descendants of z l will have larger f-values than z l , and so z2 will be expanded next. Therefore y ' will not be expanded as long as x ' Is not expanded. Fur thermore , x ' will not be expanded as long as it realizes ~ts minimum in some node m the sidetree at y , because when this is the case, there is always some node z l m the sidetree at x with the same fs-value to y ' and then this z l will be chosen for expansion instead of x ' . (We had a worst case so ties are always resolved in the most unfavorable way.) So, at the moment x ' is expanded, it realizes its minimum in y ' , and at the same moment y ' realizes its minimum in x ' , and fs(x') = ft(,v') is the minimum of all distances between nodes from S and 'F. []

(b) At that i teration, fs(x') < fs(zl) = ft(z2), or

gs(x') + [l(x ', y ') + gt(Y') < gs(zl) + /-/(zl, y ' ) + gt(y'),

and thus

[ K - ( R + 1 ) ] /2+ i + ( R - 1 ) ( I + 8 ) + [ K - ( R + I ) ] / 2 + I < [ K - ( R + I ) ] / 2 + n + (R + n ) / ( 1 + 8) + [ K - (R + 1)]/2 + 1

o r

2 [ K - (R + 1)]/2 + 2 + ( R - 1)(1 + 8) < 2 [ K - (R + 1)]/2 + n + 1 + (R + n ) / ( 1 + 8 ) . (A1)

At the next iteration, we have in S three kinds of nodes: x" ~ r (x ' ) , x" ~ s.p.; v E F(x') , v ~ s.p.; z l ~ F"(x), z l ~ s.p. So

°~°° ~ °° °°

\ °°° °°°° ~

,°o*°°° ~

z2L~,~.. \ °%°°° "'-.... \Y

n °*%° /

J.~

FIG 8 BHFFA Dashed hne is f~(zl), dotted hne is ft(z2), both before expansion of x' and y'

Page 14: An Improved Bidirectional Heuristic Search Algorithmasa/courses/cs440/fall09/assignments/...tional search. The property of ending with a shortest path between start state and goal

190 D. DE CHAMPEAUX AND L. SINT

f t (z2) = gt(z2) + minue~ (g~(u) + [ t (u , z2))

K - ( R + 1) = n + + min

2

" K - (R + 1) + 2 +

2

i K - ( R + 1) + 2 +

2

K - (R + 1) + n + - -

2

n + ( R - 1) ~g~(x") + n(x", z2))

1 + 8

n + (R + 1) 1 + 8 (gs(v) +/:/(v, z2))

2n + (R + 1) (g~(zl) + H(z l , z2))

1 + 3

K - ( R + 1) K - ( R + 1) n + ( R - 1) = n + + +

1 + 8 1 + 8 1 + 8

2 K - (R + 1) R + n 1 + n + - - - - + 2 ,

1 + 8 1 + 8 1 + 8

+ 2

whde

f t{Y') -< g~(x") + gt(Y ') + H(x", y ') K - ( R + 1) K - ( R + 1)

- + 2 + 2 2

So

+ 1 + ( R - 2 ) ( 1 + 8 ) .

K - (R + 1) f t (Y') --< 2:

2

2K - (R + 1) 2

2 g - (R + 1) < 2

2 K - (R + 1) < 2

2 K - (R + 1) < 2

and so now y ' will be expanded .

+ 3 + ( R - 2 ) ( 1 + 8 )

+ 2 + ( R - 1)(1 + 8 ) - 8

+ 2 + ( R - 1 ) ( 1 + 8 )

R + n + n + 1 + 1 + 8 (according to (A1))

R + n 1 + n + - - + 2 - - - = f t(z2) ,

1 + 8 1 + 8

[]

(c) A node in the sidetree of x ' always realizes its m i n i m u m in y" and vice versa, because if z l ~ F"~(x') and z2 ~ F"z(y'),

K - R + I K - R + I g~(zl) + gt(x') + H(z l , x ' ) = + n l +

2 2 K - R + I K - R + I

< + n l + 2 2

= gs(zl) + gt(z2) + f / ( z l , z2) .

(d)

f~(x") --< gs(x") + gt(Y") + _-I(x", y") < gs(X") + gt(Y') + lf-l(x", y ' ) = fs(z2);

and so z2 won ' t be expanded anymore . []

ACKNOWLEDGMENT. Discussions with Ira Pohl on earher drafts were highly appreci- ated.

R - 3 + n l + 1 +

1 + 8 R - 2 + n l + n 2

+ n 2 + 1 + 8

[]

REFERENCES

1 DE CrlAMPEAUX, D , AND SLUT, L An optlmahty theorem for a b~-d~rectional heuristic search algorithm Rep of Inst. voor Bedrqfseconomm en Accountancy, U van Amsterdam, Amsterdam. 1975

Page 15: An Improved Bidirectional Heuristic Search Algorithmasa/courses/cs440/fall09/assignments/...tional search. The property of ending with a shortest path between start state and goal

A n Improved Bidirectional Heuristic Search Algor i thm 191

2 DORAN, J., AND MICHIE, D Experiments with the graph traverser program. Proc. Royal Soc A 294 (1966), 253-259

3. NILSSON, N J Problem-Solwng Methods Ln Artzfictal lntelhgence. McGraw-Hall, New York, 1971. 4 POHL, I Bl-dlrectlonal heunsUc search m path problems. Stanford U , Stanford, Cahf., 1969 5 POHL, I. Bl-dtrecttonal search. Machine lntelhgence 6, 1971, pp 127-140. 6 ROSENSERG, R S Look-ahead and one-person games U. of British Columbm, Vancouver, Canada,

1972. 7 SACERDOTI, E. D Planmng m a hierarchy of abstraction spaces. Proc. Third Int. Joint Conf Artlf Intel ,

Stanford, Cahf, 1973, pp 412-422

RECEIVED AUGUST 1975; REVISED JULY 1976

Journal of the AssoclaUon for Computing Machinery, Vol 24, No 2, Aprd 1977