Finding Hypernetworks in Directed Hypergraphs

The term “hypernetwork” (more precisely, s -hypernetwork and ( s, d )-hypernetwork) has been recently adopted to denote some logical structures contained in a directed hypergraph. A hypernetwork identiﬁes the core of a hypergraph model, obtained by ﬁltering oﬀ redundant components. Therefore, ﬁnding hypernetworks has a notable relevance both from a theoretical and from a computational point of view. In this paper we provide a simple and fast algorithm for ﬁnding s -hypernetworks, which substantially improves on a method previously proposed in the literature. We also point out two linearly solvable particular cases. Finding an ( s, d )-hypernetwork is known to be a hard problem, and only one polynomially solvable class has been found so far. Here we point out that this particular case is solvable in linear time.


Introduction
In the last two decades, hyperpaths in directed hypergraphs have often been used to devise formal models and solution methods in many application areas; see [1,2,5,7,8,9] to mention a few.Only recently however, Volpentesta [10] investigated some hypergraph structures, referred to as hypernetworks, defined in terms of sets of hyperpaths.In particular, the s-hypernetwork is the union of all the hyperpaths with origin s, while the (s, d)-hypernetwork is the union of all the hyperpaths with origin s and destination d.
Hypernetworks were proposed (see [10] and references therein) in the Virtual Enterprise context, where they provide a formal model for a network of (potentially) cooperating economic actors, capable of responding to specific business opportunities.In general, a hypernetwork represents the relevant part of a hypergraph model, that contains all the feasible solutions while excluding redundant components.On the computational side, working on the hypernetwork rather than the whole hypergraph can lead to substantial savings in execution time.This happens in particular when shortest hyperpaths must be repeatedly computed, possibly a huge number of times [5,6].For example, the preprocessing phase described in [5,Section 4] actually finds an (s, d)-hypernetwork.
As shown in [10], the s-hypernetwork H s contained in a given hypergraph H can be found in polynomial time.However, the algorithm proposed in [10] requires a rather involved analysis, and has a high computational complexity.
Here we present a simple and fast method, whose complexity is at most quadratic in the size of H.We also point out that H s can be computed in linear time for two well known particular classes, namely, directed graphs and acyclic hypergraphs.
Opposed to finding H s , finding an (s, d) hypernetwork is an NP-hard problem, even in the case of directed graphs [10].In [10] the problem is shown to be polynomially solvable for the class of stratified hypergraphs, but no complexity bound is provided.Here we point out that stratified hypergraphs actually coincide with acyclic hypergraphs, and we show that this case can be solved in linear time.
On the theoretical side, we point out the relation between hypernetworks and other known concepts, namely, flow hypergraphs and dominators.These relations were not observed explicitly in [10], even if similar results were given; note that our treatment is different from, and substantially simpler than, the one in [10].
The paper is organized as follows.In the next section we introduce our notation and recall some known results.In Section 3 we deal with finding s-hypernetworks, while in Section 4 we deal with (s, d) hypernetworks.Conclusions, and suggestions for further research, are reported in Section 5.

Definitions and main properties
A directed hypergraph is a pair H = (V, E), where V is the set of nodes and E is the set of hyperarcs; a hyperarc is a pair e = (T (e), h(e)) where ∅ = T (e) ⊂ V and h(e) ∈ V \ T (e).Clearly, the hypergraphs considered here contain directed graphs as a subclass.
In the literature the term hypergraph is often referred to the broader class introduced by Gallo et al. [1], who define a hyperarc as an ordered pair (X, Y ) where X and Y are two disjoint subsets of nodes.The hypergraphs addressed in our paper, where |Y | = 1 for each hyperarc, are called B-graphs in [1]; the symmetric case where |X| = 1 is referred to as F-graphs.Observe that we obtain an F-graph from a B-graph (and vice-versa) by reversing the direction of hyperarcs, i.e., by replacing each pair (X, Y ) by (Y, X).
A hypergraph ).In the following we take S(H) as the size of the input problem, assuming n+m = O(S(H)); in particular, we have S(H) ≥ max{n, m}) if there are no isolated nodes, i.e., F S(u) ∪ BS(u) = ∅ for each u ∈ V .
A path P st in a hypergraph H is a sequence of nodes and hyperarcs: where, for i = 1, . . ., q, v i ∈ T (e i ) and ii. it takes linear time O(S(H)) to check wether H is acyclic and, in that case, to obtain a topological order.
The concepts of hyperconnection and hyperpath are captured by the following definitions.Definition 1. (hyperconnection) A node u ∈ V is hyperconnected to s in H if either u = s or there exists a hyperarc e ∈ BS(u) such that each node v ∈ T (e) is hyperconnected to s. Definition 2. (hyperpath) A hyperpath from an origin node s to a destination node t (i.e., an s-t hyperpath) is a minimal hypergraph π = (V π , E π ) where t is hyperconnected to s.
In Definition 2 minimality of π means that it does not exist any π ′ ⊂ π where t is hyperconnected to s.Clearly, t is hyperconnected to s in H if and only if H contains a hyperpath from s to t.Note that a hyperpath in a directed graph is a simple (i.e., non-looping) directed path.The following properties of hyperpaths are well known, see e.g.[6].
thus there is at least one u-t path in π; iii.for each u ∈ V π \ {s} there is exactly one e ∈ E π such that u = h(e); iv. for each u ∈ V π \ {t}, π contains exactly one hyperpath from s to u.
Given a hypergraph H = (V, E) and a distinguished source node s ∈ V , we denote by Π s the set of hyperpaths with origin node s in H, and by Π sd the set of hyperpaths from s to d = s in H. Definition 3. (hypernetworks) Given H = (V, E) and s ∈ V , the s-hypernetwork H s = (V s , E s ) is the union of all the hyperpaths in Π s , i.e., is the union of all the hyperpaths in Π sd , i.e., Clearly, V s is the set of nodes hyperconnected to s in H; from now on we restrict ourselves to (s, d)-hypernetworks where d ∈ V s , i.e., Π sd is not empty.Note that we have E s ⊆ E (s) , where is the set of hyperarcs with nodes in V s ; thus we have H s ⊆ H (s) , where H (s) = (V s , E (s) ), and this inclusion can be strict, as shown in Example 1.
Example 1.In the hypergraph H in Figure 1 we have V s = {s, a, b, c, d}; nodes and hyperarcs in dotted lines do not belong to H (s) .Hyperarc 6 belongs to H (s) , but not to H s .Indeed, any hyperpath from s to d must contain hyperarc 5, by Property 2.iii; thus a hyperpath containing 6 would contain a cycle (a, 5, d, 6, a), contradicting Property 2.i.Hypernetworks can be related to the concepts of flow hypergraph and dominator.Flow hypergraphs, introduced by Guedes et al. [4], extend the well known concept of flowgraph to the broader class of hypergraphs introduced by Gallo et al. [1].We say that H = (V, E) is a flow hypergraph with source s ∈ V if each node in V is hyperconnected to s in H; this can be denoted by H = (V, E, s).It is easy to see that hypernetworks (both H s and H sd ) as well as the hypergraph H (s) = (V s , E (s) ) are flow hypergraphs.Moreover, the concept of dominator in a flowgraph can be extended to flow hypergraphs.

Definition 4. Given two distinguished nodes u and v in a flow hypergraph
Note that a reflexive version of the dominance relation is referred to as "s-indispensability" in [10]; however, the connection with dominance is not pointed out there.

Finding the s-hypernetwork
As discussed above, to identify H s we can proceed as follows: first build the hypergraph H (s) = (V s , E (s) ) and then remove from E (s) all those hyperarcs that do not belong to any hyperpath in Π s .The set V s can be found in O(S(H)) time, applying procedure B-Visit [1]; given V s , E (s) can be found in time O(S(H)).Thus building H (s) takes linear time in the size of H.
In the following we show how to derive the hypernetwork H s from H (s) , first for the general case and then for two easier classes.We exploit the following quite intuitive fact, following from Property 2.iv: a hyperarc e in E (s) belongs to H s if and only if it belongs to a hyperpath from s to h(e) in H (s) .Hyperarcs that do not fulfill this condition are removed, and the remaining ones define H s .

The general case
Besides finding hyperarcs to be removed from H (s) , our algorithm generates an n × n {0, 1} matrix D (the analogue of the "s-indispensability matrix" in [10]) where D ij = 1 if node v i is a dominator of node v j in H (s) , and D ij = 0 otherwise.Here we assume an arbitary but fixed ordering of the nodes in To improve efficiency, all the hyperarcs in the backward star of a node are processed at the same time.Thus the algorithm works in stages, processing a node u ∈ V s \ {s} at each stage; recall that BS(u) is not empty.For each u, a hypergraph H u = (V u , E u ) is obtained from H (s) as follows: for each hyperarc e ∈ BS(u) a new node u e is introduced, and e is replaced by a new hyperarc e u = (T (e), u e ).Formally, Note that, in H u , node u has an empty backward star, and each node u e has an empty forward star; moreover, S(H u ) = S(H (s) ).
Example 1 (continued) The hypergraph H (s) shown in Figure 1 appears on the left in Figure 2  Let us denote by V u s the set of nodes hyperconnected to s in H u ; clearly, u ∈ V u s .The set V u s provides all the necessary information to identify the hyperarcs in BS(u) that must be removed and the nodes dominated by u.
Lemma 1.Given a hyperarc e ∈ E (s) with h(e) = u, e ∈ E s if and only if node u e ∈ V u s .
Proof.(if) Let π be a hyperpath from s to u e in H u ; clearly, π contains hyperarc e u , and does not contain node u, thus by replacing e u by e we obtain a hyperpath from s to u in H (s) .(only if) Let π ⊆ H (s) be an s-u hyperpath containing e: by replacing e by e u we obtain a hyperpath from s to u e in H u .
(only if) Suppose there is an s-v hyperpath π in H u ; clearly, π does not contain u; by Property 2.ii, π does not contain any node u e , thus π ⊆ H (s) .
Example 1 (continued) Consider again the hypergraph H u , for u = a, in Figure 2. We have recall that hyperarc 6 does not belong to H s , while hyperarc 1 belongs to H s .Moreover, we have b, d ∈ V u s ; indeed, node a dominates nodes b and d in H (s) .

5.
for all e ∈ BS(u): if u e ∈ V u s then R e := f alse else R e := true; 6.
for all j ∈ {1, . . ., n}: Our algorithm, referred to as FindHs, is described in Table 1.We use a label R to mark hyperarcs to be removed from H (s) , in particular, we set R e = true if hyperarc e is removed, and R e = false otherwise.Line 1 writes the first row of D; the main loop starts at line 2, and each stage consists of lines 3-6.Lines 3 and 4 take O(S(H)) time, while lines 5 and 6 take O(m) and O(n) time, respectively.All the step of the algorithm require O(S(H)) space, but a further O(n 2 ) space is required for matrix D. Note however that it is not necessary to store D during the algorithm, i.e., each row i of D can be sent to output and discarded at the end of step 6; in this case, the overall requirement becomes FindHs reduces complexity by a factor nm at least.Moreover, it is easy to define classes of hypergraphs where S(H) is O(m) while T is Θ(n); in these cases the improvement increases to a factor n 2 m.
Combining Lemma 1 and Lemma 2, and taking into account the structure of a hypergraph H u , we obtain the following relevant relation.

Property 3.
A hyperarc e ∈ E (s) belongs to H s if and only if h(e) does not dominate any node v ∈ T (e) in the flow hypergraph H (s) .Property 3 implies that H s can be determined in linear time O(S(H)) if the matrix D is available.Moreover, even if D is not known, H (s) can be determined in linear time if all the relevant information about dominators in H (s) is available in a suitable form; we exploit this fact to devise linear time methods for two particular classes.

Linearly solvable cases
The hypernetwork H s can be found in linear time O(S(H)) for two nontrivial classes of hypegraphs: acyclic hypergraphs and directed graphs.Note that hypergraphs in these classes can be recognized in linear time.The two classes require quite different algorithmic techniques, and we discuss them separately, pointing out the information about dominators that is relevant to each case.
Acyclic hypergraphs.This case turns out to be quite simple, since if H is acyclic then H s = H (s) (the "only if" relation does not hold here).This follows from Property 3, observing that in an acyclic hypergraph the node h(e) does not dominate any node in T (e).More precisely, h(e) does not belong to any hyperpath from s to u ∈ T (e): if this happens, by Property 2.ii there is a path from h(e) to u, that together with e gives a cycle.Note that, for acyclic hypergraphs, a quite limited information on the dominance relation suffices to find H s ; in fact, we find H s without computing the matrix D. We leave as an open question whether it is possible to find D in less than O(n • S(H)) time for an acyclic hypergraph.
Directed graphs.This case is definitely more complex.Recall that, in directed graphs, a hyperpath corresponds to a simple directed path, i.e., H (s) is a flowgraph.It is easy to see (and actually follows from Property 3) that an arc (u, v) ∈ E (s) belongs to a simple path from s to v in H (s) if and only if v is not a dominator of u.Our method checks this condition efficiently, exploiting some known results about dominance in flowgraphs, described below.
In a flowgraph G = (N, A, s) a node u is an immediate dominator of node v if there is no dominator w of v such that u dominates w.Each node v = s in G has a unique immediate dominator, and this implicitly defines a directed spanning tree T = (N, A T ), rooted at s, where (u, v) ∈ A T if u is the immediate dominator of node v.Note that arcs in A T do not necessarily correspond to arcs in A. The dominators of a node v are the nodes in the unique path from s to v in T .The immediate dominators, and thus the tree T , can be found in linear time O(|A|), although this task is definitely far from trivial, see [3] and references therein.Now suppose that we computed the tree T = (V s , A T ) in the flowgraph H (s) = (V s , E (s) ).In order to find the arcs to be removed from E (s) we perform a depth first visit of T .The visit is performed by the recursive procedure DFVisit, shown in Table 2.We maintain a node label l that marks active nodes: a node u is active (i.e., l(u) = true) if and only if the visit of the subtree rooted at u started but did not yet terminate.It is easy to see that, when DFVisit(u) is called and line 1 is executed, the active nodes are exactly those in the path from s to u in T , i.e., u and its dominators.At that point (line 2) we process each arc (u, v) ∈ E (s) : if v is active then we set R e := true, otherwise we set R e := f alse.Then (line 3) we recursively call DFVisit(w) for each successor w of u in T .Initially, all the node labels are set to false; the visit of T is started by the call DFVisit(s).Clearly, the whole process takes linear time O(m).
procedure DFVisit(u) 1. l(u) := true; 2. for all e = (u, v) ∈ E (s) : if l(v) = true then R e := true else R e := f alse; 3. for all (u, w) ∈ A T : call DFVisit(w); 4. l(u) := f alse; return For directed graphs, the matrix D is redundant, since the dominance re-lation is completely described by T .Observe that, opposed to what happens for acyclic hypergraphs, here we exploit the complete knowledge of the dominance relation to find H s .We do not know if H s may be found in linear time, or at least in less than O(nm) time, without computing T .

Finding an (s, d)-hypernetwork
The problem of finding an (s, d)-hypernetwork in a hypergraph H is in general NP-hard, but it can be solved in linear time if H is acyclic.We prove this result first, and then we point out the relations with stratified hypergraphs.

A linear time method for acyclic hypergraphs
Similar to H s , finding H sd is rather simple, and does not require knowledge of the dominance relation.We exploit a general property of acyclic hypergraphs [8, Property 2.1] that in our context can be restated as follows: Recall that each (s, d)-hypernetwork H sd = (V sd , E sd ) is contained in H s , and that H s = H (s) if H is acyclic.To obtain H sd it may be necessary to remove some hyperarcs and nodes from H (s) .Observe that H sd contains at least one path P ud for each node u ∈ V sd , as follows immediately from Property 2.ii.Therefore, we can safely remove a node u ∈ V s if there is no path from u to d in H (s) .Let us denote by V (sd) ⊆ V s the set of remaining nodes, i.e., u ∈ V (sd) if and only if d is connected to u in H (s) ; moreover, let Proof.It follows immediately from Property 2.ii that V sd ⊆ V (sd) , and thus E sd ⊆ E (sd) .It remains to show that E (sd) ⊆ E sd , which implies V (sd) ⊆ V sd .First note that if u ∈ V (sd) then we have e ∈ E (sd) for each e ∈ E (s) such that h(e) = u, which implies that H (sd) = (V (sd) , E (sd) , s) is a flow hypergraph, due to Property 4. Consider a generic hyperarc e 0 ∈ E (sd) with h(e 0 ) = u, and a path P ud = (u = v 1 , e 1 , v 2 , e 2 , ..., e q , v q+1 = d) contained in H (sd) .Note that it can be q = 0, i.e., u = d.Obtain H ′ ⊆ H (sd)  from H (sd) as follows: for i = 1, . . ., q + 1 remove from E (sd) all the hyperarcs in BS(v i ) except e i−1 .From Property 4, H ′ is a flow hypergraph; moreover, by Property 2.iii, every hyperpath from s to d in H ′ contains the path P ud , and thus contains e 0 .In conclusion, e 0 ∈ E sd .
The set V (sd) can be easily found in linear time O(S(H)) by a backward version of procedure Visit [1].It follows that an (s, d)-hypernetwork in an acyclic hypergraph can be found in linear time.

Acyclic and stratified hypergraphs
The definition of stratified hypergraphs ([10, Definition 4.4]) can be restated as follows.
1. let u ∈ N i and v ∈ N j : if i ≥ j then there does not exist any hyperarc e ∈ BS(v) such that u ∈ T (e); 2. for each u ∈ N i , i = 1, . . ., k, there exists a hyperarc e with h(e) = u and T (e) ⊆ ∪ j=0,i−1 N j .
Let us say that a hypergraph is nonempty if it contains at least one hyperarc.Note that a stratified hypergraph must be nonempty.

Property 5. A hypergraph H = (V, E) is stratified if and only if it is a nonempty acyclic hypergraph.
Proof.(if) Let V = {v 1 , v 2 , . . ., v n } be a topological order satisfying (1).Let N 0 = {v i ∈ V : BS(v i ) = ∅}, i.e., N 0 is the set of nodes with an empty backward star; since H is nonempty, N 0 ⊂ V .We sort the nodes in V \ N 0 according to the topological order, i.e., we let For each e = (T (e), v o(j) ) ∈ E, and for each v o(i) ∈ T (e), we have i < j by Property 1.i.We define N i = {v o(i) } for each i = 1, . . ., k; it is routine to check that the partition N 0 , N 1 , . . ., N k satisfies conditions 5.1 and 5.2.(only if) It is easy to see that H is acyclic since, for each e ∈ E, a node u ∈ T (e) cannot be connected to the node h(e).
Property 5 shows that our linear time method completes a polynomiality result already given in [10].Note that this polynomiality result exploits some nontrivial theoretical properties of (s, d)-hypernetworks (namely, Theorem 4.1 in [10]) that hold true also if the hypergraph is not acyclic.Our approach is simpler and more direct, since we derive our result from a known property of acyclic hypergraphs, namely Property 4.
Remark 1.In the original statement of condition 1. in Definition 5, i.e., condition (4.1) in [10,Definition 4.4], the inequality "i > j" appears instead of "i ≥ j" (probably due to a typographical error).This actually results in a weaker condition, that allows e.g. a hyperarc e ∈ E such that T (e) ∪ {h(e)} ⊆ N i .Clearly, the weaker condition defines a proper extension of acyclic hypergraphs.Unfortunately, the polynomiality result does not extend to this broader class, unless P = N P .To see this, consider a generic hypergraph H = (V, E) and a pair of nodes s and d in V .Define a hypergraph H ′ adding to H a new node d ′ and a new arc (d, d ′ ).Choosing N 0 = V and N 1 = {d ′ } we see that H ′ is stratified according to the weaker condition.Clearly, every s-d hyperpath in H corresponds to a unique s-d ′ hyperpath in H ′ , and vice-versa.Thus finding the (s, d ′ )-hypernetwork in H ′ is as hard as finding the (s, d)-hypernetwork in H, i.e., NP-hard.

Conclusions
Hypernetworks in directed hypergraphs have been introduced as a formal descriptive tool within a specific application.In our paper we pointed out that finding hypernetworks has a relevant interest, from a computational point of view, in many different contexts.
We provided a fast and simple method for finding the s-hypernetwork, and two non-trivial classes solvable in linear time.For one of this two classes we also devised a linear time method for finding the (s, d)-hypernetwork.On the theoretical side, we pointed out the relations between hypernetworks, flow hypergraphs, and dominators.
Our results may be extended along two different directions.On one side, find classes where hypernetworks can be identified exploiting a partial knowledge of the dominators, as for acyclic hypergraphs.On the other side, find classes where dominators can be found in less than O(n • S(H)) time.One possible candidate class are the reducible flow hypergraphs [4].Independently of hypernetworks, we believe that the computation of dominators in flow hypergraphs may be an interesting subject for further research.
For each node u ∈ V we define the forward star F S(u) = {e ∈ E : u ∈ T (e)} and the backward star BS(u) = {e ∈ E : h(e) = u}.We let n = |V | and m = |E|, while the size of hypergraph H is denoted by S(H) = e∈E (|T (e)| + 1

Figure 1 :
Figure 1: A hypergraph H, and the hypergraphs H (s) and H s in H.
; on the right, the hypergraph H u for u = a is shown.The two hyperarcs 1 and 6 in BS(a) are replaced by the new hyperarcs 1 a and 6 a , respectively, introducing two new nodes a 1 = h(1 a ) and a 6 = h(6 a ).The nodes hyperconnected to s in H u (shown in thick lines) are c and a 1 .

Theorem 1 .
Algorithm FindHs finds the hypernetwork H s and writes the matrix D in O(n • S(H)) time, with an O(S(H)) space requirement.The forward procedure proposed in [10] finds H s with time complexity O(n 2 m 2 T ), where T = max e∈E |T (e)|.In general S(H) is O(mT ), thus Node t is connected to node s if a path P st exists in H.A cycle is a path P st , where t ∈ T (e 1 ).