Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

MinSTCutDijkstra.h
Go to the documentation of this file.
1 
33 #pragma once
34 
35 #include <ogdf/basic/GraphCopy.h>
36 #include <ogdf/graphalg/Dijkstra.h>
37 #include <ogdf/basic/DualGraph.h>
40 
41 namespace ogdf {
42 
50 template<typename TCost>
51 class MinSTCutDijkstra : public MinSTCutModule<TCost> {
52 public:
54 
58  virtual bool
59  call(const Graph &graph, const EdgeArray<TCost> &weight, node s, node t, List<edge> &edgeList, edge e_st) override;
60 
64  virtual bool call(const Graph &graph, node s, node t, List<edge> &edgeList, edge e_st) override {
65  EdgeArray<TCost> weight(graph, 1);
66  return call(graph, weight, s, t, edgeList, e_st);
67  }
68 
70 };
71 
72 template<typename TCost>
73 bool MinSTCutDijkstra<TCost>::call(const Graph &graph, const EdgeArray<TCost> &weight,
74  node s, node t, List<edge> &edgeList, edge e_st) {
75  delete m_gc;
76  m_gc = new GraphCopy(graph);
78 
79  MinSTCutModule<TCost>::preprocessingDual(graph, *m_gc, CE, s, t, e_st);
80 
82 
83  DualGraph dual(CE);
84  if (e_st != nullptr) {
85  e_st = m_gc->copy(e_st);
86  } else {
87  e_st = m_gc->searchEdge(m_gc->copy(s), m_gc->copy(t));
88  }
89  edgeList.clear();
90  node source = dual.dualNode(CE.rightFace(e_st->adjSource()));
91  node target = dual.dualNode(CE.leftFace(e_st->adjSource()));
92 
93 
94  EdgeArray<TCost> weightDual(dual, 0);
95  TCost sumOfWeights(0);
96  for (edge e : m_gc->edges) {
97  if (e != e_st) {
98  weightDual[dual.dualEdge(e)] = weight[m_gc->original(e)];
99  sumOfWeights += weightDual[dual.dualEdge(e)];
100  OGDF_ASSERT(sumOfWeights > sumOfWeights - weightDual[dual.dualEdge(e)]);
101  }
102  }
103  weightDual[dual.dualEdge(e_st)] = sumOfWeights + 1;
104  List<node> sourceNodeList;
105  sourceNodeList.pushFront(source);
106  NodeArray<edge> prevEdge(dual);
107  NodeArray<TCost> distance(dual);
108  Dijkstra<TCost> D;
109  D.call(dual, weightDual, sourceNodeList, prevEdge, distance);
110 
111  node v = target;
112  do {
113  edge eDual = prevEdge[v];
114  OGDF_ASSERT(eDual != nullptr);
115  edge eG = dual.primalEdge(eDual);
116  OGDF_ASSERT(eG != nullptr);
117  edgeList.pushBack(m_gc->original(eG));
119  v = (v == eDual->target() ? eDual->source() : eDual->target());
120  } while (v != source);
121  return true;
122 }
123 }
node target() const
Returns the target node of the edge.
Definition: Graph_d.h:327
void clear()
Removes all elements from the list.
Definition: List.h:1394
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:336
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: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 )))...
adjEntry adjSource() const
Returns the corresponding adjacancy entry at source node.
Definition: Graph_d.h:330
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.
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:548
Dynamic arrays indexed with nodes.
Definition: Graph_d.h:423
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:1303
Declaration of graph copy classes.
Class for the representation of edges.
Definition: Graph_d.h:291
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:250
Class for the representation of nodes.
Definition: Graph_d.h:167
const edge & primalEdge(edge e) const
Returns the edge in the primal graph corresponding to e.
Definition: DualGraph.h:72
virtual bool call(const Graph &graph, const EdgeArray< TCost > &weight, node s, node t, List< edge > &edgeList, edge e_st) override
The actual algorithm call.
const Graph & original() const
Returns a reference to the original graph.
Definition: GraphCopy.h:287
const node & dualNode(face f) const
Returns the node in the dual graph corresponding to f.
Definition: DualGraph.h:86
virtual bool call(const Graph &graph, node s, node t, List< edge > &edgeList, edge e_st) override
The actual algorithm call.
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:325
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