|
Open Graph Drawing Framework |
v. 2023.09 (Elderberry)
|
|
|
Go to the documentation of this file.
81 template<
typename TCost>
83 using BlockType = std::pair<Graph*, EdgeArray<edge>*>;
105 (
m_block[i].first !=
nullptr) ? std::numeric_limits<int>::max() : 0;
116 TCost newSolution = pNewDelEdges->
size();
119 newSolution = TCost(0);
120 for (
edge e : *pNewDelEdges) {
121 newSolution += (*m_pCost)[origEdge[e]];
126 std::lock_guard<std::mutex> guard(
m_mutex);
195 if (G.numberOfEdges() < 9) {
205 for (
edge e : G.edges) {
207 blockEdges[componentID[e]].pushFront(e);
215 for (
int i = 0; i < nBlocks; i++) {
216 if (blockEdges[i].size() < 9) {
227 for (
edge e : blockEdges[i]) {
228 if (copyV[e->
source()] ==
nullptr) {
232 if (copyV[e->
target()] ==
nullptr) {
240 for (
node v : marked) {
247 unsigned int nThreads = min(this->
maxThreads(), (
unsigned int)nRuns);
252 parCall(block, pCost, nRuns, nThreads, delEdges);
256 for (
int i = 0; i < nBlocks; i++) {
257 delete block[i].first;
258 delete block[i].second;
271 const int nBlocks = block.
size();
276 for (
int i = 0; i < nBlocks; ++i) {
277 bestDelEdges[i] =
nullptr;
278 bestSolution[i] = (block[i].first !=
nullptr) ? std::numeric_limits<TCost>::max() : 0;
281 for (
int run = 0; run < nRuns; ++run) {
282 for (
int i = 0; i < nBlocks; ++i) {
283 if (bestSolution[i] > 1) {
284 const Graph& B = *block[i].first;
292 planarize(B, numbering, *pCurrentDelEdges);
294 TCost currentSolution;
295 if (pCost ==
nullptr) {
296 currentSolution = pCurrentDelEdges->
size();
299 for (
edge e : *pCurrentDelEdges) {
300 currentSolution += (*pCost)[origEdge[e]];
304 if (currentSolution < bestSolution[i]) {
305 delete bestDelEdges[i];
306 bestDelEdges[i] = pCurrentDelEdges;
307 bestSolution[i] = currentSolution;
309 delete pCurrentDelEdges;
316 for (
int i = 0; i < nBlocks; ++i) {
317 if (bestDelEdges[i] !=
nullptr) {
319 for (
edge e : *bestDelEdges[i]) {
322 delete bestDelEdges[i];
329 unsigned int nThreads,
List<edge>& delEdges) {
334 for (
unsigned int i = 0; i < nThreads - 1; ++i) {
335 worker[i] =
new Worker(&master);
336 thread[i] =
Thread(*worker[i]);
341 for (
unsigned int i = 0; i < nThreads - 1; ++i) {
359 for (
node v : G.nodes) {
362 if (numbering[e->
opposite(v)] > numbering[v]) {
363 PlanarLeafKey* L =
new PlanarLeafKey(e);
364 inLeaves[v].pushFront(L);
367 table[numbering[v]] = v;
370 for (
node v : G.nodes) {
371 for (PlanarLeafKey* L : inLeaves[v]) {
372 outLeaves[L->userStructKey()->opposite(v)].pushFront(L);
380 for (
int i = 2; i < G.numberOfNodes(); i++) {
382 T.
Reduction(outLeaves[table[i]], eliminatedKeys);
383 totalEliminatedKeys.
conc(eliminatedKeys);
389 edge e = key->userStructKey();
394 for (
node v : G.nodes) {
395 while (!inLeaves[v].empty()) {
396 PlanarLeafKey* L = inLeaves[v].popFrontRet();
409 for (
int i = 0; i < nBlocks; ++i) {
417 planarize(B, numbering, *pCurrentDelEdges);
419 pCurrentDelEdges = master.
postNewResult(i, pCurrentDelEdges);
420 delete pCurrentDelEdges;
The namespace for all OGDF objects.
Interface for planar subgraph algorithms.
Includes declaration of graph class.
@ Feasible
The solution is feasible.
std::mutex m_mutex
thread synchronization
const EdgeArray< TCost > * m_pCost
edge cost (may be 0)
void buildSolution(List< edge > &delEdges)
int m_nBlocks
number of blocks
std::atomic< int > m_runs
The class template PQLeafKey is a derived class of class template PQBasicKey.
Declaration of class PlanarSubgraphPQTree.
Singly linked lists (maintaining the length of the list).
List< edge > * postNewResult(int i, List< edge > *pNewDelEdges)
Computation of a planar subgraph using PQ-trees.
virtual void Cleanup()
Removes the entire PQ-tree.
Worker & operator=(const Worker &other)
Class for adjacency list elements.
static void doWorkHelper(ThreadMaster &master)
@ Optimal
The solution is optimal.
edge theEdge() const
Returns the edge associated with this adjacency entry.
Declaration of st-Numbering functions.
int runs() const
Returns the current number of randomized runs.
ThreadMaster(const Array< BlockType > &block, const EdgeArray< TCost > *pCost, int runs)
bool isSelfLoop() const
Returns true iff the edge is a self-loop (source node = target node).
const Graph & block(int i) const
Declaration of interface for planar subgraph algorithms.
virtual int Initialize(SListPure< PlanarLeafKey * > &leafKeys)
Initializes a new PQ-tree with a set of leaves.
std::pair< Graph *, EdgeArray< edge > * > BlockType
Declaration of singly linked lists and iterators.
Decralation of GraphElement and GraphList classes.
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.
Worker(ThreadMaster *pMaster)
virtual bool Reduction(SListPure< PlanarLeafKey * > &leafKeys, SList< PQLeafKey< edge, whaInfo *, bool > * > &eliminatedKeys)
Reduces a set of leaves.
node source() const
Returns the source node of the edge.
RegisteredArray for nodes, edges and adjEntries of a graph.
Data type for general directed graphs (adjacency list representation).
Declaration and implementation of the class PQLeafKey.
void ReplaceRoot(SListPure< PlanarLeafKey * > &leafKeys)
Replaces the pertinent subtree by a set of new leaves.
Declaration of class whaInfo.
PlanarSubgraphFast()
Creates an instance of the fast planar subgraph algorithm with default settings (runs = 10).
int biconnectedComponents(const Graph &G, EdgeArray< int > &component, int &nonEmptyComponents)
Computes the biconnected components of G.
Declaration of Thread class representing threads.
Basic declarations, included by all source files.
node newNode(int index=-1)
Creates a new node and returns it.
Array< List< edge > * > m_bestDelEdges
best solution for block
Declaration and implementation of Array class and Array algorithms.
node opposite(node v) const
Returns the adjacent node different from v.
Class for the representation of edges.
const Array< BlockType > & m_block
the blocks (graph and edge mapping)
Declaration of doubly linked lists and iterators.
int m_nRuns
The number of runs for randomization.
void seqCall(const Array< BlockType > &block, const EdgeArray< TCost > *pCost, int nRuns, bool randomize, List< edge > &delEdges)
Realizes the sequential implementation.
bool considerBlock(int i) const
void conc(SList< E > &L2)
Appends L2 to this list and makes L2 empty.
void init(const Graph *base=nullptr)
Reinitializes the array. Associates the array with the matching registry of base.
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.
INDEX size() const
Returns the size (number of elements) of the array.
int size() const
Returns the number of elements in the list.
Declares base class for all module types.
Threads supporting OGDF's memory management.
node target() const
Returns the target node of the edge.
Array< TCost > m_bestSolution
value of best solution for block
int computeSTNumbering(const Graph &G, NodeArray< int > &numbering, node s=nullptr, node t=nullptr, bool randomized=false)
Computes an st-Numbering of G.
ReturnType
The return type of a module.
edge newEdge(node v, node w, int index=-1)
Creates a new edge (v,w) and returns it.
Class for the representation of nodes.
Declaration of class PlanarLeafKey.
void runs(int nRuns)
Sets the number of randomized runs to nRuns.
virtual void emptyAllPertinentNodes()
Does a clean up after a reduction.
Declaration of simple graph algorithms.
SListIterator< E > pushBack(const E &x)
Adds element x at the end of the list.
iterator pushBack(const E &x)
Adds element x at the end of the list.
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
void clear()
Removes all elements from the list.
virtual PlanarSubgraphFast * clone() const override
Returns a new instance of fast planar subgraph with the same option settings.
void parCall(const Array< BlockType > &block, const EdgeArray< TCost > *pCost, int nRuns, unsigned int nThreads, List< edge > &delEdges)
Realizes the parallel implementation.
static void planarize(const Graph &G, NodeArray< int > &numbering, List< edge > &delEdges)
Performs a planarization on a biconnected component of G.