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

Energy-based Layout


Loads a graph and applies energy-based layout (fast multipole multilevel algorithm).


#include <ogdf/energybased/FMMMLayout.h>
#include <ogdf/fileformats/GraphIO.h>
using namespace ogdf;
int main()
	Graph G;
	GraphAttributes GA(G);
	if (!GraphIO::readGML(G, "sierpinski_04.gml") ) {
		cerr << "Could not load sierpinski_04.gml" << endl;
		return 1;
	node v;
		GA.width(v) = GA.height(v) = 10.0;
	FMMMLayout fmmm;
	GraphIO::writeGML(GA, "sierpinski_04-layout.gml");
	return 0;

Example graph: sierpinski_04.gml


We first declare a Graph G with GraphAttributes GA and load it from the GML file sierpinski_04.gml. Since this file does not contain any format information (it is just the pure graph structure), we can load it via the Graph object G and not its attributes GA. Before we call a layout algorithm, we assign a width and height of 10.0 to each node.

The actual layout algorithm for energy-based layout (fast multipole multilevel method) is encapsulated by the class FMMMLayout. We create an object fmmm of this class and set some parameters. In particular, we decide to set only high-level parameters (it would also be possible to set more fine-grained options, but this requires a deeper understanding of the algorithm) and want to have a very high layout quality. We set the desired edge length to 15.0 which goes well with our node sizes of 10.0 times 10.0. Then, we call the algorithm by passing the graph attributes GA to its call method. GA stores a reference to the graph G itself which is taken as input to the algorithm. The algorithm stores the computed layout information in GA and we finally write this layout to the GML file sierpinski_04-layout.gml.


Graph layout:


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