Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

MaxFlowModule.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/Graph.h>
35 #include <ogdf/basic/EpsilonTest.h>
36 
37 namespace ogdf {
38 
39 template <typename T>
41 {
42 protected:
45  const Graph *m_G;
47  const node *m_s;
48  const node *m_t;
49 
50 private:
51  bool usingExternFlow = false;
52  bool doingAReInit = false;
53 
54  void destroy()
55  {
56  if (!usingExternFlow) {
57  delete m_flow;
58  }
59  delete m_et;
60  }
61 
62 public:
65  : m_et(nullptr), m_flow(nullptr), m_G(nullptr), m_s(nullptr), m_t(nullptr) { }
66 
68 
73  explicit MaxFlowModule(const Graph &graph, EdgeArray<T> *flow = nullptr)
74  : m_s(nullptr), m_t(nullptr)
75  {
76  init(graph, flow);
77  }
78 
80  virtual ~MaxFlowModule()
81  {
82  destroy();
83  }
84 
88 
93  virtual void init(const Graph &graph, EdgeArray<T> *flow = nullptr)
94  {
95  // if re-init after an init with internal flow:
96  if (doingAReInit) {
97  destroy();
98  }
99  m_G = &graph;
100  if (flow) {
101  m_flow = flow;
102  usingExternFlow = true;
103  }
104  else {
105  usingExternFlow = false; // in case of a re-init
106  m_flow = new EdgeArray<T>(*m_G, 0);
107  }
108  m_et = new EpsilonTest();
109  doingAReInit = true;
110  }
111 
114 
117  void useEpsilonTest(const double &eps)
118  {
119  delete m_et;
120  m_et = new EpsilonTest(eps);
121  }
122 
136  virtual T computeValue(const EdgeArray<T> &cap, const node &s, const node &t) = 0;
137 
141  virtual void computeFlowAfterValue() = 0;
142 
146 
150  {
152  flow = *m_flow;
153  }
154 
157  bool isFeasibleInstance() const {
158  for (edge e : m_G->edges) {
159  if ((*m_cap)[e] < 0) {
160  return false;
161  }
162  }
163  return true;
164  }
165 
167 
175  {
176  T val = computeValue(cap, s, t);
177  computeFlowAfterValue(flow);
178  return val;
179  }
180 };
181 
182 }
void useEpsilonTest(const double &eps)
Change the used EpsilonTest from StandardEpsilonTest to a user given EpsilonTest. ...
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:492
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
const node * m_t
Pointer to the sink node.
Definition: MaxFlowModule.h:48
EpsilonTest * m_et
Pointer to the used EpsilonTest.
Definition: MaxFlowModule.h:43
virtual void computeFlowAfterValue()=0
Compute the flow itself after the flow value is already computed. Only used in algorithms with 2 phas...
Dynamic arrays indexed with edges.
Definition: EdgeArray.h:112
T computeFlow(EdgeArray< T > &cap, node &s, node &t, EdgeArray< T > &flow)
Only a shortcut for computeValue and computeFlowAfterValue.
const Graph * m_G
Pointer to the given graph.
Definition: MaxFlowModule.h:45
Compare floating point numbers with epsilons and integral numbers with normal compare operators...
virtual ~MaxFlowModule()
Destructor that deletes m_flow if it is an internal flow array.
Definition: MaxFlowModule.h:80
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
Definition: Graph_d.h:568
const node * m_s
Pointer to the source node.
Definition: MaxFlowModule.h:47
void computeFlowAfterValue(EdgeArray< T > &flow)
Compute the flow itself after the flow value is already computed. Only used in algorithms with 2 phas...
EdgeArray< T > * m_flow
Pointer to (extern) flow array.
Definition: MaxFlowModule.h:44
Class for the representation of edges.
Definition: Graph_d.h:292
bool doingAReInit
Is the next "init" call a re-init?
Definition: MaxFlowModule.h:52
Class for the representation of nodes.
Definition: Graph_d.h:169
bool isFeasibleInstance() const
Return whether the instance is feasible, i.e. the capacities are non-negative.
MaxFlowModule()
Empty Constructor.
Definition: MaxFlowModule.h:64
Includes declaration of graph class.
virtual T computeValue(const EdgeArray< T > &cap, const node &s, const node &t)=0
Compute only the value of the flow.
bool usingExternFlow
Is an extern flow array given in the constructor?
Definition: MaxFlowModule.h:51
The namespace for all OGDF objects.
const EdgeArray< T > * m_cap
Pointer to the given capacity array.
Definition: MaxFlowModule.h:46
MaxFlowModule(const Graph &graph, EdgeArray< T > *flow=nullptr)
Constructor that calls init.
Definition: MaxFlowModule.h:73