Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
MinSTCutDijkstra.h
Go to the documentation of this file.
1
32#pragma once
33
36#include <ogdf/basic/Graph.h>
38#include <ogdf/basic/List.h>
39#include <ogdf/basic/basic.h>
42
43namespace ogdf {
44
54template<typename TCost>
55class MinSTCutDijkstra : public MinSTCutModule<TCost> {
56public:
58
62 virtual bool call(const Graph& graph, const EdgeArray<TCost>& weight, node s, node t,
63 List<edge>& edgeList, edge e_st = nullptr) override;
64
68 virtual bool call(const Graph& graph, node s, node t, List<edge>& edgeList,
69 edge e_st = nullptr) override {
70 EdgeArray<TCost> weight(graph, 1);
71 return call(graph, weight, s, t, edgeList, e_st);
72 }
73
74 using MinSTCutModule<TCost>::m_gc;
75};
76
77template<typename TCost>
78bool MinSTCutDijkstra<TCost>::call(const Graph& graph, const EdgeArray<TCost>& weight, node s,
79 node t, List<edge>& edgeList, edge e_st) {
80 delete m_gc;
81 m_gc = new GraphCopy(graph);
83
84 MinSTCutModule<TCost>::preprocessingDual(graph, *m_gc, CE, s, t, e_st);
85
87
88 DualGraph dual(CE);
89 if (e_st != nullptr) {
90 e_st = m_gc->copy(e_st);
91 } else {
92 e_st = m_gc->searchEdge(m_gc->copy(s), m_gc->copy(t));
93 }
94 edgeList.clear();
95 node source = dual.dualNode(CE.rightFace(e_st->adjSource()));
96 node target = dual.dualNode(CE.leftFace(e_st->adjSource()));
97
98
99 EdgeArray<TCost> weightDual(dual, 0);
100 TCost sumOfWeights(0);
101 for (edge e : m_gc->edges) {
102 if (e != e_st) {
103 weightDual[dual.dualEdge(e)] = weight[m_gc->original(e)];
104 sumOfWeights += weightDual[dual.dualEdge(e)];
105 OGDF_ASSERT(sumOfWeights > sumOfWeights - weightDual[dual.dualEdge(e)]);
106 }
107 }
108 weightDual[dual.dualEdge(e_st)] = sumOfWeights + 1;
109 List<node> sourceNodeList;
110 sourceNodeList.pushFront(source);
111 NodeArray<edge> prevEdge(dual);
112 NodeArray<TCost> distance(dual);
114 D.call(dual, weightDual, sourceNodeList, prevEdge, distance);
115
116 node v = target;
117 do {
118 edge eDual = prevEdge[v];
119 OGDF_ASSERT(eDual != nullptr);
120 edge eG = dual.primalEdge(eDual);
121 OGDF_ASSERT(eG != nullptr);
122 edgeList.pushBack(m_gc->original(eG));
123 MinSTCutModule<TCost>::m_direction[m_gc->original(eG)] = eDual->target() != v;
124 v = (v == eDual->target() ? eDual->source() : eDual->target());
125 } while (v != source);
126 return true;
127}
128}
Declaration of CombinatorialEmbedding and face.
Includes declaration of dual graph class.
Includes declaration of graph class.
Declaration of graph copy classes.
Declaration of doubly linked lists and iterators.
Template of base class of min-st-cut algorithms.
Basic declarations, included by all source files.
Combinatorial embeddings of planar graphs with modification functionality.
face rightFace(adjEntry adj) const
Returns the face to the right of adj, i.e., the face containing adj.
face leftFace(adjEntry adj) const
Returns the face to the left of adj, i.e., the face containing the twin of adj.
Dijkstra's single source shortest path algorithm.
Definition Dijkstra.h:60
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:253
A dual graph including its combinatorial embedding of an embedded graph.
Definition DualGraph.h:61
const edge & primalEdge(edge e) const
Returns the edge in the primal graph corresponding to e.
Definition DualGraph.h:161
const node & dualNode(face f) const
Returns the node in the dual graph corresponding to f.
Definition DualGraph.h:175
const edge & dualEdge(edge e) const
Returns the edge in the dual graph corresponding to e.
Definition DualGraph.h:182
Class for the representation of edges.
Definition Graph_d.h:364
adjEntry adjSource() const
Returns the corresponding adjacancy entry at source node.
Definition Graph_d.h:408
node target() const
Returns the target node of the edge.
Definition Graph_d.h:402
node source() const
Returns the source node of the edge.
Definition Graph_d.h:399
Copies of graphs supporting edge splitting.
Definition GraphCopy.h:390
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:866
Doubly linked lists (maintaining the length of the list).
Definition List.h:1451
void clear()
Removes all elements from the list.
Definition List.h:1626
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition List.h:1547
iterator pushFront(const E &x)
Adds element x at the beginning of the list.
Definition List.h:1534
Min-st-cut algorithm, that calculates the cut by calculating the shortest path between the faces adja...
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.
virtual bool call(const Graph &graph, node s, node t, List< edge > &edgeList, edge e_st=nullptr) override
The actual algorithm call.
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...
Class for the representation of nodes.
Definition Graph_d.h:241
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition Graph_d.h:717
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition Graph_d.h:659
Implementation of Dijkstra's single source shortest path algorithm.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:52
The namespace for all OGDF objects.