Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

MaxFlowSTPlanarDigraph.h
Go to the documentation of this file.
1 
34 #pragma once
35 
39 #include <ogdf/basic/DualGraph.h>
40 #include <ogdf/graphalg/Dijkstra.h>
41 
42 namespace ogdf {
43 
45 
48 template <typename TCap>
49 class MaxFlowSTPlanarDigraph : public MaxFlowModule<TCap> {
50 private:
51 
53  void createBackArcs(Graph &gr, EdgeArray<TCap> &new_costs) {
54  // gr = dg.
55  for (edge e = gr.lastEdge(); e != nullptr; e = e->pred()) {
56  edge e_new_dg = gr.newEdge(e->target(), e->source());
57  new_costs[e_new_dg] = 0;
58  }
59  }
60 
61 public:
69  TCap computeValue(const EdgeArray<TCap> &cap, const node &s, const node &t) override {
70  // clear old flow
71  (*this->m_flow).fill(0);
72  // store capacity, source and sink
73  this->m_cap = &cap;
74  this->m_s = &s;
75  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)] = 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] =
105  dists[dg.dualNode(ce.leftFace(copyG.copy(e)->adjSource()))] -
106  dists[dg.dualNode(ce.rightFace(copyG.copy(e)->adjSource()))];
107  }
108 
109  // compute flow value
110  TCap flowValue = 0;
111  for (adjEntry adj : s->adjEntries) {
112  edge e = adj->theEdge();
113  if (e->source() == s) {
114  flowValue += (*this->m_flow)[e];
115  } else {
116  flowValue -= (*this->m_flow)[e];
117  }
118  }
119  return flowValue;
120  }
121 
124  void computeFlowAfterValue() override { /* nothing to do here */
125  }
126 
127  void init(const Graph &graph, EdgeArray<TCap> *flow = nullptr) override {
128  OGDF_ASSERT(isConnected(graph));
129  OGDF_ASSERT(isPlanar(graph));
130  MaxFlowModule<TCap>::init(graph, flow);
131  }
132 
133  // use methods from super class
138 };
139 
140 } // namespace
void computeFlowAfterValue() override
Implementation of computeFlowAfterValue from the super class. This does nothing, because the algorith...
edge theEdge() const
Returns the edge associated with this adjacency entry.
Definition: Graph_d.h:95
void setExternalFace(face f)
Sets the external face to f.
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
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:472
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, a new ("internal") array will be created. If a flow array is given, the algorithm uses this "external" array.
Definition: MaxFlowModule.h:93
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
const node * m_t
Pointer to the sink node.
Definition: MaxFlowModule.h:48
Interface for Max Flow Algorithms.
TCap computeValue(const EdgeArray< TCap > &cap, const node &s, const node &t) override
Compute only the value of the flow.
const Graph * m_G
Pointer to the given graph.
Definition: MaxFlowModule.h:45
edge lastEdge() const
Returns the last edge in the list of all edges.
Definition: Graph_d.h:605
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. ...
face rightFace(adjEntry adj) const
Returns the face to the right of adj, i.e., the face containing adj.
Dynamic arrays indexed with nodes.
Definition: Graph_d.h:423
Implementation of Dijkstra&#39;s single source shortest path algorithm.
Computes a max flow in s-t-planar network via dual shortest paths.
const node * m_s
Pointer to the source node.
Definition: MaxFlowModule.h:47
edge newEdge(node v, node w)
Creates a new edge (v,w) and returns it.
EdgeArray< TCap > * m_flow
Pointer to (extern) flow array.
Definition: MaxFlowModule.h:44
bool isPlanar(const Graph &G)
Returns true, if G is planar, false otherwise.
Faces in a combinatorial embedding.
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 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
edge pred() const
Returns the predecessor in the list of all edges.
Definition: Graph_d.h:342
bool isSTPlanar(const Graph &graph, const node s, const node t)
Returns whether G is s-t-planar (i.e.
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, a new ("internal") array will be created. If a flow array is given, the algorithm uses this "external" array.
const edge & dualEdge(edge e) const
Returns the edge in the dual graph corresponding to e.
Definition: DualGraph.h:93
Declaration of simple graph algorithms.
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
edge splitFace(adjEntry adjSrc, adjEntry adjTgt)
Splits a face by inserting a new edge.
The namespace for all OGDF objects.
Declaration of extended graph algorithms.
bool isConnected(const Graph &G)
Returns true iff G is connected.
Combinatorial embeddings of planar graphs with modification functionality.
const EdgeArray< TCap > * m_cap
Pointer to the given capacity array.
Definition: MaxFlowModule.h:46
Class for adjacency list elements.
Definition: Graph_d.h:78
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:41
void createBackArcs(Graph &gr, EdgeArray< TCap > &new_costs)
Create back arcs for all edges and set the backedges&#39; new_costs to zero.
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.
Definition: Graph_d.h:198