## 5 A Mathematical Heuristic for the Hypergraph Layout
The objective function \(L\) that is minimized in step 3 is the number of hyperedge crossings:  
\[\min\sum_{e_{1},e_{2}\in E_{H}}CT_{e_{1},e_{2}}. \tag{26}\]  
For each pair of hyperedges \(e_{1}=(S_{1},T_{1})\) and \(e_{2}=(S_{2},T_{2})\), one can calculate the number of source nodes \(v\in S_{2}\) and target nodes \(u\in T_{2}\) that are inside the area of crossings of hyperedge \(e_{1}\). We denote these numbers as \(acs(e_{1},e_{2})\) and \(act(e_{1},e_{2})\), respectively. Then, the system of constraints for the integer programming problem with objective function (26) is as follows:  
\[CT_{e_{1},e_{2}}\geq acs(e_{1},e_{2})+act(e_{2},e_{1})-M\times(1-HO_{e_{1},e_{ 2}}) \tag{27}\] \[\forall\ e_{1},\ e_{2}\in E_{H^{\prime}}:e_{1}\prec e_{2}.\]  
Figure 11: An example of a hypergraph transformation: (**a**) original hypergraph \(H\); (**b**) restructuring a hypergraph into a directed graph with balancing vertices; (**c**) restructuring a hypergraph into a directed graph. \[CT_{e_{1},e_{2}}\geq acs(e_{2},e_{1})+act(e_{1},e_{2})-M\times HO_{e_{1},e_{2}} \tag{28}\] \[\forall\ e_{1},\ e_{2}\in E_{H^{\prime}}:e_{1}\prec e.\] \[0\leq HO_{e_{1},e_{2}}-HO_{e_{1},e_{3}}+HO_{e_{2},e_{3}}\leq 1\] (29) \[\forall\ e_{1},\ e_{2},\ e_{3}\in E_{H^{\prime}}:\ e_{1}\prec e_{2} \prec e_{3}.\] \[CT_{e_{1},e_{2}}\geq 0,\ HO_{e_{1},e_{2}}\in\{0,\ 1\}\quad \forall\ e_{1},\ e_{2}\in E_{H^{\prime}}:e_{1}\prec e_{2}. \tag{30}\]  
Constraints (27) and (28) are a simplified version of conditions (12)-(15) from the optimization model described in Section 3. The simplification is based on the fact that the \(x\)-coordinates of vertices are known. Expression (29) coincides with condition (18) and ensures that the transitivity condition is satisfied for the positions of the horizontal segments of any triplet of hyperedges. Condition (30) determines the domains of all of the variables in the problem. The function \(horizontalSegmentsOrdering\)--see Algorithm 1--is the solution to the mixed-integer program in (26)-(30). It returns the relative order of horizontal segments of the hyperedges. In step 4, all non-feasible overlaps of vertical segments of hyperedges are removed by using the integer program proposed in [7]. This solution is denoted as the _removeOverlapping_ function in Algorithm 1. Non-feasible overlaps must be eliminated by shifting the vertices on layers by a certain integer number of \"single shifts\" for each corresponding vertex \(x\)-coordinate while maintaining the relative order of the vertices on the layers. The objective function of the integer programming problem minimizes the total number of shifts of vertices, and the constraints are (7)-(21) with fixed values of the \(HO\) variables for every pair of hyperedges. The last step of the mathematical heuristic is the port assignment procedure when the relative order of ports is determined by the \(assigningPorts\) function for each hypergraph vertex--see Algorithm 4--where the \(arrangingSymmetrically\) function determines the \(x\)-coordinates of the port vertices by placing them symmetrically to the \(x\)-coordinate of the generating vertex without breaking the relative order of the port vertices. ```
Data: hierarchical hypergraph \(H=(V,E_{H},\lambda)\), abcissas' vertices \(\widetilde{X}\), horizontal segment ordering \(HO\) Result: hypergraph drawing \(D\) forall\(u\in V\)do forall\(K\in\{K_{U}(u),K_{L}(u)\}\)do forall\(p\in K\)do \(s(p)\gets 0\); forall\(j\in K\setminus\{p\}:j\prec p\)do \(s(p)\gets s(p)+\sum\limits_{j}ORD_{j,p}\); /* (33) */  end forall\(i\in K\setminus\{p\}:p\prec i\)do \(s(p)\gets s(p)+\sum\limits_{j}(1-ORD_{p,i})\); /* (33) */  end forall\(K\) in increasing order by the value of \(s(p)\); \(arrangingSymmetrically(K,\widetilde{X}(u))\);  end for\(D\leftarrow\) Draw\(H\) as far as all of the necessary characteristics of the hypergraph elements are known. end forall
```  
**Algorithm 4**The \(assigningPorts\) function.