Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
PlanarSubgraphModule.h
Go to the documentation of this file.
1
32#pragma once
33
34#include <ogdf/basic/Graph.h>
36#include <ogdf/basic/List.h>
37#include <ogdf/basic/Module.h>
38#include <ogdf/basic/Thread.h>
40#include <ogdf/basic/basic.h>
41#include <ogdf/basic/memory.h>
42
43#include <algorithm>
44
45namespace ogdf {
46
52template<typename TCost>
53class PlanarSubgraphModule : public Module, public Timeouter {
54 unsigned int m_maxThreads;
55
56public:
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
164protected:
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}
Includes declaration of graph class.
Declaration of graph copy classes.
Declaration of doubly linked lists and iterators.
Declares base class for all module types.
Declaration of Thread class representing threads.
Declares base class for modules with timeout functionality.
Basic declarations, included by all source files.
Class for the representation of edges.
Definition Graph_d.h:364
const Graph & original() const
Returns a reference to the original graph.
Definition GraphCopy.h:104
Copies of graphs supporting edge splitting.
Definition GraphCopy.h:390
void delEdge(edge e) override
Removes edge e and clears the list of edges corresponding to e's original edge.
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:866
Doubly linked lists (maintaining the length of the list).
Definition List.h:1451
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition List.h:1547
Base class for modules.
Definition Module.h:49
ReturnType
The return type of a module.
Definition Module.h:52
static bool isSolution(ReturnType ret)
Returns true iff ret indicates that the module returned a feasible solution.
Definition Module.h:67
Interface for planar subgraph algorithms.
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.
unsigned int maxThreads() const
Returns the maximal number of used threads.
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.
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.
void maxThreads(unsigned int n)
Sets the maximal number of used threads to n.
ReturnType callAndDelete(GraphCopy &GC, List< edge > &delOrigEdges)
Makes G planar by deleting edges.
ReturnType operator()(const Graph &G, List< edge > &delEdges)
Returns the set of edges delEdges which have to be deleted to obtain the planar subgraph.
unsigned int m_maxThreads
The maximal number of used threads.
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.
PlanarSubgraphModule()
Initializes a planar subgraph module (default constructor).
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.
virtual PlanarSubgraphModule * clone() const =0
Returns a new instance of the planar subgraph module with the same option settings.
ReturnType callAndDelete(GraphCopy &GC, const List< edge > &preferredEdges, List< edge > &delOrigEdges, bool preferredImplyPlanar=false)
Makes GC planar by deleting edges.
ReturnType call(const Graph &G, List< edge > &delEdges)
Returns the set of edges delEdges which have to be deleted to obtain the planar subgraph.
class for timeout funtionality.
Definition Timeouter.h:46
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition Graph_d.h:717
#define OGDF_MALLOC_NEW_DELETE
Makes the class use malloc for memory allocation.
Definition memory.h:92
Declaration of memory manager for allocating small pieces of memory.
The namespace for all OGDF objects.