|
1 | 1 | # Graph Conversions |
| 2 | + |
| 3 | +While the **HGL** module treats hypergraphs as first-class, n-ary topological entities, there are many scenarios where you may need to interface with traditional graph algorithms, export data for standard graph visualization tools, or simplify relations. |
| 4 | + |
| 5 | +To bridge this gap, CPP-GL provides zero-cost abstractions to convert or project hypergraphs from the HGL module into standard graphs from the **GL** module. |
| 6 | + |
| 7 | +This section covers the two primary conversion methodologies and the fundamental differences in how they preserve or discard structural data: |
| 8 | + |
| 9 | +- [Incidence Graph Conversion](#incidence-graph-conversion): Lossless conversion to a bipartite graph. |
| 10 | +- [Projection Conversions](#projection-conversions): Lossy conversion that collapses hyperedges. |
| 11 | + |
| 12 | +--- |
| 13 | + |
| 14 | +## Information Loss & Structural Integrity |
| 15 | + |
| 16 | +When converting a hypergraph to a standard graph, you must decide how to handle the n-ary nature of hyperedges. |
| 17 | + |
| 18 | +--- |
| 19 | + |
| 20 | +## Incidence Graph Conversion |
| 21 | + |
| 22 | +The incidence graph conversion (also known as *star expansion*) translates a hypergraph $H = (V, E)$ into a standard bipartite graph $G = (V', E')$, where $V' = V \cup E$. Every hyperedge in the original hypergraph becomes a distinct vertex in the new graph, and standard edges are drawn between the original vertices and the new "hyperedge" vertices based on their incidence. |
| 23 | + |
| 24 | +> [!IMPORTANT] Topological Preservation |
| 25 | +> |
| 26 | +> **Incidence Graph Conversions** are **lossless**. They preserve the exact mathematical topology of the hypergraph by converting hyperedges into secondary "dummy" vertices, creating a strict Bipartite Graph. |
| 27 | +
|
| 28 | +### Undirected Hypergraphs |
| 29 | + |
| 30 | +For an undirected hypergraph, the resulting incidence graph is a standard **Undirected Bipartite Graph**. If a vertex $v$ belongs to a hyperedge $e$, an undirected edge $\{v, e\}$ is created. |
| 31 | + |
| 32 | +#### Formal Definition: |
| 33 | + |
| 34 | +Given an undirected hypergraph $H = (V, E)$, its incidence graph is an undirected bipartite graph $G = (V \cup E, E')$, where the new edge set is defined as: |
| 35 | + |
| 36 | +$$ |
| 37 | +E' = \big\{ \{v, e\} : v \in V \land e \in E \land v \in e \big\} |
| 38 | +$$ |
| 39 | + |
| 40 | +<div align="center" markdown="1"> |
| 41 | + |
| 42 | +{: width="700" } |
| 43 | +{: width="700" } |
| 44 | + |
| 45 | +</div> |
| 46 | + |
| 47 | +### BF-Directed Hypergraphs |
| 48 | + |
| 49 | +For a BF-directed hypergraph, the resulting incidence graph is a **Directed Bipartite Graph**. The directional flow is strictly preserved: |
| 50 | +- If a vertex $v$ is in the **tail** of $e$, a directed edge $(v, e)$ is created. |
| 51 | +- If a vertex $v$ is in the **head** of $e$, a directed edge $(e, v)$ is created. |
| 52 | + |
| 53 | +#### Formal Definition: |
| 54 | + |
| 55 | +Given a BF-directed hypergraph $H = (V, E)$, its incidence graph is a directed bipartite graph $G = (V \cup E, E')$, where the new directed edge set $E'$ connects *tail* vertices to hyperedge-nodes and hyperedge-nodes to *head* vertices: |
| 56 | + |
| 57 | +$$ |
| 58 | +E' = \big\{ (v, e) : v \in V \land e \in E \land v \in T(e) \big\} \cup \big\{ (e, v) : v \in V \land e \in E \land v \in H(e) \big\} |
| 59 | +$$ |
| 60 | + |
| 61 | +<div align="center" markdown="1"> |
| 62 | + |
| 63 | +{: width="700" } |
| 64 | +{: width="700" } |
| 65 | + |
| 66 | +</div> |
| 67 | + |
| 68 | +### Example Usage |
| 69 | + |
| 70 | +The [**hgl::incidence_graph**](../cpp-gl/group__HGL-Core.md#function-incidence_graph) utility handles this transformation automatically, ensuring IDs are safely shifted to prevent collisions between the original vertices and the newly promoted hyperedge vertices. |
| 71 | + |
| 72 | +```cpp |
| 73 | +#include <hgl/conversion.hpp> |
| 74 | + |
| 75 | +auto bipartite_graph = hgl::incidence_graph<gl::undirected_graph<>>(hg); // (1)! |
| 76 | +``` |
| 77 | + |
| 78 | +1. We assume `hg` is an instance of a *undirected* hypergraph. |
| 79 | + |
| 80 | +--- |
| 81 | + |
| 82 | +## Projection Conversions |
| 83 | + |
| 84 | +Projections are useful when you only care about the direct relationships between the actual data elements and want to discard the concept of the hyperedges entirely. |
| 85 | + |
| 86 | +> [!IMPORTANT] Topological Preservation |
| 87 | +> |
| 88 | +> **Projection Conversions** are **lossy**. They collapse the hyperedges, creating direct edges between the original vertices. This inherently destroys the higher-order grouping information (e.g., you can no longer tell if three vertices were connected by one 3-ary hyperedge or three separate pairwise edges). |
| 89 | +
|
| 90 | +### Clique Expansion (Undirected Hypergraphs) |
| 91 | + |
| 92 | +When projecting an undirected hypergraph, every hyperedge is replaced by a "clique" (a fully connected subgraph) amongst its incident vertices. If vertices $v_1, v_2, v_3$ share a hyperedge, the projection generates pairwise edges $\{v_1, v_2\}, \{v_2, v_3\}$, and $\{v_1, v_3\}$. Hyperedges containing only a single vertex typically project to a self-loop. |
| 93 | + |
| 94 | +#### Formal Definition: |
| 95 | + |
| 96 | +Given an undirected hypergraph $H = (V, E)$, its clique expansion is an undirected graph $G = (V, E')$, where every hyperedge is replaced by a fully connected subgraph of its incident vertices: |
| 97 | + |
| 98 | +$$ |
| 99 | +E' = \big\{ \{u, v\} : (\exists e \in E)(u, v \in e)\big\} |
| 100 | +$$ |
| 101 | + |
| 102 | +<div align="center" markdown="1"> |
| 103 | + |
| 104 | +{: width="700" } |
| 105 | +{: width="700" } |
| 106 | + |
| 107 | +</div> |
| 108 | + |
| 109 | +### Flow Graph / Bipartite Projection (BF-Directed) |
| 110 | + |
| 111 | +When projecting a BF-directed hypergraph, the hyperedge acts as a directional bridge. The projection generates a standard directed edge from every vertex in the hyperedge's *tail* to every vertex in its *head*. |
| 112 | + |
| 113 | +If a hyperedge has tail vertices $\{v_1, v_2\}$ and head vertices $\{v_3, v_4\}$, the projection yields four directed edges: $(v_1, v_3), (v_1, v_4), (v_2, v_3)$, and $(v_2, v_4)$. |
| 114 | + |
| 115 | +#### Formal Definition: |
| 116 | + |
| 117 | +Given a BF-directed hypergraph $H = (V, E)$, its flow graph projection is a directed graph $G = (V, E')$, where every hyperedge creates a directed Cartesian product from its tail vertices to its head vertices: |
| 118 | + |
| 119 | +$$ |
| 120 | +E' = \big\{ (u, v) : (\exists e \in E)(u \in T(e) \land v \in H(e))\big\} |
| 121 | +$$ |
| 122 | + |
| 123 | +<div align="center" markdown="1"> |
| 124 | + |
| 125 | +{: width="700" } |
| 126 | +{: width="700" } |
| 127 | + |
| 128 | +</div> |
| 129 | + |
| 130 | +### Example Usage |
| 131 | + |
| 132 | +The [**hgl::projection**](../cpp-gl/group__HGL-Core.md#function-projection) utility handles this transformation automatically, ensuring no duplicate edges and properly handling self-loops (for undirected hypergraphs). |
| 133 | + |
| 134 | +```cpp |
| 135 | +#include <hgl/conversion.hpp> |
| 136 | + |
| 137 | +auto flow_graph = hgl::projection<gl::directed_graph<>>(hg); // (1)! |
| 138 | +``` |
| 139 | + |
| 140 | +1. We assume `hg` is an instance of a *BF-directed* hypergraph. |
0 commit comments