Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

CrossingMinimizationModule.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/Graph.h>
35 #include <ogdf/basic/GraphCopy.h>
36 #include <ogdf/basic/GraphList.h>
37 #include <ogdf/basic/Module.h>
38 #include <ogdf/basic/Timeouter.h>
39 #include <ogdf/basic/basic.h>
40 #include <ogdf/basic/memory.h>
41 
42 #include <cstdint>
43 
44 namespace ogdf {
45 class PlanRep;
46 
49 public:
52 
55 
58 
60  virtual CrossingMinimizationModule* clone() const = 0;
61 
63 
77  ReturnType call(PlanRep& pr, int cc, int& crossingNumber,
78  const EdgeArray<int>* pCostOrig = nullptr,
79  const EdgeArray<bool>* pForbiddenOrig = nullptr,
80  const EdgeArray<uint32_t>* pEdgeSubGraphs = nullptr) {
81  return doCall(pr, cc, pCostOrig, pForbiddenOrig, pEdgeSubGraphs, crossingNumber);
82  }
83 
85 
99  ReturnType operator()(PlanRep& pr, int cc, int& crossingNumber,
100  const EdgeArray<int>* pCostOrig = nullptr,
101  const EdgeArray<bool>* pForbiddenOrig = nullptr,
102  const EdgeArray<uint32_t>* pEdgeSubGraphs = nullptr) {
103  return call(pr, cc, crossingNumber, pCostOrig, pForbiddenOrig, pEdgeSubGraphs);
104  }
105 
106 protected:
108 
122  virtual ReturnType doCall(PlanRep& pr, int cc, const EdgeArray<int>* pCostOrig,
123  const EdgeArray<bool>* pForbiddenOrig, const EdgeArray<uint32_t>* pEdgeSubGraphs,
124  int& crossingNumber) = 0;
125 
136  static int computeCrossingNumber(GraphCopy& graphCopy, const EdgeArray<int>* pCost,
137  const EdgeArray<uint32_t>* pEdgeSubGraphs) {
138  if (pCost == nullptr) {
139  return graphCopy.numberOfNodes() - graphCopy.original().numberOfNodes();
140  } else {
141  int crossingNumber = 0;
142  for (node v : graphCopy.nodes) {
143  if (graphCopy.isDummy(v)) {
144  // Dummy node (crossing) found, calculate its cost.
145  edge e1 = graphCopy.original(v->firstAdj()->theEdge());
146  edge e2 = graphCopy.original(v->lastAdj()->theEdge());
147  if (pEdgeSubGraphs != nullptr) {
148  int subgraphCounter = 0;
149  for (int i = 0; i < 32; i++) {
150  if (((*pEdgeSubGraphs)[e1] & (1 << i)) != 0
151  && ((*pEdgeSubGraphs)[e2] & (1 << i)) != 0) {
152  subgraphCounter++;
153  }
154  }
155  crossingNumber += (subgraphCounter * (*pCost)[e1] * (*pCost)[e2]);
156  } else {
157  crossingNumber += (*pCost)[e1] * (*pCost)[e2];
158  }
159  }
160  }
161  return crossingNumber;
162  }
163  }
164 
166 };
167 
168 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
Graph.h
Includes declaration of graph class.
ogdf::PlanRep
Planarized representations (of a connected component) of a graph.
Definition: PlanRep.h:69
ogdf::CrossingMinimizationModule
Base class for crossing minimization algorithms.
Definition: CrossingMinimizationModule.h:48
ogdf::NodeElement::lastAdj
adjEntry lastAdj() const
Returns the last entry in the adjacency list.
Definition: Graph_d.h:289
ogdf::GraphCopyBase::isDummy
bool isDummy(node v) const
Returns true iff v has no corresponding node in the original graph.
Definition: GraphCopy.h:173
ogdf::GraphCopy
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:391
Timeouter.h
Declares base class for modules with timeout functionality.
ogdf::CrossingMinimizationModule::operator()
ReturnType operator()(PlanRep &pr, int cc, int &crossingNumber, const EdgeArray< int > *pCostOrig=nullptr, const EdgeArray< bool > *pForbiddenOrig=nullptr, const EdgeArray< uint32_t > *pEdgeSubGraphs=nullptr)
Computes a planarized representation of the input graph.
Definition: CrossingMinimizationModule.h:99
ogdf::AdjElement::theEdge
edge theEdge() const
Returns the edge associated with this adjacency entry.
Definition: Graph_d.h:160
ogdf::Graph::nodes
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
Definition: Graph_d.h:932
OGDF_MALLOC_NEW_DELETE
#define OGDF_MALLOC_NEW_DELETE
Makes the class use malloc for memory allocation.
Definition: memory.h:92
ogdf::Graph::numberOfNodes
int numberOfNodes() const
Returns the number of nodes in the graph.
Definition: Graph_d.h:982
ogdf::Module
Base class for modules.
Definition: Module.h:49
GraphList.h
Decralation of GraphElement and GraphList classes.
GraphCopy.h
Declaration of graph copy classes.
ogdf::CrossingMinimizationModule::computeCrossingNumber
static int computeCrossingNumber(GraphCopy &graphCopy, const EdgeArray< int > *pCost, const EdgeArray< uint32_t > *pEdgeSubGraphs)
Computes the (weighted) crossing number of the planarization graphCopy.
Definition: CrossingMinimizationModule.h:136
ogdf::CrossingMinimizationModule::call
ReturnType call(PlanRep &pr, int cc, int &crossingNumber, const EdgeArray< int > *pCostOrig=nullptr, const EdgeArray< bool > *pForbiddenOrig=nullptr, const EdgeArray< uint32_t > *pEdgeSubGraphs=nullptr)
Computes a planarized representation of the input graph.
Definition: CrossingMinimizationModule.h:77
ogdf::CrossingMinimizationModule::CrossingMinimizationModule
CrossingMinimizationModule()
Initializes a crossing minimization module (default constructor).
Definition: CrossingMinimizationModule.h:51
basic.h
Basic declarations, included by all source files.
OGDF_EXPORT
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:101
ogdf::NodeElement::firstAdj
adjEntry firstAdj() const
Returns the first entry in the adjaceny list.
Definition: Graph_d.h:286
ogdf::CrossingMinimizationModule::CrossingMinimizationModule
CrossingMinimizationModule(const CrossingMinimizationModule &cmm)
Initializes an crossing minimization module (copy constructor).
Definition: CrossingMinimizationModule.h:54
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:363
ogdf::CrossingMinimizationModule::~CrossingMinimizationModule
virtual ~CrossingMinimizationModule()
Destructor.
Definition: CrossingMinimizationModule.h:57
ogdf::Timeouter
class for timeout funtionality.
Definition: Timeouter.h:46
Module.h
Declares base class for all module types.
ogdf::Module::ReturnType
ReturnType
The return type of a module.
Definition: Module.h:52
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:240
memory.h
Declaration of memory manager for allocating small pieces of memory.
ogdf::GraphCopyBase::original
const Graph & original() const
Returns a reference to the original graph.
Definition: GraphCopy.h:105
ogdf::internal::EdgeArrayBase2
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition: Graph_d.h:716