Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

MaxFlowSTPlanarDigraph.h
Go to the documentation of this file.
1 
34 #pragma once
35 
36 #include <ogdf/basic/DualGraph.h>
39 #include <ogdf/graphalg/Dijkstra.h>
41 
42 namespace ogdf {
43 
45 
48 template<typename TCap>
49 class MaxFlowSTPlanarDigraph : public MaxFlowModule<TCap> {
50 private:
52  void createBackArcs(Graph& gr, EdgeArray<TCap>& new_costs) {
53  // gr = dg.
54  for (edge e = gr.lastEdge(); e != nullptr; e = e->pred()) {
55  edge e_new_dg = gr.newEdge(e->target(), e->source());
56  new_costs[e_new_dg] = 0;
57  }
58  }
59 
60 public:
68  TCap computeValue(const EdgeArray<TCap>& cap, const node& s, const node& t) override {
69  // clear old flow
70  (*this->m_flow).fill(0);
71  // store capacity, source and sink
72  this->m_cap = &cap;
73  this->m_s = &s;
74  this->m_t = &t;
76 
77  OGDF_ASSERT(isSTPlanar(*this->m_G, s, t));
78  GraphCopy copyG(*this->m_G);
79  node copyS = copyG.copy(s);
80  node copyT = copyG.copy(t);
81  CombinatorialEmbedding ce(copyG);
82  adjEntry adjAtTarget;
83  adjEntry adjAtSource = ce.findCommonFace(copyS, copyT, adjAtTarget, false);
84  face f_infty = ce.rightFace(adjAtSource);
85  ce.setExternalFace(f_infty);
86 
87  // split the external face
88  edge ts_edge = ce.splitFace(adjAtTarget, adjAtSource);
89  DualGraph dg(ce);
90 
91  EdgeArray<TCap> costs(dg, 0);
92  for (edge e : (*this->m_G).edges) {
93  costs[dg.dualEdge(copyG.copy(e))] = cap[e];
94  }
95  createBackArcs(dg, costs);
96  costs[dg.dualEdge(ts_edge)] = std::numeric_limits<TCap>::max();
97 
98  Dijkstra<TCap> dij;
99  NodeArray<edge> preds(dg, nullptr);
100  NodeArray<TCap> dists(dg, 0);
101  dij.call(dg, costs, dg.dualNode(f_infty), preds, dists, true); // directed
102 
103  for (edge e : (*this->m_G).edges) {
104  (*this->m_flow)[e] = dists[dg.dualNode(ce.leftFace(copyG.copy(e)->adjSource()))]
105  - dists[dg.dualNode(ce.rightFace(copyG.copy(e)->adjSource()))];
106  }
107 
108  // compute flow value
109  TCap flowValue = 0;
110  for (adjEntry adj : s->adjEntries) {
111  edge e = adj->theEdge();
112  if (e->source() == s) {
113  flowValue += (*this->m_flow)[e];
114  } else {
115  flowValue -= (*this->m_flow)[e];
116  }
117  }
118  return flowValue;
119  }
120 
123  void computeFlowAfterValue() override { /* nothing to do here */
124  }
125 
126  void init(const Graph& graph, EdgeArray<TCap>* flow = nullptr) override {
127  OGDF_ASSERT(isConnected(graph));
128  OGDF_ASSERT(isPlanar(graph));
129  MaxFlowModule<TCap>::init(graph, flow);
130  }
131 
132  // use methods from super class
137 };
138 
139 }
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
ogdf::MaxFlowModule< TCap >::isFeasibleInstance
bool isFeasibleInstance() const
Return whether the instance is feasible, i.e. the capacities are non-negative.
Definition: MaxFlowModule.h:147
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:54
MaxFlowModule.h
Interface for Max Flow Algorithms.
ogdf::ConstCombinatorialEmbedding::findCommonFace
adjEntry findCommonFace(const node v, const node w, bool left=true) const
Identifies a common face of two nodes and returns the respective adjacency entry.
Definition: CombinatorialEmbedding.h:362
ogdf::MaxFlowModule< TCap >::m_t
const node * m_t
Pointer to the sink node.
Definition: MaxFlowModule.h:47
ogdf::DualGraphBase
A dual graph including its combinatorial embedding of an embedded graph.
Definition: DualGraph.h:42
ogdf::MaxFlowSTPlanarDigraph::createBackArcs
void createBackArcs(Graph &gr, EdgeArray< TCap > &new_costs)
Create back arcs for all edges and set the backedges' new_costs to zero.
Definition: MaxFlowSTPlanarDigraph.h:52
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::isPlanar
bool isPlanar(const Graph &G)
Returns true, if G is planar, false otherwise.
Definition: extended_graph_alg.h:274
ogdf::isConnected
bool isConnected(const Graph &G)
Returns true iff G is connected.
ogdf::MaxFlowSTPlanarDigraph::init
void init(const Graph &graph, EdgeArray< TCap > *flow=nullptr) override
Initialize the problem with a graph and optional flow array. If no flow array is given,...
Definition: MaxFlowSTPlanarDigraph.h:126
ogdf::CombinatorialEmbedding::splitFace
edge splitFace(adjEntry adjSrc, adjEntry adjTgt, bool sourceAfter=false)
Splits a face by inserting a new edge.
ogdf::AdjElement
Class for adjacency list elements.
Definition: Graph_d.h:135
ogdf::ConstCombinatorialEmbedding::setExternalFace
void setExternalFace(face f)
Sets the external face to f.
Definition: CombinatorialEmbedding.h:301
ogdf::Dijkstra
Dijkstra's single source shortest path algorithm.
Definition: Dijkstra.h:53
ogdf::AdjElement::theEdge
edge theEdge() const
Returns the edge associated with this adjacency entry.
Definition: Graph_d.h:153
ogdf::MaxFlowModule< TCap >::m_s
const node * m_s
Pointer to the source node.
Definition: MaxFlowModule.h:46
ogdf::MaxFlowModule< TCap >::m_G
const Graph * m_G
Pointer to the given graph.
Definition: MaxFlowModule.h:44
ogdf::NodeElement::adjEntries
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.
Definition: Graph_d.h:264
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::pred
edge pred() const
Returns the predecessor in the list of all edges.
Definition: Graph_d.h:429
ogdf::EdgeElement::source
node source() const
Returns the source node of the edge.
Definition: Graph_d.h:391
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::Graph::lastEdge
edge lastEdge() const
Returns the last edge in the list of all edges.
Definition: Graph_d.h:998
ogdf::GraphCopy::copy
edge copy(edge e) const override
Returns the first edge in the list of edges corresponding to edge e.
Definition: GraphCopy.h:457
ogdf::MaxFlowModule::init
virtual void init(const Graph &graph, EdgeArray< T > *flow=nullptr)
Initialize the problem with a graph and optional flow array. If no flow array is given,...
Definition: MaxFlowModule.h:87
ogdf::DualGraphBase::dualEdge
const edge & dualEdge(edge e) const
Returns the edge in the dual graph corresponding to e.
Definition: DualGraph.h:177
ogdf::MaxFlowModule
Definition: MaxFlowModule.h:40
ogdf::CombinatorialEmbedding
Combinatorial embeddings of planar graphs with modification functionality.
Definition: CombinatorialEmbedding.h:397
ogdf::MaxFlowSTPlanarDigraph::computeValue
TCap computeValue(const EdgeArray< TCap > &cap, const node &s, const node &t) override
Compute only the value of the flow.
Definition: MaxFlowSTPlanarDigraph.h:68
ogdf::MaxFlowSTPlanarDigraph::computeFlowAfterValue
void computeFlowAfterValue() override
Implementation of computeFlowAfterValue from the super class. This does nothing, because the algorith...
Definition: MaxFlowSTPlanarDigraph.h:123
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::MaxFlowModule< TCap >::m_cap
const EdgeArray< TCap > * m_cap
Pointer to the given capacity array.
Definition: MaxFlowModule.h:45
ogdf::MaxFlowSTPlanarDigraph
Computes a max flow in s-t-planar network via dual shortest paths.
Definition: MaxFlowSTPlanarDigraph.h:49
ogdf::Graph::newEdge
edge newEdge(node v, node w, int index=-1)
Creates a new edge (v,w) and returns it.
Definition: Graph_d.h:1075
ogdf::DualGraphBase::dualNode
const node & dualNode(face f) const
Returns the node in the dual graph corresponding to f.
Definition: DualGraph.h:170
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:233
ogdf::isSTPlanar
bool isSTPlanar(const Graph &graph, const node s, const node t)
Returns whether G is s-t-planar (i.e.
Definition: extended_graph_alg.h:287
simple_graph_alg.h
Declaration of simple graph algorithms.
ogdf::MaxFlowModule< TCap >::m_flow
EdgeArray< TCap > * m_flow
Pointer to (extern) flow array.
Definition: MaxFlowModule.h:43
ogdf::internal::EdgeArrayBase2
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition: Graph_d.h:709
ogdf::FaceElement
Faces in a combinatorial embedding.
Definition: CombinatorialEmbedding.h:109