Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

MinSTCutDijkstra.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/GraphCopy.h>
35 #include <ogdf/graphalg/Dijkstra.h>
36 #include <ogdf/basic/DualGraph.h>
39 
40 namespace ogdf {
41 
49 template<typename TCost>
50 class MinSTCutDijkstra : public MinSTCutModule<TCost> {
51 public:
53 
57  virtual bool
58  call(const Graph &graph, const EdgeArray<TCost> &weight, node s, node t, List<edge> &edgeList, edge e_st = nullptr) override;
59 
63  virtual bool call(const Graph &graph, node s, node t, List<edge> &edgeList, edge e_st = nullptr) override {
64  EdgeArray<TCost> weight(graph, 1);
65  return call(graph, weight, s, t, edgeList, e_st);
66  }
67 
69 };
70 
71 template<typename TCost>
72 bool MinSTCutDijkstra<TCost>::call(const Graph &graph, const EdgeArray<TCost> &weight,
73  node s, node t, List<edge> &edgeList, edge e_st) {
74  delete m_gc;
75  m_gc = new GraphCopy(graph);
77 
78  MinSTCutModule<TCost>::preprocessingDual(graph, *m_gc, CE, s, t, e_st);
79 
81 
82  DualGraph dual(CE);
83  if (e_st != nullptr) {
84  e_st = m_gc->copy(e_st);
85  } else {
86  e_st = m_gc->searchEdge(m_gc->copy(s), m_gc->copy(t));
87  }
88  edgeList.clear();
89  node source = dual.dualNode(CE.rightFace(e_st->adjSource()));
90  node target = dual.dualNode(CE.leftFace(e_st->adjSource()));
91 
92 
93  EdgeArray<TCost> weightDual(dual, 0);
94  TCost sumOfWeights(0);
95  for (edge e : m_gc->edges) {
96  if (e != e_st) {
97  weightDual[dual.dualEdge(e)] = weight[m_gc->original(e)];
98  sumOfWeights += weightDual[dual.dualEdge(e)];
99  OGDF_ASSERT(sumOfWeights > sumOfWeights - weightDual[dual.dualEdge(e)]);
100  }
101  }
102  weightDual[dual.dualEdge(e_st)] = sumOfWeights + 1;
103  List<node> sourceNodeList;
104  sourceNodeList.pushFront(source);
105  NodeArray<edge> prevEdge(dual);
106  NodeArray<TCost> distance(dual);
107  Dijkstra<TCost> D;
108  D.call(dual, weightDual, sourceNodeList, prevEdge, distance);
109 
110  node v = target;
111  do {
112  edge eDual = prevEdge[v];
113  OGDF_ASSERT(eDual != nullptr);
114  edge eG = dual.primalEdge(eDual);
115  OGDF_ASSERT(eG != nullptr);
116  edgeList.pushBack(m_gc->original(eG));
118  v = (v == eDual->target() ? eDual->source() : eDual->target());
119  } while (v != source);
120  return true;
121 }
122 }
node target() const
Returns the target node of the edge.
Definition: Graph_d.h:328
void clear()
Removes all elements from the list.
Definition: List.h:1451
virtual bool call(const Graph &graph, const EdgeArray< TCost > &weight, node s, node t, List< edge > &edgeList, edge e_st=nullptr) override
The actual algorithm call.
Min-st-cut algorithm, that calculates the cut by calculating the shortest path between the faces adja...
node copy(node v) const
Returns the node in the graph copy corresponding to v.
Definition: GraphCopy.h:335
Includes declaration of dual graph class.
Dijkstra&#39;s single source shortest path algorithm.
Definition: Dijkstra.h:52
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition: List.h:1373
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:492
adjEntry adjSource() const
Returns the corresponding adjacancy entry at source node.
Definition: Graph_d.h:333
void call(const Graph &G, const EdgeArray< T > &weight, const List< node > &sources, NodeArray< edge > &predecessor, NodeArray< T > &distance, bool directed=false)
Calculates, based on the graph G with corresponding edge costs and source nodes, the shortest paths a...
Definition: Dijkstra.h:61
face rightFace(adjEntry adj) const
Returns the face to the right of adj, i.e., the face containing adj.
edge searchEdge(node v, node w, bool directed=false) const
Searches and returns an edge connecting nodes v and w in time O( min(deg(v ), deg(w )))...
bool preprocessingDual(const Graph &graph, GraphCopy &gc, CombinatorialEmbedding &CE, node source, node target, edge e_st)
This method preprocesses gc for minstcut calculations, by adding an st-edge if needed and embedding g...
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
Definition: Graph_d.h:568
Dynamic arrays indexed with nodes.
Definition: Graph_d.h:438
Implementation of Dijkstra&#39;s single source shortest path algorithm.
iterator pushFront(const E &x)
Adds element x at the beginning of the list.
Definition: List.h:1360
Declaration of graph copy classes.
virtual bool call(const Graph &graph, node s, node t, List< edge > &edgeList, edge e_st=nullptr) override
The actual algorithm call.
Class for the representation of edges.
Definition: Graph_d.h:292
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:249
Class for the representation of nodes.
Definition: Graph_d.h:169
const edge & primalEdge(edge e) const
Returns the edge in the primal graph corresponding to e.
Definition: DualGraph.h:72
const Graph & original() const
Returns a reference to the original graph.
Definition: GraphCopy.h:286
const node & dualNode(face f) const
Returns the node in the dual graph corresponding to f.
Definition: DualGraph.h:86
A dual graph including its combinatorial embedding of an embedded graph.
Definition: DualGraph.h:48
const edge & dualEdge(edge e) const
Returns the edge in the dual graph corresponding to e.
Definition: DualGraph.h:93
face leftFace(adjEntry adj) const
Returns the face to the left of adj, i.e., the face containing the twin of adj.
node source() const
Returns the source node of the edge.
Definition: Graph_d.h:326
The namespace for all OGDF objects.
Declaration of extended graph algorithms.
Template of base class of min-st-cut algorithms.
Combinatorial embeddings of planar graphs with modification functionality.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:41