Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

PlanarSubgraphCactus.h
Go to the documentation of this file.
1 
32 #pragma once
33 
37 
38 namespace ogdf {
39 
41 
48 template<typename TCost>
50 {
51 public:
52  virtual PlanarSubgraphCactus *clone() const override {
53  return new PlanarSubgraphCactus();
54  }
55 
56 protected:
58  const Graph &graph,
59  const List<edge> &,
60  List<edge> &delEdges,
61  const EdgeArray<TCost> *pCost,
62  bool preferedImplyPlanar) override
63  {
64  OGDF_ASSERT(isConnected(graph));
66 
67  delEdges.clear();
68  GraphCopy copy(graph);
69  DisjointSets<> components(copy.numberOfNodes());
70  NodeArray<int> id(copy);
71  for (node v : copy.nodes) {
72  id[v] = components.makeSet();
73  }
74 
75  EdgeArray<bool> includeEdge(copy, false);
76 
77  List<edge> edges;
78  copy.allEdges(edges);
79 
80  // sort weighted edges
81  if(pCost != nullptr) {
82  EdgeComparer edgeCmp(copy, *pCost);
83  AdjEntryComparer adjCmp(edgeCmp);
84  edges.quicksort(edgeCmp);
85 
86  for(node v : copy.nodes) {
87  List<adjEntry> newOrder;
88  v->allAdjEntries(newOrder);
89  newOrder.quicksort(adjCmp);
90  copy.sort(v, newOrder);
91  }
92  }
93 
94  // select triangles
95  for (edge e : edges) {
96  node s = e->source();
97  node t = e->target();
98  int setS = components.find(id[s]);
99  int setT = components.find(id[t]);
100 
101  if(setS != setT) {
102  for(adjEntry adj : s->adjEntries) {
103  edge f = adj->theEdge();
104  node v = f->opposite(s);
105  int setV = components.find(id[v]);
106 
107  if(setV != setS && setV != setT) {
108  edge g = copy.searchEdge(v, t);
109 
110  if(g != nullptr) {
111  includeEdge[e] = includeEdge[f] = includeEdge[g] = true;
112  components.link(components.link(setS, setT), setV);
113  break;
114  }
115  }
116  }
117  }
118  }
119 
120  // connect the subgraph and store the result
121  for(edge e : edges) {
122  int setS = components.find(id[e->source()]);
123  int setT = components.find(id[e->target()]);
124 
125  if(setS != setT) {
126  includeEdge[e] = true;
127  components.link(setS, setT);
128  }
129 
130  if(!includeEdge[e]) {
131  delEdges.pushBack(copy.original(e));
132  }
133  }
134 
136  }
137 
138 private:
139  class EdgeComparer {
140  private:
143  public:
144  EdgeComparer(const GraphCopy &copy, const EdgeArray<TCost> &weight) : m_copy(copy), m_weight(weight) { }
145 
146  bool less(const edge &e, const edge &f) const {
147  return m_weight[m_copy.original(e)] < m_weight[m_copy.original(f)];
148  }
149  };
150 
152  private:
154  public:
155  explicit AdjEntryComparer(const EdgeComparer &edgeComparer) : m_edgeComparer(edgeComparer) { }
156 
157  bool less(adjEntry adjA, adjEntry adjB) const {
158  return m_edgeComparer.less(adjA->theEdge(), adjB->theEdge());
159  }
160 
161  };
162 };
163 
164 }
void clear()
Removes all elements from the list.
Definition: List.h:1394
EdgeComparer(const GraphCopy &copy, const EdgeArray< TCost > &weight)
edge theEdge() const
Returns the edge associated with this adjacency entry.
Definition: Graph_d.h:95
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition: List.h:1316
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:472
edge searchEdge(node v, node w) const
Searches and returns an edge connecting nodes v and w in time O( min(deg(v ), deg(w )))...
void sort(node v, const ADJ_ENTRY_LIST &newOrder)
Sorts the adjacency list of node v according to newOrder.
Definition: Graph_d.h:1019
virtual PlanarSubgraphCactus * clone() const override
Returns a new instance of the planar subgraph module with the same option settings.
ReturnType
The return type of a module.
Definition: Module.h:51
virtual Module::ReturnType doCall(const Graph &graph, const List< edge > &, List< edge > &delEdges, const EdgeArray< TCost > *pCost, bool preferedImplyPlanar) override
Computes the set of edges delEdges which have to be deleted to obtain the planar subgraph.
void quicksort()
Sorts the list using Quicksort.
Definition: List.h:1097
const EdgeComparer & m_edgeComparer
Interface for planar subgraph algorithms.
static void copy(const T &from, T &to)
Definition: Alg.h:61
The solution is feasible.
A Union/Find data structure for maintaining disjoint sets.
Definition: DisjointSets.h:81
Class for the representation of edges.
Definition: Graph_d.h:291
void allEdges(EDGELIST &edgeList) const
Returns a list with all edges of the graph.
Definition: Graph_d.h:643
void allAdjEntries(ADJLIST &adjList) const
Returns a list with all adjacency entries of this node.
Definition: Graph_d.h:226
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:250
AdjEntryComparer(const EdgeComparer &edgeComparer)
Class for the representation of nodes.
Definition: Graph_d.h:167
node opposite(node v) const
Returns the adjacent node different from v.
Definition: Graph_d.h:335
const Graph & original() const
Returns a reference to the original graph.
Definition: GraphCopy.h:287
bool isSimpleUndirected(const Graph &G)
Returns true iff G contains neither self-loops nor undirected parallel edges.
Maximum planar subgraph approximation algorithm by Calinescu et al.
bool less(adjEntry adjA, adjEntry adjB) const
bool less(const edge &e, const edge &f) const
Declaration of simple graph algorithms.
Implementation of disjoint sets data structures (union-find functionality).
The namespace for all OGDF objects.
Declaration of interface for planar subgraph algorithms.
int numberOfNodes() const
Returns the number of nodes in the graph.
Definition: Graph_d.h:578
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
Definition: Graph_d.h:545
bool isConnected(const Graph &G)
Returns true iff G is connected.
Class for adjacency list elements.
Definition: Graph_d.h:78
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:41