<?xml version="1.0" encoding="ISO-8859-1"?><article xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<front>
<journal-meta>
<journal-id>1645-9911</journal-id>
<journal-title><![CDATA[Tékhne - Revista de Estudos Politécnicos]]></journal-title>
<abbrev-journal-title><![CDATA[Tékhne]]></abbrev-journal-title>
<issn>1645-9911</issn>
<publisher>
<publisher-name><![CDATA[Instituto Politécnico do  Cávado e do Ave]]></publisher-name>
</publisher>
</journal-meta>
<article-meta>
<article-id>S1645-99112009000200004</article-id>
<title-group>
<article-title xml:lang="en"><![CDATA[APAC: An exact algorithm for retrieving cycles and paths in all kinds of graphs]]></article-title>
</title-group>
<contrib-group>
<contrib contrib-type="author">
<name>
<surname><![CDATA[Simões]]></surname>
<given-names><![CDATA[Ricardo]]></given-names>
</name>
<xref ref-type="aff" rid="A01"/>
<xref ref-type="aff" rid="A02"/>
<xref ref-type="aff" rid="A03"/>
</contrib>
</contrib-group>
<aff id="A03">
<institution><![CDATA[,University of Minho Institute for Polymers and Composites Laboratory Institute of Nanostructures, Nanomodelling and Nanofabrication (I3N)]]></institution>
<addr-line><![CDATA[ ]]></addr-line>
</aff>
<aff id="A01">
<institution><![CDATA[,Polytechnic Institute of Cávado and Ave  ]]></institution>
<addr-line><![CDATA[Barcelos ]]></addr-line>
<country>Portugal</country>
</aff>
<aff id="A02">
<institution><![CDATA[,University of Minho IPC - Institute for Polymers and Composites ]]></institution>
<addr-line><![CDATA[Guimarães ]]></addr-line>
<country>Portugal</country>
</aff>
<pub-date pub-type="pub">
<day>00</day>
<month>12</month>
<year>2009</year>
</pub-date>
<pub-date pub-type="epub">
<day>00</day>
<month>12</month>
<year>2009</year>
</pub-date>
<numero>12</numero>
<fpage>39</fpage>
<lpage>55</lpage>
<copyright-statement/>
<copyright-year/>
<self-uri xlink:href="http://scielo.pt/scielo.php?script=sci_arttext&amp;pid=S1645-99112009000200004&amp;lng=en&amp;nrm=iso"></self-uri><self-uri xlink:href="http://scielo.pt/scielo.php?script=sci_abstract&amp;pid=S1645-99112009000200004&amp;lng=en&amp;nrm=iso"></self-uri><self-uri xlink:href="http://scielo.pt/scielo.php?script=sci_pdf&amp;pid=S1645-99112009000200004&amp;lng=en&amp;nrm=iso"></self-uri><abstract abstract-type="short" xml:lang="en"><p><![CDATA[This paper presents an alorithm for retrieving all paths and all cycles between two vertices in random directed or undirected connected graphs. This algorithm can be easily implemented and is highly modular; with minor changes it can be adapted to obtain different parameters from the graphs. It is also demonstrated that the complexity of the algorithm increases linearly with the number of paths. The algorithm can be used in a myriad of applications. Aside from calculating all the paths and cycles in a graph, it can be used to calculate all the paths with length l between two vertices in the graph, as well as a solution to the clique decision problem. Thus, it has applications in computer networks, material science and electric networks, as well as in any problem where it is necessary to know the number of paths (not the optimal paths) in a directed or undirected connected graph or in multigraphs. The algorithms currently available in the literature, such as the depth-first search (DFS), are unable to solve this type of problems in a straightforward way.]]></p></abstract>
<abstract abstract-type="short" xml:lang="pt"><p><![CDATA[Este artigo apresenta um algoritmo para identificar todos os caminhos e todos os ciclos entre dois vértices em grafos conexos aleatórios (orientados ou não orientados). O algoritmo pode ser facilmente implementado e é altamente modular; com pequenas alterações pode ser adaptado para obter diferentes parâmetros a partir dos grafos. Também demonstramos que a complexidade do algoritmo aumenta linearmente com o número de caminhos. Este algoritmo pode ser utilizado num vasto número de aplicações. Para além de calcular todos os caminhos e ciclos num grafo, pode também ser utilizado para calcular todos os caminhos com comprimento l entre dois vértices do grafo, assim como solucionar o problema de decisão clique. Assim, tem aplicações em redes de computadores, ciência de materiais e redes eléctricas, assim como qualquer problema em que seja necessário saber o número de caminhos (não o caminho óptimo) num grafo conexos (orientados ou não orientados) ou multi-grafos. Os algoritmos actualmente disponíveis na literatura, como o depth-first search (DFS), não conseguem resolver este tipo de problema de forma simples.]]></p></abstract>
<kwd-group>
<kwd lng="en"><![CDATA[graph theory]]></kwd>
<kwd lng="en"><![CDATA[connected graphs]]></kwd>
<kwd lng="en"><![CDATA[random graphs]]></kwd>
<kwd lng="en"><![CDATA[network paths]]></kwd>
<kwd lng="en"><![CDATA[nanofiber networks]]></kwd>
<kwd lng="pt"><![CDATA[teoria de grafos]]></kwd>
<kwd lng="pt"><![CDATA[grafos conexos]]></kwd>
<kwd lng="pt"><![CDATA[grafos aleatórios]]></kwd>
<kwd lng="pt"><![CDATA[redes]]></kwd>
<kwd lng="pt"><![CDATA[nanofibras]]></kwd>
</kwd-group>
</article-meta>
</front><body><![CDATA[ <p align="center"><b>APAC: An exact algorithm for retrieving cycles and paths    in all kinds of graphs</b></p>     <p align="center">Ricardo Simões <sup>[<a href="#1">1</a>]<a name="top1"></a></sup>,<sup>[<a href="#2">2</a>]<a name="top2"></a></sup></p>     <p align="center">&nbsp;</p>      <p><b>Abstract.</b> This paper presents an alorithm for retrieving all paths and    all cycles between two vertices in random directed or undirected connected graphs.    This algorithm can be easily implemented and is highly modular; with minor changes    it can be adapted to obtain different parameters from the graphs. It is also    demonstrated that the complexity of the algorithm increases linearly with the    number of paths. The algorithm can be used in a myriad of applications. Aside    from calculating all the paths and cycles in a graph, it can be used to calculate    all the paths with length l between two vertices in the graph, as well as a    solution to the clique decision problem. Thus, it has applications in computer    networks, material science and electric networks, as well as in any problem    where it is necessary to know the number of paths (not the optimal paths) in    a directed or undirected connected graph or in multigraphs. The algorithms currently    available in the literature, such as the depth-first search (DFS), are unable    to solve this type of problems in a straightforward way.</p>      <p><b>Keywords:</b> graph theory, connected graphs, random graphs; network paths,    nanofiber networks</p>     <p>&nbsp;</p>      <p><b>Resumo. </b>Este artigo apresenta um algoritmo para identificar todos os caminhos e todos os ciclos entre dois vértices em grafos conexos aleatórios (orientados ou não orientados). O algoritmo pode ser facilmente implementado e é altamente modular; com pequenas alterações pode ser adaptado para obter diferentes parâmetros a partir dos grafos. Também demonstramos que a complexidade do algoritmo aumenta linearmente com o número de caminhos.</p>      <p>Este algoritmo pode ser utilizado num vasto número de aplicações. Para além de calcular todos os caminhos e ciclos num grafo, pode também ser utilizado para calcular todos os caminhos com comprimento l entre dois vértices do grafo, assim como solucionar o problema de decisão clique. Assim, tem aplicações em redes de computadores, ciência de materiais e redes eléctricas, assim como qualquer problema em que seja necessário saber o número de caminhos (não o caminho óptimo) num grafo conexos (orientados ou não orientados) ou multi-grafos. Os algoritmos actualmente disponíveis na literatura, como o depth-first search (DFS), não conseguem resolver este tipo de problema de forma simples.</p>      <p><b>Palavras-chave: </b>teoria de grafos, grafos conexos, grafos aleatórios,    redes, nanofibras</p>     <p>&nbsp;</p>      ]]></body>
<body><![CDATA[<p><b>1. Introduction</b></p>      <p>This article focuses on the problem of finding all the paths and all the cycles between two vertices in random directed or undirected connected graphs. This information can be used, for example, as a metric in several situations that arise in random network problems. </p>      <p>Finding all paths on a graph implies finding the longest simple path in the graph. As the later is a NP-Complete problem, the overall problem is thus NP-Complete (Berman &amp; Schnitger, 1989; Cormen, 2005). With this in mind, a simple and highly modular algorithm was developed, which was termed APAC (All Paths And Cycles), and which can be used in all types of relatively dense graphs.</p>      <p>A typical solution for finding the shortest paths between all vertices in an unweighted graph is running a breadth-first search for all vertices in the graph. Another type of problem that is closer to the problem of finding all paths and cycles in a graph, is the “<i>k</i>-shortest paths” one. This optimization problem focuses on finding the <i>k</i> best solutions between two vertices. There is extensive literature for this kind of problem, with several algorithms that can solve the problem; (Brander &amp; Sinclair, 1995; Eppstein, 1999; Hershberger et at, 2007) and their references are a good starting point.</p>      <p>The main difficulty in using some instance of “<i>k</i>-shortest paths” algorithms in the current problem is that they are based in an optimization problem, and most of them only work for specific types of graphs (directed or undirected). Aside from that, they rely on sophisticated data structures, which makes them far from trivial to implement. Yet another constrain is that the definition of paths varies from algorithm to algorithm; whereas some find the <i>k-</i>shortest paths with repeated vertices, others define the paths without repeated vertices.</p>      <p>The intention here is to apply the developed APAC algorithm to less dense subgraphs that emerge from a random network (Barabasi &amp; Albert, 1999), graphs where the number of edges is lower than in a complete graph. A priori, the number of paths is known to be small. Therefore, an algorithm that scales linearly with the number of the paths in a graph is appropriate for the type of problems describe above.</p>      <p>Aside from the obvious application of identifying the paths and cycles in a graph, this paper also indicates two other possible applications of this algorithm:</p>      <blockquote>       <p>&nbsp;&#183 Generation of one of the required inputs for the use of a known graph      distance metric (Horst &amp; Kim, 1998), based on the maximum common subgraph      (MCS) of two graphs. </p>       <p>&nbsp;&#183 Study the variation of the number of paths in response to parameters      of a physical system (namely in this case, the network complexity).</p>       ]]></body>
<body><![CDATA[<p>&nbsp;</p> </blockquote>     <p><b>2. Notation</b></p>      <p>Throughout this article, the book of Cormen (2005) is used for the terminology and notation not defined here. </p>      <p>&nbsp;</p>      <p ><b>Definition 1</b>. </b>The set of all vertices (<i>&#957;<sub>i</sub></i>)    is <b>V</b>. The set of all edges (<i>e<sub>ij</sub></i>) is <b>E</b>.</p>      <p><b>Definition 2</b>. </b>A <b>digraph</b> (<b>G</b>) is a finite collection    of vertices and directed edges (<i>e<sub>ij</sub></i>) joining certain pairs of vertices, with <b>G</b>    = (<b>V</b>, <b>E</b>).</p>      <p><b>Definition 3</b>. </b>A <b>graph</b> (<b>G</b>) is a finite collection of    vertices <i>&#957;<sub>1</sub></i>, <i>&#957;<sub>2</sub></i>, <i>&#957;<sub>3</sub></i>...,<i>&#957;<sub>n</sub></i>    and undirected <b>edges</b>  <i>e<sub>ij</sub></i>=<i>e<sub>ji</sub></i> joining certain pairs of vertices, with <b>G</b>    = (<b>V</b>, <b>E</b>).</p>      <p><b>Definition 4</b>. A <b>path</b> (<b>P</b>) between vertices is a sequence    of edges (with no repeated vertices) that allows one to proceed in a continuous    manner from one vertex to another. The <b>length</b> of a path is its number    of edges.</p>      <p><b>Definition 5</b>. </b>A <b>cycle</b> (<b>C</b>) is a closed path (<b>P)</b>.    This is, a path where the initial vertex (<i>&#957;<sub>0</sub></i>) is equal    to the final vertex (<i>&#957;<sub>n</sub></i>). </p>      <p><b>Definition 6</b>. The <b>degree</b> (<b>d</b>) of a vertex (<i>d<b>(</b>&#957;<sub>i</sub><b>)</b></i>) in an undirected    graph is the number of edges incident to (<b>&#957;</b>).</p>      ]]></body>
<body><![CDATA[<p><b>Definition 7</b>. </b>Let G, G<sub>1</sub>, and G<sub>2</sub> be graphs.    G is a common subgraph of G<sub>1</sub> and G<sub>2</sub> if there exists subgraph    isomorphisms from G to G<sub>1</sub> and from G to G<sub>2</sub>; definition    5 in (Horst &amp; Kim, 1998).</p>      <p><b>Definition 8</b>. </b>A common subgraph G of G<sub>1</sub> and G<sub>2</sub>    is maximal if there exists no other common subgraph G' of G<sub>1</sub> and    G<sub>2</sub> that has more nodes than G; definition 6 in (Horst &amp; Kim,    1998).</p>      <p >&nbsp;</b><b>Definition 9</b>. </b>from (Horst &amp; Kim, 1998):<b> </b>The    distance of two non-empty graphs <i>G<sub>1</sub>, G<sub>2</sub></i> is defined as:</p>      <p><img src="/img/revistas/tek/n12/n12a04e1.jpg" width="273" height="59"></p>      
<p>&nbsp;</p>      <p>Where MCS is defined as the maximum common subgraph of two graphs, and &#124;<i>V(G)</i>&#124; is the    number of nodes of the graph G.</p>      <p >&nbsp;</b></p>      <p ><b>Definition 10</b>. </b>The average degree of a graph is given by:</p>      <p><img src="/img/revistas/tek/n12/n12a04e2.jpg" width="184" height="60"></p>      
<p>&nbsp;</p>      ]]></body>
<body><![CDATA[<p ><b>Theorem 1</b>. </b>from (Horst &amp; Kim, 1998):<b> </b>For any graphs    <i>G<sub>1</sub>, G<sub>2</sub></i> and <i>G<sub>3</sub></i>, the following properties hold true:</p>      <p><i>&nbsp;</i></p>      <p><i>1. </i>0&#8804; <i>d</i><b>(</b><i>G<sub>1</sub>, G<sub>2</sub></i><b>)    </b>&#8804;1</p>      <p><i>2.</i> <i>d</i><b>(</b><i>G<sub>1</sub>, G<sub>2</sub></i><b>)</b>=0, which    implies that <i>G<sub>1</sub></i> and <i>G<sub>2</sub></i> are isomorphic to each other.</p>      <p><i>3.</i> <i>d</i><b>(</b><i>G<sub>1</sub>, G<sub>2</sub></i><b>)</b> = <i>d</i><b>(</b><i>G<sub>2</sub>, G<sub>1</sub></i><b>)</b></p>      <p><i>4.</i> <i>d</i><b>(</b><i>G<sub>1</sub>, G<sub>3</sub></i><b>)</b> &#8804;    <i>d</i><b>(</b><i>G<sub>1</sub>, G<sub>2</sub></i><b>)</b> +<i> d</i><b>(</b><i>G<sub>2</sub>,    G<sub>3</sub></i><b>)</b> </p>      <p><i>Proof</i> in (Horst &amp; Kim, 1998).</p>      <p>&nbsp;</p>      <p><b>3. Related work</b></p>      <p>In a pioneer paper, Lars-Erik (1996) developed an algorithm that solves the    problem of finding all paths, as a reachability matrix, in a directed graph.    That algorithm is suitable if the number of edges is lower than the number of    nodes. It uses an incidence matrix (A) as an input and outputs the reachability    matrix (B). To build the reachability matrix the author represents A as a list    of all edges or pair of nodes and uses the known equation B = (A + I)<sup> n-1</sup>,    where I is the unit matrix. The algorithm selects a pair of vertices &#123;<i>&#957;<sub>a</sub></i>&#125;,    &#123;<i>&#957;<sub>b</sub></i>&#125; &#8712; <i>V</i><b>(</b><i>G</i><b>)</b>    and verifies whether &#123;<i>e<sub>ab</sub></i>&#125; &#8712; <i>E</i><b>(</b><i>G</i><b>)</b>; applied sequentially, this enables the reachability matrix    to be built. The first steps of our algorithm are based in this initial work;    however, the present work is not looking for the reachability matrix but for    all simple paths between any two given vertices.</p>      ]]></body>
<body><![CDATA[<p>Horst and Kim (1998) introduced a new distance metric based on the topology    of the graph and formally proved it. The previous mentioned metric is based    in the MCS, which is also a NP-Complete problem (Berman &amp; Schnitger, 1989;    Gary &amp; Johnson, 1979). One needs two less dense graphs to use the metric    in an efficient way. To circumvent this problem one can construct from the initial    graph (<i>G</i>) a subgraph (<i>G<sub>1</sub></i>) using the <i>k</i>-shortest    paths of <i>G</i>. The second induced subgraph (<i>G<sub>2</sub></i>) is constructed    by retrieving all the paths in the initial graph, after the application of an    edge-deletion algorithm (similar to the algorithms described in (Albert et al,    2000; Broder et al, 2000, Farid &amp; Christensen, 2006). Thus, using the previously    described procedure, the MCS based metric can be applied to two graphs in a    relatively fast way. This is possible because one can control the density of    <i>G<sub>1</sub></i> (by varying the <i>k</i>-shortest paths) and it is known    that the induced subgraph (<i>G<sub>2</sub></i>) has a number of edges higher than the vertices    but lower than a complete graph.</p>      <p>In the context of the <i>k</i>-shortest problem (simple paths between a single origin and a single destination), Brander and Sinclair (1995) selected and studied, from more than seventy papers, four algorithms [Yen, 1971; Lawler, 1972; Katoh et al, 1982; Hoffman &amp; Pavley, 1959). These were chosen by their expected speed of operation in undirected graphs, with no parallel edges, no self-loops and no negative edges. The numerical study shows that the Lawler (1972) algorithm, with <i>O </i>(kn<sup>3</sup>) for the computational complexity, had the best result. Other references for the same problem can be found in (Eppstein, 1999; Hershberger et al, 2007).</p>      <p>For the problem of finding the maximum common subgraph, the work by Bunke et    al (2002) provides a comparative study between a space search based algorithm,    and one based on clique detection performed on randomly connected graphs. As    a result of this study, the authors conclude that for low density graphs the    best algorithm is the space based one.</p>     <p>&nbsp;</p>      <p><b>4. APAC algorithm</b></p>      <p>In the design of this algorithm, it is important to keep in mind the issue of solving a NP – Complete problem. Thus, let us set a limit to less dense connected graphs, meaning, graphs where the number of edges is larger than the number of vertices but lower than in a complete graph. Another important aspect is the types of graphs where this algorithm is planned to be implemented. The graphs can be undirected, directed, or even graphs with parallel edges (multigraphs). Finally the algorithm must be sufficiently modular; with simple modifications, one can explore other attributes of the paths without having to rewrite large parts of code or the need to employ a different algorithm.</p>      <p>The depth-first search (DFS) approach resembles this algorithm, but as can    be seen in the following sections, the APAC algorithm does not need to keep    track of all visited vertices, and only stores the feasible paths. Thus, the    data structures used by the DFS to keep track of the discovered vertices are    not present in the APAC algorithm. Another important difference is the range    of application of the two algorithms, which is quite different. The APAC algorithm    retrieves all paths in a graph (and the respective cycles), while the DFS is    used to transverse directed and undirected graphs but does not retrieve all    paths in a graph. Due to that, the DFS is typically used as a subroutine in    other algorithms (Cormen, 2005).</p>     <p>&nbsp;</p>      <p><b>4.1 Description</b></p>      <p>In this section are presented some definitions required to understand the APAC algorithm pseudo-code shown in Figure 1. </p>      ]]></body>
<body><![CDATA[<blockquote>        <p>&nbsp;&#183; PUSH: This a Stack function;      typically adds one object to the stack.</p>       <p>&nbsp;&#183; Adj: Adjacency list.</p>       <p>&nbsp;&#183; STACK-EMPTY: This is a Stack      function; returns true if is empty. </p>       <p>&nbsp;&#183; TAIL: This set function      returns the last vertex. </p>       <p>&nbsp;&#183; POP: Removes the element      at the top of the stack.</p>       <p>&nbsp;&#183; FIND-NODE: Returns true      if an existing vertex already exists in a given set.</p>       <p>&nbsp;&#183; OUT-PATH: Return a found      path to some data structure or write it to disk.</p>       <p>&nbsp;&#183; OUT-CYCLE: Return a found      cycle to some data structure or write it to disk.</p>       <p>&nbsp;&#183; {s}: Is the initial vertex.</p>       ]]></body>
<body><![CDATA[<p>&nbsp;&#183; {t}: Is the final vertex.</p>       <p>&nbsp;</p> </blockquote>     <p align="center"><img src="/img/revistas/tek/n12/n12a04f1.jpg" width="556" height="381"></p>     
<p align="center"><b>Figure 1. APAC algorithm</b></p>     <p>&nbsp;</p>      <p><b>4.2 Analysis of the algorithm</b></p>      <p ><b>Lemma 1</b>. Each call to the function Out-Path constructs a unique    path between (<i>&#957;<sub>m</sub></i>, <i>&#957;<sub>n</sub></i>).</p>      <p><i>Proof. </i>Suppose that the claim is true for some undirected graph (G) with no self-loops.</p>      <p>From a starting vertex {s} one can construct (<i>n-1</i>) unique sets P (line 2), from the fact that these sets are the edges incident to {s}, and that imposed condition of no self-loops in the graph.</p>      <p>Then, from line (8) in the algorithm, it is known that &#123;<i>&#957;</i>&#125; &#8712; <i>Adj</i>&#91;<i>u</i>&#93;    which implies that (<i>u, &#957;</i>) &#8712; <i>E(G)</i>. From line (9) it is imposed that    there are no repeated vertices in the set P. If the condition in line (9) and    (10) is fulfilled by the definition of a path (definition 4), (<i>u,v</i>) is    a path. The set P is also unique because, at each step of the algorithm, either    the the (<i>s,t</i>) path is found or the set P is incremented with another    edge (line 13). As the added edges of the graph are unique (there are no repeated    vertices), then P is unique.</p>      ]]></body>
<body><![CDATA[<p><b>Theorem 2. </b>Let G be an undirected or directed connected graph with no self-loops. </p>      <p>It is claimed that: </p>      <blockquote>        <p>(a)&nbsp;&nbsp;&nbsp;&nbsp; The algorithm finds all simple paths. </p>       <p>(b)&nbsp;&nbsp;&nbsp;&nbsp; The algorithm finds all cycles. </p>       <p>(c)&nbsp;&nbsp;&nbsp;&nbsp; The algorithm terminates.</p>       <p>(d)&nbsp;&nbsp;&nbsp;&nbsp; The algorithm complexity is <i>O </i>(Cn<sub>paths</sub>).</p> </blockquote>     <p><i>Proof.</i> From Lemma 1, it is known that the set of edges (paths) retrieved    in line (11) is unique. Suppose that for some undirected connected graph G and    for any given iteration of the algorithm there exists a set P (sequence of vertices)    such that all vertices that belong to P are unique. Finally suppose that the    condition in line (9) is always fulfilled. For all &#123;<i>&#957;</i>&#125; &#8712; <i>Adj</i>&#91;<i>u</i>&#93; in    line (8), if &#123;<i>&#957;</i>&#125;=&#123;<i>t</i>&#125; then by Lemma 1    Out-Path generates a unique path, otherwise if &#123;<i>&#957;</i>&#125;&#8800;&#123;<i>t</i>&#125; the    set <i>P=P</i>&#8746;&#123;<i>&#957;</i>&#125; is moved to the stack. In the    later case, as this is a ”last in first out” (LIFO) procedure, that set P will    be analyzed in the next iteration. If the <i>for</i> in line (8) is not called    then this means <i>Adj</i>&#91;<i>u</i>&#93; = &#216;, and the P set is cleared    by the instruction in line (16). If at this point the stack is also empty, the    algorithm terminates by the instruction in line (6), proving (c).</p>      <p>For each set P retrieved from the stack in line (7), the instruction in line (10) will be tested for <i>w</i> vertices associated to that specific set. According to line (10), if one of those vertices is {t}, then a unique path has been found according to Lemma 1. Since this occurs n times, for every set P in which one of the <i>w</i> vertices is equal to {t}, all the n unique paths in the graph are found, proving (a). Continuing with the last argument, and supposing that parameters are imposed such that the condition in line (9) is not fulfilled, then the Out-Cycle is called producing a cycle with length <i>l</i>, which proves (b). </p>      <p>Let T(m) be the maximum possible computational execution time for the APAC algorithm. Here, m is the maximum number of iterations of the <i>while</i> cycle of line (6), C<sub>init</sub> is the computational execution cost associated to the first 5 lines, and C<sub>9</sub> is the overall cost in the execution of line (9). The number of iterations in line (8) can be approximated to &lt;d(G)&gt;, where &lt;d(G)&gt; is the average degree of the graph. On average, n<sub>paths</sub> is the average path length multiplied by the number of paths. Based on these assumptions, Equation 1 shows the derivation of the execution time of the APAC algorithm.</p>      ]]></body>
<body><![CDATA[<p>      <img src="/img/revistas/tek/n12/n12a04e3.jpg" width="485" height="94"></p>      
<p>As can be seen, the algorithm scales linearly with the number of paths, assuming that the number of paths is very large with respect to the average degree, proving (d).</p>      <p>The algorithm was tested using the model proposed by Erdos and Renyi (1959) for generating a random graph. In their pioneer work, they study the distribution of the minimum and maximum degree in a random graph. </p>      <p>They generate a random graph by initially defining a maximum number of edges and, from an initial set of disconnected vertices, randomly picking one pair of vertices and forming an edge.</p>      <p>A similar procedure was followed for generating the graphs (undirected). In this method, the number of vertices was fixed to 10, and 10000 connected graphs were generated with a random number of edges. The maximum number of edges was set to that of a complete graph.</p>      <p>For each generated graph, the APAC algorithm was applied and it was found that    the time complexity agrees with the expected values; see Figure 2.<a name="f2"></a></p>     <p>&nbsp;</p>      <p align="center"><img src="/img/revistas/tek/n12/n12a04f2.jpg" width="471" height="367"></p>     
<p align="center"><a href="#topf2"><b>Figure 2</b></a><b>.  Wall time vs number    of paths</b></p>     <p>&nbsp;</p>      ]]></body>
<body><![CDATA[<p ><b>4.3 Modularization examples</b></p>      <p>If one uses a queue instead of a stack then a “first in first out” (FIFO) policy is obtained. With this simple modification, one can change the way paths appear in the output.</p>      <p>Let us turn our attention to the graph represented in Figure 3. By applying    the APAC algorithm to this graph, the stack has two initial sets, {s,A} ,{s,C}.    Observing Figure 3, the maximum length of a path in the graph can be easily    seen to be three and the minimum length to be two.</p>     <p>&nbsp;</p>      <p align="center"><img src="/img/revistas/tek/n12/n12a04f3.jpg" width="302" height="239"></p>      
<p align="center"><b>Figure 3. Example undirected Graph</b></p>      <p>&nbsp;</p>      <p>Using the stack as a dynamic set, the order of the paths will be {s,C,t},{s,C,D,t},{s,A,t},{s,A,B,t}. If instead a queue is used the order of paths will be {s,C,t},{s,A,t},{s,C,D,t},{s,A,B,t}</p>      <p>Thus, with this simple change, the order of appearance of paths is changed. </p>      <p>Another modification that can be used (using a queue) is adding another restriction    in line 6. If the length of the set is higher than some threshold, then stop    the <i>while</i> cycle. With the previous modification the algorithm only retrieves    the paths of length k, which enables easy finding of k-shortest paths (with    no costs associated in the edges). Using the stack procedure ensures that every    possible path is exhausted from an initial branch of the graph.</p>     ]]></body>
<body><![CDATA[<p>&nbsp;</p>       <p><b>4.4 Implementation considerations</b></p>      <p>In practical terms, it should be pointed out that the initial graph is stored    in an adjacency list type data structure and the paths and the cycles are stored    as sequences of edges in some user defined data structure. The algorithm was    implemented using the data structures provided by the C++ standard template    library. The study shown in <a href="#f2">Figure 2</a><a name="topf2"></a> was    generated in a laptop computer with a core2 duo intel processor, and the code    was compiled using the GNU C++ complier. </p>      <p>The algorithm presented in Figure 4 is the one implemented. One can easily    see that it is the same algorithm presented in section 4.1 and analyzed in section    4.2. Note that in section 4.2 it was necessary to move the initial iteration    out the while cycle, only to facilitate the analysis of the algorithm. The time    bounds are not affected by this small change.</p>     <p>&nbsp;</p>      <p align="center"><img src="/img/revistas/tek/n12/n12a04f4.jpg" width="399" height="316"></p>      
<p align="center"><b>Figure 4. The implemented algorithm</b></p>     <p>&nbsp;</p>        <p><b>5. Application Examples</b></p>      <p>In this section two of the multiple applications of the algorithm are described.  </p>     ]]></body>
<body><![CDATA[<p>&nbsp;</p>      <p><b>5.1 Graph distance metric</b></p>      <p>Let us consider the initial undirected graph represented in Figure 5.<a name="topf5"></a></p>     <p>&nbsp;</p>      <p align="center"><img src="/img/revistas/tek/n12/n12a04f5.jpg" width="269" height="190"></p>      
<p align="center"><b><a href="#f5">Figure 5</a>. Initial graph (G).</b></p>      <p>&nbsp;</p>      <p>For this graph, the previously described <i>MCS</i>-based metric (Horst &amp;    Kim, 1998) will be applied. For this purpose, the version of APAC with the queue    instead of the stack will be employed, and a prescribed path length of 3 edges    is imposed (the minimum value in this graph). The “k-shortest path” subgraph    G<sub>1</sub> is represented in Figure 6.</p>     <p>&nbsp;</p>      <p align="center"><img src="/img/revistas/tek/n12/n12a04f6.jpg" width="269" height="191"></p>      
]]></body>
<body><![CDATA[<p align="center"><b>Figure 6. Subgraph G1. Solid lines and nodes represent edges    of the subgraph; dashed lines and nodes represent edges from the initial graph    (shown only for visualization purposes).</b></p>     <p>&nbsp;</p>      <p>The previous subgraph was built with paths of length k retrieved from the graph    represented in <a name="f5"></a><a href="#topf5">Figure 5</a>. Now using an    edge-deletion algorithm, specific paths can be retrieved from the initial graph,    namely {s,4,5,6,7,t} and {s,1,7,t}, from which graph G<sub>2</sub> is built;    see Figure 7. Note that this graph is also a subgraph of G.</p>     <p>&nbsp;</p>      <p align="center"><img src="/img/revistas/tek/n12/n12a04f7.jpg" width="286" height="203"></p>      
<p align="center" ><b>Figure 7. G2 induced graph, by some deleted edge algorithm.    Solid lines and nodes represent edges of the subgraph; dashed lines and nodes    represent edges from the initial graph (shown only for visualization purposes)</b></p>     <p >&nbsp;</p>      <p>Using Definition 9, a possible maximum common subgraph can be found (note that    the MCS is not unique), as shown in Figure 8.</p>     <p>&nbsp;</p>      <p align="center"><img src="/img/revistas/tek/n12/n12a04f8.jpg" width="292" height="130"></p>      
]]></body>
<body><![CDATA[<p align="center" ><b>Figure 8. The maximum common subgraph of G2 and G1.</b></p>     <p >&nbsp;</p>      <p>Applying the distance metric to G1 and G2, one can find d(G1, G2) = 0.14. Using    the previous metric, it is possible to find the distance between two graphs,    or the degree of isomorphism that exists between the two graphs (the lower the    distance, the more isomorphic the graphs are). This can be a very important    aspect in solving problems under some specific contexts.</p>     <p>&nbsp;</p>        <p><b>5.2 Study on the effect of the average degree</b></p>      <p>One can also apply the APAC algorithm to random (undirected) graphs generated from randomly positioned particles in a 3D volume. By considering an increasing range for interactions between particles (in small steps), the average degree is increased. For each range of interactions, an edge-deletion algorithm is applied (Albert, 2000; Broder, 2000; Farid &amp; Christensen, 2006), giving rise to an induced subgraph. One can then employ the APAC algorithm to both the initial graph and the induced subgraph; this is then repeated for each average degree. The result is shown in Figure 9. </p>      <p>&nbsp;</p>      <p align="center"><img src="/img/revistas/tek/n12/n12a04f9.jpg" width="553" height="337"></p>      
<p align="center" ><b>Figure 9. Variation of the average degree versus the number    of paths.</b></p>     <p >&nbsp;</p>      ]]></body>
<body><![CDATA[<p>It was found that the number of paths increases substantially at specific average    degrees, due to specific spatial arrangements of the particles. However, it    was also observed that this does not influence the number of paths in the induced    subgraph (that results from the edge-deletion algorithm), which indicates that    a higher range of interactions does not seem to influence the paths relevant    for the applied edge-deletion algorithm.</p>     <p>&nbsp;</p>        <p><b>6. Concluding Remarks</b></p>      <p>A simple and highly modular algorithm, termed APAC, was developed to identify all paths in lower dense graphs, which is a NP-Complete problem. </p>      <p>Traditional <i>k-</i>shortest paths algorithms are not suited for finding the total number of paths between two nodes in a graph. They are designed for optimization problems, for specific types of graphs, and include several other constrains. Using APAC, it is possible to find which edges those paths are comprised of. Moreover, this search can be performed on all types of graphs. Since the edges belonging to each path are known, the length of different paths can be compared, and a subgraph can also be built with these edges. The ability to build these subgraphs is a valuable resource, since it allows characterizing topological features of the system under study. </p>      <p>The APAC algorithm used in the context of a distance graph metric (Horst &amp; Kim, 1998) can provide valuable information for different problems, both those related to physical as well as information systems. This metric could be applied, for example, to the problem of dielectric breakdown (Beale &amp; Duxbury, 1988; Gyure &amp; Beale, 1992), answering some unsolved questions related to minimum shortest paths and breakdown paths. The algorithm can be easily adapted to deploy other metrics, which can be valued as they may relate to important properties of the system or to its behavior.</p>      <p>This algorithm can be a useful tool for complex system analysis. In this framework,    a clear example of a potential application would be information networks, such    as the publications citation network and the world wide web.</p>     <p>&nbsp;</p>      <p><b>Acknowledgements</b></p>      <p>The author would like to thank the contribution of Jaime Silva (University    of Minho, Portugal) to the development and coding of the APAC algorithm, and    Richard Vaia (Air Force Research Laboratories, USA) for providing the original    challenge of developing improved methods to predict the electrical properties    of nanocomposites, and to acknowledge the Foundation for Science and Technology,    Lisbon, through the 3° Quadro Comunitario de Apoio, the POCTI and FEDER programs.</p>     ]]></body>
<body><![CDATA[<p>&nbsp;</p>        <p><b>Referências</b></p>      <!-- ref --><p>Albert, R., Jeong, H., &amp; Barabási, A. L. (2000). Error and attack tolerance in complex networks, Nature 406, 378.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[&#160;<a href="javascript:void(0);" onclick="javascript: window.open('/scielo.php?script=sci_nlinks&ref=000165&pid=S1645-9911200900020000400001&lng=','','width=640,height=500,resizable=yes,scrollbars=1,menubar=yes,');">Links</a>&#160;]<!-- end-ref --><p>Barabasi, A. L., &amp; Albert, R. (1999). Emergence of scaling in random networks, Science 286, 509-512.</p>      <p>Beale, P. D., &amp; Duxbury, P. M. (1988). Theory of dielectric breakdown in metal-loaded dielectrics, Phys. Rev. B 37, 2785-2791.</p>      <p>Berman, P., &amp; Schnitger, G. (1989). On the complexity of approximating the independent set problem, Proc. of the 6th Annual Sym. on Theoretical Aspects of Computer Science on STACS 89, Paderborn, Germany, 256-268.</p>      <p>Brander, A. W., &amp; Sinclair, M. C. (1995). A comparative study of k-shortest path algorithms, Proc. 11th UK Performance Engineering Worksh. for Computer and Telecommunications Systems, Liverpool, 370-379.</p>      <p>Broder, A., et al (2000). Computer Networks 33, 309-320.</p>      <p>Bunke, H., Foggia, P., Guidobaldi, C., Guidobaldi, C., Sansone, C., &amp; Vento, M. (2002). A Comparison of algorithms for maximum common subgraph on randomly connected graphs, Structural, Syntactic, and Statistical Pattern Recognition, Springer, 85-106.</p>      <p>Cormen, T. T., Leiserson, C. E., &amp; Rivest, R. L. (2005). Introduction to algorithms, second edition, MIT Press, Cambridge MA USA.</p>      ]]></body>
<body><![CDATA[<p>Eppstein, D. (1999) Finding the k shortest paths, SIAM J. Comput. 28, 652-673.</p>      <p>Erdos, P., &amp; Reny, A. (1959). On random graphs, Publicationes Mathematicae 6, 290–297.</p>      <p>Farid, N., &amp; Christensen, K. (2006). New J. Phys. 8, 212-229. </p>      <p>Gary, M. R., &amp; Johnson, D. S. (1979). Computers and intractability: a guide to the theory of np-completeness, WH. Freeman and Co, New York NY USA.    </p>      <p>Gyure, M. F., &amp; Beale, P. D. (1992). Dielectric Breakdown in continuous models of metal-loaded dielectrics, Phys. Rev. B 46, 3736-3746.</p>      <p>Hershberger, J., Suri, S., &amp; Bhosle, A. (2007). On the difficulty of some shortest path problems, ACM Trans. Algorithms 3, No. 5.</p>      <p>Hoffman, W., &amp; Pavley, R. (1959). Method for the solution of the nth best path problem, Journal of the Association for Computing Machinary 6, 506-514.</p>      <p>Horst, B., Kim, S. (1998). A Graph distance metric based on the maximal common subgraph, Pattern Recognition Letters 19, 255-259.</p>      <p>Katoh, N., Ibaraki, T., &amp; Mine, H. (1982). An efficient algorithm for the k shortest simple paths, Networks 12, 411-427.</p>      <p>Lars-Erik, T. (1996). An algorithm for computing all paths in a graph, BIT 6, 347-349.</p>      ]]></body>
<body><![CDATA[<p>Lawler, E. L. (1972). A procedure for computing the k best solutions to discrete optimization problems and its applications to the shortest path problem, Management Science Theory Series 18, 401-405.</p>      <p> Yen, J. Y. (1971). Finding the k-shortest loopless paths in a network, Management Science 17, 712-716.</p>      <p>&nbsp;</p>      <p><b>Brief CV</b></p>      <p><b>Ricardo Simoes</b> is an Associate Professor at the Polytechnic Institute    of Cávado and Ave, Portugal. He conducts research activities at the Institute    for Polymers and Composites of the University of Minho, and the Associate Laboratory    Institute of Nanostructures, Nanomodelling and Nanofabrication (I3N). He cooperates    with the MIT-Portugal program (Engineering Design and Advanced Manufacturing    area).</p>      <p>He has a 5-year bachelor degree in Polymer Engineering from the University of Minho and a PhD in Materials Science and Engineering from the University of North Texas, USA. He is currently coordinating projects in mobile health (MIT-Portugal program), RFID (SimeI&amp;DT), automotive (with Ford Motor Company), nanomaterials (with the US Air Force Research Labs), and medical devices (with Health Cluster Portugal). He has over 40 scientific/technical publications, over 20 oral presentations at international conferences, and 8 invited lectures in several countries.</p>      <p><SUP>[<a href="#top1">1</a>]<a name="1"></a></SUP> Polytechnic Institute of    Cávado and Ave, Campus do IPCA, 4750-810 Barcelos, Portugal; <a href="mailto:rsimoes@ipca.pt">rsimoes@ipca.pt</a></p>            <p><sup>[<a href="#top2">2</a>]<a name="2"></a></sup> IPC – Institute for Polymers    and Composites, University of Minho, Campus de Azurém, 4800-058 Guimarães, Portugal; <a href="mailto:rsimoes@dep.uminho.pt">    rsimoes@dep.uminho.pt</a></p>         ]]></body><back>
<ref-list>
<ref id="B1">
<nlm-citation citation-type="journal">
<person-group person-group-type="author">
<name>
<surname><![CDATA[Albert]]></surname>
<given-names><![CDATA[R.]]></given-names>
</name>
<name>
<surname><![CDATA[Jeong]]></surname>
<given-names><![CDATA[H.]]></given-names>
</name>
<name>
<surname><![CDATA[Barabási]]></surname>
<given-names><![CDATA[A. L.]]></given-names>
</name>
</person-group>
<article-title xml:lang="en"><![CDATA[Error and attack tolerance in complex networks]]></article-title>
<source><![CDATA[Nature]]></source>
<year>2000</year>
<volume>406</volume>
<page-range>378</page-range></nlm-citation>
</ref>
</ref-list>
</back>
</article>
