A problem in a sample code

44 views
Skip to first unread message

lc Z

unread,
Sep 13, 2023, 9:35:54 AM9/13/23
to ogdf
I tried the following sample code in ex-basic, and it's strange that when the GML file (output-plan.gml), only the graph information is saved, and there is no other information, for example, the position of its vertices. But item 5 in the documentation said that it provides a planar representation. Do I miss something?
Finally, the resulting graph (i.e., its nodes and edges) is written to a file using ogdf::GraphlO::write. We specify the desired output format (GML) by passing it the correct writer function ogdf::GraphlO::writeGML.
I got 93 corssings in the shell, and 
Creator "ogdf::GraphIO::writeGML"
graph
[
directed 1
node
[
id 0
]
node
[
id 1
]
node
[
id 2
]
node
[
id 3
]
node
[
id 4
]
node
[
id 5
]
...



lc Z

unread,
Sep 13, 2023, 9:37:02 AM9/13/23
to ogdf
I use the code as follows:

using namespace ogdf;
int main()
{
randomSimpleGraph(G, 100, 150);
int crossNum;
PlanRep PR(G);
SP.call(PR, 0, crossNum);
std::cout << crossNum << " crossings" << std::endl;
GraphIO::write(PR, "output-plan.gml", GraphIO::writeGML);
return 0;
}

Dagobert Smart

unread,
Sep 15, 2023, 3:29:36 PM9/15/23
to ogdf
Hello,
I see how the documentation might not be easy to understand. I'll try to explain:

The input graph G is a potentially non-planar graph (in your case: with 100 nodes). If you would draw it in the plane, you'd likely get many edge crossings. Now imagine that you replace every edge crossing in a drawing of G by a new dummy node with degree 4. The result is a planar representation PR, usually called a "planarization", of G.
Observe that PR is planar as it contains no crossings anymore. Moreover, it contains the original nodes of G as well as several dummy vertices with degree 4 as substitutes for crossings (in your case, PR has 100 + 93 = 193 nodes).

The SubgraphPlanarizer computes such a planarization PR without ever calculating coordinates for the nodes.
So you're right that the result of the algorithm is only a new graph. There are no coordinates for the vertices computed.
Depending on what you want to do, you can use PR in several ways:

* If you want to know whether a node in PR is an original node of the input graph or a dummy node, use `PR.isDummy(myNode)`.

* If you want a planar embedding of PR, you can call `planarEmbed(PR)`. This ensures a specific cyclic order of incident edges around each node v. More precisely, v->adjEntries will be ordered such that for any assignment of x/y-coordinates to the nodes, there is some way to route the edges between them without crossings.

* If you want a planar drawing of PR, you can call any planar layout algorithm on PR. To directly output a nice drawing of a planarization of your input graph G (without computing PR yourself), call the PlanarizationLayout on G.

Best regards,
Dagobert
Reply all
Reply to author
Forward
0 new messages