INFORMATION
SCIENCES
19,25 l-259
A Method for Computing Heuristia
251
(1979)
in Problem S&ing+
GIOVANNI GUIDA Milan Po&technic Artificial Intelligence Project, Istituto a? Ekttrotecnica ed Eiettronica, Politecnico a? Mikno, Milae Ita& and MARCO SOMALVICOt Stanford Artificial Intelligence Laboratory, Conputer Science Department, Stanford Uniowsi@, Stanford California Communicated by Azriel Rosenfeld
ABSTRACT The purpose of this paper is to propose a formal framework for structuring and embedding the heuristic information, in o_rderto allow an algorithmic computation, in quite general cases, of the evaluation function An) of the classical Hart-Nilsson-Raphael algorithm. The notion of semantic graph is first introduced, in which the atomic notion of node is expanded by associating to it an internal structure where the heuristic information is inserted. It is
proved that h(n) can be computed by solving an auxiliaq problem, obtained from the original one by adding new arcs, and of s4er complexity than that onw. A new algorithm is then defined for the computation of h(n) and for the determination of minimal solutions. The validity of the model proposed is discussed in detail.
1.
INTRODUCTION
The problem of finding an optimal path through a graph in an efficient way is still a central one in many domains of scientific and engineering importance [6, 11, lo]. Heuristic search strategies, which aim to combine the two often contrasting requirements of generality and efficiency, have heen proposed by *A vemion of this paper has been presented at the AISB/GI Gmfe.rence on Artificial Intelligence, Hamburg, Weat Germany, 18-20 July 1978. tRescnt address: Mii Polytechnic Artificial IntelIige-nce Project, Istituto di Elettrotecnica ed Elettronica, Politecnico di Milano, Milan, Italy. QElaevier North Holland, Inc., 1979
oo2&o2s5/79/09251-0909’01.75
252
GIOVANNI GUIDA AND MARCO SOMALVICO
several authors in the past [6, 21. These methods are all based on the assumption that the graph model cannot embed all the relevant information for an efficient solution of the problem ill, 91. Therefore, supplementary heuristic information must be drawn from the semantic domain of the problem to be solved. This new ~fo~ation is then utilized to guide the search of the path through the graph. Depending on the formal way in which the heuristic information is expressed and on the manner in which it is used, different algorithms have been proposed. We are interested in this paper in ~examining more closely the Hart-N&son-Raphael algorithm [6], which still represents a central result within heuristic search. In this algorithm, the heuristic information is embedded in a function f(n), called the evaluation function, which maps each node n of the graph in an integer. Nothing is still said about the manner in which the heuristic information can be utilized in order to compute the evaluation function (more precisely, the part I;(n) of j(n)) in a general Mse. The purpose of this paper is to propose a formal framework for structuring and embedding the heuristic information in order to allow an algorithmic computation, in a general case, of the function f;(n) of the Hart-NilssonRaphael algorithm. The central idea is to expand the atomic notion of node of a graph by associating to it an internal structure in which the heuristic information is inserted. Moreover, the notion of arc is expressed in a new logical formalism, more suitable than the algebraic one for the processing required in the computation of i;(n). It is then proved that 6((n) can be computed, for each it, by solving an auxiliary problem, easily obtainable from the original one and of smaller complexity. An algorithm is also proposed for the computation of &(n) and for the determination of minimal solutions. The implications of this new algorithm and the validity of the whole model are discussed in detail. Hints are given as well for a critical comparison (and possibly for an abstract evaluation) between the computational complexity of the new algorithm proposed and the classical Dijkstra-Dantzig algorithm [7, 81. In the paper, unitary costs are supposed to be associated to the arcs of the graph; the extension to the general case of arbitrary (nonnegative) costs is straight forward. 2. BASIC DEFINITIONS In this section we present the basic concepts and definitions of our theory. Let us first recall some fundamental definitions about graphs. A (directed) graph is a pair G = (N, E) where (1) N is a nonempty set of nales; (2) E~NXNisthesetofthearcsofG.
~OMP~I~G
HEURISTICS IN PROBLEM SOLVING
253
A path of a graph G = (N, E) from a node n, to a node 9 is a string of nodes a=nenln2... a,, such that
no= n,, (“t,&+dEE
for
t-O,1 ,..., k-l,
?l&= 821 The fength Ial of a path a=non,... arcs in it.
n, is the integer k, i.e., the number of
On the basis of the formal structures above presented, we introduce now our first definition of the problem, which strictly reflects the classical models proposed within the state-space approach 110, 121. We call this definition a syntactic descr~tion. In fact, it is only structural, or syntactic, in the sense that the internal nature of nodes and arcs is not taken into account and these elemenfs are just considered as atomic concepts. This simple model will constitute the skeleton of the new representation that we shall introduce later on and that we shall denote as semantic description. A problem is a quadruple P = (N, E, i, F) where (N, E) is a graph and (1) i EN is the initial node; (2) F c N is the set of the &zul nodes. A solution x of a problem P= (N, E, i, F) is a path of (N, E) from i to a node fEF.
A solution X of a problem P is minimal iff
The semantic description of the state-space approach to problem solving we are now going to introduce is just a particular case of the more general concept of problem task presented in [5]. This particular case has beenchosen in order to show in detail how the introduction of semantic elements into old syntactic models can allow the definition of more efficient search algorithms. In fact, the semantic description is just intended to enable the computer to process and utilize in the correct way, by means of a fully auto~~c procedure, some heuristic information, supplied to it within the problem representation itself. In particular, the central purpose of the semantic model we propose is to constitute a formal basis for structuring and embedding the heuristic information in order to allow an algorithmic computation, in a general case, of the evaluation function of the Hart-N&son-Raphael algorithm. The richer information, which is proper to the semantic description, is embedded in the
254
GIOVANNI GUIDA AND MARCO SOMALVICO
state-space representation by expanding the notion of state, and by associating to each node a structure in which the new information is inserted 112, 51. Before presenting the definition of semantic problem, let us emich, from a formal point of view, the graph structure presented above. Let . . . ,uk), a k-tuple of attributes; (1) 4.4=(w22, (2) for i==l,2,..., k, K be a finite nonempty set of u&es, associated to the attribute a,EA (where the symbol E denotes “membership” in the k-tuple), called the domain of a#; (3) V=(V,, VW.., V,), the k-tuple of domains.
An attribute-value pair for an attribute a,EA is a pair ci=(ai,u,) where 0, E v,. The att~bute-clue pair set associated to an attribute a, EA is the set Ci=
(CilCj=((ai,Ui)
A
Ui~
Y,},
A semantic node (S-node) ii is an element of the set
which is called the universal S-node set defined on the pair (A, V). A (directed) semantic graph (S-graph) is a quadruple e= (A, V, II, A) where A and V are as in the above definition, and (1) II is a finite set of predicates of one argument on the set R, called properties; (2) A is a finite set of predicates of two arguments on the set r, called legal conditions. The predicates R EII and XE A, which are expressed in some logical calculus, are not unique; i.e., they cfvl have several equivalent expressions [lo, 121.We must therefore assume that they are to be reduced to some canonical form. The logical expressions for II and X are formulated by utilizing the attributes and the values. To each S-graph it is possible to associate exactly one underlying graph, which constitutes the most elementary syntactic skeleton of the S-graph. More precisely, the underlying graph of the S-graph e=(A, V, Il,A) is the graph G=(lV,E) such that
COMPUTING HEURISTICS IN PROBLEM SOLVING
255
Note that the concepts of graph and S-graph reflect two different generation strategies, implicitly contained in their definitions. In fact, the definition of a syntactic graph is obtained by specifying (by means of the set E) which nodes of an originally fi& separate graph (i.e., a graph having only the nodes in N and no arcs) have to be connected by an arc. On the other hand, the definition of an S-graph is obtained by specifying (by means of the sets II and A) which nodes, within a set of possible ones, belong to the graph and which arcs have to be pruned from an originally complete graph. The concepts of path and length are still valid and maintain their meaning for S-graphs if one refers them to the underlying graphs. Let us present now the definition of semantic problem. A semantic problem (S-problem) (A, V, II, A) is an S-graph and
is a sextuple P = (A, V, II, A, i, F), where
(1) i E N is the initial S-node; (2) F C N is the set of the j%ral S-nodes, if (N,E) is the graph underlying (A, V, l&A). The concepts of solution and minimal solution above presented are still valid for S-problems. Let us illustrate this definition by means of a simple example. We will consider the well-known classical eight puzzle, and we refer for its description to the literature [lo]. In this problem, we identify, according to the previous definitions, the following 94uple A of attributes:
where a,, is the empty tile and a,, for i= 1,2,. . .,8, is the ith tile. For i= 01, ,***, 8, the set of values 5 associated to the tile ai is the set of all the possible positions of the ith tile. Recalling the description of the puzzle, it is trivial to observe that the sets of values associated to every tile are all equal, namely, v,=JxS
for
i-0,1,2 ,..., 8,
where 3 is the set of the first three natural numbers, i.e., 3= { 1,2,3}. For each u, =(x,y) E vi, the first element x denotes the row occupied by the tile 4, while the second element y denotes the column occupied by the tile a,.
256
GIOVANNI
GUIDA
AND MARCO
SOMALVICO
In order to complete the semantic description of the puzzle, the sets of properties and of the legal conditions H and A have to be enumerated. In this puzzle the only condition to be fulfilled is that two tiles are not allowed to occupy the same position. Therefore we introduce the following property a,, defined as a logical predicate of one argument on g (recall that g= ((co, c39 (% 4, ***9(a,, d)):
for each &j-O, l,..., 8. According to the description, we have to formalize that only two tiles can be moved at the same time. Therefore we define the legal condition h,:
for ij-O,,..., 8, where (3!i) means “there exists exactly one i such that”. The legal condition AZ is related to the fact that one of the moved tiles must be the empty tile:
Another fact, which is defined by the legal condition h,, expresses that the exchange between two tiles can be made only if they are in the same row or in the same column:
8. The last legal condition for each i=O,l,..., two tiles that are moved must be adjacent:
X, is related to the fact that the
for each i-41 ,..., 8. Let us now see why the new S-problem model introduced is adequate for the purpose we proposed it for. In fact, the S-graph structure on which it is based can embed more information than the graph model. Moreover, it represents a valid formalism for representing problems within the state-space approach. We shall show, in the next section, how the supplementary information contained in the S-problem model can be effectively used for the precise definition of a new heuristically guided search algorithm. 3.
COMPUTING
THE EVALUATION
FUNCTION
This section is devoted to presenting a formal framework which allows the automatic computation of the function 6((n) on the basis of the supplementary
COMPUTING HELJRISTICS IN PROBLEM SOLVING
257
information embedded in the problem representation prepared. An algorithm which performs the proposed technique is provided. In the following, we assume knowledge of the H~-N~~on-~p~el algorithm f61. Let us fit introduce a prehminary definition. Given an S-problem ir- (A, V, II, A, i, F), an auxiliury S-problem for B is an S-problem P = (A ‘, V’, II’, A’, i’, F’) such that A’=A,
V’=V,
IS-II,
A’ch,
i’=i,
F’-F.
Let F 4 P mean that p is an auxiliary S-problem of E Tx-mo~.
Let p
and 3 be a minimal solution of F; then 12’1
Proof. The formal proof of the theorem is quite easy to obtain, but also rather hard to express. Let us only recall, in an informal way, its main steps. Because of the definition of auxiliary S-problem the graph undderlying Y (more precisely, P-Q’, V’, II’, A’)) is more connex, i.e., it has more arcs, than the graph underlying P (more precisely, 6- (A, V, I&A)). In other words, the set of the arcs of Pis a subset of the set of the arcs of P. Moreover, h(i) is the actual length of a minimal solution X of E Therefore the thesis follows.
This theorem constitutes the basis for a modified version of the classical Hart-Nilsson-Raphael algorithm that we are going to present. ALWRITHMG. (1) Given the S-problem &= (A, V, Ii, A, i, F), put i in the OPEN list and construct an auxiliary S-problem P ( p such that F ==(,4,V, II, A’, i, F). Find a minimal solution of p and compute the evaluation function&z) on the base of the above theorem. (2) Select the node 5 in the OPBN listwhose value of f is the smallest. Resolve ties arbitrarily, but always in favor of any node SF. (3) If SF, put g in the CLOSEID list and terminate the algorithm (4) Otherwise, put g in the CLOSBD listand compute all the successors of ii. For each successor iJ of g construct the auxiliary S-problem P” = (A, V,ll,A’,$F). Find a minimal solution for each S-problem B”, taking into account the experience already developed (i.e., the paths already constructed) in solving other auxiliary S-problems Bfl, all sharing the same underlying graph. Compute the evaluation functionj(3) for all the successors i$ of A on the base of the above theorem. (5) Put in the OPEN list all the successors 5 of g not already in the CU)SED list and, also, the successors i$ of 5 already in the CLOSEDlist for which&) is smaller now than it was when i$ was inserted in the CLOSED list. Go back to Step (2).
258
GIOVANNI GUIDA AND MARCO SOMALVICO
4. CONCLUSIONS The algorithm proposed doesn’t specify how to construct the auxiliary S-problem p (i.e., how to choose A’ CA). The choice of A’ implies the precise evaluation of the relations existing between the following three entities: the extent of A’ in comparison with A, the goodness of the estimate 6(K) compared to h(3), and the complexity of the resulting auxiliary S-problem Y. Clearly, both 6(g) and the complexity of P’increase as A’ approaches A. In particular, if A’=11 we obtain the optimal estimate h(3, but the solution of P’ (possibly by means of the Dijkstra-Dantzig algorithm) requires too much computational effort. A more precise insight into this question can be obtained by introducing the definition of the power of each legal condition XE A. The power ]lhl]of a legal condition h E A is the integer IIXJ(= #N’-
#N,
where #A denotes the cardinality of the set A, and where (1) N’ is the set of arcs of the graph underlying the S-graph having A’- A - {h} as legal condition set; (2) N is the set of arcs of the graph underlying the S-graph having A as legal condition set. The power of a legal condition X gives an estimate of the greater connexness of the graph underlying the auxiliary S-problem P’ obtained by setting A’A - {A} with respect to the graph underlying F. Clearly, the computation of the power of each legal condition requires an effort (run time and memory storage) which must also be carefully taken into account. We are now developing a theoretical investigation to evaluate the trade-off on the complexity of the different techniques for choosing the set A [7,8]. Experimental tests of the method are also planned. REFERENCES 1 C. L. Chang and J. R. Slagle, An admissible and optimal algorithm for searching AND/OR graphs, Artijicial Intelligence 2: 117-128 (1971). 2 G. Enwt, Sufficient conditions for the success of GF’S, J. Assoc. Cornput.Mach. 16:517533 (Oct. 1969). 3 G. Guida, D. Mandrioli, and M. Somalvico, An integrated theory of problems as an algebraic base for complexity understanding and automatic problem solving, in Proceedings of the 7th ZFIP Conference on Optimization Techniques, Nice, Sept. 1975, Springer, Heidelberg. 4 G. Guidon,D. Mandrioli, and M. Somalvico, An integrated model of problem solvers, Information Sci. 13: 1l-33 (1977).
COMPUTING
HEURISTICS
IN PROBLEM
SOLVING
259
5 G. Guida and M. Somalvico, Semantics in problem representation and search, If. Processing L.&t. 5(5):141-145 (1976). 6 P. E. Hart, N. J. Nilsson, and B. Raphael, A formal basis for the heuristic dctcrmi~tion of minimum cost paths, IEEE Tranr. @stems Sci. Q&met. SSC-14(2):100-107 (July 1968). 7 D. B. Johnson, A note on Dijkstra’s shortest path algorithm, J. Assoc. Cornput. Mach. 20:385-388 (July 1973). 8 A. Martelli, On the complexity of admissible search algorithms, Artificial Intelligence 8:1-13 (1977). 9 U. Montanari, Heuristically guided search and chromosome matching, Artificial InteNigence 1:227-245 (1970). 10 N. J. Nilsson, Problem-Soloing MetW in Artificial Intelligence McGraw-Hill, New York, 1971. 11 I. Pohl, Heuristic search viewed as path finding in a graph, Art~~ciul Intelligence 1: 193204 (1970). 12 A. Saqiovanni Vincent& and M. Somalvico, State-space approach to problem-solving optimization, in Proceedings of the 5th IFIP Conference on Optimisation Techniques, Rome, May 1973, Springer, Hcidclbfz8. Receiced Febrwy
1979