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/GraphCopy.h>
35 #include <ogdf/basic/Logger.h>
36 #include <ogdf/basic/Module.h>
37 #include <ogdf/basic/Thread.h>
38 #include <ogdf/basic/Timeouter.h>
39 
40 namespace ogdf {
41 
47 template<typename TCost>
48 class PlanarSubgraphModule : public Module, public Timeouter {
49  unsigned int m_maxThreads;
50 
51 public:
54 #ifdef OGDF_MEMORY_POOL_NTS
55  m_maxThreads = 1;
56 #else
57  m_maxThreads = max(1u, Thread::hardware_concurrency());
58 #endif
59  }
60 
69  ReturnType call(const Graph& G, const EdgeArray<TCost>& cost, const List<edge>& preferredEdges,
70  List<edge>& delEdges, bool preferredImplyPlanar = false) {
71  return doCall(G, preferredEdges, delEdges, &cost, preferredImplyPlanar);
72  }
73 
81  ReturnType call(const Graph& G, const List<edge>& preferredEdges, List<edge>& delEdges,
82  bool preferredImplyPlanar = false) {
83  return doCall(G, preferredEdges, delEdges, nullptr, preferredImplyPlanar);
84  }
85 
92  ReturnType call(const Graph& G, const EdgeArray<TCost>& cost, List<edge>& delEdges) {
93  List<edge> preferredEdges;
94  return doCall(G, preferredEdges, delEdges, &cost);
95  }
96 
102  ReturnType call(const Graph& G, List<edge>& delEdges) {
103  List<edge> preferredEdges;
104  return doCall(G, preferredEdges, delEdges);
105  }
106 
108  ReturnType operator()(const Graph& G, const List<edge>& preferredEdges, List<edge>& delEdges,
109  bool preferredImplyPlanar = false) {
110  return call(G, preferredEdges, delEdges, preferredImplyPlanar);
111  }
112 
114  ReturnType operator()(const Graph& G, List<edge>& delEdges) { return call(G, delEdges); }
115 
123  ReturnType callAndDelete(GraphCopy& GC, const List<edge>& preferredEdges,
124  List<edge>& delOrigEdges, bool preferredImplyPlanar = false) {
125  List<edge> delEdges;
126  ReturnType retValue = call(GC, preferredEdges, delEdges, preferredImplyPlanar);
127  if (isSolution(retValue)) {
128  for (edge eCopy : delEdges) {
129  delOrigEdges.pushBack(GC.original(eCopy));
130  GC.delEdge(eCopy);
131  }
132  }
133  return retValue;
134  }
135 
142  List<edge> preferredEdges;
143  return callAndDelete(GC, preferredEdges, delOrigEdges);
144  }
145 
147  virtual PlanarSubgraphModule* clone() const = 0;
148 
150  unsigned int maxThreads() const { return m_maxThreads; }
151 
153  void maxThreads(unsigned int n) {
154 #ifndef OGDF_MEMORY_POOL_NTS
155  m_maxThreads = n;
156 #endif
157  }
158 
159 protected:
160  // computes set of edges delEdges, which have to be deleted
161  // in order to get a planar subgraph; edges in preferredEdges
162  // should be contained in planar subgraph
163  // must be implemented by derived classes!
176  virtual ReturnType doCall(const Graph& G, const List<edge>& preferredEdges, List<edge>& delEdges,
177  const EdgeArray<TCost>* pCost = nullptr, bool preferredImplyPlanar = false) = 0;
178 
180 };
181 
182 }
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
ogdf::Module::isSolution
static bool isSolution(ReturnType ret)
Returns true iff ret indicates that the module returned a feasible solution.
Definition: Module.h:65
ogdf::PlanarSubgraphModule
Interface for planar subgraph algorithms.
Definition: PlanarSubgraphModule.h:48
ogdf::PlanarSubgraphModule::maxThreads
void maxThreads(unsigned int n)
Sets the maximal number of used threads to n.
Definition: PlanarSubgraphModule.h:153
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:114
ogdf::GraphCopy
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:384
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:69
ogdf::PlanarSubgraphModule::PlanarSubgraphModule
PlanarSubgraphModule()
Initializes a planar subgraph module (default constructor).
Definition: PlanarSubgraphModule.h:53
Timeouter.h
Declares base class for modules with timeout functionality.
Logger.h
Contains logging functionality.
ogdf::PlanarSubgraphModule::m_maxThreads
unsigned int m_maxThreads
The maximal number of used threads.
Definition: PlanarSubgraphModule.h:49
OGDF_MALLOC_NEW_DELETE
#define OGDF_MALLOC_NEW_DELETE
Makes the class use malloc for memory allocation.
Definition: memory.h:91
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:123
ogdf::Module
Base class for modules.
Definition: Module.h:47
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:81
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:108
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:862
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.
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:356
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:150
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:102
ogdf::Module::ReturnType
ReturnType
The return type of a module.
Definition: Module.h:50
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:92
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:141
ogdf::List::pushBack
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition: List.h:1537
ogdf::GraphCopyBase::original
const Graph & original() const
Returns a reference to the original graph.
Definition: GraphCopy.h:98
ogdf::internal::EdgeArrayBase2
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition: Graph_d.h:709