## 5 A Mathematical Heuristic for the Hypergraph Layout  
The problem of the hypergraph layout in (5)-(21) can be solved using the following five-step mathematical heuristic:  
1. Find the order of the vertices on each layer;
2. Assign preliminary abscissas to the vertices;
3. Find the relative order of horizontal segments for orthogonal hyperedges with source nodes on the same layer;
4. Remove the non-feasible overlapping of vertical segments;
5. Assign ports to the vertical segments. Note that the aesthetic criteria used in the heuristic coincide with those in Section 3. The mathematical heuristic is sketched below; see Algorithm 1. Figure 10: An example of the optimal layout of the hypergraph with the same ordinates of horizontal segments. ```
Data: hierarchical hypergraph \(H=(V,E_{H},\lambda)\) Result: hypergraph drawing \(D\) \(ord\leftarrow\)\(ordering(hypergraphRestructuring_{1}(H))\); \(X\leftarrow\)\(assigning\)\(Abscissas(hypergraphRestructuring_{2}(H),ord)\); \(HO\leftarrow\)\(horizontalSegmentsOrdering(H,X)\); /* (26)-(30) */ \(\widetilde{X}\leftarrow\)\(removeOverlapping(H,X,HO)\); \(D\leftarrow\)\(assigning\)\(Ports(H,\widetilde{X},HO)\); /* (31)-(33) */
```  
**Algorithm 1**A mathematical heuristic for the hypergraph layout. The first step (vertex ordering) includes a pre-processing procedure for the initial hypergraph \(H\); the corresponding function is denoted as \(hypergraphRestructuring_{1}\) in Algorithm 1. A detailed description of this function that returns a graph corresponding to hypergraph \(H\) is given in Algorithm 2. ```
Data: hierarchical hypergraph \(H=(V,E_{H},\lambda)\) Result: hierarchical graph \(G_{1}\) \(i\leftarrow|V|\); \(E_{G_{1}}\leftarrow\mathcal{O}\); \(V_{G_{1}}\gets V\); forall\(e=(S,T)\in E_{H}\)do \(V_{G_{1}}\gets V_{G_{1}}\cup\{v_{i+1}\}\); forall\(u\in S\)do \(E_{G_{1}}\gets E_{G_{1}}\cup(u,v_{i+1})\); \(\lambda_{G_{1}}(u)\gets 2\times\lambda(u)-1\);  end forall\(u\in T\)do \(E_{G_{1}}\gets E_{G_{1}}\cup(v_{i+1},u)\); \(\lambda_{G_{1}}(u)\gets 2\times\lambda(u)-1\);  end forallChoose\(u\in S\); \(\lambda_{G_{1}}(v_{i+1})\leftarrow\lambda_{G_{1}}(u)+1\); \(i\gets i+1\);  end forall\(G_{1}\leftarrow(V_{G_{1}},E_{G_{1}},\lambda_{G_{1}})\);
```  
**Algorithm 2**The \(hypergraphRestructuring_{1}\) function. To convert the hypergraph into a graph with the \(hypergraphRestructuring_{1}\) function, the so-called \"balancing vertex\" is introduced for each hyperedge \(e=(S,T)\); see Figure 0(a),b. Then, each vertex \(v\in S\cup T\) incident to the hyperedge is connected by a directed edge to the balancing vertex. This approach enables one to correctly take into account all possible intersections of edges. The order of the vertices on the layers from \(hypergraphRestructuring_{1}(H)\) is determined using the _ordering_ function; see Algorithm 1. The vertex-ordering problem is solved using an integer program [10] that minimizes the number of edge crossings in a directed acyclic graph. To assign preliminary abscissas to the vertices (step 2 of the mathematical heuristic), the function \(assigning\)\(Abscissas\) is used. Again, hypergraph \(H\) is pre-processed with the \(hypergraphRestructuring_{2}\) function; see Algorithm 3. As a result of the transformation, every pair of adjacent vertices on the adjacent layers is connected by a directed edge; see Figure 0(c). Then, \(x\)-coordinates are assigned to the vertices based on the solution to a linear programming problem with objective function (6); see [9]. Note that the relative vertex order on each layer remains. Once step 2 is over, three introduced functions--_horizontalSegmentsOrdering_, _removeOverlapping_, and _assigningPorts_--are applied to obtain the hypergraph drawing. These functions correspond to steps 3, 4, and 5 of the mathematical heuristic, and their detailed description is presented below. Knowing the \(x\)-coordinates of the vertices, the order of the horizontal segments of the hyperedges is determined.