Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
MaxFlowSTPlanarDigraph.h
Go to the documentation of this file.
1
34#pragma once
35
38#include <ogdf/basic/Graph.h>
41#include <ogdf/basic/basic.h>
46
47#include <limits>
48
49namespace ogdf {
50
52
55template<typename TCap>
57private:
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
67public:
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
141 using MaxFlowModule<TCap>::computeFlow;
144};
145
146}
Declaration of CombinatorialEmbedding and face.
Includes declaration of dual graph class.
Includes declaration of graph class.
Declaration of graph copy classes.
Decralation of GraphElement and GraphList classes.
Interface for Max Flow Algorithms.
Basic declarations, included by all source files.
Class for adjacency list elements.
Definition Graph_d.h:143
Combinatorial embeddings of planar graphs with modification functionality.
edge splitFace(adjEntry adjSrc, adjEntry adjTgt, bool sourceAfter=false)
Splits a face by inserting a new edge.
face rightFace(adjEntry adj) const
Returns the face to the right of adj, i.e., the face containing adj.
void setExternalFace(face f)
Sets the external face to f.
face leftFace(adjEntry adj) const
Returns the face to the left of adj, i.e., the face containing the twin of adj.
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.
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 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 source() const
Returns the source node of the edge.
Definition Graph_d.h:399
Faces in a combinatorial embedding.
Copies of graphs supporting edge splitting.
Definition GraphCopy.h:390
edge copy(edge e) const override
Returns the first edge in the list of edges corresponding to edge e.
Definition GraphCopy.h:463
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:866
edge lastEdge() const
Returns the last edge in the list of all edges.
Definition Graph_d.h:1003
edge newEdge(node v, node w, int index=-1)
Creates a new edge (v,w) and returns it.
Definition Graph_d.h:1080
const node * m_t
Pointer to the sink node.
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,...
EdgeArray< TCap > * m_flow
Pointer to (extern) flow array.
void useEpsilonTest(const double &eps)
Change the used EpsilonTest from StandardEpsilonTest to a user given EpsilonTest.
bool isFeasibleInstance() const
Return whether the instance is feasible, i.e. the capacities are non-negative.
const Graph * m_G
Pointer to the given graph.
const node * m_s
Pointer to the source node.
const EdgeArray< TCap > * m_cap
Pointer to the given capacity array.
MaxFlowModule()
Empty Constructor.
TCap computeFlow(EdgeArray< TCap > &cap, node &s, node &t, EdgeArray< TCap > &flow)
Only a shortcut for computeValue and computeFlowAfterValue.
Computes a max flow in s-t-planar network via dual shortest paths.
void createBackArcs(Graph &gr, EdgeArray< TCap > &new_costs)
Create back arcs for all edges and set the backedges' new_costs to zero.
TCap computeValue(const EdgeArray< TCap > &cap, const node &s, const node &t) override
Compute only the value of the flow.
void computeFlowAfterValue() override
Implementation of computeFlowAfterValue from the super class. This does nothing, because the algorith...
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,...
Class for the representation of nodes.
Definition Graph_d.h:241
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.
Definition Graph_d.h:272
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
Declaration of extended graph algorithms.
Implementation of Dijkstra's single source shortest path algorithm.
bool isConnected(const Graph &G)
Returns true iff G is connected.
bool isSTPlanar(const Graph &graph, const node s, const node t)
Returns whether G is s-t-planar (i.e.
bool isPlanar(const Graph &G)
Returns true, if G is planar, false otherwise.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:52
The namespace for all OGDF objects.
Declaration of simple graph algorithms.