Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

MaxFlowSTPlanarDigraph.h
Go to the documentation of this file.
1 
34 #pragma once
35 
37 #include <ogdf/basic/DualGraph.h>
38 #include <ogdf/basic/Graph.h>
39 #include <ogdf/basic/GraphCopy.h>
40 #include <ogdf/basic/GraphList.h>
41 #include <ogdf/basic/basic.h>
44 #include <ogdf/graphalg/Dijkstra.h>
46 
47 #include <limits>
48 
49 namespace ogdf {
50 
52 
55 template<typename TCap>
56 class MaxFlowSTPlanarDigraph : public MaxFlowModule<TCap> {
57 private:
59  void createBackArcs(Graph& gr, EdgeArray<TCap>& new_costs) {
60  // gr = dg.
61  for (edge e = gr.lastEdge(); e != nullptr; e = e->pred()) {
62  edge e_new_dg = gr.newEdge(e->target(), e->source());
63  new_costs[e_new_dg] = 0;
64  }
65  }
66 
67 public:
75  TCap computeValue(const EdgeArray<TCap>& cap, const node& s, const node& t) override {
76  // clear old flow
77  (*this->m_flow).fill(0);
78  // store capacity, source and sink
79  this->m_cap = &cap;
80  this->m_s = &s;
81  this->m_t = &t;
83 
84  OGDF_ASSERT(isSTPlanar(*this->m_G, s, t));
85  GraphCopy copyG(*this->m_G);
86  node copyS = copyG.copy(s);
87  node copyT = copyG.copy(t);
88  CombinatorialEmbedding ce(copyG);
89  adjEntry adjAtTarget;
90  adjEntry adjAtSource = ce.findCommonFace(copyS, copyT, adjAtTarget, false);
91  face f_infty = ce.rightFace(adjAtSource);
92  ce.setExternalFace(f_infty);
93 
94  // split the external face
95  edge ts_edge = ce.splitFace(adjAtTarget, adjAtSource);
96  DualGraph dg(ce);
97 
98  EdgeArray<TCap> costs(dg, 0);
99  for (edge e : (*this->m_G).edges) {
100  costs[dg.dualEdge(copyG.copy(e))] = cap[e];
101  }
102  createBackArcs(dg, costs);
103  costs[dg.dualEdge(ts_edge)] = std::numeric_limits<TCap>::max();
104 
105  Dijkstra<TCap> dij;
106  NodeArray<edge> preds(dg, nullptr);
107  NodeArray<TCap> dists(dg, 0);
108  dij.call(dg, costs, dg.dualNode(f_infty), preds, dists, true); // directed
109 
110  for (edge e : (*this->m_G).edges) {
111  (*this->m_flow)[e] = dists[dg.dualNode(ce.leftFace(copyG.copy(e)->adjSource()))]
112  - dists[dg.dualNode(ce.rightFace(copyG.copy(e)->adjSource()))];
113  }
114 
115  // compute flow value
116  TCap flowValue = 0;
117  for (adjEntry adj : s->adjEntries) {
118  edge e = adj->theEdge();
119  if (e->source() == s) {
120  flowValue += (*this->m_flow)[e];
121  } else {
122  flowValue -= (*this->m_flow)[e];
123  }
124  }
125  return flowValue;
126  }
127 
130  void computeFlowAfterValue() override { /* nothing to do here */
131  }
132 
133  void init(const Graph& graph, EdgeArray<TCap>* flow = nullptr) override {
134  OGDF_ASSERT(isConnected(graph));
135  OGDF_ASSERT(isPlanar(graph));
136  MaxFlowModule<TCap>::init(graph, flow);
137  }
138 
139  // use methods from super class
144 };
145 
146 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
Graph.h
Includes declaration of graph class.
ogdf::MaxFlowModule< TCap >::isFeasibleInstance
bool isFeasibleInstance() const
Return whether the instance is feasible, i.e. the capacities are non-negative.
Definition: MaxFlowModule.h:148
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:66
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:371
ogdf::MaxFlowModule< TCap >::m_t
const node * m_t
Pointer to the sink node.
Definition: MaxFlowModule.h:48
ogdf::DualGraphBase
A dual graph including its combinatorial embedding of an embedded graph.
Definition: DualGraph.h:47
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:59
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:285
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:279
ogdf::GraphCopy
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:391
ogdf::isPlanar
bool isPlanar(const Graph &G)
Returns true, if G is planar, false otherwise.
Definition: extended_graph_alg.h:284
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:133
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:142
ogdf::ConstCombinatorialEmbedding::setExternalFace
void setExternalFace(face f)
Sets the external face to f.
Definition: CombinatorialEmbedding.h:310
ogdf::Dijkstra
Dijkstra's single source shortest path algorithm.
Definition: Dijkstra.h:60
ogdf::AdjElement::theEdge
edge theEdge() const
Returns the edge associated with this adjacency entry.
Definition: Graph_d.h:160
ogdf::MaxFlowModule< TCap >::m_s
const node * m_s
Pointer to the source node.
Definition: MaxFlowModule.h:47
ogdf::MaxFlowModule< TCap >::m_G
const Graph * m_G
Pointer to the given graph.
Definition: MaxFlowModule.h:45
GraphList.h
Decralation of GraphElement and GraphList classes.
ogdf::NodeElement::adjEntries
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.
Definition: Graph_d.h:271
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:253
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:436
ogdf::EdgeElement::source
node source() const
Returns the source node of the edge.
Definition: Graph_d.h:398
GraphCopy.h
Declaration of graph copy classes.
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:658
ogdf::EdgeElement::adjSource
adjEntry adjSource() const
Returns the corresponding adjacancy entry at source node.
Definition: Graph_d.h:407
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:869
ogdf::Graph::lastEdge
edge lastEdge() const
Returns the last edge in the list of all edges.
Definition: Graph_d.h:1006
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:464
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:88
ogdf::DualGraphBase::dualEdge
const edge & dualEdge(edge e) const
Returns the edge in the dual graph corresponding to e.
Definition: DualGraph.h:182
basic.h
Basic declarations, included by all source files.
CombinatorialEmbedding.h
Declaration of CombinatorialEmbedding and face.
ogdf::MaxFlowModule
Definition: MaxFlowModule.h:41
ogdf::CombinatorialEmbedding
Combinatorial embeddings of planar graphs with modification functionality.
Definition: CombinatorialEmbedding.h:406
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:75
ogdf::MaxFlowSTPlanarDigraph::computeFlowAfterValue
void computeFlowAfterValue() override
Implementation of computeFlowAfterValue from the super class. This does nothing, because the algorith...
Definition: MaxFlowSTPlanarDigraph.h:130
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:363
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:46
ogdf::MaxFlowSTPlanarDigraph
Computes a max flow in s-t-planar network via dual shortest paths.
Definition: MaxFlowSTPlanarDigraph.h:56
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:1083
ogdf::DualGraphBase::dualNode
const node & dualNode(face f) const
Returns the node in the dual graph corresponding to f.
Definition: DualGraph.h:175
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:240
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:297
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:44
ogdf::internal::EdgeArrayBase2
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition: Graph_d.h:716
ogdf::FaceElement
Faces in a combinatorial embedding.
Definition: CombinatorialEmbedding.h:118