Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
Graph Generators

Provides various graph generator functions. More...

Graph operations

using ogdf::NodeMap = NodeArray< NodeArray< node > >
 
void ogdf::graphUnion (Graph &G1, const Graph &G2)
 Forms the disjoint union of G1 and G2.
 
void ogdf::graphUnion (Graph &G1, const Graph &G2, NodeArray< node > &map2to1, bool parallelfree=false, bool directed=false)
 Forms the union of G1 and G2 while identifying nodes from G2 with nodes from G1.
 
void ogdf::graphProduct (const Graph &G1, const Graph &G2, Graph &product, NodeMap &nodeInProduct, const std::function< void(node, node)> &addEdges)
 Computes the graph product of G1 and G2, using a given function to add edges.
 
void ogdf::cartesianProduct (const Graph &G1, const Graph &G2, Graph &product, NodeMap &nodeInProduct)
 Computes the Cartesian product of G1 and G2 and assigns it to product, with \(E = \{(\langle v_1,w_1\rangle, \langle v_1,w_2\rangle) | (w_1,w_2) \in E_2\} \cup \{(\langle v_1,w_1\rangle, \langle v_2,w_1\rangle) | (v_1,v_2) \in E_1\} \).
 
void ogdf::tensorProduct (const Graph &G1, const Graph &G2, Graph &product, NodeMap &nodeInProduct)
 Computes the tensor product of G1 and G2 and assigns it to product, with \(E = \{(\langle v_1,w_1\rangle, \langle v_2,w_2\rangle) | (v_1,v_2) \in E_1 \land (w_1,w_2) \in E_2\} \).
 
void ogdf::lexicographicalProduct (const Graph &G1, const Graph &G2, Graph &product, NodeMap &nodeInProduct)
 Computes the lexicographical product of G1 and G2 and assigns it to product, with \(E = \{(\langle v_1,w_1\rangle, \langle v_2,w_2\rangle) | (v_1,v_2) \in E_1\} \cup \{(\langle v_1,w_1\rangle, \langle v_1,w_2\rangle) | (w_1,w_2) \in E_2\} \).
 
void ogdf::strongProduct (const Graph &G1, const Graph &G2, Graph &product, NodeMap &nodeInProduct)
 Computes the strong product of G1 and G2 and assigns it to product, with \(E = \{(\langle v_1,w_1\rangle, \langle v_1,w_2\rangle) | (w_1,w_2) \in E_2\} \cup \{(\langle v_1,w_1\rangle, \langle v_2,w_1\rangle) | (v_1,v_2) \in E_1\} \cup \{(\langle v_1,w_1\rangle, \langle v_2,w_2\rangle) | (v_1,v_2) \in E_1 \land (w_1,w_2) \in E_2\} \).
 
void ogdf::coNormalProduct (const Graph &G1, const Graph &G2, Graph &product, NodeMap &nodeInProduct)
 Computes the co-normal product of G1 and G2 and assigns it to product, with \(E = \{(\langle v_1,w_1\rangle, \langle v_2,w_2\rangle) | (v_1,v_2) \in E_1 \lor (w_1,w_2) \in E_2\} \).
 
void ogdf::modularProduct (const Graph &G1, const Graph &G2, Graph &product, NodeMap &nodeInProduct)
 Computes the modular product of G1 and G2 and assigns it to product, with \(E = \{(\langle v_1,w_1\rangle, \langle v_2,w_2\rangle) | (v_1,v_2) \in E_1 \land (w_1,w_2) \in E_2\} \cup \{(\langle v_1,w_1\rangle, \langle v_2,w_2\rangle) | (v_1,v_2) \not\in E_1 \land (w_1,w_2) \not\in E_2\} \).
 
void ogdf::rootedProduct (const Graph &G1, const Graph &G2, Graph &product, NodeMap &nodeInProduct, node rootInG2)
 Computes the rooted product of G1 and G2, rooted in rootInG2, and assigns it to product.
 

Deterministic graph generators

void ogdf::customGraph (Graph &G, int n, List< std::pair< int, int > > edges, Array< node > &nodes)
 Creates a custom graph using a list of pairs to determine the graph's edges.
 
void ogdf::customGraph (Graph &G, int n, List< std::pair< int, int > > edges)
 Creates a custom graph using a list of pairs to determine the graph's edges.
 
void ogdf::circulantGraph (Graph &G, int n, Array< int > jumps)
 Creates a circulant graph.
 
void ogdf::regularLatticeGraph (Graph &G, int n, int k)
 Creates a regular lattice graph.
 
void ogdf::regularTree (Graph &G, int n, int children)
 Creates a regular tree.
 
void ogdf::completeGraph (Graph &G, int n)
 Creates the complete graph K_n.
 
void ogdf::completeKPartiteGraph (Graph &G, const Array< int > &signature)
 Creates the complete k-partite graph K_{k1,k2,...,kn}.
 
void ogdf::completeBipartiteGraph (Graph &G, int n, int m)
 Creates the complete bipartite graph K_{n,m}.
 
void ogdf::wheelGraph (Graph &G, int n)
 Creates the graph W_n: A wheel graph.
 
void ogdf::cubeGraph (Graph &G, int n)
 Creates the graph Q^n: A n-cube graph.
 
void ogdf::globeGraph (Graph &G, int meridians, int latitudes)
 Creates a globe graph with a given number of meridians and latitudes.
 
void ogdf::suspension (Graph &G, int s)
 Modifies G by adding its s-th suspension.
 
void ogdf::gridGraph (Graph &G, int n, int m, bool loopN, bool loopM)
 Creates a (toroidal) grid graph on n x m nodes.
 
void ogdf::petersenGraph (Graph &G, int n=5, int m=2)
 Creates a generalized Petersen graph.
 
void ogdf::emptyGraph (Graph &G, int nodes)
 Creates a graph with nodes nodes and no edges.
 

Randomized graph generators

template<typename D >
void ogdf::randomGeographicalThresholdGraph (Graph &G, Array< int > &weights, D &dist, double threshold, std::function< double(double)> h, int dimension=2)
 Creates a random geometric graph where edges are created based on their distance and the weight of nodes.
 
template<typename D >
void ogdf::randomGeographicalThresholdGraph (Graph &G, Array< int > &weights, D &dist, double threshold, int alpha=2, int dimension=2)
 Creates a random geometric graph where edges are created based on their distance and the weight of nodes.
 
void ogdf::randomHierarchy (Graph &G, int n, int m, bool planar, bool singleSource, bool longEdges)
 Creates a random hierarchical graph.
 
void ogdf::randomRegularGraph (Graph &G, int n, int d)
 Creates a random d-regular graph.
 
void ogdf::randomGraph (Graph &G, int n, int m)
 Creates a random graph.
 
bool ogdf::randomSimpleGraph (Graph &G, int n, int m)
 Creates a random simple graph.
 
bool ogdf::randomSimpleGraphByProbability (Graph &G, int n, double pEdge)
 Creates a random simple graph.
 
bool ogdf::randomSimpleConnectedGraph (Graph &G, int n, int m)
 Creates a random simple and connected graph.
 
void ogdf::randomBiconnectedGraph (Graph &G, int n, int m)
 Creates a random biconnected graph.
 
void ogdf::randomPlanarConnectedGraph (Graph &G, int n, int m)
 Creates a random connected (simple) planar (embedded) graph.
 
void ogdf::randomPlanarBiconnectedGraph (Graph &G, int n, int m, bool multiEdges=false)
 Creates a random planar biconnected (embedded) graph.
 
void ogdf::randomPlanarBiconnectedDigraph (Graph &G, int n, int m, double p=0, bool multiEdges=false)
 Creates a random planar biconnected acyclic (embedded) digraph.
 
void ogdf::randomUpwardPlanarBiconnectedDigraph (Graph &G, int n, int m)
 Creates a random upward planar biconnected (embedded) digraph.
 
void ogdf::randomPlanarCNBGraph (Graph &G, int n, int m, int b)
 Creates a random planar graph, that is connected, but not biconnected.
 
void ogdf::randomTriconnectedGraph (Graph &G, int n, double p1, double p2)
 Creates a random triconnected (and simple) graph.
 
void ogdf::randomPlanarTriconnectedGraph (Graph &G, int n, int m)
 Creates a random planar triconnected (and simple) graph.
 
void ogdf::randomPlanarTriconnectedGraph (Graph &G, int n, double p1, double p2)
 Creates a random planar triconnected (and simple) graph.
 
void ogdf::randomTree (Graph &G, int n)
 Creates a random tree (simpler version.
 
void ogdf::randomTree (Graph &G, int n, int maxDeg, int maxWidth)
 Creates a random tree.
 
void ogdf::randomClusterPlanarGraph (ClusterGraph &C, Graph &G, int cNum)
 Assigns random clusters to a given graph G.
 
void ogdf::randomClusterGraph (ClusterGraph &C, Graph &G, int cNum)
 Assigns random clusters to a given graph G.
 
void ogdf::randomClusterGraph (ClusterGraph &C, const Graph &G, const node root, int moreInLeaves)
 Assigns a specified cluster structure to a given graph G, and assigns vertices to clusters.
 
void ogdf::randomDigraph (Graph &G, int n, double p)
 Creates a random (simple) directed graph.
 
void ogdf::randomSeriesParallelDAG (Graph &G, int edges, double p=0.5, double flt=0.0)
 Creates a random (simple, biconnected) series parallel DAG.
 
void ogdf::randomGeometricCubeGraph (Graph &G, int nodes, double threshold, int dimension=2)
 Creates a random geometric graph by laying out nodes in a unit n-cube. Nodes with a distance < threshold are connected, 0 <= threshold <= sqrt(dimension). The graph is simple.
 
void ogdf::randomWaxmanGraph (Graph &G, int nodes, double alpha, double beta, double width=1.0, double height=1.0)
 Generates a Waxman graph where nodes are uniformly randomly placed in a grid, then edges are inserted based on nodes' euclidean distances.
 
void ogdf::preferentialAttachmentGraph (Graph &G, int nodes, int minDegree)
 Creates a graph where new nodes are more likely to connect to nodes with high degree.
 
void ogdf::randomWattsStrogatzGraph (Graph &G, int n, int k, double probability)
 Creates a "small world" graph as described by Watts & Strogatz.
 
void ogdf::randomChungLuGraph (Graph &G, Array< int > expectedDegreeDistribution)
 Creates a graph where edges are inserted based on given weights.
 
void ogdf::randomEdgesGraph (Graph &G, std::function< double(node, node)> probability)
 Inserts edges into the given graph based on probabilities given by a callback function.
 

Detailed Description

Provides various graph generator functions.

Typedef Documentation

◆ NodeMap

Definition at line 72 of file operations.h.

Function Documentation

◆ cartesianProduct()

void ogdf::cartesianProduct ( const Graph G1,
const Graph G2,
Graph product,
NodeMap nodeInProduct 
)

Computes the Cartesian product of G1 and G2 and assigns it to product, with \(E = \{(\langle v_1,w_1\rangle, \langle v_1,w_2\rangle) | (w_1,w_2) \in E_2\} \cup \{(\langle v_1,w_1\rangle, \langle v_2,w_1\rangle) | (v_1,v_2) \in E_1\} \).

Multi-edges are kept and incorporated into the graph product.

Parameters
G1is the first input graph.
G2is the second input graph.
productis assigned the graph product.
nodeInProductis assigned a mapping from nodes of (G1, G2) to product.

◆ circulantGraph()

void ogdf::circulantGraph ( Graph G,
int  n,
Array< int jumps 
)

Creates a circulant graph.

Generates a simple, undirected graph on \(n\) nodes \(V := v_0,v_1,\ldots,v_{n-1}\) that contains exactly the edges \( \{v_iv_{i+d}\colon v_i \in V, d \in \text{jumps}\} \) where node indices are to be understood modulo \(n\). The order of nodes induced by G is the sequence \(V\) given above.

Parameters
Gis assigned the generated graph.
nis the number of nodes of the generated graph.
jumpsis the array of distances for edges to be created.
The parameterized class Array implements dynamic arrays of type E.
Definition Array.h:214
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:521
void circulantGraph(Graph &G, int n, Array< int > jumps)
Creates a circulant graph.

◆ completeBipartiteGraph()

void ogdf::completeBipartiteGraph ( Graph G,
int  n,
int  m 
)

Creates the complete bipartite graph K_{n,m}.

The returned graph is directed acyclic.

Parameters
Gis assigned the generated graph.
nis the number of nodes of the first partition set.
mis the number of nodes of the second partition set.

◆ completeGraph()

void ogdf::completeGraph ( Graph G,
int  n 
)

Creates the complete graph K_n.

The returned graph is directed acyclic.

Parameters
Gis assigned the generated graph.
nis the number of nodes of the generated graph.

◆ completeKPartiteGraph()

void ogdf::completeKPartiteGraph ( Graph G,
const Array< int > &  signature 
)

Creates the complete k-partite graph K_{k1,k2,...,kn}.

The returned graph is directed acyclic.

Parameters
Gis assigned the generated graph.
signaturecontains the positive values k1, k2, ..., kn.

◆ coNormalProduct()

void ogdf::coNormalProduct ( const Graph G1,
const Graph G2,
Graph product,
NodeMap nodeInProduct 
)

Computes the co-normal product of G1 and G2 and assigns it to product, with \(E = \{(\langle v_1,w_1\rangle, \langle v_2,w_2\rangle) | (v_1,v_2) \in E_1 \lor (w_1,w_2) \in E_2\} \).

Multi-edges are kept and incorporated into the graph product.

Parameters
G1is the first input graph.
G2is the second input graph.
productis assigned the graph product.
nodeInProductis assigned a mapping from nodes of (G1, G2) to product.

◆ cubeGraph()

void ogdf::cubeGraph ( Graph G,
int  n 
)

Creates the graph Q^n: A n-cube graph.

Parameters
Gis assigned the generated graph.
nis the number of the cube's dimensions (n>=0).

◆ customGraph() [1/2]

void ogdf::customGraph ( Graph G,
int  n,
List< std::pair< int, int > >  edges 
)
inline

Creates a custom graph using a list of pairs to determine the graph's edges.

Parameters
Gis assigned the generated graph.
nis the number of nodes of the generated graph.
edgesis a list of pairs, each one representing two nodes that should be connected by an edge in the generated graph.

Definition at line 59 of file deterministic.h.

◆ customGraph() [2/2]

void ogdf::customGraph ( Graph G,
int  n,
List< std::pair< int, int > >  edges,
Array< node > &  nodes 
)

Creates a custom graph using a list of pairs to determine the graph's edges.

Parameters
Gis assigned the generated graph.
nis the number of nodes of the generated graph.
edgesis a list of pairs, each one representing two nodes that should be connected by an edge in the generated graph.
nodesresulting array mapping node index to the actual node

◆ emptyGraph()

void ogdf::emptyGraph ( Graph G,
int  nodes 
)

Creates a graph with nodes nodes and no edges.

Parameters
Gis assigned the generated graph.
nodesis the number of nodes of the generated graph.

◆ globeGraph()

void ogdf::globeGraph ( Graph G,
int  meridians,
int  latitudes 
)

Creates a globe graph with a given number of meridians and latitudes.

The graph will contain a node at each crossing of a meridian and a latitude, and a node at each pole, hence meridians * latitudes + 2 nodes overall.

Parameters
Gis assigned the generated graph.
meridiansis the number of meridians.
latitudesis the number of latitudes.

◆ graphProduct()

void ogdf::graphProduct ( const Graph G1,
const Graph G2,
Graph product,
NodeMap nodeInProduct,
const std::function< void(node, node)> &  addEdges 
)

Computes the graph product of G1 and G2, using a given function to add edges.

First, product is cleared. \(|V(G1)|\cdot|V(G2)|\) nodes are added to it and addEdges is called for each pair of nodes in \(V(G1) \times V(G2)\).

Parameters
G1is the first input graph.
G2is the second input graph.
productis assigned the graph product.
nodeInProductis assigned a mapping from nodes of (G1, G2) to product.
addEdgesA function that adds edges to the graph product for each pair of nodes in \(V(G1) \times V(G2)\).

◆ graphUnion() [1/2]

void ogdf::graphUnion ( Graph G1,
const Graph G2 
)
inline

Forms the disjoint union of G1 and G2.

Parameters
G1is the first graph and assigned the graph union.
G2is the second graph.

Definition at line 52 of file operations.h.

◆ graphUnion() [2/2]

void ogdf::graphUnion ( Graph G1,
const Graph G2,
NodeArray< node > &  map2to1,
bool  parallelfree = false,
bool  directed = false 
)

Forms the union of G1 and G2 while identifying nodes from G2 with nodes from G1.

Parameters
G1is the first graph and assigned the graph union.
G2is the second graph.
map2to1identifies nodes from G2 with nodes from G1. Empty entries in map2to1 have to be nullptr. It is assigned a mapping from nodes in G2 to the union G1.
parallelfreesets whether the resulting graph union should not contain multi-edges.
directedsets whether the graph union is treated as directed or undirected when detecting multi-edges. It only has an effect if parallelfree is set.

◆ gridGraph()

void ogdf::gridGraph ( Graph G,
int  n,
int  m,
bool  loopN,
bool  loopM 
)

Creates a (toroidal) grid graph on n x m nodes.

Parameters
Gis assigned the generated graph.
nis the number of nodes on first axis.
mis the number of nodes on second axis.
loopNif the grid is cyclic on first axis
loopMif the grid is cyclic on second axis

◆ lexicographicalProduct()

void ogdf::lexicographicalProduct ( const Graph G1,
const Graph G2,
Graph product,
NodeMap nodeInProduct 
)

Computes the lexicographical product of G1 and G2 and assigns it to product, with \(E = \{(\langle v_1,w_1\rangle, \langle v_2,w_2\rangle) | (v_1,v_2) \in E_1\} \cup \{(\langle v_1,w_1\rangle, \langle v_1,w_2\rangle) | (w_1,w_2) \in E_2\} \).

Warning
The lexicographical product is not commutative!

Multi-edges are kept and incorporated into the graph product.

Parameters
G1is the first input graph.
G2is the second input graph.
productis assigned the graph product.
nodeInProductis assigned a mapping from nodes of (G1, G2) to product.

◆ modularProduct()

void ogdf::modularProduct ( const Graph G1,
const Graph G2,
Graph product,
NodeMap nodeInProduct 
)

Computes the modular product of G1 and G2 and assigns it to product, with \(E = \{(\langle v_1,w_1\rangle, \langle v_2,w_2\rangle) | (v_1,v_2) \in E_1 \land (w_1,w_2) \in E_2\} \cup \{(\langle v_1,w_1\rangle, \langle v_2,w_2\rangle) | (v_1,v_2) \not\in E_1 \land (w_1,w_2) \not\in E_2\} \).

Multi-edges are kept and incorporated into the graph product.

Parameters
G1is the first input graph.
G2is the second input graph.
productis assigned the graph product.
nodeInProductis assigned a mapping from nodes of (G1, G2) to product.

◆ petersenGraph()

void ogdf::petersenGraph ( Graph G,
int  n = 5,
int  m = 2 
)

Creates a generalized Petersen graph.

Creates an outer cycle of nodes 1, ..., n, each of which has a direct neighbor (a corresponding inner node). For two outer nodes i, j, there is an edge between their corresponding inner nodes if the absolute difference of i and j equals the jump length m.

If no values for n or m are given, assume the standard Petersen graph of 5 nodes and a jump length of 2.

Parameters
Gis assigned the generated graph.
nis the number of nodes on the outer cycle.
mis the length of jumps for the inner part.

◆ preferentialAttachmentGraph()

void ogdf::preferentialAttachmentGraph ( Graph G,
int  nodes,
int  minDegree 
)

Creates a graph where new nodes are more likely to connect to nodes with high degree.

Implements the Preferential Attachment algorithm as described in: Emergence of Scaling in Random Networks Albert-Laszlo Barabasi and Reka Albert https://arxiv.org/abs/cond-mat/9910332v1 This algorithm creates edges based on the degree of nodes, so it is most useful to apply this to a pre-built graph. If no graph is supplied, a complete graph of minDegree nodes is generated and the algorithm adds nodes - minDegree nodes. If a graph is supplied, it must contain at least minDegree nodes of degree 1.

Parameters
Gis the input graph (see above) and is assigned the expanded graph.
nodesis the number of nodes to be added to graph.
minDegreeis the minimum degree of new nodes.

◆ randomBiconnectedGraph()

void ogdf::randomBiconnectedGraph ( Graph G,
int  n,
int  m 
)

Creates a random biconnected graph.

Parameters
Gis assigned the generated graph.
nis the number of nodes of the generated graph.
mis the number of edges of the generated graph.
Note
n has a lower bound of 3, and m a lower bound of n. If the parameters are smaller than that, they get increased prior to the algorithm.

◆ randomChungLuGraph()

void ogdf::randomChungLuGraph ( Graph G,
Array< int expectedDegreeDistribution 
)

Creates a graph where edges are inserted based on given weights.

Implements the algorithm described in: The average distance in a random graph with given expected degrees Fang Chung and Linyuan Lu http://www.math.ucsd.edu/~fan/wp/aveflong.pdf

Given an expected degree distribution of length n: \(w:=(w_1, ..., w_n)\) with \(0 < w_k < n\).

Let \(S:=\sum_{k=1}^{n}w_k\) be the sum over all expected degrees. Consider each edge independently and insert it with probability \(p_{ij} := \frac{w_i \, w_j}{S}\). Therefore, to get percentages in \((0,1)\) we assert that \(\max\limits_k(w_k)^2 < S\).

Precondition
Each degree must be strictly between 0 and n, and the square of the maximal expected degree must be lower than the sum of all expected degrees.
Parameters
Gis assigned the generated graph.
expectedDegreeDistributionis a list of expected degrees, or weights, for the individual nodes. Its length defines the number of nodes n.

◆ randomClusterGraph() [1/2]

void ogdf::randomClusterGraph ( ClusterGraph C,
const Graph G,
const node  root,
int  moreInLeaves 
)

Assigns a specified cluster structure to a given graph G, and assigns vertices to clusters.

This function is called with a graph G and the root of a second graph, resembling a tree, that gives the cluster structure. Then, the vertices of G are randomly assigned to the clusters, where we can guarantee that any leaf-cluster has (on average) moreInLeaves-times more vertices than a non-leaf cluster. (E.g. if moreInLeaves = 5, any leaf will contain roughly 5 times more vertices than an inner cluster)

Parameters
Cis a cluster graph for G, to be assigned the solution.
Gis the input graph.
rootis a node in some other graph (say T). T is a tree that we will consider rooted at root. T is the pattern for the cluster hierarchy.
moreInLeavesis a factor such that leaf-clusters have on average moreInLeaves-times more vertices than inner clusters
Precondition
G contains at least twice as many nodes as T has leaves.

◆ randomClusterGraph() [2/2]

void ogdf::randomClusterGraph ( ClusterGraph C,
Graph G,
int  cNum 
)

Assigns random clusters to a given graph G.

This function is called with a graph G and creates randomly clusters.

Parameters
Gis the input graph.
Cis a cluster graph for G.
cNumis the maximal number of clusters introduced.
Precondition
G is connected and not empty and C is initialized with G.

◆ randomClusterPlanarGraph()

void ogdf::randomClusterPlanarGraph ( ClusterGraph C,
Graph G,
int  cNum 
)

Assigns random clusters to a given graph G.

This function is called with a graph G and creates randomly clusters. The resulting cluster graph is always c-connected and, if G is planar, also c-planar.

Parameters
Gis the input graph.
Cis a cluster graph for G.
cNumis the maximal number of Clusters introduced.
Precondition
G is connected and not empty and C is initialized with G.

◆ randomDigraph()

void ogdf::randomDigraph ( Graph G,
int  n,
double  p 
)

Creates a random (simple) directed graph.

Parameters
Gis assigned the generated graph.
nis the number of nodes in the generated graph.
pis the probability that an edge is created (for each node pair)

◆ randomEdgesGraph()

void ogdf::randomEdgesGraph ( Graph G,
std::function< double(node, node)>  probability 
)

Inserts edges into the given graph based on probabilities given by a callback function.

Iterates through each distinct pair of nodes and inserts an edge with the probability returned by the provided callback function.

The resulting graph is guaranteed to be simple if:

  • the input graph had no edges, or
  • the input graph was simple and the callback function returns 0 for each pair of nodes that was connected before.
Parameters
Gis a graph that should have at least two nodes (so edges can be generated)
probabilityis a callback function that, for any given pair of nodes, returns a probability between 0 and 1 for the two nodes to be connected.

◆ randomGeographicalThresholdGraph() [1/2]

template<typename D >
void ogdf::randomGeographicalThresholdGraph ( Graph G,
Array< int > &  weights,
D &  dist,
double  threshold,
int  alpha = 2,
int  dimension = 2 
)

Creates a random geometric graph where edges are created based on their distance and the weight of nodes.

This generator uses \(r^{-\alpha}\) for the given alpha as heuristic function.

See also
randomGeographicalThresholdGraph(Graph &G, Array<int> &weights, D &dist, double threshold, std::function<double(double)> h, int dimension) for detailed description.
Template Parameters
Dthe random distribution to use (see dist).
Parameters
Gis assigned the generated graph.
weightshas the weights for all nodes in the graph.
distis a random number distribution, e.g. std::uniform_int_distribution<>. It should likely generate values in roughly the same order of magnitude as 1/threshold.
thresholdis the threshold for edge insertion.
alphais the constant in the heuristic function.
dimensionis the dimension the nodes are laid out in.

Definition at line 120 of file randomGeographicalThresholdGraph.h.

◆ randomGeographicalThresholdGraph() [2/2]

template<typename D >
void ogdf::randomGeographicalThresholdGraph ( Graph G,
Array< int > &  weights,
D &  dist,
double  threshold,
std::function< double(double)>  h,
int  dimension = 2 
)

Creates a random geometric graph where edges are created based on their distance and the weight of nodes.

Geographical threshold graphs with small-world and scale-free properties Naoki Masuda, Hiroyoshi Miwa, Norio Konno https://arxiv.org/abs/cond-mat/0409378

Distribute vertices using an exponential distribution in a d-dimensional Euclidean space. Then a pair of vertices with weights w,w' and Euclidean distance \(r:=||w-w'||\) are connected iff for the heuristic function h holds: \((w+w')*h(r) < \mathrm{threshold}\).

Template Parameters
Dthe random distribution to use (see dist).
Parameters
Gis assigned the generated graph.
weightshas the weights for all nodes in the graph.
distis a random number distribution, e.g. std::uniform_int_distribution<>. It should likely generate values in roughly the same order of magnitude as h(threshold).
thresholdis the threshold for edge insertion.
his a function that should be decreasing in the distance supplied to it.
dimensionis the dimension the nodes are laid out in.

Definition at line 67 of file randomGeographicalThresholdGraph.h.

◆ randomGeometricCubeGraph()

void ogdf::randomGeometricCubeGraph ( Graph G,
int  nodes,
double  threshold,
int  dimension = 2 
)

Creates a random geometric graph by laying out nodes in a unit n-cube. Nodes with a distance < threshold are connected, 0 <= threshold <= sqrt(dimension). The graph is simple.

Parameters
Gis assigned the generated graph.
nodesis the number of nodes of the generated graph.
thresholdis threshold radius of nodes which will be connected.
dimensionis the dimension of the cube.

◆ randomGraph()

void ogdf::randomGraph ( Graph G,
int  n,
int  m 
)

Creates a random graph.

Parameters
Gis assigned the generated graph.
nis the number of nodes of the generated graph.
mis the number of edges of the generated graph.

◆ randomHierarchy()

void ogdf::randomHierarchy ( Graph G,
int  n,
int  m,
bool  planar,
bool  singleSource,
bool  longEdges 
)

Creates a random hierarchical graph.

Parameters
Gis assigned the generated graph.
nis the number of nodes.
mis the number of edges.
planardetermines if the resulting graph is (level-)planar.
singleSourcedetermines if the graph is a single-source graph.
longEdgesdetermines if the graph has long edges (spanning 2 layers or more); otherwise the graph is proper.

◆ randomPlanarBiconnectedDigraph()

void ogdf::randomPlanarBiconnectedDigraph ( Graph G,
int  n,
int  m,
double  p = 0,
bool  multiEdges = false 
)

Creates a random planar biconnected acyclic (embedded) digraph.

Parameters
Gis assigned the generated graph.
nis the number of nodes of the generated graph.
mis the number of edges of the generated graph.
pup to m * p edges will be reversed preversing acyclicity; default = 0.0.
multiEdgesdetermines if the generated graph may contain multi-edges; default = false.
Precondition
d is between 0.0 and 1.0
Note
n has a lower bound of 3, and m has a lower bound of n and an upper bound of \(3n-6\). The supplied values are adjusted if they are out of these bounds.

◆ randomPlanarBiconnectedGraph()

void ogdf::randomPlanarBiconnectedGraph ( Graph G,
int  n,
int  m,
bool  multiEdges = false 
)

Creates a random planar biconnected (embedded) graph.

Parameters
Gis assigned the generated graph.
nis the number of nodes of the generated graph.
mis the number of edges of the generated graph.
multiEdgesdetermines if the generated graph may contain multi-edges.
Note
n has a lower bound of 3, and m has a lower bound of n and an upper bound of \(3n-6\). The supplied values are adjusted if they are out of these bounds.

◆ randomPlanarCNBGraph()

void ogdf::randomPlanarCNBGraph ( Graph G,
int  n,
int  m,
int  b 
)

Creates a random planar graph, that is connected, but not biconnected.

Parameters
Gis assigned the generated graph.
nis the max. number of nodes in each biconnected component
mis the max. number of edges in each biconnected component
bis the number of biconnected components
Precondition
It holds that n > 1, m >= n (unless n = 2, m = 1) and b > 1.

◆ randomPlanarConnectedGraph()

void ogdf::randomPlanarConnectedGraph ( Graph G,
int  n,
int  m 
)

Creates a random connected (simple) planar (embedded) graph.

Parameters
Gis assigned the generated graph.
nis the number of nodes of the generated graph.
mis the number of edges of the generated graph.
Note
n has a lower bound of 1, and m has a lower bound of n and an upper bound of \(3n-6\). The supplied values are adjusted if they are out of these bounds.

◆ randomPlanarTriconnectedGraph() [1/2]

void ogdf::randomPlanarTriconnectedGraph ( Graph G,
int  n,
double  p1,
double  p2 
)

Creates a random planar triconnected (and simple) graph.

This graph generator creates a planar triconnected graph by successive node splitting. It starts with the K_4 and performs n -4 node splits. Each such split operation distributes a node's neighbors to the two nodes resulting from the split. Aftewards, two further edges can be added; the probability for adding these edges is given by p1 and p2. The higher these probabilities, the denser the resulting graph. Note that a simple planar triconnected graph has between 1.5n and 3n -6 edges.

Precondition
0.0 <= p1, p2 <= 1.0.
Parameters
Gis assigned the generated graph.
nis the number of nodes in the generated graph.
p1is the probability for the first additional edge to be added.
p2is the probability for the second additional edge to be added.
Note
n has a lower bound of 4 and will get increased to this if smaller.

◆ randomPlanarTriconnectedGraph() [2/2]

void ogdf::randomPlanarTriconnectedGraph ( Graph G,
int  n,
int  m 
)

Creates a random planar triconnected (and simple) graph.

This graph generator works in two steps.

  1. A planar triconnected 3-regular graph is constructed using successive splitting of pairs of nodes. The constructed graph has n nodes and 1.5n edges.
  2. The remaining edges are inserted by successive splitting of faces with degree four or greater. The resulting graph also represents a combinatorial embedding.
Parameters
Gis assigned the generated graph.
nis the number of nodes in the generated graph.
mis the number of edges in the generated graph.
Note
  • n >= 4 and n must be even; otherwise, n is adjusted to the next feasible integer.
  • 1.5n <= m <= 3n -6; otherwise, m is adjusted to a feasible value.

◆ randomRegularGraph()

void ogdf::randomRegularGraph ( Graph G,
int  n,
int  d 
)

Creates a random d-regular graph.

Parameters
Gis assigned the generated graph.
nis the number of nodes of the generated graph.
dis the degree of each vertex
Precondition
n * d must be even
Warning
This method is not guaranteed to terminate!

◆ randomSeriesParallelDAG()

void ogdf::randomSeriesParallelDAG ( Graph G,
int  edges,
double  p = 0.5,
double  flt = 0.0 
)

Creates a random (simple, biconnected) series parallel DAG.

This function creates a random series parallel biconnected DAG. Note, that the resulting graph is trivially upward planar! To use this generator for experiments, e.g. concerning upward planarity, you can fit the graph by reversing some edges with the parameter 0 < flt < 1.

Parameters
Gis assigned the generated graph.
edgesis the number of edges in the generated graph.
p= probability of a series composition; default = 0.5
flt= up to edges*flt edges will be reversed preversing acyclicity; default = 0.0
Precondition
p is in \([0.0, 1.0]\), and flt is in \([0.0, 1.0)\).

◆ randomSimpleConnectedGraph()

bool ogdf::randomSimpleConnectedGraph ( Graph G,
int  n,
int  m 
)

Creates a random simple and connected graph.

Parameters
Gis assigned the generated graph.
nis the number of nodes of the generated graph.
mis the number of edges of the generated graph.

◆ randomSimpleGraph()

bool ogdf::randomSimpleGraph ( Graph G,
int  n,
int  m 
)

Creates a random simple graph.

Parameters
Gis assigned the generated graph.
nis the number of nodes of the generated graph.
mis the number of edges of the generated graph.

◆ randomSimpleGraphByProbability()

bool ogdf::randomSimpleGraphByProbability ( Graph G,
int  n,
double  pEdge 
)

Creates a random simple graph.

Algorithm based on PreZER/LogZER from: Sadegh Nobari, Xuesong Lu, Panagiotis Karras, and Stéphane Bressan. 2011. Fast random graph generation. In Proceedings of the 14th International Conference on Extending Database Technology (EDBT/ICDT '11), ACM, New York, NY, USA, 331-342. DOI=http://dx.doi.org/10.1145/1951365.1951406

Parameters
Gis assigned the generated graph.
nis the number of nodes of the generated graph.
pEdgeis the probability for each edge to be added into the graph.
Precondition
/p pEdge is in [0, 1]

◆ randomTree() [1/2]

void ogdf::randomTree ( Graph G,
int  n 
)

Creates a random tree (simpler version.

Parameters
Gis assigned the tree.
nis the number of nodes of the tree.

◆ randomTree() [2/2]

void ogdf::randomTree ( Graph G,
int  n,
int  maxDeg,
int  maxWidth 
)

Creates a random tree.

Parameters
Gis assigned the tree.
nis the number of nodes of the tree.
maxDegis the maximal allowed node degree; 0 means no restriction.
maxWidthis the maximal allowed width of a level; 0 means no restriction.
Note
if maxDeg or maxWidth are 0 (or negative), they are set to n

◆ randomTriconnectedGraph()

void ogdf::randomTriconnectedGraph ( Graph G,
int  n,
double  p1,
double  p2 
)

Creates a random triconnected (and simple) graph.

The graph generator proceeds as follows. It starts with a K_4 and performs then n -4 split node operations on randomly selected nodes of the graph constructed so far. Each such operation splits a node v into two nodes x and y and distributes v's neighbors to the two nodes such that each node gets at least two neighbors. Additionally, the edge (x,y) is inserted.

The neighbors are distributed such that a neighbor of v becomes

  • only a neighbor of x with probability p1;
  • only a neighbor of y with probability p1;
  • a neighbor of both x and y with probability 1.0 - p1 - p2.
Parameters
Gis assigned the generated graph.
nis the number of nodes in the generated graph.
p1is the probability that an edge is moved only to the left node after splitting a node.
p2is the probability that an edge is moved only to the right node after splitting a node.

The probability for a neighbor to be moved to both split nodes is 1.0 - p1 - p2. The higher this probability, the higher the density of the resulting graph.

Precondition
The probabilities p1 and p2 must lie between 0.0 and 1.0, and p1 + p2 <= 1.0.
Note
n has a lower bound of 4 and will get increased to this if smaller.

◆ randomUpwardPlanarBiconnectedDigraph()

void ogdf::randomUpwardPlanarBiconnectedDigraph ( Graph G,
int  n,
int  m 
)

Creates a random upward planar biconnected (embedded) digraph.

Parameters
Gis assigned the generated graph.
nis the number of nodes of the generated graph.
mis the number of edges of the generated graph.
Note
n has a lower bound of 3, and m has a lower bound of n and an upper bound of \(3n-6\). The supplied values are adjusted if they are out of these bounds.

◆ randomWattsStrogatzGraph()

void ogdf::randomWattsStrogatzGraph ( Graph G,
int  n,
int  k,
double  probability 
)

Creates a "small world" graph as described by Watts & Strogatz.

Takes a regular lattice graph and, with given probability, rewires each edge to a random other non-neighbor.

Collective dynamics of ‘small-world’ networks https://www.nature.com/articles/30918.pdf

Warning
This implementation does not perform very well if k is close to half of n for large graphs.
Parameters
Gis assigned the generated graph.
nis the number of nodes of the generated graph.
kis the initial degree of each node and must be even and smaller than half of n.
probabilitydetermines how likely each edge is rewired. A probability of 0 will not modify the graph, while one of 1 will cause full randomness.

◆ randomWaxmanGraph()

void ogdf::randomWaxmanGraph ( Graph G,
int  nodes,
double  alpha,
double  beta,
double  width = 1.0,
double  height = 1.0 
)

Generates a Waxman graph where nodes are uniformly randomly placed in a grid, then edges are inserted based on nodes' euclidean distances.

Routing of Multipoint Connections
Bernard M. Waxman (1988)

After generating the nodes, edges are inserted between each pair of nodes v, w with probability based on their euclidean distance \(\beta \exp{\frac{-||v-w||}{m \, \alpha}}\) where \(m:=\max\limits_{u,v}||u-v||\).

Parameters
Gis assigned the generated graph.
nodesis the number of nodes of the generated graph.
alphais a parameter for the probability in the range (0,1]. Small values increase the density of short edges relative to longer ones.
betais a parameter for the probability in the range (0,1]. Large values result in a graph with higher edge density.
widthis the width of the area the nodes are distributed in.
heightis the height of the area the nodes are distributed in.

◆ regularLatticeGraph()

void ogdf::regularLatticeGraph ( Graph G,
int  n,
int  k 
)

Creates a regular lattice graph.

Generates a cycle on n sequential nodes, where any two nodes whose distance is at most k / 2 are connected by an additional edge.

See also
circulantGraph(Graph&, int, Array<int>)
Parameters
Gis assigned the generated graph.
nis the number of nodes in the graph.
kis the degree of each node.
Precondition
n must be at least 4, k must be an even number between 0 and n-2.

◆ regularTree()

void ogdf::regularTree ( Graph G,
int  n,
int  children 
)

Creates a regular tree.

Parameters
Gis assigned the tree.
nis the number of nodes of the tree.
childrenis the number of children per node. root has index 0, the next level has indizes 1...children, the children of node 1 have indizes children+1...2*children, etc. if number of nodes does not allow a regular node, the "last" node will have fewer children.

◆ rootedProduct()

void ogdf::rootedProduct ( const Graph G1,
const Graph G2,
Graph product,
NodeMap nodeInProduct,
node  rootInG2 
)

Computes the rooted product of G1 and G2, rooted in rootInG2, and assigns it to product.

Multi-edges are kept and incorporated into the graph product.

Parameters
G1is the first input graph.
G2is the second input graph.
productis assigned the graph product.
nodeInProductis assigned a mapping from nodes of (G1, G2) to product.
rootInG2is the node of G2 that is identified with every node of G1 once in order to create the rooted product.

◆ strongProduct()

void ogdf::strongProduct ( const Graph G1,
const Graph G2,
Graph product,
NodeMap nodeInProduct 
)

Computes the strong product of G1 and G2 and assigns it to product, with \(E = \{(\langle v_1,w_1\rangle, \langle v_1,w_2\rangle) | (w_1,w_2) \in E_2\} \cup \{(\langle v_1,w_1\rangle, \langle v_2,w_1\rangle) | (v_1,v_2) \in E_1\} \cup \{(\langle v_1,w_1\rangle, \langle v_2,w_2\rangle) | (v_1,v_2) \in E_1 \land (w_1,w_2) \in E_2\} \).

Multi-edges are kept and incorporated into the graph product.

Parameters
G1is the first input graph.
G2is the second input graph.
productis assigned the graph product.
nodeInProductis assigned a mapping from nodes of (G1, G2) to product.

◆ suspension()

void ogdf::suspension ( Graph G,
int  s 
)

Modifies G by adding its s-th suspension.

A suspension node is a node that is connected to all other nodes in the graph. This function adds s such suspension nodes that will not be directly connected to each other.

Parameters
Gis the graph to extend.
sis the amount of suspension nodes to add.

◆ tensorProduct()

void ogdf::tensorProduct ( const Graph G1,
const Graph G2,
Graph product,
NodeMap nodeInProduct 
)

Computes the tensor product of G1 and G2 and assigns it to product, with \(E = \{(\langle v_1,w_1\rangle, \langle v_2,w_2\rangle) | (v_1,v_2) \in E_1 \land (w_1,w_2) \in E_2\} \).

Multi-edges are kept and incorporated into the graph product.

Parameters
G1is the first input graph.
G2is the second input graph.
productis assigned the graph product.
nodeInProductis assigned a mapping from nodes of (G1, G2) to product.

◆ wheelGraph()

void ogdf::wheelGraph ( Graph G,
int  n 
)

Creates the graph W_n: A wheel graph.

Parameters
Gis assigned the generated graph.
nis the number of nodes on the rim of the wheel (W_n).
Precondition
n must be at least 2.