Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

PlanarSubgraphModule.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/Graph.h>
35 #include <ogdf/basic/GraphCopy.h>
36 #include <ogdf/basic/List.h>
37 #include <ogdf/basic/Module.h>
38 #include <ogdf/basic/Thread.h>
39 #include <ogdf/basic/Timeouter.h>
40 #include <ogdf/basic/basic.h>
41 #include <ogdf/basic/memory.h>
42 
43 #include <algorithm>
44 
45 namespace ogdf {
46 
52 template<typename TCost>
53 class PlanarSubgraphModule : public Module, public Timeouter {
54  unsigned int m_maxThreads;
55 
56 public:
59 #ifdef OGDF_MEMORY_POOL_NTS
60  m_maxThreads = 1;
61 #else
62  m_maxThreads = max(1u, Thread::hardware_concurrency());
63 #endif
64  }
65 
74  ReturnType call(const Graph& G, const EdgeArray<TCost>& cost, const List<edge>& preferredEdges,
75  List<edge>& delEdges, bool preferredImplyPlanar = false) {
76  return doCall(G, preferredEdges, delEdges, &cost, preferredImplyPlanar);
77  }
78 
86  ReturnType call(const Graph& G, const List<edge>& preferredEdges, List<edge>& delEdges,
87  bool preferredImplyPlanar = false) {
88  return doCall(G, preferredEdges, delEdges, nullptr, preferredImplyPlanar);
89  }
90 
97  ReturnType call(const Graph& G, const EdgeArray<TCost>& cost, List<edge>& delEdges) {
98  List<edge> preferredEdges;
99  return doCall(G, preferredEdges, delEdges, &cost);
100  }
101 
107  ReturnType call(const Graph& G, List<edge>& delEdges) {
108  List<edge> preferredEdges;
109  return doCall(G, preferredEdges, delEdges);
110  }
111 
113  ReturnType operator()(const Graph& G, const List<edge>& preferredEdges, List<edge>& delEdges,
114  bool preferredImplyPlanar = false) {
115  return call(G, preferredEdges, delEdges, preferredImplyPlanar);
116  }
117 
119  ReturnType operator()(const Graph& G, List<edge>& delEdges) { return call(G, delEdges); }
120 
128  ReturnType callAndDelete(GraphCopy& GC, const List<edge>& preferredEdges,
129  List<edge>& delOrigEdges, bool preferredImplyPlanar = false) {
130  List<edge> delEdges;
131  ReturnType retValue = call(GC, preferredEdges, delEdges, preferredImplyPlanar);
132  if (isSolution(retValue)) {
133  for (edge eCopy : delEdges) {
134  delOrigEdges.pushBack(GC.original(eCopy));
135  GC.delEdge(eCopy);
136  }
137  }
138  return retValue;
139  }
140 
147  List<edge> preferredEdges;
148  return callAndDelete(GC, preferredEdges, delOrigEdges);
149  }
150 
152  virtual PlanarSubgraphModule* clone() const = 0;
153 
155  unsigned int maxThreads() const { return m_maxThreads; }
156 
158  void maxThreads(unsigned int n) {
159 #ifndef OGDF_MEMORY_POOL_NTS
160  m_maxThreads = n;
161 #endif
162  }
163 
164 protected:
165  // computes set of edges delEdges, which have to be deleted
166  // in order to get a planar subgraph; edges in preferredEdges
167  // should be contained in planar subgraph
168  // must be implemented by derived classes!
181  virtual ReturnType doCall(const Graph& G, const List<edge>& preferredEdges, List<edge>& delEdges,
182  const EdgeArray<TCost>* pCost = nullptr, bool preferredImplyPlanar = false) = 0;
183 
185 };
186 
187 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::Module::isSolution
static bool isSolution(ReturnType ret)
Returns true iff ret indicates that the module returned a feasible solution.
Definition: Module.h:67
ogdf::PlanarSubgraphModule
Interface for planar subgraph algorithms.
Definition: PlanarSubgraphModule.h:53
Graph.h
Includes declaration of graph class.
ogdf::PlanarSubgraphModule::maxThreads
void maxThreads(unsigned int n)
Sets the maximal number of used threads to n.
Definition: PlanarSubgraphModule.h:158
ogdf::PlanarSubgraphModule::operator()
ReturnType operator()(const Graph &G, List< edge > &delEdges)
Returns the set of edges delEdges which have to be deleted to obtain the planar subgraph.
Definition: PlanarSubgraphModule.h:119
ogdf::GraphCopy
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:391
ogdf::PlanarSubgraphModule::call
ReturnType call(const Graph &G, const EdgeArray< TCost > &cost, const List< edge > &preferredEdges, List< edge > &delEdges, bool preferredImplyPlanar=false)
Returns the set of edges delEdges which have to be deleted to obtain the planar subgraph.
Definition: PlanarSubgraphModule.h:74
ogdf::PlanarSubgraphModule::PlanarSubgraphModule
PlanarSubgraphModule()
Initializes a planar subgraph module (default constructor).
Definition: PlanarSubgraphModule.h:58
Timeouter.h
Declares base class for modules with timeout functionality.
ogdf::PlanarSubgraphModule::m_maxThreads
unsigned int m_maxThreads
The maximal number of used threads.
Definition: PlanarSubgraphModule.h:54
OGDF_MALLOC_NEW_DELETE
#define OGDF_MALLOC_NEW_DELETE
Makes the class use malloc for memory allocation.
Definition: memory.h:92
ogdf::PlanarSubgraphModule::callAndDelete
ReturnType callAndDelete(GraphCopy &GC, const List< edge > &preferredEdges, List< edge > &delOrigEdges, bool preferredImplyPlanar=false)
Makes GC planar by deleting edges.
Definition: PlanarSubgraphModule.h:128
ogdf::Module
Base class for modules.
Definition: Module.h:49
ogdf::PlanarSubgraphModule::call
ReturnType call(const Graph &G, const List< edge > &preferredEdges, List< edge > &delEdges, bool preferredImplyPlanar=false)
Returns the set of edges delEdges which have to be deleted to obtain the planar subgraph.
Definition: PlanarSubgraphModule.h:86
ogdf::PlanarSubgraphModule::operator()
ReturnType operator()(const Graph &G, const List< edge > &preferredEdges, List< edge > &delEdges, bool preferredImplyPlanar=false)
Returns the set of edges delEdges which have to be deleted to obtain the planar subgraph.
Definition: PlanarSubgraphModule.h:113
GraphCopy.h
Declaration of graph copy classes.
ogdf::List< edge >
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:869
Thread.h
Declaration of Thread class representing threads.
ogdf::GraphCopy::delEdge
void delEdge(edge e) override
Removes edge e and clears the list of edges corresponding to e's original edge.
basic.h
Basic declarations, included by all source files.
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:363
List.h
Declaration of doubly linked lists and iterators.
ogdf::PlanarSubgraphModule::clone
virtual PlanarSubgraphModule * clone() const =0
Returns a new instance of the planar subgraph module with the same option settings.
ogdf::PlanarSubgraphModule::maxThreads
unsigned int maxThreads() const
Returns the maximal number of used threads.
Definition: PlanarSubgraphModule.h:155
ogdf::Timeouter
class for timeout funtionality.
Definition: Timeouter.h:46
Module.h
Declares base class for all module types.
ogdf::PlanarSubgraphModule::call
ReturnType call(const Graph &G, List< edge > &delEdges)
Returns the set of edges delEdges which have to be deleted to obtain the planar subgraph.
Definition: PlanarSubgraphModule.h:107
ogdf::Module::ReturnType
ReturnType
The return type of a module.
Definition: Module.h:52
ogdf::PlanarSubgraphModule::call
ReturnType call(const Graph &G, const EdgeArray< TCost > &cost, List< edge > &delEdges)
Returns the set of edges delEdges which have to be deleted to obtain the planar subgraph.
Definition: PlanarSubgraphModule.h:97
memory.h
Declaration of memory manager for allocating small pieces of memory.
ogdf::PlanarSubgraphModule::doCall
virtual ReturnType doCall(const Graph &G, const List< edge > &preferredEdges, List< edge > &delEdges, const EdgeArray< TCost > *pCost=nullptr, bool preferredImplyPlanar=false)=0
Computes the set of edges delEdges which have to be deleted to obtain the planar subgraph.
ogdf::PlanarSubgraphModule::callAndDelete
ReturnType callAndDelete(GraphCopy &GC, List< edge > &delOrigEdges)
Makes G planar by deleting edges.
Definition: PlanarSubgraphModule.h:146
ogdf::List::pushBack
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition: List.h:1547
ogdf::GraphCopyBase::original
const Graph & original() const
Returns a reference to the original graph.
Definition: GraphCopy.h:105
ogdf::internal::EdgeArrayBase2
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition: Graph_d.h:716