Generate an acyclic random graph
This example shows how to generate a random graph, make it acyclic by removing edges, and then store it as a GML file.
Step-by-step explanation
- We first have to include all header files declaring the classes and functions we want to use. OGDF's header files are contained in subdirectories of a common include directory
ogdf. Here we use the class ogdf::Graph, a graph generator function ogdf::randomSimpleGraph(), an algorithm for making a digraph acyclic (ogdf::DfsAcyclicSubgraph), and functionality for exporting graphs provided by ogdf::GraphIO.
- ttt
Manual creation and layout of graphs
int main()
{
const int LEN = 11;
for(int i = 1; i < LEN; ++i) {
GA.x(left) = -5*(i+1);
GA.y(left) = -20*i;
GA.width(left) = 10*(i+1);
GA.height(left) = 15;
GA.x(bottom) = 20*(LEN-i);
GA.y(bottom) = 5*(LEN+1-i);
GA.width(bottom) = 15;
GA.height(bottom) = 10*(LEN+1-i);
}
return 0;
}