|
Open Graph Drawing Framework |
v. 2023.09 (Elderberry)
|
|
|
Generate an acyclic random graph
This example shows how to generate a random plane triangulation, decompose it into its 4-connected components, and draw each of them from the outside in.
#include <memory>
#include <string>
constexpr int n = 16;
{
ga.directed() = false;
}
}
int i = 0;
ga.directed() = false;
for (
const node v : treeNode.
g->nodes) {
}
});
return 0;
}
Step-by-step explanation
- The class FourBlockTree is declared in ogdf/decomposition/FourBlockTree.h
- We create a random plane graph. Because of its high number of edges, it must be maximally planar, i.e., triangulated.
- We use the function FourBlockTree::construct to build its 4-block tree. The 4-block tree is represented by its root, which has members
- g, the 4-connected component
- originalNodes, a map from nodes in g to the corresponding nodes in the original graph
- externalFace, an adjEntry to the right of which the externalFace of the 4-connected component lies
- parent, a raw pointer to its parent node (or nullptr, if this is the root)
- parentFace, the adjEntry in parent corresponding to externalFace (or nullptr, if this is the root)
- children, a vector of unique_ptrs to the child nodes
- For our simple application of traversing the 4-block tree bottom-up, we can use the method preorder, which calls its argument on each node of the 4-block tree in preorder. A similar method named postorder exists as well. For each node of the 4-block tree, we draw it and save the drawing under a unique filename. To this end we use PlanarStraightLayout. We use originalNodes to assign multiple occurrences of the same node in the 4-block tree the same label.
The namespace for all OGDF objects.
Stores additional attributes of a graph (like layout information).
Declaration of class GraphAttributes which extends a Graph by additional attributes.
Includes declaration of graph class.
Declaration of basic types for graphics.
static bool write(const Graph &G, const string &filename, WriterFunc writer=nullptr)
Writes graph G to a file with name filename and infers the format to use from the file's extension.
static const long edgeStyle
Corresponds to edge attributes strokeColor(edge), strokeType(edge), and strokeWidth(edge).
static const long nodeStyle
Corresponds to node attributes strokeColor(node), strokeType(node), strokeWidth(node),...
static bool drawSVG(const GraphAttributes &A, std::ostream &os, const SVGSettings &settings)
int index() const
Returns the (unique) node index.
Declaration of class PlanarStraightLayout which represents a planar straight-line drawing algorithm.
std::unique_ptr< Graph > g
The 4-connected component.
void callFixEmbed(GraphAttributes &AG, adjEntry adjExternal=nullptr)
Calls the grid layout algorithm with a fixed planar embedding (general call).
Class for adjacency list elements.
Declaration of randomized graph generators.
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
static std::unique_ptr< FourBlockTree > construct(const Graph &g, adjEntry externalFace)
Construct a 4-block tree of the given graph.
NodeArray< node > originalNodes
The nodes in the original graph corresponding to the nodes in g.
Decralation of GraphElement and GraphList classes.
Declares class GraphIO which provides access to all graph read and write functionality.
Declaration of FourBlockTree.
node firstNode() const
Returns the first node in the list of all nodes.
Data type for general directed graphs (adjacency list representation).
static const long nodeLabel
Corresponds to node attribute label(node).
adjEntry cyclicSucc() const
Returns the cyclic successor in the adjacency list.
A node in a 4-block tree.
static const long edgeGraphics
Corresponds to edge attribute bends(edge).
adjEntry firstAdj() const
Returns the first entry in the adjaceny list.
adjEntry externalFace
A half-edge in g such that the external face of g is to its right.
Implementation of the Planar-Straight layout algorithm.
std::string to_string(const std::function< std::ostream &(std::ostream &)> &func)
Class for the representation of nodes.
static const long nodeGraphics
Corresponds to node attributes x(node), y(node), width(node), height(node), and shape(node).
void randomPlanarConnectedGraph(Graph &G, int n, int m)
Creates a random connected (simple) planar (embedded) graph.