Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

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 
65  m_maxThreads = psm.m_maxThreads;
66  }
67 
68  // destruction
69  virtual ~PlanarSubgraphModule() { }
70 
71 
80  ReturnType call(const Graph &G,
81  const EdgeArray<TCost> &cost,
82  const List<edge> &preferredEdges,
83  List<edge> &delEdges,
84  bool preferredImplyPlanar = false)
85  {
86  return doCall(G,preferredEdges,delEdges,&cost,preferredImplyPlanar);
87  }
88 
89 
97  ReturnType call(const Graph &G,
98  const List<edge> &preferredEdges,
99  List<edge> &delEdges,
100  bool preferredImplyPlanar = false)
101  {
102  return doCall(G,preferredEdges,delEdges,nullptr,preferredImplyPlanar);
103  }
104 
105 
112  ReturnType call(const Graph &G, const EdgeArray<TCost> &cost, List<edge> &delEdges) {
113  List<edge> preferredEdges;
114  return doCall(G,preferredEdges,delEdges, &cost);
115  }
116 
122  ReturnType call(const Graph &G, List<edge> &delEdges) {
123  List<edge> preferredEdges;
124  return doCall(G,preferredEdges,delEdges);
125  }
126 
127 
130  const List<edge> &preferredEdges,
131  List<edge> &delEdges,
132  bool preferredImplyPlanar = false)
133  {
134  return call(G,preferredEdges,delEdges,preferredImplyPlanar);
135  }
136 
138  ReturnType operator()(const Graph &G, List<edge> &delEdges) {
139  return call(G,delEdges);
140  }
141 
142 
151  const List<edge> &preferredEdges,
152  List<edge> &delOrigEdges,
153  bool preferredImplyPlanar = false)
154  {
155  List<edge> delEdges;
156  ReturnType retValue = call(GC, preferredEdges, delEdges, preferredImplyPlanar);
157  if(isSolution(retValue)) {
158  for (edge eCopy : delEdges) {
159  delOrigEdges.pushBack(GC.original(eCopy));
160  GC.delEdge(eCopy);
161  }
162  }
163  return retValue;
164  }
165 
172  List<edge> preferredEdges;
173  return callAndDelete(GC,preferredEdges,delOrigEdges);
174  }
175 
177  virtual PlanarSubgraphModule *clone() const = 0;
178 
180  unsigned int maxThreads() const { return m_maxThreads; }
181 
183  void maxThreads(unsigned int n) {
184 #ifndef OGDF_MEMORY_POOL_NTS
185  m_maxThreads = n;
186 #endif
187  }
188 
189 protected:
190  // computes set of edges delEdges, which have to be deleted
191  // in order to get a planar subgraph; edges in preferredEdges
192  // should be contained in planar subgraph
193  // must be implemented by derived classes!
206  virtual ReturnType doCall(const Graph &G,
207  const List<edge> &preferredEdges,
208  List<edge> &delEdges,
209  const EdgeArray<TCost> *pCost = nullptr,
210  bool preferredImplyPlanar = false) = 0;
211 
212 
213 
215 };
216 
217 } // end namespace ogdf
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:1316
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:472
#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:291
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:250
const Graph & original() const
Returns a reference to the original graph.
Definition: GraphCopy.h:287
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.
PlanarSubgraphModule(const PlanarSubgraphModule &psm)
Initializes a planar subgraph module (copy constructor).
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.