Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

PlanarSubgraphModule.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/GraphCopy.h>
35 #include <ogdf/basic/Module.h>
36 #include <ogdf/basic/Logger.h>
37 #include <ogdf/basic/Timeouter.h>
38 #include <ogdf/basic/Thread.h>
39 
40 
41 namespace ogdf {
42 
48 template<typename TCost>
49 class PlanarSubgraphModule : public Module, public Timeouter {
50 
51  unsigned int m_maxThreads;
52 
53 public:
56 #ifdef OGDF_MEMORY_POOL_NTS
57  m_maxThreads = 1;
58 #else
59  m_maxThreads = max(1u, Thread::hardware_concurrency());
60 #endif
61  }
62 
63 
72  ReturnType call(const Graph &G,
73  const EdgeArray<TCost> &cost,
74  const List<edge> &preferredEdges,
75  List<edge> &delEdges,
76  bool preferredImplyPlanar = false)
77  {
78  return doCall(G,preferredEdges,delEdges,&cost,preferredImplyPlanar);
79  }
80 
81 
89  ReturnType call(const Graph &G,
90  const List<edge> &preferredEdges,
91  List<edge> &delEdges,
92  bool preferredImplyPlanar = false)
93  {
94  return doCall(G,preferredEdges,delEdges,nullptr,preferredImplyPlanar);
95  }
96 
97 
104  ReturnType call(const Graph &G, const EdgeArray<TCost> &cost, List<edge> &delEdges) {
105  List<edge> preferredEdges;
106  return doCall(G,preferredEdges,delEdges, &cost);
107  }
108 
114  ReturnType call(const Graph &G, List<edge> &delEdges) {
115  List<edge> preferredEdges;
116  return doCall(G,preferredEdges,delEdges);
117  }
118 
119 
122  const List<edge> &preferredEdges,
123  List<edge> &delEdges,
124  bool preferredImplyPlanar = false)
125  {
126  return call(G,preferredEdges,delEdges,preferredImplyPlanar);
127  }
128 
130  ReturnType operator()(const Graph &G, List<edge> &delEdges) {
131  return call(G,delEdges);
132  }
133 
134 
143  const List<edge> &preferredEdges,
144  List<edge> &delOrigEdges,
145  bool preferredImplyPlanar = false)
146  {
147  List<edge> delEdges;
148  ReturnType retValue = call(GC, preferredEdges, delEdges, preferredImplyPlanar);
149  if(isSolution(retValue)) {
150  for (edge eCopy : delEdges) {
151  delOrigEdges.pushBack(GC.original(eCopy));
152  GC.delEdge(eCopy);
153  }
154  }
155  return retValue;
156  }
157 
164  List<edge> preferredEdges;
165  return callAndDelete(GC,preferredEdges,delOrigEdges);
166  }
167 
169  virtual PlanarSubgraphModule *clone() const = 0;
170 
172  unsigned int maxThreads() const { return m_maxThreads; }
173 
175  void maxThreads(unsigned int n) {
176 #ifndef OGDF_MEMORY_POOL_NTS
177  m_maxThreads = n;
178 #endif
179  }
180 
181 protected:
182  // computes set of edges delEdges, which have to be deleted
183  // in order to get a planar subgraph; edges in preferredEdges
184  // should be contained in planar subgraph
185  // must be implemented by derived classes!
198  virtual ReturnType doCall(const Graph &G,
199  const List<edge> &preferredEdges,
200  List<edge> &delEdges,
201  const EdgeArray<TCost> *pCost = nullptr,
202  bool preferredImplyPlanar = false) = 0;
203 
205 };
206 
207 }
void maxThreads(unsigned int n)
Sets the maximal number of used threads to n.
unsigned int m_maxThreads
The maximal number of used threads.
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition: List.h:1373
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:492
#define OGDF_MALLOC_NEW_DELETE
Makes the class use malloc for memory allocation.
Definition: memory.h:91
PlanarSubgraphModule()
Initializes a planar subgraph module (default constructor).
Declares base class for all module types.
unsigned int maxThreads() const
Returns the maximal number of used threads.
Base class for modules.
Definition: Module.h:47
ReturnType
The return type of a module.
Definition: Module.h:51
virtual void delEdge(edge e) override
Removes edge e and clears the list of edges corresponding to e&#39;s original edge.
class for timeout funtionality.
Definition: Timeouter.h:47
Interface for planar subgraph algorithms.
Contains logging functionality.
Declaration of graph copy classes.
Declaration of Thread class representing threads.
Class for the representation of edges.
Definition: Graph_d.h:292
ReturnType callAndDelete(GraphCopy &GC, const List< edge > &preferredEdges, List< edge > &delOrigEdges, bool preferredImplyPlanar=false)
Makes GC planar by deleting edges.
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:249
const Graph & original() const
Returns a reference to the original graph.
Definition: GraphCopy.h:286
virtual PlanarSubgraphModule * clone() const =0
Returns a new instance of the planar subgraph module with the same option settings.
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.
ReturnType callAndDelete(GraphCopy &GC, List< edge > &delOrigEdges)
Makes G planar by deleting edges.
Declares base class for modules with timeout functionality.
static bool isSolution(ReturnType ret)
Returns true iff ret indicates that the module returned a feasible solution.
Definition: Module.h:66
ReturnType call(const Graph &G, List< edge > &delEdges)
Returns the set of edges delEdges which have to be deleted to obtain the planar subgraph.
The namespace for all OGDF objects.
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.
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.
ReturnType operator()(const Graph &G, List< edge > &delEdges)
Returns the set of edges delEdges which have to be deleted to obtain the planar subgraph.
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.
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.