67 template<
typename TCost>
70 using BlockType = std::pair<Graph*,EdgeArray<edge>*>;
83 : m_bestSolution(block.size())
84 , m_bestDelEdges(block.size())
85 , m_nBlocks(block.size())
91 m_bestDelEdges[i] =
nullptr;
92 m_bestSolution[i] = (m_block[i].first !=
nullptr) ? std::numeric_limits<int>::max() : 0;
101 return *m_block[i].first;
105 return m_bestSolution[i] > 1;
109 TCost newSolution = pNewDelEdges->
size();
110 if(m_pCost !=
nullptr) {
112 newSolution = TCost(0);
113 for(
edge e : *pNewDelEdges)
114 newSolution += (*m_pCost)[origEdge[e]];
118 std::lock_guard<std::mutex> guard(m_mutex);
120 if(newSolution < m_bestSolution[i]) {
121 std::swap(pNewDelEdges, m_bestDelEdges[i]);
122 m_bestSolution[i] = newSolution;
132 if(m_bestDelEdges[i] !=
nullptr) {
134 for(
edge e : *m_bestDelEdges[i])
136 delete m_bestDelEdges[i];
142 return --m_runs >= 0;
196 bool preferedImplyPlanar)
override 211 blockEdges[componentID[e]].pushFront(e);
218 for(
int i = 0; i < nBlocks; i++) {
219 if(blockEdges[i].size() < 9) {
229 for (
edge e : blockEdges[i]) {
230 if (copyV[e->
source()] ==
nullptr) {
231 copyV[e->
source()] = bc->newNode();
234 if (copyV[e->
target()] ==
nullptr) {
235 copyV[e->
target()] = bc->newNode();
239 (*origE)[bc->newEdge(copyV[e->
source()],copyV[e->
target()])] = e;
242 for (
node v : marked)
248 unsigned int nThreads = min(this->
maxThreads(), (
unsigned int)nRuns);
253 parCall(block, pCost, nRuns, nThreads, delEdges);
256 for(
int i = 0; i < nBlocks; i++) {
257 delete block[i].first;
258 delete block[i].second;
275 const int nBlocks = block.
size();
280 for(
int i = 0; i < nBlocks; ++i) {
281 bestDelEdges[i] =
nullptr;
282 bestSolution[i] = (block[i].first !=
nullptr) ? std::numeric_limits<TCost>::max() : 0;
285 for(
int run = 0; run < nRuns; ++run) {
286 for(
int i = 0; i < nBlocks; ++i) {
287 if(bestSolution[i] > 1) {
288 const Graph &
B = *block[i].first;
296 planarize(B, numbering, *pCurrentDelEdges);
298 TCost currentSolution;
299 if(pCost ==
nullptr) {
300 currentSolution = pCurrentDelEdges->
size();
303 for(
edge e : *pCurrentDelEdges)
304 currentSolution += (*pCost)[origEdge[e]];
307 if(currentSolution < bestSolution[i]) {
308 delete bestDelEdges[i];
309 bestDelEdges[i] = pCurrentDelEdges;
310 bestSolution[i] = currentSolution;
312 delete pCurrentDelEdges;
318 for(
int i = 0; i < nBlocks; ++i) {
319 if(bestDelEdges[i] !=
nullptr) {
321 for(
edge e : *bestDelEdges[i])
323 delete bestDelEdges[i];
332 unsigned int nThreads,
339 for(
unsigned int i = 0; i < nThreads-1; ++i) {
340 worker[i] =
new Worker(&master);
341 thread[i] =
Thread(*worker[i]);
346 for(
unsigned int i = 0; i < nThreads-1; ++i) {
367 if (numbering[e->
opposite(v)] > numbering[v]) {
368 PlanarLeafKey* L =
new PlanarLeafKey(e);
369 inLeaves[v].pushFront(L);
372 table[numbering[v]] = v;
376 for (PlanarLeafKey *L : inLeaves[v]) {
377 outLeaves[L->userStructKey()->opposite(v)].pushFront(L);
387 T.
Reduction(outLeaves[table[i]], eliminatedKeys);
388 totalEliminatedKeys.
conc(eliminatedKeys);
394 edge e = key->userStructKey();
400 while (!inLeaves[v].empty()) {
401 PlanarLeafKey *L = inLeaves[v].popFrontRet();
414 for(
int i = 0; i < nBlocks; ++i) {
422 planarize(B, numbering, *pCurrentDelEdges);
424 pCurrentDelEdges = master.
postNewResult(i, pCurrentDelEdges);
425 delete pCurrentDelEdges;
node target() const
Returns the target node of the edge.
void clear()
Removes all elements from the list.
int computeSTNumbering(const Graph &G, NodeArray< int > &numbering, node s=nullptr, node t=nullptr, bool randomized=false)
Computes an st-Numbering of G.
edge theEdge() const
Returns the edge associated with this adjacency entry.
Array< List< edge > * > m_bestDelEdges
best solution for block
iterator pushBack(const E &x)
Adds element x at the end of the list.
Data type for general directed graphs (adjacency list representation).
Timeouter & operator=(const Timeouter &t)
static void doWorkHelper(ThreadMaster &master)
void init()
Reinitializes the array. Associates the array with no graph.
virtual void Cleanup()
Removes the entire PQ-tree.
unsigned int maxThreads() const
Returns the maximal number of used threads.
virtual Module::ReturnType doCall(const Graph &G, const List< edge > &preferedEdges, List< edge > &delEdges, const EdgeArray< TCost > *pCost, bool preferedImplyPlanar) override
Returns true, if G is planar, false otherwise.
Declaration of class PlanarLeafKey.
bool considerBlock(int i) const
std::pair< Graph *, EdgeArray< edge > * > BlockType
ReturnType
The return type of a module.
Singly linked lists (maintaining the length of the list).
const Graph & block(int i) const
Declaration of st-Numbering functions.
Computation of a planar subgraph using PQ-trees.
void seqCall(const Array< BlockType > &block, const EdgeArray< TCost > *pCost, int nRuns, bool randomize, List< edge > &delEdges)
Realizes the sequential implementation.
Worker(ThreadMaster *pMaster)
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
int numberOfEdges() const
Returns the number of edges in the graph.
Dynamic arrays indexed with nodes.
Interface for planar subgraph algorithms.
void buildSolution(List< edge > &delEdges)
PlanarSubgraphFast()
Creates an instance of the fast planar subgraph algorithm with default settings (runs = 10)...
INDEX size() const
Returns the size (number of elements) of the array.
The solution is feasible.
Declaration of Thread class representing threads.
Class for the representation of edges.
void parCall(const Array< BlockType > &block, const EdgeArray< TCost > *pCost, int nRuns, unsigned int nThreads, List< edge > &delEdges)
Realizes the parallel implementation.
virtual bool Reduction(SListPure< PlanarLeafKey *> &leafKeys, SList< PQLeafKey< edge, whaInfo *, bool > *> &eliminatedKeys)
Reduces a set of leaves.
void ReplaceRoot(SListPure< PlanarLeafKey *> &leafKeys)
Replaces the pertinent subtree by a set of new leaves.
Class for the representation of nodes.
int m_nRuns
The number of runs for randomization.
void conc(SList< E > &L2)
Appends L2 to this list and makes L2 empty.
node opposite(node v) const
Returns the adjacent node different from v.
void runs(int nRuns)
Sets the number of randomized runs to nRuns.
virtual int Initialize(SListPure< PlanarLeafKey *> &leafKeys)
Initializes a new PQ-tree with a set of leaves.
int runs() const
Returns the current number of randomized runs.
The class template PQLeafKey is a derived class of class template PQBasicKey.
SListIterator< E > pushBack(const E &x)
Adds element x at the end of the list.
bool isSelfLoop() const
Returns true iff the edge is a self-loop (source node = target node).
std::atomic< int > m_runs
Threads supporting OGDF's memory management.
std::mutex m_mutex
thread synchronization
int size() const
Returns the number of elements in the list.
Declaration of simple graph algorithms.
node source() const
Returns the source node of the edge.
Array< TCost > m_bestSolution
value of best solution for block
int biconnectedComponents(const Graph &G, EdgeArray< int > &component, int &nonEmptyComponents)
Computes the biconnected components of G.
The namespace for all OGDF objects.
Declaration of class PlanarSubgraphPQTree.
Declaration of interface for planar subgraph algorithms.
int numberOfNodes() const
Returns the number of nodes in the graph.
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
const Array< BlockType > & m_block
the blocks (graph and edge mapping)
static void planarize(const Graph &G, NodeArray< int > &numbering, List< edge > &delEdges)
Performs a planarization on a biconnected component of G.
ThreadMaster(const Array< BlockType > &block, const EdgeArray< TCost > *pCost, int runs)
virtual PlanarSubgraphFast * clone() const override
Returns a new instance of fast planar subgraph with the same option settings.
int m_nBlocks
number of blocks
Class for adjacency list elements.
const EdgeArray< TCost > * m_pCost
edge cost (may be 0)
List< edge > * postNewResult(int i, List< edge > *pNewDelEdges)
virtual void emptyAllPertinentNodes()
Does a clean up after a reduction.
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.