Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

MaxFlowModule.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/EpsilonTest.h>
35 #include <ogdf/basic/Graph.h>
36 #include <ogdf/basic/GraphList.h>
37 
38 namespace ogdf {
39 
40 template<typename T>
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  if (!usingExternFlow) {
56  delete m_flow;
57  }
58  delete m_et;
59  }
60 
61 public:
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 
165  T computeFlow(EdgeArray<T>& cap, node& s, node& t, EdgeArray<T>& flow) {
166  T val = computeValue(cap, s, t);
167  computeFlowAfterValue(flow);
168  return val;
169  }
170 };
171 
172 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
EpsilonTest.h
Compare floating point numbers with epsilons and integral numbers with normal compare operators.
Graph.h
Includes declaration of graph class.
ogdf::MaxFlowModule::MaxFlowModule
MaxFlowModule()
Empty Constructor.
Definition: MaxFlowModule.h:63
ogdf::MaxFlowModule::isFeasibleInstance
bool isFeasibleInstance() const
Return whether the instance is feasible, i.e. the capacities are non-negative.
Definition: MaxFlowModule.h:148
ogdf::EpsilonTest
Definition: EpsilonTest.h:39
ogdf::MaxFlowModule::m_t
const node * m_t
Pointer to the sink node.
Definition: MaxFlowModule.h:48
ogdf::MaxFlowModule::~MaxFlowModule
virtual ~MaxFlowModule()
Destructor that deletes m_flow if it is an internal flow array.
Definition: MaxFlowModule.h:78
ogdf::MaxFlowModule::m_et
EpsilonTest * m_et
Pointer to the used EpsilonTest.
Definition: MaxFlowModule.h:43
ogdf::MaxFlowModule::computeFlow
T computeFlow(EdgeArray< T > &cap, node &s, node &t, EdgeArray< T > &flow)
Only a shortcut for computeValue and computeFlowAfterValue.
Definition: MaxFlowModule.h:165
ogdf::MaxFlowModule::m_s
const node * m_s
Pointer to the source node.
Definition: MaxFlowModule.h:47
ogdf::MaxFlowModule::m_G
const Graph * m_G
Pointer to the given graph.
Definition: MaxFlowModule.h:45
GraphList.h
Decralation of GraphElement and GraphList classes.
ogdf::MaxFlowModule::useEpsilonTest
void useEpsilonTest(const double &eps)
Change the used EpsilonTest from StandardEpsilonTest to a user given EpsilonTest.
Definition: MaxFlowModule.h:110
ogdf::MaxFlowModule::computeFlowAfterValue
virtual void computeFlowAfterValue()=0
Compute the flow itself after the flow value is already computed. Only used in algorithms with 2 phas...
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:869
ogdf::MaxFlowModule::computeFlowAfterValue
void computeFlowAfterValue(EdgeArray< T > &flow)
Compute the flow itself after the flow value is already computed. Only used in algorithms with 2 phas...
Definition: MaxFlowModule.h:141
ogdf::MaxFlowModule::computeValue
virtual T computeValue(const EdgeArray< T > &cap, const node &s, const node &t)=0
Compute only the value of the flow.
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::MaxFlowModule::doingAReInit
bool doingAReInit
Is the next "init" call a re-init?
Definition: MaxFlowModule.h:52
ogdf::Graph::edges
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
Definition: Graph_d.h:935
ogdf::MaxFlowModule
Definition: MaxFlowModule.h:41
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:363
ogdf::MaxFlowModule::destroy
void destroy()
Definition: MaxFlowModule.h:54
ogdf::MaxFlowModule::m_cap
const EdgeArray< T > * m_cap
Pointer to the given capacity array.
Definition: MaxFlowModule.h:46
ogdf::MaxFlowModule::MaxFlowModule
MaxFlowModule(const Graph &graph, EdgeArray< T > *flow=nullptr)
Constructor that calls init.
Definition: MaxFlowModule.h:72
ogdf::MaxFlowModule::usingExternFlow
bool usingExternFlow
Is an extern flow array given in the constructor?
Definition: MaxFlowModule.h:51
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:240
ogdf::MaxFlowModule::m_flow
EdgeArray< T > * 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