|
tgen
|
Labeled weighted tree generator. More...

Classes | |
| struct | value |
| Labeled tree value. More... | |
Public Member Functions | |
| wtree (int n) | |
| Creates a tree generator with specified number of vertices. | |
| wtree & | add_edge (int u, int v) |
| Restricts generator s.t. some edge is present. | |
| value | gen () const |
| Generates a uniformly random value from the set of valid trees. | |
| Public Member Functions inherited from tgen::gen_base< wtree< VWeight, EWeight > > | |
| auto | gen_list (int size, Args &&...args) const |
| Generates a list of several generation calls. | |
| auto | gen_until (Pred predicate, int max_tries, Args &&...args) const |
| Generates a random value from the valid set until a condition is met. | |
| auto | distinct (Args &&...args) const |
| Creates distinct generator for current generator. | |
Static Public Member Functions | |
| static value | gen_skewed (int n, int elongation) |
| Random skewed tree (large diameter). | |
| static value | gen_kruskal (int n) |
| Kruskal-like random labeled tree. | |
Labeled weighted tree generator.
Defines a set of trees on n vertices, subject to preset edges. A uniformly random tgen::wtree::value from that set (satisfying the constraints) is produced by tgen::wtree::gen.
There are also structured, non-uniform static generation methods:
|
inline |
Creates a tree generator with specified number of vertices.
| n | Number of vertices. |
O(1).
|
inline |
Restricts generator s.t. some edge is present.
| u | First endpoint. |
| v | Second endpoint. |
Preset edges must not form a cycle.
O(log n).
|
inline |
Generates a uniformly random value from the set of valid trees.
O(n).
|
inlinestatic |
Kruskal-like random labeled tree.
| n | Vertex count. |
Repeatedly samples a random vertex pair and adds it when it connects two different components (union-find), until the graph is a tree.
O(n log(n) alpha(n)) expected time.
|
inlinestatic |
Random skewed tree (large diameter).
| n | Vertex count. |
| elongation | Passed to tgen::wnext; controls how star-like or path-like the tree is. |
For each i from 1 to n-1, the parent of i is tgen::wnext(i, elongation), in [0, i).
If elongation is small (negative), you will likely get a star.
If elongation is large (positive), you will likely get a path.
O(n).