Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
MaxFlowModule.h
Go to the documentation of this file.
1
32#pragma once
33
35#include <ogdf/basic/Graph.h>
37
38namespace ogdf {
39
40template<typename T>
42protected:
45 const Graph* m_G;
47 const node* m_s;
48 const node* m_t;
49
50private:
51 bool usingExternFlow = false;
52 bool doingAReInit = false;
53
54 void destroy() {
55 if (!usingExternFlow) {
56 delete m_flow;
57 }
58 delete m_et;
59 }
60
61public:
64 : m_et(nullptr), m_flow(nullptr), m_G(nullptr), m_cap(nullptr), m_s(nullptr), m_t(nullptr) { }
65
67
72 explicit MaxFlowModule(const Graph& graph, EdgeArray<T>* flow = nullptr)
73 : m_s(nullptr), m_t(nullptr) {
74 init(graph, flow);
75 }
76
78 virtual ~MaxFlowModule() { destroy(); }
79
83
88 virtual void init(const Graph& graph, EdgeArray<T>* flow = nullptr) {
89 // if re-init after an init with internal flow:
90 if (doingAReInit) {
91 destroy();
92 }
93 m_G = &graph;
94 if (flow) {
95 m_flow = flow;
96 usingExternFlow = true;
97 } else {
98 usingExternFlow = false; // in case of a re-init
99 m_flow = new EdgeArray<T>(*m_G, 0);
100 }
101 m_et = new EpsilonTest();
102 doingAReInit = true;
103 }
104
107
110 void useEpsilonTest(const double& eps) {
111 delete m_et;
112 m_et = new EpsilonTest(eps);
113 }
114
128 virtual T computeValue(const EdgeArray<T>& cap, const node& s, const node& t) = 0;
129
133 virtual void computeFlowAfterValue() = 0;
134
138
143 flow = *m_flow;
144 }
145
148 bool isFeasibleInstance() const {
149 for (edge e : m_G->edges) {
150 if ((*m_cap)[e] < 0) {
151 return false;
152 }
153 }
154 return true;
155 }
156
158
166 T val = computeValue(cap, s, t);
168 return val;
169 }
170};
171
172}
Compare floating point numbers with epsilons and integral numbers with normal compare operators.
Includes declaration of graph class.
Decralation of GraphElement and GraphList classes.
Class for the representation of edges.
Definition Graph_d.h:364
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:866
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
Definition Graph_d.h:932
const node * m_t
Pointer to the sink node.
virtual ~MaxFlowModule()
Destructor that deletes m_flow if it is an internal flow array.
bool usingExternFlow
Is an extern flow array given in the constructor?
virtual void computeFlowAfterValue()=0
Compute the flow itself after the flow value is already computed. Only used in algorithms with 2 phas...
MaxFlowModule(const Graph &graph, EdgeArray< T > *flow=nullptr)
Constructor that calls 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,...
EdgeArray< T > * 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.
virtual T computeValue(const EdgeArray< T > &cap, const node &s, const node &t)=0
Compute only the value of the flow.
bool doingAReInit
Is the next "init" call a re-init?
const node * m_s
Pointer to the source node.
const EdgeArray< T > * m_cap
Pointer to the given capacity array.
MaxFlowModule()
Empty Constructor.
T computeFlow(EdgeArray< T > &cap, node &s, node &t, EdgeArray< T > &flow)
Only a shortcut for computeValue and computeFlowAfterValue.
void computeFlowAfterValue(EdgeArray< T > &flow)
Compute the flow itself after the flow value is already computed. Only used in algorithms with 2 phas...
EpsilonTest * m_et
Pointer to the used EpsilonTest.
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
The namespace for all OGDF objects.