Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

MinSTCutDijkstra.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/DualGraph.h>
35 #include <ogdf/basic/GraphCopy.h>
37 #include <ogdf/graphalg/Dijkstra.h>
39 
40 namespace ogdf {
41 
51 template<typename TCost>
52 class MinSTCutDijkstra : public MinSTCutModule<TCost> {
53 public:
55 
59  virtual bool call(const Graph& graph, const EdgeArray<TCost>& weight, node s, node t,
60  List<edge>& edgeList, edge e_st = nullptr) override;
61 
65  virtual bool call(const Graph& graph, node s, node t, List<edge>& edgeList,
66  edge e_st = nullptr) override {
67  EdgeArray<TCost> weight(graph, 1);
68  return call(graph, weight, s, t, edgeList, e_st);
69  }
70 
72 };
73 
74 template<typename TCost>
75 bool MinSTCutDijkstra<TCost>::call(const Graph& graph, const EdgeArray<TCost>& weight, node s,
76  node t, List<edge>& edgeList, edge e_st) {
77  delete m_gc;
78  m_gc = new GraphCopy(graph);
80 
81  MinSTCutModule<TCost>::preprocessingDual(graph, *m_gc, CE, s, t, e_st);
82 
84 
85  DualGraph dual(CE);
86  if (e_st != nullptr) {
87  e_st = m_gc->copy(e_st);
88  } else {
89  e_st = m_gc->searchEdge(m_gc->copy(s), m_gc->copy(t));
90  }
91  edgeList.clear();
92  node source = dual.dualNode(CE.rightFace(e_st->adjSource()));
93  node target = dual.dualNode(CE.leftFace(e_st->adjSource()));
94 
95 
96  EdgeArray<TCost> weightDual(dual, 0);
97  TCost sumOfWeights(0);
98  for (edge e : m_gc->edges) {
99  if (e != e_st) {
100  weightDual[dual.dualEdge(e)] = weight[m_gc->original(e)];
101  sumOfWeights += weightDual[dual.dualEdge(e)];
102  OGDF_ASSERT(sumOfWeights > sumOfWeights - weightDual[dual.dualEdge(e)]);
103  }
104  }
105  weightDual[dual.dualEdge(e_st)] = sumOfWeights + 1;
106  List<node> sourceNodeList;
107  sourceNodeList.pushFront(source);
108  NodeArray<edge> prevEdge(dual);
109  NodeArray<TCost> distance(dual);
110  Dijkstra<TCost> D;
111  D.call(dual, weightDual, sourceNodeList, prevEdge, distance);
112 
113  node v = target;
114  do {
115  edge eDual = prevEdge[v];
116  OGDF_ASSERT(eDual != nullptr);
117  edge eG = dual.primalEdge(eDual);
118  OGDF_ASSERT(eG != nullptr);
119  edgeList.pushBack(m_gc->original(eG));
120  MinSTCutModule<TCost>::m_direction[m_gc->original(eG)] = eDual->target() != v;
121  v = (v == eDual->target() ? eDual->source() : eDual->target());
122  } while (v != source);
123  return true;
124 }
125 }
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:54
ogdf::DualGraphBase
A dual graph including its combinatorial embedding of an embedded graph.
Definition: DualGraph.h:42
ogdf::MinSTCutModule::preprocessingDual
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...
Definition: MinSTCutModule.h:108
ogdf::ConstCombinatorialEmbedding::leftFace
face leftFace(adjEntry adj) const
Returns the face to the left of adj, i.e., the face containing the twin of adj.
Definition: CombinatorialEmbedding.h:276
extended_graph_alg.h
Declaration of extended graph algorithms.
ogdf::ConstCombinatorialEmbedding::rightFace
face rightFace(adjEntry adj) const
Returns the face to the right of adj, i.e., the face containing adj.
Definition: CombinatorialEmbedding.h:270
ogdf::GraphCopy
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:384
ogdf::MinSTCutDijkstra::call
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.
Definition: MinSTCutDijkstra.h:75
ogdf::Dijkstra
Dijkstra's single source shortest path algorithm.
Definition: Dijkstra.h:53
ogdf::List::pushFront
iterator pushFront(const E &x)
Adds element x at the beginning of the list.
Definition: List.h:1524
ogdf::MinSTCutModule
Definition: MinSTCutModule.h:40
ogdf::Dijkstra::call
void call(const Graph &G, const EdgeArray< T > &weight, const List< node > &sources, NodeArray< edge > &predecessor, NodeArray< T > &distance, bool directed=false, bool arcsReversed=false, node target=nullptr, T maxLength=std::numeric_limits< T >::max())
Calculates, based on the graph G with corresponding edge costs and source nodes, the shortest paths a...
Definition: Dijkstra.h:246
DualGraph.h
Includes declaration of dual graph class.
ogdf::EdgeElement::source
node source() const
Returns the source node of the edge.
Definition: Graph_d.h:391
GraphCopy.h
Declaration of graph copy classes.
ogdf::List< edge >
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:651
ogdf::EdgeElement::adjSource
adjEntry adjSource() const
Returns the corresponding adjacancy entry at source node.
Definition: Graph_d.h:400
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:862
ogdf::MinSTCutDijkstra::MinSTCutDijkstra
MinSTCutDijkstra()
Definition: MinSTCutDijkstra.h:54
ogdf::MinSTCutDijkstra
Min-st-cut algorithm, that calculates the cut by calculating the shortest path between the faces adja...
Definition: MinSTCutDijkstra.h:52
ogdf::DualGraphBase::dualEdge
const edge & dualEdge(edge e) const
Returns the edge in the dual graph corresponding to e.
Definition: DualGraph.h:177
ogdf::DualGraphBase::primalEdge
const edge & primalEdge(edge e) const
Returns the edge in the primal graph corresponding to e.
Definition: DualGraph.h:156
ogdf::CombinatorialEmbedding
Combinatorial embeddings of planar graphs with modification functionality.
Definition: CombinatorialEmbedding.h:397
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:356
Dijkstra.h
Implementation of Dijkstra's single source shortest path algorithm.
ogdf::EdgeElement::target
node target() const
Returns the target node of the edge.
Definition: Graph_d.h:394
ogdf::DualGraphBase::dualNode
const node & dualNode(face f) const
Returns the node in the dual graph corresponding to f.
Definition: DualGraph.h:170
MinSTCutModule.h
Template of base class of min-st-cut algorithms.
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:233
ogdf::MinSTCutDijkstra::call
virtual bool call(const Graph &graph, node s, node t, List< edge > &edgeList, edge e_st=nullptr) override
The actual algorithm call.
Definition: MinSTCutDijkstra.h:65
ogdf::List::pushBack
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition: List.h:1537
ogdf::internal::EdgeArrayBase2
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition: Graph_d.h:709
ogdf::List::clear
void clear()
Removes all elements from the list.
Definition: List.h:1616