|
tgen
|
Generation of simple labeled graphs (undirected or directed). More...
Classes | |
| struct | tgen::wgraph< VWeight, EWeight > |
| Labeled weighted graph generator. More... | |
| struct | tgen::wgraph< VWeight, EWeight >::value |
| Labeled graph value. More... | |
Typedefs | |
| template<typename VWeight> | |
| using | tgen::vgraph = wgraph<VWeight, int> |
| Vertex-weighted labeled graphs. | |
| template<typename EWeight> | |
| using | tgen::egraph = wgraph<int, EWeight> |
| Edge-weighted labeled graphs. | |
| using | tgen::graph = wgraph<int, int> |
| Unweighted labeled graphs. | |
Functions | |
| graph::value | tgen::K (int n) |
| Complete undirected graph. | |
| graph::value | tgen::P (int n, bool is_directed=false) |
| Path graph. | |
| graph::value | tgen::C (int n, bool is_directed=false) |
| Cycle graph. | |
| graph::value | tgen::S (int n) |
| Star undirected graph. | |
| graph::value | tgen::K (int n1, int n2) |
| Complete bipartite undirected graph. | |
Generation of simple labeled graphs (undirected or directed).
Vertices are labeled 0 through n-1. Isomorphism is not factored out: two different labeled graphs are distinct.
The template tgen::wgraph<VWeight, EWeight> is the general generator. It fixes n and a target edge count m, optional preset edges, and directed / self-loop mode. It only randomizes edges (which pairs of vertices are adjacent); vertex and edge weights are not sampled by the generator. Attach them on tgen::wgraph::value with tgen::wgraph::value::set_vertex_weights / tgen::wgraph::value::set_edge_weights when needed. Use tgen::wgraph::value::edge_weighted on an edgeless graph to enable weighted add_edge(u, v, w) calls before any edges exist.
Convenient aliases (same constructors and methods as tgen::wgraph):
Prints a random simple graph on 5 vertices with 6 edges, including (0,1).
Random connected graph on 8 vertices with 10 edges, including edge (0,1).
Random DAG on 8 vertices with 12 directed edges.
Skewed connected graph on 10 vertices with 15 edges (elongation 100, spread 2).
Triangle with string edge weights and a leading n/m line when printed.
Weighted directed graph built edge by edge with edge_weighted.
Standard graphs (tgen::K, tgen::P, tgen::C, and tgen::S) are deterministic helpers that return tgen::wgraph::value.
For labeled trees (exactly n-1 undirected edges), see the Trees module and tgen::wtree.
| using tgen::egraph = wgraph<int, EWeight> |
Edge-weighted labeled graphs.
Same as tgen::wgraph<int, EWeight> (vertex weight type is a dummy int).
| using tgen::graph = wgraph<int, int> |
Unweighted labeled graphs.
Same as tgen::wgraph<int, int> (vertex and edge weight types are dummy int).
| using tgen::vgraph = wgraph<VWeight, int> |
Vertex-weighted labeled graphs.
Same as tgen::wgraph<VWeight, int> (edge weight type is a dummy int).
|
inline |
Cycle graph.
| n | Number of vertices. |
| is_directed | If true, edges are i -> (i+1) % n; otherwise the graph is undirected. |
O(n).
|
inline |
Complete undirected graph.
| n | Number of vertices. |
O(n^2).
|
inline |
Complete bipartite undirected graph.
| n1 | Number of vertices on the left side. |
| n2 | Number of vertices on the right side. |
The vertices on the left side are indexed in [0, n1), and those on right side in [n1, n1 + n2).
O(n1 * n2).
|
inline |
Path graph.
| n | Number of vertices. |
| is_directed | If true, edges are i -> i+1 for i in [0, n - 2); otherwise the graph is undirected. |
The endpoints of the path are vertices 0 and n - 1.
O(n).
|
inline |
Star undirected graph.
| n | Total number of vertices. |
The center of the star is vertex 0.
O(n).