Open
Graph Drawing
Framework

 v. 2025.10-dev (Foxglove)
 

Loading...
Searching...
No Matches
one-planarity.cpp
Go to the documentation of this file.
1#include <ogdf/basic/Graph.h>
4#include <ogdf/basic/List.h>
5#include <ogdf/basic/Module.h>
6#include <ogdf/basic/basic.h>
13
14#include <memory>
15#include <set>
16#include <vector>
17
18using namespace ogdf;
19using namespace oneplan_backtracking;
21
22int main() {
23 // Creating a solver that uses at most 1000 threads and extracts up to 1000 Kuratowski-subdivisions in each step
24 OnePlanarityBacktracking solver(1000, 1000);
25
26 Graph K5;
27 completeGraph(K5, 5);
28 // Testing 1-Planarity:
29 OGDF_ASSERT(solver.testOnePlanarity(K5) == ReturnType::Feasible);
30
31 // A corresponding planarization can be obtained as follows:
32 OnePlanarization planarization;
33 solver.testOnePlanarity(K5, &planarization);
34 OGDF_ASSERT(isPlanar(planarization));
35 OGDF_ASSERT(planarization.numberOfNodes() == 6); // 1 additional crossing vertex
36 OGDF_ASSERT(planarization.kiteEdges().size() == 0); // No kite edges in a complete graph
37 OGDF_ASSERT(planarization.numberOfEdges()
38 == 12); // K5 minus 2 edges plus 4 edges incident to crossing vertex
39
40 // kite edges are mapped to nullptr, edges incident to crossing vertices are mapped to the corresponding crossing edge:
41 for (node crossingVertex : planarization.crossingVertices()) {
42 OGDF_ASSERT(crossingVertex->degree() == 4);
43 std::set<edge> originalEdges;
44 for (adjEntry adj : crossingVertex->adjEntries) {
45 originalEdges.insert(planarization.original(adj->theEdge()));
46 }
47 OGDF_ASSERT(originalEdges.size() == 2);
48 }
49
50 planarEmbed(planarization); // Represents a 1-planar embedding of K5
51
52 // Testing IC- or NIC-planarity:
53 OGDF_ASSERT(solver.testICPlanarity(K5) == ReturnType::Feasible);
54 OGDF_ASSERT(solver.testNICPlanarity(K5) == ReturnType::Feasible);
55
56 // No-instances:
57 Graph K7;
58 completeGraph(K7, 7);
59 OGDF_ASSERT(solver.testOnePlanarity(K7) == ReturnType::NoFeasibleSolution);
60
61 // Implementing custom filters:
62 class BipartiteDensityFilter : public PartialSolutionFilter {
63 // Bipartite 1-planar graphs have at most 3n-8 edges. This must also hold for the planarization of a partial solution.
64 bool canCut(OnePlanarization& pl) override {
65 return isBipartite(pl) && pl.numberOfEdges() > 3 * pl.numberOfNodes() - 8;
66 }
67 };
68
69 class MyOneplanSolver : public OnePlanarityBacktracking {
70 public:
71 MyOneplanSolver() : OnePlanarityBacktracking() {
72 m_filters.emplace_back(new BipartiteDensityFilter);
73 }
74 };
75
76 Graph K45;
77 completeBipartiteGraph(K45, 4, 5);
78 MyOneplanSolver mySolver;
79 OGDF_ASSERT(mySolver.testOnePlanarity(K45) == ReturnType::NoFeasibleSolution);
80 OGDF_ASSERT(mySolver.processedNodes() <= 1);
81}
Includes declaration of graph class.
Decralation of GraphElement and GraphList classes.
Declaration and implementation of NodeSet, EdgeSet, and AdjEntrySet classes.
Declaration of doubly linked lists and iterators.
Declares base class for all module types.
The main class of the 1-Planarity backtracker.
Declaration of the OnePlanarization class.
Filters for partial solutions in backtracking for the 1-Planarity problem.
Basic declarations, included by all source files.
Class for adjacency list elements.
Definition Graph_d.h:143
const Graph & original() const
Returns a reference to the original graph.
Definition GraphCopy.h:104
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:866
int numberOfNodes() const
Returns the number of nodes in the graph.
Definition Graph_d.h:979
int numberOfEdges() const
Returns the number of edges in the graph.
Definition Graph_d.h:982
ReturnType
The return type of a module.
Definition Module.h:52
Class for the representation of nodes.
Definition Graph_d.h:241
int size() const
Returns the number of elements in this set.
A backtracking implementation for the 1-Planarity problem.
Module::ReturnType testOnePlanarity(const Graph &G, OnePlanarization *out=nullptr)
Tests whether G is 1-planar.
Module::ReturnType testNICPlanarity(const Graph &G, OnePlanarization *out=nullptr)
Tests whether G is NIC-Planar.
Module::ReturnType testICPlanarity(const Graph &G, OnePlanarization *out=nullptr)
Tests whether G is IC-Planar.
The graph corresponding to a partial solution for the 1-Planarity problem.
const NodeSet & crossingVertices() const
Returns the set of all crossing vertices in the graph.
const EdgeSet & kiteEdges() const
Returns the set of all kite edges in the graph.
Interface of filters for partial solutions for 1-Planarity.
virtual bool canCut(OnePlanarization &pl)=0
Returns true if the partial solution represented by pl can be classified as non-realizable,...
Declaration of deterministic graph generators.
Declaration of extended graph algorithms.
bool planarEmbed(Graph &G)
Returns true, if G is planar, false otherwise. If true is returned, G will be planarly embedded.
bool isPlanar(const Graph &G)
Returns true, if G is planar, false otherwise.
bool isBipartite(const Graph &G, NodeArray< bool > &color)
Checks whether a graph is bipartite.
void completeBipartiteGraph(Graph &G, int n, int m)
Creates the complete bipartite graph K_{n,m}.
void completeGraph(Graph &G, int n)
Creates the complete graph K_n.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:52
The namespace for all OGDF objects.
int main()
Declaration of simple graph algorithms.