Algorithms for path searching and for graph connectivity analysis

Algorithms for path searching and for graph connectivity analysis

Advances 0965-9978(95)00025-9 ELSEVIER Sqftware 23 (1995) 27.-35 C] 1995 Elsevier Science Limited Printed in Great Britain. All rights reserved 096...

980KB Sizes 0 Downloads 102 Views

Advances

0965-9978(95)00025-9

ELSEVIER

Sqftware 23 (1995) 27.-35 C] 1995 Elsevier Science Limited Printed in Great Britain. All rights reserved 0965-9978:95/$09.50 in Engineering

Algorithms for path searching and for graph connectivity analysis A. Recuero Institute

Eduardo

Torroja-CSIC,

Serrano Galvache S/N, 28033 Madrid,

Spain

(Received 16 May 1994;revisedversion received1 May 1995;accepted11 May 1995) Threealgorithmsfor the searchof orientedpathsin digraphsare described,based in the generationof a tree, in which an BFS isdone,in the first one, and a DFS is done, in the other two algorithms. The first one is aimed at finding all the optimum paths betweentwo vertices. The secondone is aimed at solving this problem,as well asat finding the Hamiltonian paths beginningin a vertex, or at finding all the cyclesof any order in the digraph. The third one isaimedat finding all the Eulerianpaths or circuits. Two more algorithms,for the analysisof graph connectivity, usingthe sametype of techniquesare also described,one aimedat separatingan unconnectedgraph into connectedsubgraphs,and the other aimed at searchingfor all existing bridges.All five algorithmsare fully describedand they are alsoimplementedin a structured form, usingQB as the programming language. A very compact schemeis proposed to store all the required information, using only one-dimensionarrays without pointers, which allows simpleprogramminglanguagesto be used. Key words: graphs,paths, connectivity, algorithms.

1 INTRODUCTION

name is mentioned, while many important namesappear Hamilton, Kirchoff, Djikstra, (Koenig, Tutte, Kuratowski, Venn, Menge, Rerge, Harari, Fulkerson, Girdle, etc). Interested readers can find fundamentals and applications in Refs 1-5, where many references can also be found. In this paper, four classical abstract problems in oriented paths searching in a digraph, and another two on graph connectivity analysis will be considered, and someapplications indicated. A set of algorithms to solve these problems is described, all of them based on the generation of a tree, which provide us with an efficient and easy way to implement solutions.

Let us consider a network formed by a set of N vertices, identified by the numbers from 1 to iV, connected by means of a set of W edges to each of which a certain weight is assigned,either directed in one or both senses (digraph), or non-directed (graph). A one-way edge is also called an arc. In a digraph two vertices may be connected by one or more arcs with a possibility of a vertex being even connected to itself by a loop. In a graph, loops are not accepted and only one edge may exist between two vertices. Two vertices connected by one edge, or two edgeswith a common vertex, are called adjacent. The number of vertices is called graph order, and the number of edges graph size. The graph GO associated to a digraph G is the result of converting all arcs in edges and of eliminating all redundant edges. Graphs can be used to solve problems in many different areas, hierarchical ordering as in lineage trees, different games, enterpreneurial organization, syntactical analysis, electronic circuits, structural analysis, map colouring, communication networks, activities scheduling, flows, and so forth. They have been used for many centuries, but their present development comes from Euler’s works. Many mathematicians have worked separately and made contributions, so that no paramount

1.1 Oriented paths and cycles in a digraph An oriented path connecting two vertices, is a set of consecutive arcs, the first one beginning in the first vertex and the last one ending in the second vertex, which can be traversed respecting their orientations. If the last vertex coincides with the first one, the oriented path becomesan oriented circuit. Paths are called simple when all nodes are different, except the first and last ones in cycles, that is, when they do not include internal circuits. The first problem consists in finding all the optimum 27

28

A. Recuero 18

16

20 4

3

20

16

Fig. 1. Hamilton’s puzzle.

oriented paths connecting two vertices, that is, those for which the sum of the weights assigned to their edges is minimum. As an additional condition, some vertices may be excluded from the paths (forbidden vertices). It could be, for instance, a communication network, where the weights associated to each edge would be the time or the cost to travel along it. The solutions would be the different alternative ways to go from one point to another, and the forbidden vertices would be places where a problem has appeared. A practical case could be the consultation on the best way to go from one station to another, in an underground network. A simple description may consist of assigning a vertex to every station, and a sequence of edges to represent every line. A better description is the one in which every station is represented by a vertex, corresponding to the hall, and one more vertex per line. The hall vertex is connected to every line vertex by means of a couple of arcs: one to go, to which the walk time plus the average waiting time of the line is assigned, and the other to return, to which the walk time is assigned. Between two line vertices, at the same station, a couple of arcs exist, to each of which, the walk time plus the average waiting time of the destination line are assigned. Between every two successive stations in the same line a two-way edge exists to which the travel times are assigned. In this description, vertices and edges

remain constant although the weights associated with edges may vary according to the day and the different periods of time, mainly depending on train passage frequency. Should any problem exist in any line, the corresponding line stations must be set as forbidden vertices. The second problem is that of finding all the oriented simple paths that begin at a vertex and pass through every vertex. These paths are called Hamiltonian, after the Irish mathematician William R. Hamilton, who marketed a puzzle based on the skeleton of a dodecahedron which, beginning in a vertex, should be traversed crossing all the other vertices and ending in the first one. Figure 1 shows a perspective drawing of a dodecahedron, together with an isomorphic planar graph, in which one of the 60 existing solutions is marked. Again, the additional condition of the existence of forbidden vertices may be set, and also optimum paths may be searched, taking into account the sum of the weights associated to the intervening edges. If the last vertex of a Hamiltonian path is adjacent to the first one, a Hamiltonian cycle can be formed. If only Hamiltonian cycles are searched for, Hamiltonian paths beginning at any vertex may be used as a basis. This problem is also known as the traveling ‘salesman problem’.6 Consider, for instance, the knight chess problem: how can a knight traverse once and only once all squares in a chess-board. If a graph is set where every square is represented by a vertex and edges are set connecting vertices which a knight can pass going from one to the other in one movement the solution to this problem are Hamiltonian paths. The third problem is that of finding all the oriented cycles of length A4, that is, those containing M edges connecting M distinct vertices, that exist in the digraph. Should M coincide with N, the problem reverts to that of Hamiltonian cycles. The fourth problem is that of finding all the oriented paths or circuits that traverse once every edge in the digraph. In this problem, neither forbidden vertices nor optimum paths are of interest. They are called Eulerian after the Swiss mathematician Leonhard Euler, father of Graph Theory, who demonstrated the impossibility of traversing the seven bridges at Konigsberg only once during a Sunday stroll. Figure 2 shows a sketch of these bridges, connecting two islands and both banks of river Pregel. The degree of a vertex in a graph is the number of edges that have this vertex as an end. In a digraph, the in and out degrees of a vertex are the number of edges that come in or go out from the vertex; two-way edges must be counted only once, either as in or as out, they are to be traversed once. When both degrees coincide, the vertex is said to be balanced. In the case of graphs the necessary and sufficient condition for the existence of Eulerian paths is that only 0 or 2 odd degree vertices exist. If this number is 0, circuits will exist, and if it is 2, there will exist paths beginning at one of those vertices

Path searching and graph connectivity

Fig. 2. Bridges of Kiinigsberg. and ending at the other. In the case of digraphs if all vertices in the digraph are balanced and it is connected, Eulerian circuits will exist. Usually, there will exist Eulerian paths unless it is evident that they will not. Let us see now their application in solving the order N domino problem. An order N domino is a set of N * (N - 1) / 2 rectangular pieces divided into two square parts in which a couple of numbers from 0 to N - 1 are written forming all possible combinations with repetitions. We want to know how many assemblages can be formed, putting all pieces one next to another so that the adjacent squares of two different pieces have the same number. If an N-complete graph, that is with N vertices and edges connecting every pair of vertices completed with loops connecting every vertex to itself is established, every edge will represent one piece. The solutions of the domino problem will be all Eulerian paths or circuits. As a consequence of the necessary and sufficient condition, no domino of even order, except the one of order 2, will have any solution. The one of order 2 has only the trivial solution (O,O), (O,l), (l,l), that is an Eulerian path, while the rest of odd order dominos will have Eulerian circuits as a solution. 1.2 Graph connectivity The first problem is to know whether a graph is connected, and if it is not, split it into connected subgraphs. A graph is said to be connected if there is a path connecting every pair of vertices. A practical application case arises in algorithms for the reduction of the bandwidth of the stiffness matrix of a structure. Most algorithms described in the specialized bibliography are meant to act on single structures, so that they fail when they are applied to sets of independent structures, this case sometimes appears when structural CAD systems are used. To overcome this malfunction, the independent structures must be separated, and the algorithm applied to each of them.7 These algorithms produce a new numbering of the structure nodes, so that the maximum difference between the numbers of two nodes, belonging to the same element, is minimized. The second problem is that of finding all bridges present in a graph. An edge is said to be a bridge if its elimination would cause a connected graph to become

29

analysis

disconnected. They are critical edges, since, for instance, in a communications network, a problem in a bridge would cause some parts of the network to become isolated. If every edge is a bridge, the graph is a tree. The analysis of digraph connectivity is usually reduced to that of the associated graph. In other cases, algorithms can be applied to solve the problems described in the previous section. This is the case of checking if the digraph is strongly connected (every pair of vertices is connected by an oriented path), or if it is rooted (a vertex exists that is connected to all other vertices by an oriented path). 2 STORAGE

OF THE NETWORK

DESCRIPTION

A scheme for the storage of the network description, very compact and easy to be handled by the algorithms, consists of the following one-dimension arrays: -T,

integer, with as many elements as edge directions, containing the final vertices of each edge direction. It contains all the meaningful information of the adjacency matrix, and it is called an adjacency list. -DIST, integer or real, according to the type of weight assigned to edges, with as many elements as T, containing the weights assigned to each edge direction. It is only used when optimum paths are searched for. -EDGE, integer, with as many elements as T, containing the order number in which edges are described, and which identifies it. It is used only when all edges must be considered, such as in Eulerian paths or in bridge detection. - POST, integer, with N + 1 elements, that indicates that all the edges whose initial vertex is Z, are those whose final vertices are contained in elements T(Z) to T(Z+ 1) - 1, their weights are contained in the corresponding elements of DIST, and their order numbers are contained in the corresponding elements of EDGE. This information only changes when the network is modified, so that it can be generated once, and stored in disk files, from where it can be retrieved when necessary. Since no pointer is needed to use this scheme or the schemes to store the information specific to any of the algorithms described here, any programming language may be used to implement the algorithms described below. 3 FIRST

ALGORITHM:

OPTIMUM

PATHS

The first algorithm described is meant to solve the first path problem. It is based on the generation of a tree, in whose first level the initial vertex is placed, and every new level is formed by all vertices adjacent to those of

30

A. Recuero

the previous level. This tree progresses only while its nodes can be included in a solution. An exhaustive breadth-first search (BFS) is done along with the generation, rejecting the inclusion of those nodes which do not pass the verifications. The solutions will be in depth traverses in this tree. Each node in this tree has three associated numbers: - the number of the corresponding vertex (node label). -the sum of the weights associated to the edges connecting the node to the root (node value). -the number of the node from which it was generated (father node), used to facilitate the backward traverses. Besides, in a separate table, the best distances from the initial vertex to all other vertices already reached are kept. Before a new node is created, the following verifications are made: The present node value coincides with the best distance to its label. Otherwise, the same vertex would have later been reached in the same level with a better distance. The following verifications are made on the node to be created. The node label is not a forbidden vertex. The node label is not the final vertex. The node value is smaller than the present best distance to the final vertex. The node value is not greater than the present best distance to the node label. These verifications must be made in the indicated order, although (d) and (e) may be simultaneous. If (a) fails, no sub-tree stems from the present node. If(b) - (e) fail, the corresponding branch is not created, avoiding: the passage through forbidden vertices; the progress after a solution is reached; the progress in evidently nonoptimum paths; and the formation of a circuit; respectively. The failure to verify (c) causes an additional process. Since a possible solution has been reached, depending on the node value when compared to the best solution already obtained, the list of solutions is initiated, the new solution is appended to the list, or the solution is ignored. Slight changes in the verifications lead to other interesting results. Condition (e), as expressed, allows the search for all existing optimum paths. If only one optimum path is searched for, the node would be created if the node value improves the previous best distance from the initial vertex. If condition (d) is removed, an optimum path from the initial vertex to every other vertices will also be found. This could serve, for instance, to build a table showing the best distances between any two towns, through a road system. The process is terminated when no new level can be created. The list of solutions at that moment will contain all optimum oriented paths.

Since no vertex can be repeated in an depth-first traverse of the tree, the highest possible level is N- NFV - 1 (NFV is the number of forbidden vertices). A vertex may be used as node label for several nodes, in the same levels or in different ones, but every new appearance of the vertex means that the node value decreases or keeps the previous value. If only one optimum path is searched for, two nodes with the same label must have different node values. When it appears more than once in the same level, only those with smaller values will be considered roots for new sub-trees.

3.1 Storage scheme for the local information A compact scheme to store the local information used by this algorithm consists of the following one-dimension arrays -A,

which contains the node labels, one after another in the generation sequence. - DINI, which contains the node values, in the same order as in A. -B, which contains the node fathers, in the same order as in A. -C, which contains the best distances from the initial vertex to every vertex. It may also be used to mark the forbidden vertices. A and B are integer, while C and DIN1 must be of an adequate type to store accumulated values. The list of solutions consists of the present best distance from the initial to the final vertex, and a list of the father nodes of those nodes whose label should be the final vertex. This information allows the reconstruction of the whole path, by traversing the tree backwards.

3.2 Example 1 The first example is the regular square grid in Fig. 3, with 9 vertices and 24 arcs with weight 1. If there is no forbidden vertex, there are 6 optimum oriented paths from 1 to 9. They are: l-2-3-6-9, l-2-5-6-9, I-2-5-8-9, l-4-5-6-9, l-4-5-8-9, l-4-7-8-9 In this case, the tree is developed until level 4, since vertex 9 should appear as node label at level 5. Vertex 5 labels two nodes at level 3, and vertices 6 and 8 label three nodes at level 4, but in all cases the same label corresponds to the same value. When vertex 5 is forbidden, there are only two solutions: l-2-3-6-9, l-4-7-8-9 If arc 2-5 has a weight of 2, and there is no forbidden vertex, four optimum oriented paths would exist from 1

Path searching and graph connectivity

31

analysis

The check procedure verifies if a solution has been reached. If so, the list of solutions is initiated or completed, according to the circumstances. In any case, the back-track procedure is triggered. The verifications to be made, according to the problem to be solved, are described below.

Fig. 3.

to 9. In this case, vertex 5 also labels two nodes at level 3, but the first one has a node value greater than the second one, so that it is not used as root of a new subtree. 4 SECOND ALGORITHM: HAMILTONIAN PATHS, CYCLES, AND OPTIMUM PATHS

The second algorithm is meant to solve the first three problems described in Section 1.1. It is also based on the generation and an exhaustive search of a tree, but in this case, a depth-first search (DFS) is used. Three procedures are used: the first one moves forwards along the tree, the second one moves backwards, and the third one checks for the validity of the solution. The local information to be kept is: -for every node of the path under scrutiny: label nodes, and value nodes. - for every vertex: whether it is included in the path or not, and the last edge, with origin in this vertex, which was examined for inclusion in the path. The list of solutions must in this case be kept complete. The forward move procedure first checks if the present node is the final vertex; if so, the check procedure is triggered. Otherwise, it tries to advance to the following level by means of the next edge with origin in the present node label. If this advance is possible, the new level is generated, the corresponding label and value assigned, the new vertex marked as included, the list of edges updated, and the forward procedure repeated; otherwise, the back-track procedure is triggered. The back-track procedure first checks if the present level is level 1, in which case the algorithm is ended. Otherwise, the present node label is set as not included, the list of edges with origin in this vertex is re-initiated, the present level is decreased by 1, and the forward procedure triggered.

4.1 Hamiltonian

path

The verifications are:

to be made in the forward procedure

(a) The present level is N- NFV. If so, the check procedure is triggered. (b) The list of edges with origin in the present node label is exhausted. If so, the back-track procedure is triggered. If verifications (a) and (b) are passed, the next edge of the list is considered, and its final vertex used as trial label for the next level node. The next verifications are made on this trial node. (c) The node label is not already included in the path. It avoids the formation of circuits. (d) The node value is not greater than the total distance already obtained. This verification is made only when optimum paths are searched for. If verifications (c) and (d) are passed, the trial node is accepted. In any case, the forward procedure is repeated. The verifications to be made in the back-track procedure are those indicated in Section 4. No verification must be made in the check procedure, unless optimum Hamiltonian paths are searched. In this latter case, if the present solution value improves the best solution previously obtained, the list of solutions is initiated, if it equals the best solution, the list is enlarged, and if it is worse, the present solution is discarded. This algorithm may also be used to find all Hamiltonian cycles; in such a case, the choice of the initial vertex is irrelevant. In the check procedure, a solution is reached only when the initial and final node labels are adjacent vertices. 4.2 Length M cycles

When all length A4 (A4 > 2) cycles are searched, a loop is made where vertices from 1 to N - M+ 1 are successively considered as initial vertex, unless they are forbidden. The verifications to be made in the forward procedure are the same as in the previous section, except verification (a), that now becomes: (a) The present level is M. In the back-track made are:

procedure,

the verifications

to be

(a) The present level is 1 the node label is not

32

A. Recuero

N- M+ 1. If so, the present node label is set as forbidden, the list of included edges cancelled, the next vertex used as initial node label, and the loop repeated. (b) The present level is 1 and the present node label is iv-hf+1. If so, the loop is exited, and the algorithm ended. If these verifications are passed, the operations indicated in Section 4 are performed. In the check procedure, the adjacency of the final and initial vertices is verified. If they are adjacent, the solution exists. In any case, the back-track procedure is triggered. If N coincides with M, the result would be Hamiltonian cycles. 4.3 Optimum

paths

The verifications to be made in this case, in the three procedures, are the same as in Section 4.1 for optimum Hamiltonian paths, except verification (a) in the forward procedure that becomes: (a) The present node label is the final vertex. This algorithm requires less core memory than the first one, but the tree may be developed in a larger extent, especially when solution paths are short. Besides, in this algorithm, a complete description of the solutions has to be kept, while in the first one, only the father node of every solution’s last node has to be kept, since the rest of the description is contained in the tree information. 4.4 Local information

storage scheme

A very compact scheme for the storage of the information used by the algorithm is provided by the following one-dimension arrays: - A, which contains the node labels. It may have up to N- NFV elements. -DIST, which contains the node values. It has as many elements as A. - YA, which indicates whether a vertex has been included as node label in the path under scrutiny or not. It may also be used to mark the forbidden vertices. - LAST, which indicates the last edge, with origin in every vertex, that has been considered for inclusion in the path, and is therefore included.

4.5 Example 2 As the second example, the Petersen graph has been chosen. It is so-called after the Danish mathematician Julius Petersen, who included it in one of his textbooks, although it had already been used in previous works. An interesting study on this graph can be found in Ref. 8. It is a non-planar graph, frequently used due to its interest (for instance, it is the smallest ‘snark’). It consists of 10 vertices and 15 bi-directional edges, and one of his layouts is shown in Fig. 4. All its vertices are of degree 3, and it has a great symmetry, since all its nodes are equivalent. Twenty-four Hamiltonian paths, beginning in any vertex, can be found, if no forbidden vertex exists, and 8 if one vertex is forbidden. Twenty-four length 5, 20 length 6, 30 length 8 and 40 length 9 cycles can be found, if no forbidden vertex is considered. There are no length 3, 4 ,7 or 10 cycles. If one vertex is forbidden, there are 4 Hamiltonian cycles (40 length 9 circuits / 10 vertices). That is, it is a hipoHamiltonian graph. So, if vertex 5 is forbidden, the Hamiltonian cycles are: l-2-3-4-9-7-10-8-6-1, l-6-8-10-7-9-4-3-2-1,

5 THIRD

ALGORITHM:

1-2-7-10-8-3-4-9-6-I and l-6-9-4-3-8-10-7-2.

EULERIAN

The third algorithm is meant to solve the Eulerian paths problem. As in the second one, the tree, rooted in the initial path vertex, is generated and searched depth-first but in this case, the special attention is shifted from vertices to edges. It also uses three procedures: forward, back-track, and annotation. The information used by the algorithm is: -for every node of the depth-first path under scrutiny, the node label and the order in T of the edge used to access the next level node. -for every edge, a mark to know whether it is already included in the present path or not.

A, YA and LAST are integers, while DIN1 must contain accumulated values. In fact, YA may contain only 0 and IS.

The list of solutions has to be kept complete, since they are lost along the process. They can be kept in core memory, or if they are many and large, stored in a sequential access disk file.

PATHS

Fig. 4. Petersen graph.

Path searching and graph connectivity

The forward procedure checks first if the present level is W+ 1, case in which the annotation procedure is triggered. Otherwise, it tries to progress to the next level. If it is not possible, then the back-track procedure is triggered, otherwise the next level node is accessed and labeled, the edge used is marked, its order in T recorded, and then the forward procedure repeated. The back-track procedure checks first if the present level is 1, in which case the algorithm is ended, Otherwise, the level is decreased by 1, the edge used is unmarked as included, and the forward procedure triggered. The annotation procedure simply annotates the present solution and triggers the back-track procedure. As in the second algorithm, the solutions must be completely stored. A compact scheme to store the information is provided by the following one-dimension integer arrays: containing the node labels. It has W+ 1 elements. -YA, indicates whether the corresponding edge is included in the present path or not. It may consist only of 0 and 1s. - LAST, contains the order in T of the edge used to pass from one level to the next. -A,

The list of solutions may be stored either in core memory or in a sequential access disk file, since they are lost after they are reached. 5.1 Example 3

The third example is the graph shown in Fig. 5. It consists of 6 vertices and 10 edges. Since vertices 5 and 6 are of degree 3 and the remaining vertices are of even degree, only Eulerian paths exist whose end vertices must be vertices 5 and 6. There are 120 Eulerian paths with origin in each of these vertices, every path in a set 1

analysis

33

having its reverse path in the other. If edge 5-6 is considered an arc, 88 one-way paths exist with origin in 5 and 32 with origin in 6, which adds up to 120, since the paths this restriction eliminates from one set are those allowed in the other.

6 ALGORITHM

4: GRAPH CONNECTMTY

The fourth algorithm is meant to check if a graph is connected, and in case it is not, to split it into connected sub-graphs. It is also based on the generation and BFS of a tree. A vertex is chosen as root, and its adjacent vertices give rise to the next level nodes, and they are labeled. The tree progresses, level by level, while the vertices that will give rise to nodes are not labeled. When a tree can no longer progress, a connected sub-graph has been completed; if there remain unlabeled vertices, one of them is taken as root, and the process repeated. The order in which vertexes have been labeled is the same in which they will be used as sub-tree roots. The algorithm uses two procedures, one for the search of the first vertex of a new sub-graph, and the other to generate new tree nodes. The search procedure searches for the first unlabeled vertex, which is labeled as belonging to a new sub-graph, appended to the list of labeled vertices, and used as root of a new tree; then the generation procedure is triggered. The generation procedure checks first if the number of already labeled vertices equals the order number of the last node used as root of a sub-tree. If so, the present sub-graph is completed, and the search procedure triggered. Otherwise, the next vertex in the list of already labeled vertices is taken as root of a sub-tree, and all edges with origin in this vertex examined; if the edge’s final vertex is not labeled, it is labeled as belonging to the present sub-graph, with the number of already labeled vertices increased by 1 and appended to the list of labeled vertices. If the number of already labeled vertices equals the number of vertices, the algorithm is ended, or else the generation procedure is repeated. The information used by this algorithm can be stored in two integer one-dimensional arrays of N elements: which indicates the sub-graph to which every vertex belongs (label). - YA, which contains the list of labeled vertices, in the order in which they were labeled.

- LANDV,

Fig. 5.

Band-width reduction algorithms produce an indirect address vector, which can be easily built from LANDV, providing a new numbering in which all the nodes of every independent structure are consecutively numbered, retaining the relative nodes order, thus maintaining or improving the initial band-width. The indirect address vector allows the use of the initial numbering in input data and output results, and the use of the

34

A. Recuero

improved numbering to build the stiffness matrix and to solve the system of linear equations.

7 ALGORITHM

5: BRIDGES

We shall call ‘land’ (or component) a sub-graph in which every pair of vertices is included in any circuit. A land includes no bridge, since if an edge is eliminated, there is a path connecting every pair of vertices in the land. A land has either one vertex or three or more vertices. The fifth algorithm, meant to find all bridges in a graph, splits it into its different lands; all edges not included in lands will be bridges, connecting lands. This algorithm is a variation of the second one, since it is based on generating cycles. It uses four procedures: discovery of the first vertex of a new land; forward movement along a trial path, trying to find a cycle; backward movement, along the present path when a dead end is found; annotation of a success and search for the possible origin of a new cycle. The discovery procedure looks for the first unlabeled vertex; when all vertices are labeled the algorithm is ended. The vertex is labeled as belonging to a new land, and the edges whose initial vertex is the present one are examined. If 0 or 1 edge exist, the vertex is a one-vertex land; if so, the discovery procedure is repeated. When more than one edge exists, they are successively examined; if the final vertex already belongs to a land, the edge is a bridge, so that it is marked, and the examination continued; if the final vertex is unlabeled, the edge is chosen as a possible first step in a cycle, and the forward procedure triggered, accessed at level 2. If none of the edges examined triggers the forward procedure, the discovery procedure is repeated. The forward procedure checks first if the present node label is the same as in the first level. If so, a cycle has been completed, and the annotation procedure is triggered. Then, if the list of edges with origin in the present vertex is exhausted, the back-track procedure is triggered. Otherwise, the next edge in this list is considered; if the edge final vertex is not included in the present path, or if it is the initial vertex of the path and the level is not 2, then the level is increased by 1, it is labeled with the new vertex, and the vertex and the edge are included in the present path. In any case, the forward procedure is repeated. The back-track procedure checks first if the present level is 1, and, if so, the annotation procedure is triggered. If the present level is 2, the first edge is labeled as bridge, since no circuit includes it. Then, the present level is decreased by 1, and the corresponding vertex and edge are eliminated from the lists of those included in the path; then the forward procedure is triggered. In the annotation procedure, if a cycle has been completed, all its vertices and edges are labeled as belonging to the present land. Then, the beginning of a

new cycle, in the same land, is searched for. The vertices already labeled as belonging to this land are successively examined, reviewing the edges with origin in the vertex; when an unlabeled edge is found, its final vertex is checked: if it belongs to the same land, the edge is labeled: if it belongs to another land, the edge is labeled as bridge: if it is unlabeled, the edge is chosen as first step in the possible cycle and the forwards procedure is triggered. If no new circuit can be tried, the present land is completed, with all its vertices and edges labeled: the discovery procedure is then triggered. The information used by this algorithm can be stored in the following one-dimensional integer arrays: -WAY, containing the node labels in the present path. -ARWAY, contains the order number of the edges included in the present path. -LAST, containing the order in T of the edge, with origin in each vertex, included in the path. -YA, indicating, for each vertex, whether it is included in the path or not. - LANDV, containing the land label of each vertex, - LANDE, containing the land labels of each edge. 7 EXAMPLE

4

The graph shown in Fig. 6 has been chosen to test the fourth and fifth algorithms, because it presents some conflictive situations during their execution. It consists of 13 vertices and 13 edges. The fourth algorithm splits the graph into three connected sub-graphs, whose vertices are: 1, 2, 3,4, 5, 6, 7, 8 and 13 the first one; 9, 10 and 11 the second one; and 12 the third one. The fifth algorithm shows that there are 7 lands and 4 bridges. The lands are formed by the following vertices: (I), (2, 3, 4) (5) (6, 7, 8) (9, 10, ll), (12) and (13). The four bridges are: from 1 to 2, connecting lands 1 and 2 from 4 to 5, connecting lands 2 and 3, from 5 to 6, connecting lands 3 and 4, from 2 to 13, connecting lands 2 and 7. Lands 5 and 6 are isolated from the rest of the graph. 8 CONCLUSIONS The five algorithms described here use permanent information describing the network. A compact

,$yg~ 3

4

5 Fig. 6.

6

7

Path searching

and graph

scheme to store this information is proposed which allows the algorithms to easily access it. This scheme may be generated once, and then stored in disk files. They also use local information, as they are in execution. Compact storage schemes are also proposed for this information. In all cases, the total core memory required is proportional to the network order and size. Besides, only one-dimensional arrays are used, without pointers, so that any simple programming language can support these schemes. A structured implementation in BASIC has been done which has been properly tested, showing how both the algorithms and the storage schemes are easy to implement. The algorithms are simple and clear, avoiding unnecessary operations and detecting at the earliest possible stage when they will not lead to a solution. Some of these problems can be solved, within acceptable time limits, even in large networks (optimum path, total number of short cycles, connectivity, bridges), while others lead to a combinatorial explosion in execution time (total number of Hamiltonian paths, Eulerian circuits, or long cycles). In these latter cases, exhaustive searches must be replaced by heuristic methods, making use of additional knowledge about the problem, which may lead to quasi-optimum solutions but not to the total number of solutions.

connectivity

analysis

35

ACKNOWLEDGEMENT

This paper is part of the previous work to carry out the research project; development, improvement, and integration of building CAD/CAE systems; financed by the General Directorate for Scientific and Technical Research (DGICYT), code PB93/0111.

REFERENCES

AddisonWesley, 1968, Vol. I, pp. 305-406. 2. Elmaghrabi, S., Some Network Models in Management Science. Springer, New York, 1970. 3. Kapur, J. N., Mathematical Modelling. John Wiley, 1988, 1. Knuth, D., The Art of Computer Programming.

pp. 151-76. 4. Gould, R., Graph Theory. ed. Cummings,P.C., California,

1980. 5. Dolan, A. & Aldous, S., Networks and Algorithms: An Introductory Approach. J. Wiley and Sons,England, 1993. 6. Bellmore,M. & Nemhauser,G.L., The traveling salesman problem: a survey. Oper. Res., May-June 196816(3). 7. Recuero, A. & Gutierrez, J.P., Reduction de1ancho de bandade conjuntosde estructurasindependientes. Hormigdn y Acero, 1989,173,43-48. 8. Chartrand, G. & Wilson, R., The Petersengraph. In Graphs and Applications. ed. Harari, F. & Maybe, J., J.

Wiley, 1985,pp. 70-100.