Open Graph Drawing Framework
current version:
v.2015.05 (Baobab)

Generate an acyclic random graph


Generate a random acyclic graph and store it as a GML file.


#include <ogdf/basic/Graph.h>
#include <ogdf/basic/graph_generators.h>
#include <ogdf/layered/DfsAcyclicSubgraph.h>
#include <ogdf/fileformats/GraphIO.h>
using namespace ogdf;
int main()
	Graph G;
	randomSimpleGraph(G, 10, 20);
	DfsAcyclicSubgraph DAS;
	GraphIO::writeGML(G, "test.gml");
	return 0;



#includes — All classes (and there header and source files) start with a capitalized letter, combinations of multiple words are concatenated, with capitalized first letters for each word (e.g. DfsAcyclicSubgraph). Headers and sources which do not correspond to classes, but to helper functions (like basic/graph_generators.h) do not use capitalization and use underscores (”_”) to seperate words.

using namespace ogdf; — All OGDF classes are defined within an ogdf-namespace. For simple use, it's easiest to declare that at the beginning.

Function line-by-line

Graph G instantiates a Graph-object. Therefore we require the inclusion of the header Graph.h.

randomSimpleGraph(G, 10, 20) generates a simple (i.e. no self-loops or multiple edges) random graph with 10 nodes and 20 edges. The given graph G (call by reference) becomes this new graph. This function is defined in graph_generators.h.

DfsAcyclicSubgraph DAS — We declare an object of type DfsAcyclicSubgraph (from DfsAcyclicSubgraph.h) to use in…

DAS.callAndReverse(G) — This transforms G into an acyclic graph by reversing edge directions.

GraphIO::writeGML(G, “test.gml”) finally saves the graph G in GML-format as the file test.gml.

tech/howto/genacyrangr.txt · Last modified: 2015/05/31 16:45 by stephan
This page is driven by DokuWiki