38 #define OGDF_GT_USE_MAX_ACTIVE_LABEL 39 #ifdef OGDF_GT_USE_GAP_RELABEL_HEURISTIC 42 #define OGDF_GT_USE_PUSH_RELABEL_SECOND_STAGE 51 template<
typename TCap>
56 #ifdef OGDF_GT_USE_MAX_ACTIVE_LABEL 61 #ifdef OGDF_GT_USE_GAP_RELABEL_HEURISTIC 98 #ifdef OGDF_GT_USE_MAX_ACTIVE_LABEL 101 const int label = m_label[v];
104 OGDF_ASSERT(!m_activeLabelListPosition[v].valid());
105 m_activeLabelListPosition[v] = m_activeLabelList[label].pushBack(v);
106 if (label > m_maxLabel) {
113 while (m_maxLabel > 0
114 && m_activeLabelList[m_maxLabel].empty()) {
122 m_activeLabelList[m_label[v]].del(m_activeLabelListPosition[v]);
123 m_activeLabelListPosition[v] =
nullptr;
131 #ifdef OGDF_GT_USE_GAP_RELABEL_HEURISTIC 132 if (m_labelListPosition[v].valid()) {
133 m_labelList[m_label[v]].del(m_labelListPosition[v]);
135 m_labelListPosition[v] = m_labelList[label].pushBack(v);
137 #ifdef OGDF_GT_USE_MAX_ACTIVE_LABEL 138 if (m_activeLabelListPosition[v].valid()) {
154 #ifdef OGDF_GT_USE_GAP_RELABEL_HEURISTIC 157 # ifdef OGDF_GT_USE_MAX_ACTIVE_LABEL 159 const int n = m_maxLabel + 1;
163 for (
int i = 1; i < n - 1; ++i) {
164 if (m_labelList[i].empty()) {
165 for (
int j = i + 1; j < n; ++j) {
166 while (!m_labelList[j].empty()) {
181 const TCap value = min(m_ex[v],
getCap(e) - (*this->
m_flow)[e]);
183 (*this->
m_flow)[e] += value;
187 const TCap value = min(m_ex[v], (*this->
m_flow)[adj]);
189 (*this->
m_flow)[adj] -= value;
191 m_ex[adj->twinNode()] += value;
201 dist[*this->
m_t] = 0;
203 while (!queue.
empty()) {
209 dist[x] = dist[w] + 1;
225 const int label = m_label[adj->
twinNode()];
226 if (label < minLabel) {
231 if (minLabel + 1 != m_label[v]) {
241 const int label = m_label[adj->
twinNode()];
242 if (label < minLabel) {
248 m_label[v] = minLabel + 1;
264 #ifdef OGDF_GT_USE_MAX_ACTIVE_LABEL 265 m_activeLabelListPosition.
init(*this->
m_G,
nullptr);
269 #ifdef OGDF_GT_USE_GAP_RELABEL_HEURISTIC 270 m_labelListPosition.
init(*this->
m_G,
nullptr);
284 if(*this->
m_t == *this->
m_s) {
290 curr[v] = v->firstAdj();
296 #ifdef OGDF_GT_USE_MAX_ACTIVE_LABEL 297 while (m_maxLabel != 0) {
298 OGDF_ASSERT(!m_activeLabelList[m_maxLabel].empty());
301 OGDF_ASSERT(m_activeLabelListPosition[v] == m_activeLabelList[m_maxLabel].begin());
305 node w = adj->theEdge()->target();
306 if (w != *this->
m_s) {
310 while (!active.
empty()) {
318 #ifdef OGDF_GT_USE_MAX_ACTIVE_LABEL 327 #ifdef OGDF_GT_USE_MAX_ACTIVE_LABEL 345 if (adj != v->lastAdj()) {
351 #ifdef OGDF_GT_USE_GAP_RELABEL_HEURISTIC 354 # if (OGDF_GT_GRH_STEPS > 1) 355 && relCount % OGDF_GT_GRH_STEPS == 0
374 edge e = adj->theEdge();
376 result += (*this->
m_flow)[e];
378 result -= (*this->
m_flow)[e];
388 #ifdef OGDF_GT_USE_PUSH_RELABEL_SECOND_STAGE 391 curr[v] = v->firstAdj();
393 if (this->
m_et->
greater(m_ex[v], (TCap) 0) && v != *this->
m_s && v != *this->
m_t) {
397 if (active.
empty()) {
401 m_label[*this->
m_s] = 0;
402 while (!active.
empty()) {
430 #else // USE_PUSH_RELABEL_SECOND_STAGE 431 m_ex[*this->
m_s] = m_ex[*this->
m_t] = 0;
437 while (!active.
empty()) {
439 if (this->
m_et->
greater(m_ex[v], (TCap) 0) && v != *this->
m_s && v != *this->
m_t) {
440 for (
adjEntry adj = v->firstAdj(); adj; adj = adj->
succ()) {
441 const edge e = adj->theEdge();
447 if (u != *this->
m_s) {
455 #endif // USE_PUSH_RELABEL_SECOND_STAGE node target() const
Returns the target node of the edge.
void clear()
Removes all elements from the list.
TCap getCap(const edge e) const
The parameterized class Array implements dynamic arrays of type E.
edge theEdge() const
Returns the edge associated with this adjacency entry.
void init()
Reinitializes the array. Associates the array with no graph.
void setActive(const node v)
iterator pushBack(const E &x)
Adds element x at the end of the list.
void init()
Reinitializes the array. Associates the array with no graph.
void init()
Reinitializes the array to an array with empty index set.
void relabel(const node v)
void push(const adjEntry adj)
void popFront()
Removes the first element from the list.
const node * m_t
Pointer to the sink node.
void relabelStage2(const node v)
node firstNode() const
Returns the first node in the list of all nodes.
EpsilonTest * m_et
Pointer to the used EpsilonTest.
Interface for Max Flow Algorithms.
node succ() const
Returns the successor in the list of all nodes.
const Graph * m_G
Pointer to the given graph.
std::enable_if< std::is_integral< T >::value, bool >::type less(const T &x, const T &y) const
Compare if x is LESS than y for integral types.
Array< List< node > > m_activeLabelList
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
iterator pushFront(const E &x)
Adds element x at the beginning of the list.
const node * m_s
Pointer to the source node.
void computeFlowAfterValue()
Compute the flow itself after the flow value is already computed. Only used in algorithms with 2 phas...
const_reference front() const
Returns a const reference to the first element.
bool isResidualEdge(const adjEntry adj) const
Doubly linked lists (maintaining the length of the list).
bool isAdmissible(const adjEntry adj) const
TCap computeValue(const EdgeArray< TCap > &cap, const node &s, const node &t)
Compute only the value of the flow.
EdgeArray< TCap > * m_flow
Pointer to (extern) flow array.
node twinNode() const
Returns the associated node of the corresponding adjacency entry (shorthand for twin()->theNode()).
Class for the representation of edges.
adjEntry twin() const
Returns the corresponding adjacency element associated with the same edge.
E popFrontRet()
Removes the first element from the list and returns it.
adjEntry lastAdj() const
Returns the last entry in the adjacency list.
NodeArray< ListIterator< node > > m_activeLabelListPosition
Class for the representation of nodes.
std::enable_if< std::is_integral< T >::value, bool >::type greater(const T &x, const T &y) const
Compare if x is GREATER than y for integral types.
bool isFeasibleInstance() const
Return whether the instance is feasible, i.e. the capacities are non-negative.
adjEntry succ() const
Returns the successor in the adjacency list.
node source() const
Returns the source node of the edge.
void setInactive(const node v)
The namespace for all OGDF objects.
std::enable_if< std::is_integral< T >::value, bool >::type geq(const T &x, const T &y) const
Compare if x is GEQ to y for integral types.
int numberOfNodes() const
Returns the number of nodes in the graph.
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
adjEntry firstAdj() const
Returns the first entry in the adjaceny list.
bool empty() const
Returns true iff the list is empty.
const EdgeArray< TCap > * m_cap
Pointer to the given capacity array.
node theNode() const
Returns the node whose adjacency list contains this element.
Computes a max flow via Preflow-Push (global relabeling and gap relabeling heuristic).
void setLabel(const node v, int label)
Class for adjacency list elements.
bool isActive(const node v) const
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.