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) ? 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;
208 bool preferedImplyPlanar)
override 223 blockEdges[componentID[e]].pushFront(e);
230 for(
int i = 0; i < nBlocks; i++) {
231 if(blockEdges[i].size() < 9) {
241 for (
edge e : blockEdges[i]) {
242 if (copyV[e->
source()] ==
nullptr) {
243 copyV[e->
source()] = bc->newNode();
246 if (copyV[e->
target()] ==
nullptr) {
247 copyV[e->
target()] = bc->newNode();
251 (*origE)[bc->newEdge(copyV[e->
source()],copyV[e->
target()])] = e;
254 for (
node v : marked)
260 unsigned int nThreads = min(this->
maxThreads(), (
unsigned int)nRuns);
265 parCall(block, pCost, nRuns, nThreads, delEdges);
268 for(
int i = 0; i < nBlocks; i++) {
269 delete block[i].first;
270 delete block[i].second;
287 const int nBlocks = block.
size();
292 for(
int i = 0; i < nBlocks; ++i) {
293 bestDelEdges[i] =
nullptr;
294 bestSolution[i] = (block[i].first !=
nullptr) ? numeric_limits<TCost>::max() : 0;
297 for(
int run = 0; run < nRuns; ++run) {
298 for(
int i = 0; i < nBlocks; ++i) {
299 if(bestSolution[i] > 1) {
300 const Graph &
B = *block[i].first;
308 planarize(B, numbering, *pCurrentDelEdges);
310 TCost currentSolution;
311 if(pCost ==
nullptr) {
312 currentSolution = pCurrentDelEdges->
size();
315 for(
edge e : *pCurrentDelEdges)
316 currentSolution += (*pCost)[origEdge[e]];
319 if(currentSolution < bestSolution[i]) {
320 delete bestDelEdges[i];
321 bestDelEdges[i] = pCurrentDelEdges;
322 bestSolution[i] = currentSolution;
324 delete pCurrentDelEdges;
330 for(
int i = 0; i < nBlocks; ++i) {
331 if(bestDelEdges[i] !=
nullptr) {
333 for(
edge e : *bestDelEdges[i])
335 delete bestDelEdges[i];
344 unsigned int nThreads,
351 for(
unsigned int i = 0; i < nThreads-1; ++i) {
352 worker[i] =
new Worker(&master);
353 thread[i] =
Thread(*worker[i]);
358 for(
unsigned int i = 0; i < nThreads-1; ++i) {
379 if (numbering[e->
opposite(v)] > numbering[v]) {
380 PlanarLeafKey* L =
new PlanarLeafKey(e);
381 inLeaves[v].pushFront(L);
384 table[numbering[v]] = v;
388 for (PlanarLeafKey *L : inLeaves[v]) {
389 outLeaves[L->userStructKey()->opposite(v)].pushFront(L);
399 T.
Reduction(outLeaves[table[i]], eliminatedKeys);
400 totalEliminatedKeys.
conc(eliminatedKeys);
406 edge e = key->userStructKey();
412 while (!inLeaves[v].empty()) {
413 PlanarLeafKey *L = inLeaves[v].popFrontRet();
426 for(
int i = 0; i < nBlocks; ++i) {
434 planarize(B, numbering, *pCurrentDelEdges);
436 pCurrentDelEdges = master.
postNewResult(i, pCurrentDelEdges);
437 delete pCurrentDelEdges;
node target() const
Returns the target node of the edge.
void clear()
Removes all elements from the list.
PlanarSubgraphFast & operator=(const PlanarSubgraphFast &fps)
Assignment operator. Copies option settings only.
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).
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.
~PlanarSubgraphFast()
Destructor.
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.
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
double m_timeLimit
Time limit for module calls (< 0 means no limit).
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.